Completed
Branch FET-3467-waitlists (871a70)
by
unknown
96:23 queued 82:42
created
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +3299 added lines, -3299 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -28,2114 +28,2114 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    //set in _init_page_props()
32
-    public $page_slug;
31
+	//set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    //set in define_page_props()
39
-    protected $_admin_base_url;
38
+	//set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    //set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	//set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    //navtabs
52
-    protected $_nav_tabs;
51
+	//navtabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56
-    //helptourstops
57
-    protected $_help_tour = array();
56
+	//helptourstops
57
+	protected $_help_tour = array();
58 58
 
59 59
 
60
-    //template variables (used by templates)
61
-    protected $_template_path;
60
+	//template variables (used by templates)
61
+	protected $_template_path;
62 62
 
63
-    protected $_column_template_path;
63
+	protected $_column_template_path;
64 64
 
65
-    /**
66
-     * @var array $_template_args
67
-     */
68
-    protected $_template_args = array();
65
+	/**
66
+	 * @var array $_template_args
67
+	 */
68
+	protected $_template_args = array();
69 69
 
70
-    /**
71
-     * this will hold the list table object for a given view.
72
-     *
73
-     * @var EE_Admin_List_Table $_list_table_object
74
-     */
75
-    protected $_list_table_object;
70
+	/**
71
+	 * this will hold the list table object for a given view.
72
+	 *
73
+	 * @var EE_Admin_List_Table $_list_table_object
74
+	 */
75
+	protected $_list_table_object;
76 76
 
77
-    //bools
78
-    protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
77
+	//bools
78
+	protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
79 79
 
80
-    protected $_routing;
80
+	protected $_routing;
81 81
 
82
-    //list table args
83
-    protected $_view;
82
+	//list table args
83
+	protected $_view;
84 84
 
85
-    protected $_views;
85
+	protected $_views;
86 86
 
87 87
 
88
-    //action => method pairs used for routing incoming requests
89
-    protected $_page_routes;
88
+	//action => method pairs used for routing incoming requests
89
+	protected $_page_routes;
90 90
 
91
-    protected $_page_config;
91
+	protected $_page_config;
92 92
 
93
-    //the current page route and route config
94
-    protected $_route;
93
+	//the current page route and route config
94
+	protected $_route;
95 95
 
96
-    protected $_route_config;
96
+	protected $_route_config;
97 97
 
98
-    /**
99
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
100
-     * actions.
101
-     *
102
-     * @since 4.6.x
103
-     * @var array.
104
-     */
105
-    protected $_default_route_query_args;
98
+	/**
99
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
100
+	 * actions.
101
+	 *
102
+	 * @since 4.6.x
103
+	 * @var array.
104
+	 */
105
+	protected $_default_route_query_args;
106 106
 
107
-    //set via request page and action args.
108
-    protected $_current_page;
107
+	//set via request page and action args.
108
+	protected $_current_page;
109 109
 
110
-    protected $_current_view;
110
+	protected $_current_view;
111 111
 
112
-    protected $_current_page_view_url;
112
+	protected $_current_page_view_url;
113 113
 
114
-    //sanitized request action (and nonce)
115
-    /**
116
-     * @var string $_req_action
117
-     */
118
-    protected $_req_action;
114
+	//sanitized request action (and nonce)
115
+	/**
116
+	 * @var string $_req_action
117
+	 */
118
+	protected $_req_action;
119 119
 
120
-    /**
121
-     * @var string $_req_nonce
122
-     */
123
-    protected $_req_nonce;
120
+	/**
121
+	 * @var string $_req_nonce
122
+	 */
123
+	protected $_req_nonce;
124 124
 
125
-    //search related
126
-    protected $_search_btn_label;
125
+	//search related
126
+	protected $_search_btn_label;
127 127
 
128
-    protected $_search_box_callback;
128
+	protected $_search_box_callback;
129 129
 
130
-    /**
131
-     * WP Current Screen object
132
-     *
133
-     * @var WP_Screen
134
-     */
135
-    protected $_current_screen;
130
+	/**
131
+	 * WP Current Screen object
132
+	 *
133
+	 * @var WP_Screen
134
+	 */
135
+	protected $_current_screen;
136 136
 
137
-    //for holding EE_Admin_Hooks object when needed (set via set_hook_object())
138
-    protected $_hook_obj;
137
+	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
138
+	protected $_hook_obj;
139 139
 
140
-    //for holding incoming request data
141
-    protected $_req_data;
140
+	//for holding incoming request data
141
+	protected $_req_data;
142 142
 
143
-    // yes / no array for admin form fields
144
-    protected $_yes_no_values = array();
145
-
146
-    //some default things shared by all child classes
147
-    protected $_default_espresso_metaboxes;
148
-
149
-    /**
150
-     *    EE_Registry Object
151
-     *
152
-     * @var    EE_Registry
153
-     * @access    protected
154
-     */
155
-    protected $EE = null;
156
-
157
-
158
-
159
-    /**
160
-     * This is just a property that flags whether the given route is a caffeinated route or not.
161
-     *
162
-     * @var boolean
163
-     */
164
-    protected $_is_caf = false;
165
-
166
-
167
-
168
-    /**
169
-     * @Constructor
170
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
171
-     * @access public
172
-     */
173
-    public function __construct($routing = true)
174
-    {
175
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
176
-            $this->_is_caf = true;
177
-        }
178
-        $this->_yes_no_values = array(
179
-                array('id' => true, 'text' => __('Yes', 'event_espresso')),
180
-                array('id' => false, 'text' => __('No', 'event_espresso')),
181
-        );
182
-        //set the _req_data property.
183
-        $this->_req_data = array_merge($_GET, $_POST);
184
-        //routing enabled?
185
-        $this->_routing = $routing;
186
-        //set initial page props (child method)
187
-        $this->_init_page_props();
188
-        //set global defaults
189
-        $this->_set_defaults();
190
-        //set early because incoming requests could be ajax related and we need to register those hooks.
191
-        $this->_global_ajax_hooks();
192
-        $this->_ajax_hooks();
193
-        //other_page_hooks have to be early too.
194
-        $this->_do_other_page_hooks();
195
-        //This just allows us to have extending classes do something specific
196
-        // before the parent constructor runs _page_setup().
197
-        if (method_exists($this, '_before_page_setup')) {
198
-            $this->_before_page_setup();
199
-        }
200
-        //set up page dependencies
201
-        $this->_page_setup();
202
-    }
203
-
204
-
205
-
206
-    /**
207
-     * _init_page_props
208
-     * Child classes use to set at least the following properties:
209
-     * $page_slug.
210
-     * $page_label.
211
-     *
212
-     * @abstract
213
-     * @access protected
214
-     * @return void
215
-     */
216
-    abstract protected function _init_page_props();
217
-
218
-
219
-
220
-    /**
221
-     * _ajax_hooks
222
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
223
-     * Note: within the ajax callback methods.
224
-     *
225
-     * @abstract
226
-     * @access protected
227
-     * @return void
228
-     */
229
-    abstract protected function _ajax_hooks();
230
-
231
-
232
-
233
-    /**
234
-     * _define_page_props
235
-     * child classes define page properties in here.  Must include at least:
236
-     * $_admin_base_url = base_url for all admin pages
237
-     * $_admin_page_title = default admin_page_title for admin pages
238
-     * $_labels = array of default labels for various automatically generated elements:
239
-     *    array(
240
-     *        'buttons' => array(
241
-     *            'add' => __('label for add new button'),
242
-     *            'edit' => __('label for edit button'),
243
-     *            'delete' => __('label for delete button')
244
-     *            )
245
-     *        )
246
-     *
247
-     * @abstract
248
-     * @access protected
249
-     * @return void
250
-     */
251
-    abstract protected function _define_page_props();
252
-
253
-
254
-
255
-    /**
256
-     * _set_page_routes
257
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
258
-     * route. Here's the format
259
-     * $this->_page_routes = array(
260
-     *        'default' => array(
261
-     *            'func' => '_default_method_handling_route',
262
-     *            'args' => array('array','of','args'),
263
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
264
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
265
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
266
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
267
-     *        ),
268
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
269
-     *        )
270
-     * )
271
-     *
272
-     * @abstract
273
-     * @access protected
274
-     * @return void
275
-     */
276
-    abstract protected function _set_page_routes();
277
-
278
-
279
-
280
-    /**
281
-     * _set_page_config
282
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
283
-     * Format:
284
-     * $this->_page_config = array(
285
-     *        'default' => array(
286
-     *            'labels' => array(
287
-     *                'buttons' => array(
288
-     *                    'add' => __('label for adding item'),
289
-     *                    'edit' => __('label for editing item'),
290
-     *                    'delete' => __('label for deleting item')
291
-     *                ),
292
-     *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
293
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
294
-     *            'nav' => array(
295
-     *                'label' => __('Label for Tab', 'event_espresso').
296
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
297
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
298
-     *                'order' => 10, //required to indicate tab position.
299
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
300
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
301
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
302
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
303
-     *            this flag to make sure the necessary js gets enqueued on page load.
304
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
305
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
306
-     *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
307
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
308
-     *                'tab_id' => array(
309
-     *                    'title' => 'tab_title',
310
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
311
-     *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
312
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
313
-     *                    ),
314
-     *                'tab2_id' => array(
315
-     *                    'title' => 'tab2 title',
316
-     *                    'filename' => 'file_name_2'
317
-     *                    'callback' => 'callback_method_for_content',
318
-     *                 ),
319
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
320
-     *            'help_tour' => array(
321
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
322
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
323
-     *            ),
324
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
325
-     *            'require_nonce' to FALSE
326
-     *            )
327
-     * )
328
-     *
329
-     * @abstract
330
-     * @access protected
331
-     * @return void
332
-     */
333
-    abstract protected function _set_page_config();
334
-
335
-
336
-
337
-
338
-
339
-    /** end sample help_tour methods **/
340
-    /**
341
-     * _add_screen_options
342
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
343
-     * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
344
-     *
345
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
346
-     *         see also WP_Screen object documents...
347
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
348
-     * @abstract
349
-     * @access protected
350
-     * @return void
351
-     */
352
-    abstract protected function _add_screen_options();
353
-
354
-
355
-
356
-    /**
357
-     * _add_feature_pointers
358
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
359
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
360
-     * Note: this is just a placeholder for now.  Implementation will come down the road
361
-     * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
362
-     *
363
-     * @link   http://eamann.com/tech/wordpress-portland/
364
-     * @abstract
365
-     * @access protected
366
-     * @return void
367
-     */
368
-    abstract protected function _add_feature_pointers();
369
-
370
-
371
-
372
-    /**
373
-     * load_scripts_styles
374
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
375
-     * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
376
-     *
377
-     * @abstract
378
-     * @access public
379
-     * @return void
380
-     */
381
-    abstract public function load_scripts_styles();
382
-
383
-
384
-
385
-    /**
386
-     * admin_init
387
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
388
-     *
389
-     * @abstract
390
-     * @access public
391
-     * @return void
392
-     */
393
-    abstract public function admin_init();
394
-
395
-
396
-
397
-    /**
398
-     * admin_notices
399
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
400
-     *
401
-     * @abstract
402
-     * @access public
403
-     * @return void
404
-     */
405
-    abstract public function admin_notices();
406
-
407
-
408
-
409
-    /**
410
-     * admin_footer_scripts
411
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
412
-     *
413
-     * @access public
414
-     * @return void
415
-     */
416
-    abstract public function admin_footer_scripts();
417
-
418
-
419
-
420
-    /**
421
-     * admin_footer
422
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
423
-     *
424
-     * @access  public
425
-     * @return void
426
-     */
427
-    public function admin_footer()
428
-    {
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * _global_ajax_hooks
435
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
436
-     * Note: within the ajax callback methods.
437
-     *
438
-     * @abstract
439
-     * @access protected
440
-     * @return void
441
-     */
442
-    protected function _global_ajax_hooks()
443
-    {
444
-        //for lazy loading of metabox content
445
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
446
-    }
447
-
448
-
449
-
450
-    public function ajax_metabox_content()
451
-    {
452
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
453
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
454
-        self::cached_rss_display($contentid, $url);
455
-        wp_die();
456
-    }
457
-
458
-
459
-
460
-    /**
461
-     * _page_setup
462
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
463
-     *
464
-     * @final
465
-     * @access protected
466
-     * @return void
467
-     */
468
-    final protected function _page_setup()
469
-    {
470
-        //requires?
471
-        //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.
472
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
473
-        //next verify if we need to load anything...
474
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475
-        $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476
-        global $ee_menu_slugs;
477
-        $ee_menu_slugs = (array)$ee_menu_slugs;
478
-        if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479
-            return;
480
-        }
481
-        // 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
482
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
483
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
484
-        }
485
-        // then set blank or -1 action values to 'default'
486
-        $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
487
-        //if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
488
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
489
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
-        $this->_current_view = $this->_req_action;
492
-        $this->_req_nonce = $this->_req_action . '_nonce';
493
-        $this->_define_page_props();
494
-        $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495
-        //default things
496
-        $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
497
-        //set page configs
498
-        $this->_set_page_routes();
499
-        $this->_set_page_config();
500
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
501
-        if (isset($this->_req_data['wp_referer'])) {
502
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
503
-        }
504
-        //for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
505
-        if (method_exists($this, '_extend_page_config')) {
506
-            $this->_extend_page_config();
507
-        }
508
-        //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
509
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
510
-            $this->_extend_page_config_for_cpt();
511
-        }
512
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
513
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
515
-        //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
518
-        }
519
-        //next route only if routing enabled
520
-        if ($this->_routing && ! defined('DOING_AJAX')) {
521
-            $this->_verify_routes();
522
-            //next let's just check user_access and kill if no access
523
-            $this->check_user_access();
524
-            if ($this->_is_UI_request) {
525
-                //admin_init stuff - global, all views for this page class, specific view
526
-                add_action('admin_init', array($this, 'admin_init'), 10);
527
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
529
-                }
530
-            } else {
531
-                //hijack regular WP loading and route admin request immediately
532
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
533
-                $this->route_admin_request();
534
-            }
535
-        }
536
-    }
537
-
538
-
539
-
540
-    /**
541
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
542
-     *
543
-     * @access private
544
-     * @return void
545
-     */
546
-    private function _do_other_page_hooks()
547
-    {
548
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
549
-        foreach ($registered_pages as $page) {
550
-            //now let's setup the file name and class that should be present
551
-            $classname = str_replace('.class.php', '', $page);
552
-            //autoloaders should take care of loading file
553
-            if ( ! class_exists($classname)) {
554
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555
-                $error_msg[] = $error_msg[0]
556
-                               . "\r\n"
557
-                               . sprintf( esc_html__('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',
558
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
559
-                throw new EE_Error(implode('||', $error_msg));
560
-            }
561
-            $a = new ReflectionClass($classname);
562
-            //notice we are passing the instance of this class to the hook object.
563
-            $hookobj[] = $a->newInstance($this);
564
-        }
565
-    }
566
-
567
-
568
-
569
-    public function load_page_dependencies()
570
-    {
571
-        try {
572
-            $this->_load_page_dependencies();
573
-        } catch (EE_Error $e) {
574
-            $e->get_error();
575
-        }
576
-    }
577
-
578
-
579
-
580
-    /**
581
-     * load_page_dependencies
582
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
583
-     *
584
-     * @access public
585
-     * @return void
586
-     */
587
-    protected function _load_page_dependencies()
588
-    {
589
-        //let's set the current_screen and screen options to override what WP set
590
-        $this->_current_screen = get_current_screen();
591
-        //load admin_notices - global, page class, and view specific
592
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
594
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
596
-        }
597
-        //load network admin_notices - global, page class, and view specific
598
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
601
-        }
602
-        //this will save any per_page screen options if they are present
603
-        $this->_set_per_page_screen_options();
604
-        //setup list table properties
605
-        $this->_set_list_table();
606
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
607
-        $this->_add_registered_meta_boxes();
608
-        $this->_add_screen_columns();
609
-        //add screen options - global, page child class, and view specific
610
-        $this->_add_global_screen_options();
611
-        $this->_add_screen_options();
612
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
614
-        }
615
-        //add help tab(s) and tours- set via page_config and qtips.
616
-        $this->_add_help_tour();
617
-        $this->_add_help_tabs();
618
-        $this->_add_qtips();
619
-        //add feature_pointers - global, page child class, and view specific
620
-        $this->_add_feature_pointers();
621
-        $this->_add_global_feature_pointers();
622
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
624
-        }
625
-        //enqueue scripts/styles - global, page class, and view specific
626
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
630
-        }
631
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632
-        //admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
637
-        }
638
-        //admin footer scripts
639
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
641
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
643
-        }
644
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645
-        //targeted hook
646
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
647
-    }
648
-
649
-
650
-
651
-    /**
652
-     * _set_defaults
653
-     * This sets some global defaults for class properties.
654
-     */
655
-    private function _set_defaults()
656
-    {
657
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
658
-        $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
659
-        $this->default_nav_tab_name = 'overview';
660
-        //init template args
661
-        $this->_template_args = array(
662
-                'admin_page_header'  => '',
663
-                'admin_page_content' => '',
664
-                'post_body_content'  => '',
665
-                'before_list_table'  => '',
666
-                'after_list_table'   => '',
667
-        );
668
-    }
669
-
670
-
671
-
672
-    /**
673
-     * route_admin_request
674
-     *
675
-     * @see    _route_admin_request()
676
-     * @access public
677
-     * @return void|exception error
678
-     */
679
-    public function route_admin_request()
680
-    {
681
-        try {
682
-            $this->_route_admin_request();
683
-        } catch (EE_Error $e) {
684
-            $e->get_error();
685
-        }
686
-    }
687
-
688
-
689
-
690
-    public function set_wp_page_slug($wp_page_slug)
691
-    {
692
-        $this->_wp_page_slug = $wp_page_slug;
693
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
694
-        if (is_network_admin()) {
695
-            $this->_wp_page_slug .= '-network';
696
-        }
697
-    }
698
-
699
-
700
-
701
-    /**
702
-     * _verify_routes
703
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
704
-     *
705
-     * @access protected
706
-     * @return void
707
-     */
708
-    protected function _verify_routes()
709
-    {
710
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
711
-        if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
712
-            return false;
713
-        }
714
-        $this->_route = false;
715
-        $func = false;
716
-        $args = array();
717
-        // check that the page_routes array is not empty
718
-        if (empty($this->_page_routes)) {
719
-            // user error msg
720
-            $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721
-            // developer error msg
722
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723
-            throw new EE_Error($error_msg);
724
-        }
725
-        // and that the requested page route exists
726
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
727
-            $this->_route = $this->_page_routes[$this->_req_action];
728
-            $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
729
-        } else {
730
-            // user error msg
731
-            $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732
-            // developer error msg
733
-            $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734
-            throw new EE_Error($error_msg);
735
-        }
736
-        // and that a default route exists
737
-        if ( ! array_key_exists('default', $this->_page_routes)) {
738
-            // user error msg
739
-            $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740
-            // developer error msg
741
-            $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742
-            throw new EE_Error($error_msg);
743
-        }
744
-        //first lets' catch if the UI request has EVER been set.
745
-        if ($this->_is_UI_request === null) {
746
-            //lets set if this is a UI request or not.
747
-            $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
748
-            //wait a minute... we might have a noheader in the route array
749
-            $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
750
-        }
751
-        $this->_set_current_labels();
752
-    }
753
-
754
-
755
-
756
-    /**
757
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
758
-     *
759
-     * @param  string $route the route name we're verifying
760
-     * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
761
-     */
762
-    protected function _verify_route($route)
763
-    {
764
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
765
-            return true;
766
-        } else {
767
-            // user error msg
768
-            $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769
-            // developer error msg
770
-            $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771
-            throw new EE_Error($error_msg);
772
-        }
773
-    }
774
-
775
-
776
-
777
-    /**
778
-     * perform nonce verification
779
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
780
-     *
781
-     * @param  string $nonce     The nonce sent
782
-     * @param  string $nonce_ref The nonce reference string (name0)
783
-     * @return mixed (bool|die)
784
-     */
785
-    protected function _verify_nonce($nonce, $nonce_ref)
786
-    {
787
-        // verify nonce against expected value
788
-        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
789
-            // these are not the droids you are looking for !!!
790
-            $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791
-            if (WP_DEBUG) {
792
-                $msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793
-            }
794
-            if ( ! defined('DOING_AJAX')) {
795
-                wp_die($msg);
796
-            } else {
797
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
798
-                $this->_return_json();
799
-            }
800
-        }
801
-    }
802
-
803
-
804
-
805
-    /**
806
-     * _route_admin_request()
807
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
808
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
809
-     * in the page routes and then will try to load the corresponding method.
810
-     *
811
-     * @access protected
812
-     * @return void
813
-     * @throws \EE_Error
814
-     */
815
-    protected function _route_admin_request()
816
-    {
817
-        if ( ! $this->_is_UI_request) {
818
-            $this->_verify_routes();
819
-        }
820
-        $nonce_check = isset($this->_route_config['require_nonce'])
821
-            ? $this->_route_config['require_nonce']
822
-            : true;
823
-        if ($this->_req_action !== 'default' && $nonce_check) {
824
-            // set nonce from post data
825
-            $nonce = isset($this->_req_data[$this->_req_nonce])
826
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
827
-                : '';
828
-            $this->_verify_nonce($nonce, $this->_req_nonce);
829
-        }
830
-        //set the nav_tabs array but ONLY if this is  UI_request
831
-        if ($this->_is_UI_request) {
832
-            $this->_set_nav_tabs();
833
-        }
834
-        // grab callback function
835
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
836
-        // check if callback has args
837
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
838
-        $error_msg = '';
839
-        // action right before calling route
840
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
841
-        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
842
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
843
-        }
844
-        // right before calling the route, let's remove _wp_http_referer from the
845
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
846
-        $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
847
-        if ( ! empty($func)) {
848
-            if (is_array($func)) {
849
-                list($class, $method) = $func;
850
-            } else if (strpos($func, '::') !== false) {
851
-                list($class, $method) = explode('::', $func);
852
-            } else {
853
-                $class = $this;
854
-                $method = $func;
855
-            }
856
-            if ( ! (is_object($class) && $class === $this)) {
857
-                // send along this admin page object for access by addons.
858
-                $args['admin_page_object'] = $this;
859
-            }
860
-
861
-            if (
862
-                //is it a method on a class that doesn't work?
863
-                (
864
-                    (
865
-                        method_exists($class, $method)
866
-                        && call_user_func_array(array($class, $method), $args) === false
867
-                    )
868
-                    && (
869
-                        //is it a standalone function that doesn't work?
870
-                        function_exists($method)
871
-                        && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
872
-                    )
873
-                )
874
-                || (
875
-                    //is it neither a class method NOR a standalone function?
876
-                    ! method_exists($class, $method)
877
-                    && ! function_exists($method)
878
-                )
879
-            ) {
880
-                // user error msg
881
-                $error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
882
-                // developer error msg
883
-                $error_msg .= '||';
884
-                $error_msg .= sprintf(
885
-                    __(
886
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
887
-                        'event_espresso'
888
-                    ),
889
-                    $method
890
-                );
891
-            }
892
-            if ( ! empty($error_msg)) {
893
-                throw new EE_Error($error_msg);
894
-            }
895
-        }
896
-        //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
897
-        //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.
898
-        if ($this->_is_UI_request === false
899
-            && is_array($this->_route)
900
-            && ! empty($this->_route['headers_sent_route'])
901
-        ) {
902
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
903
-        }
904
-    }
905
-
906
-
907
-
908
-    /**
909
-     * This method just allows the resetting of page properties in the case where a no headers
910
-     * route redirects to a headers route in its route config.
911
-     *
912
-     * @since   4.3.0
913
-     * @param  string $new_route New (non header) route to redirect to.
914
-     * @return   void
915
-     */
916
-    protected function _reset_routing_properties($new_route)
917
-    {
918
-        $this->_is_UI_request = true;
919
-        //now we set the current route to whatever the headers_sent_route is set at
920
-        $this->_req_data['action'] = $new_route;
921
-        //rerun page setup
922
-        $this->_page_setup();
923
-    }
924
-
925
-
926
-
927
-    /**
928
-     * _add_query_arg
929
-     * adds nonce to array of arguments then calls WP add_query_arg function
930
-     *(internally just uses EEH_URL's function with the same name)
931
-     *
932
-     * @access public
933
-     * @param array  $args
934
-     * @param string $url
935
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
936
-     *                                        url in an associative array indexed by the key 'wp_referer';
937
-     *                                        Example usage:
938
-     *                                        If the current page is:
939
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
940
-     *                                        &action=default&event_id=20&month_range=March%202015
941
-     *                                        &_wpnonce=5467821
942
-     *                                        and you call:
943
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
944
-     *                                        array(
945
-     *                                        'action' => 'resend_something',
946
-     *                                        'page=>espresso_registrations'
947
-     *                                        ),
948
-     *                                        $some_url,
949
-     *                                        true
950
-     *                                        );
951
-     *                                        It will produce a url in this structure:
952
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
953
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
954
-     *                                        month_range]=March%202015
955
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
956
-     * @return string
957
-     */
958
-    public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
959
-    {
960
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
961
-        if ($sticky) {
962
-            $request = $_REQUEST;
963
-            unset($request['_wp_http_referer']);
964
-            unset($request['wp_referer']);
965
-            foreach ($request as $key => $value) {
966
-                //do not add nonces
967
-                if (strpos($key, 'nonce') !== false) {
968
-                    continue;
969
-                }
970
-                $args['wp_referer[' . $key . ']'] = $value;
971
-            }
972
-        }
973
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * This returns a generated link that will load the related help tab.
980
-     *
981
-     * @param  string $help_tab_id the id for the connected help tab
982
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
983
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
984
-     * @uses EEH_Template::get_help_tab_link()
985
-     * @return string              generated link
986
-     */
987
-    protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
988
-    {
989
-        return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
990
-    }
991
-
992
-
993
-
994
-    /**
995
-     * _add_help_tabs
996
-     * Note child classes define their help tabs within the page_config array.
997
-     *
998
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
999
-     * @access protected
1000
-     * @return void
1001
-     */
1002
-    protected function _add_help_tabs()
1003
-    {
1004
-        $tour_buttons = '';
1005
-        if (isset($this->_page_config[$this->_req_action])) {
1006
-            $config = $this->_page_config[$this->_req_action];
1007
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1008
-            if (isset($this->_help_tour[$this->_req_action])) {
1009
-                $tb = array();
1010
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1011
-                foreach ($this->_help_tour['tours'] as $tour) {
1012
-                    //if this is the end tour then we don't need to setup a button
1013
-                    if ($tour instanceof EE_Help_Tour_final_stop) {
1014
-                        continue;
1015
-                    }
1016
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1017
-                }
1018
-                $tour_buttons .= implode('<br />', $tb);
1019
-                $tour_buttons .= '</div></div>';
1020
-            }
1021
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1022
-            if (is_array($config) && isset($config['help_sidebar'])) {
1023
-                //check that the callback given is valid
1024
-                if ( ! method_exists($this, $config['help_sidebar'])) {
1025
-                    throw new EE_Error(sprintf(__('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',
1026
-                            'event_espresso'), $config['help_sidebar'], get_class($this)));
1027
-                }
1028
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029
-                $content .= $tour_buttons; //add help tour buttons.
1030
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1031
-                $this->_current_screen->set_help_sidebar($content);
1032
-            }
1033
-            //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1034
-            if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1035
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1036
-            }
1037
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1038
-            if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039
-                $_ht['id'] = $this->page_slug;
1040
-                $_ht['title'] = __('Help Tours', 'event_espresso');
1041
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1042
-                $this->_current_screen->add_help_tab($_ht);
1043
-            }/**/
1044
-            if ( ! isset($config['help_tabs'])) {
1045
-                return;
1046
-            } //no help tabs for this route
1047
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1048
-                //we're here so there ARE help tabs!
1049
-                //make sure we've got what we need
1050
-                if ( ! isset($cfg['title'])) {
1051
-                    throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1052
-                }
1053
-                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1054
-                    throw new EE_Error(__('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',
1055
-                            'event_espresso'));
1056
-                }
1057
-                //first priority goes to content.
1058
-                if ( ! empty($cfg['content'])) {
1059
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060
-                    //second priority goes to filename
1061
-                } else if ( ! empty($cfg['filename'])) {
1062
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1063
-                    //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)
1064
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1065
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066
-                    if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067
-                        EE_Error::add_error(sprintf(__('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',
1068
-                                'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1069
-                        return;
1070
-                    }
1071
-                    $template_args['admin_page_obj'] = $this;
1072
-                    $content = EEH_Template::display_template($file_path, $template_args, true);
1073
-                } else {
1074
-                    $content = '';
1075
-                }
1076
-                //check if callback is valid
1077
-                if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1078
-                    EE_Error::add_error(sprintf(__('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.',
1079
-                            'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1080
-                    return;
1081
-                }
1082
-                //setup config array for help tab method
1083
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1084
-                $_ht = array(
1085
-                        'id'       => $id,
1086
-                        'title'    => $cfg['title'],
1087
-                        'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1088
-                        'content'  => $content,
1089
-                );
1090
-                $this->_current_screen->add_help_tab($_ht);
1091
-            }
1092
-        }
1093
-    }
1094
-
1095
-
1096
-
1097
-    /**
1098
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1099
-     *
1100
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1101
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1102
-     * @access protected
1103
-     * @return void
1104
-     */
1105
-    protected function _add_help_tour()
1106
-    {
1107
-        $tours = array();
1108
-        $this->_help_tour = array();
1109
-        //exit early if help tours are turned off globally
1110
-        if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1111
-            return;
1112
-        }
1113
-        //loop through _page_config to find any help_tour defined
1114
-        foreach ($this->_page_config as $route => $config) {
1115
-            //we're only going to set things up for this route
1116
-            if ($route !== $this->_req_action) {
1117
-                continue;
1118
-            }
1119
-            if (isset($config['help_tour'])) {
1120
-                foreach ($config['help_tour'] as $tour) {
1121
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1122
-                    //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1124
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125
-                    if ( ! is_readable($file_path)) {
1126
-                        EE_Error::add_error(sprintf(__('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', 'event_espresso'),
1127
-                                $file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1128
-                        return;
1129
-                    }
1130
-                    require_once $file_path;
1131
-                    if ( ! class_exists($tour)) {
1132
-                        $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('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.',
1134
-                                        'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135
-                        throw new EE_Error(implode('||', $error_msg));
1136
-                    }
1137
-                    $a = new ReflectionClass($tour);
1138
-                    $tour_obj = $a->newInstance($this->_is_caf);
1139
-                    $tours[] = $tour_obj;
1140
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1141
-                }
1142
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1143
-                $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1144
-                $tours[] = $end_stop_tour;
1145
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1146
-            }
1147
-        }
1148
-        if ( ! empty($tours)) {
1149
-            $this->_help_tour['tours'] = $tours;
1150
-        }
1151
-        //thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1152
-    }
1153
-
1154
-
1155
-
1156
-    /**
1157
-     * This simply sets up any qtips that have been defined in the page config
1158
-     *
1159
-     * @access protected
1160
-     * @return void
1161
-     */
1162
-    protected function _add_qtips()
1163
-    {
1164
-        if (isset($this->_route_config['qtips'])) {
1165
-            $qtips = (array)$this->_route_config['qtips'];
1166
-            //load qtip loader
1167
-            $path = array(
1168
-                    $this->_get_dir() . '/qtips/',
1169
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1170
-            );
1171
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1172
-        }
1173
-    }
1174
-
1175
-
1176
-
1177
-    /**
1178
-     * _set_nav_tabs
1179
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1180
-     *
1181
-     * @access protected
1182
-     * @return void
1183
-     */
1184
-    protected function _set_nav_tabs()
1185
-    {
1186
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1187
-        $i = 0;
1188
-        foreach ($this->_page_config as $slug => $config) {
1189
-            if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1190
-                continue;
1191
-            } //no nav tab for this config
1192
-            //check for persistent flag
1193
-            if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1194
-                continue;
1195
-            } //nav tab is only to appear when route requested.
1196
-            if ( ! $this->check_user_access($slug, true)) {
1197
-                continue;
1198
-            } //no nav tab becasue current user does not have access.
1199
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1200
-            $this->_nav_tabs[$slug] = array(
1201
-                    'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202
-                    'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1204
-                    'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205
-            );
1206
-            $i++;
1207
-        }
1208
-        //if $this->_nav_tabs is empty then lets set the default
1209
-        if (empty($this->_nav_tabs)) {
1210
-            $this->_nav_tabs[$this->default_nav_tab_name] = array(
1211
-                    'url'       => $this->admin_base_url,
1212
-                    'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1213
-                    'css_class' => 'nav-tab-active',
1214
-                    'order'     => 10,
1215
-            );
1216
-        }
1217
-        //now let's sort the tabs according to order
1218
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1219
-    }
1220
-
1221
-
1222
-
1223
-    /**
1224
-     * _set_current_labels
1225
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1226
-     *
1227
-     * @access private
1228
-     * @return void
1229
-     */
1230
-    private function _set_current_labels()
1231
-    {
1232
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1233
-            foreach ($this->_route_config['labels'] as $label => $text) {
1234
-                if (is_array($text)) {
1235
-                    foreach ($text as $sublabel => $subtext) {
1236
-                        $this->_labels[$label][$sublabel] = $subtext;
1237
-                    }
1238
-                } else {
1239
-                    $this->_labels[$label] = $text;
1240
-                }
1241
-            }
1242
-        }
1243
-    }
1244
-
1245
-
1246
-
1247
-    /**
1248
-     *        verifies user access for this admin page
1249
-     *
1250
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1251
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1252
-     * @return        BOOL|wp_die()
1253
-     */
1254
-    public function check_user_access($route_to_check = '', $verify_only = false)
1255
-    {
1256
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1257
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1258
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1259
-                ? $this->_page_routes[$route_to_check]['capability'] : null;
1260
-        if (empty($capability) && empty($route_to_check)) {
1261
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1262
-        } else {
1263
-            $capability = empty($capability) ? 'manage_options' : $capability;
1264
-        }
1265
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267
-            if ($verify_only) {
1268
-                return false;
1269
-            } else {
1270
-                if ( is_user_logged_in() ) {
1271
-                    wp_die(__('You do not have access to this route.', 'event_espresso'));
1272
-                } else {
1273
-                    return false;
1274
-                }
1275
-            }
1276
-        }
1277
-        return true;
1278
-    }
1279
-
1280
-
1281
-
1282
-    /**
1283
-     * admin_init_global
1284
-     * This runs all the code that we want executed within the WP admin_init hook.
1285
-     * This method executes for ALL EE Admin pages.
1286
-     *
1287
-     * @access public
1288
-     * @return void
1289
-     */
1290
-    public function admin_init_global()
1291
-    {
1292
-    }
1293
-
1294
-
1295
-
1296
-    /**
1297
-     * wp_loaded_global
1298
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1299
-     *
1300
-     * @access public
1301
-     * @return void
1302
-     */
1303
-    public function wp_loaded()
1304
-    {
1305
-    }
1306
-
1307
-
1308
-
1309
-    /**
1310
-     * admin_notices
1311
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1312
-     *
1313
-     * @access public
1314
-     * @return void
1315
-     */
1316
-    public function admin_notices_global()
1317
-    {
1318
-        $this->_display_no_javascript_warning();
1319
-        $this->_display_espresso_notices();
1320
-    }
1321
-
1322
-
1323
-
1324
-    public function network_admin_notices_global()
1325
-    {
1326
-        $this->_display_no_javascript_warning();
1327
-        $this->_display_espresso_notices();
1328
-    }
1329
-
1330
-
1331
-
1332
-    /**
1333
-     * admin_footer_scripts_global
1334
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1335
-     *
1336
-     * @access public
1337
-     * @return void
1338
-     */
1339
-    public function admin_footer_scripts_global()
1340
-    {
1341
-        $this->_add_admin_page_ajax_loading_img();
1342
-        $this->_add_admin_page_overlay();
1343
-        //if metaboxes are present we need to add the nonce field
1344
-        if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1345
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1346
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1347
-        }
1348
-    }
1349
-
1350
-
1351
-
1352
-    /**
1353
-     * admin_footer_global
1354
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1355
-     *
1356
-     * @access  public
1357
-     * @return  void
1358
-     */
1359
-    public function admin_footer_global()
1360
-    {
1361
-        //dialog container for dialog helper
1362
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1363
-        $d_cont .= '<div class="ee-notices"></div>';
1364
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365
-        $d_cont .= '</div>';
1366
-        echo $d_cont;
1367
-        //help tour stuff?
1368
-        if (isset($this->_help_tour[$this->_req_action])) {
1369
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370
-        }
1371
-        //current set timezone for timezone js
1372
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1373
-    }
1374
-
1375
-
1376
-
1377
-    /**
1378
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1379
-     * For child classes:
1380
-     * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1381
-     * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1382
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1383
-     *    'help_trigger_id' => array(
1384
-     *        'title' => __('localized title for popup', 'event_espresso'),
1385
-     *        'content' => __('localized content for popup', 'event_espresso')
1386
-     *    )
1387
-     * );
1388
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1389
-     *
1390
-     * @access protected
1391
-     * @return string content
1392
-     */
1393
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1394
-    {
1395
-        $content = '';
1396
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1398
-        //loop through the array and setup content
1399
-        foreach ($help_array as $trigger => $help) {
1400
-            //make sure the array is setup properly
1401
-            if ( ! isset($help['title']) || ! isset($help['content'])) {
1402
-                throw new EE_Error(__('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',
1403
-                        'event_espresso'));
1404
-            }
1405
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1406
-            $template_args = array(
1407
-                    'help_popup_id'      => $trigger,
1408
-                    'help_popup_title'   => $help['title'],
1409
-                    'help_popup_content' => $help['content'],
1410
-            );
1411
-            $content .= EEH_Template::display_template($template_path, $template_args, true);
1412
-        }
1413
-        if ($display) {
1414
-            echo $content;
1415
-        } else {
1416
-            return $content;
1417
-        }
1418
-    }
1419
-
1420
-
1421
-
1422
-    /**
1423
-     * All this does is retrive the help content array if set by the EE_Admin_Page child
1424
-     *
1425
-     * @access private
1426
-     * @return array properly formatted array for help popup content
1427
-     */
1428
-    private function _get_help_content()
1429
-    {
1430
-        //what is the method we're looking for?
1431
-        $method_name = '_help_popup_content_' . $this->_req_action;
1432
-        //if method doesn't exist let's get out.
1433
-        if ( ! method_exists($this, $method_name)) {
1434
-            return array();
1435
-        }
1436
-        //k we're good to go let's retrieve the help array
1437
-        $help_array = call_user_func(array($this, $method_name));
1438
-        //make sure we've got an array!
1439
-        if ( ! is_array($help_array)) {
1440
-            throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1441
-        }
1442
-        return $help_array;
1443
-    }
1444
-
1445
-
1446
-
1447
-    /**
1448
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1449
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1450
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1451
-     *
1452
-     * @access protected
1453
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1454
-     * @param boolean $display    if false then we return the trigger string
1455
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1456
-     * @return string
1457
-     */
1458
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1459
-    {
1460
-        if (defined('DOING_AJAX')) {
1461
-            return;
1462
-        }
1463
-        //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
1464
-        $help_array = $this->_get_help_content();
1465
-        $help_content = '';
1466
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1467
-            $help_array[$trigger_id] = array(
1468
-                    'title'   => __('Missing Content', 'event_espresso'),
1469
-                    'content' => __('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.)',
1470
-                            'event_espresso'),
1471
-            );
1472
-            $help_content = $this->_set_help_popup_content($help_array, false);
1473
-        }
1474
-        //let's setup the trigger
1475
-        $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
-        $content = $content . $help_content;
1477
-        if ($display) {
1478
-            echo $content;
1479
-        } else {
1480
-            return $content;
1481
-        }
1482
-    }
1483
-
1484
-
1485
-
1486
-    /**
1487
-     * _add_global_screen_options
1488
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1489
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1490
-     *
1491
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1492
-     *         see also WP_Screen object documents...
1493
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1494
-     * @abstract
1495
-     * @access private
1496
-     * @return void
1497
-     */
1498
-    private function _add_global_screen_options()
1499
-    {
1500
-    }
1501
-
1502
-
1503
-
1504
-    /**
1505
-     * _add_global_feature_pointers
1506
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1507
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1508
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1509
-     *
1510
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1511
-     * @link   http://eamann.com/tech/wordpress-portland/
1512
-     * @abstract
1513
-     * @access protected
1514
-     * @return void
1515
-     */
1516
-    private function _add_global_feature_pointers()
1517
-    {
1518
-    }
1519
-
1520
-
1521
-
1522
-    /**
1523
-     * load_global_scripts_styles
1524
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1525
-     *
1526
-     * @return void
1527
-     */
1528
-    public function load_global_scripts_styles()
1529
-    {
1530
-        /** STYLES **/
1531
-        // add debugging styles
1532
-        if (WP_DEBUG) {
1533
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1534
-        }
1535
-        // register all styles
1536
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538
-        //helpers styles
1539
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540
-        /** SCRIPTS **/
1541
-        //register all scripts
1542
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1543
-        wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1544
-        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1545
-        add_filter('FHEE_load_joyride', '__return_true');
1546
-        //script for sorting tables
1547
-        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1548
-        //script for parsing uri's
1549
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1550
-        //and parsing associative serialized form elements
1551
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1552
-        //helpers scripts
1553
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1556
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1557
-        //google charts
1558
-        wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1559
-        // ENQUEUE ALL BASICS BY DEFAULT
1560
-        wp_enqueue_style('ee-admin-css');
1561
-        wp_enqueue_script('ee_admin_js');
1562
-        wp_enqueue_script('ee-accounting');
1563
-        wp_enqueue_script('jquery-validate');
1564
-        //taking care of metaboxes
1565
-        if (
1566
-            empty($this->_cpt_route)
1567
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1568
-        ) {
1569
-            wp_enqueue_script('dashboard');
1570
-        }
1571
-        // LOCALIZED DATA
1572
-        //localize script for ajax lazy loading
1573
-        $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1574
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1575
-        /**
1576
-         * help tour stuff
1577
-         */
1578
-        if ( ! empty($this->_help_tour)) {
1579
-            //register the js for kicking things off
1580
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1581
-            //setup tours for the js tour object
1582
-            foreach ($this->_help_tour['tours'] as $tour) {
1583
-                $tours[] = array(
1584
-                        'id'      => $tour->get_slug(),
1585
-                        'options' => $tour->get_options(),
1586
-                );
1587
-            }
1588
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1589
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1590
-        }
1591
-    }
1592
-
1593
-
1594
-
1595
-    /**
1596
-     *        admin_footer_scripts_eei18n_js_strings
1597
-     *
1598
-     * @access        public
1599
-     * @return        void
1600
-     */
1601
-    public function admin_footer_scripts_eei18n_js_strings()
1602
-    {
1603
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1604
-        EE_Registry::$i18n_js_strings['confirm_delete'] = __('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!!!', 'event_espresso');
1605
-        EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1606
-        EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1607
-        EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1608
-        EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1609
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1610
-        EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1611
-        EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1612
-        EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1613
-        EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1614
-        EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1615
-        EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1616
-        EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1617
-        EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1618
-        EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1619
-        EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1620
-        EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1621
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1622
-        EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1623
-        EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1624
-        EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1625
-        EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1626
-        EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1627
-        EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1628
-        EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1629
-        EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1630
-        EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1631
-        EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1632
-        EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1633
-        EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1634
-        EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1635
-        EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1636
-        EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1637
-        EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1638
-        EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1639
-        EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1640
-        EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1641
-        EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1642
-        EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1643
-    }
1644
-
1645
-
1646
-
1647
-    /**
1648
-     *        load enhanced xdebug styles for ppl with failing eyesight
1649
-     *
1650
-     * @access        public
1651
-     * @return        void
1652
-     */
1653
-    public function add_xdebug_style()
1654
-    {
1655
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1656
-    }
1657
-
1658
-
1659
-    /************************/
1660
-    /** LIST TABLE METHODS **/
1661
-    /************************/
1662
-    /**
1663
-     * this sets up the list table if the current view requires it.
1664
-     *
1665
-     * @access protected
1666
-     * @return void
1667
-     */
1668
-    protected function _set_list_table()
1669
-    {
1670
-        //first is this a list_table view?
1671
-        if ( ! isset($this->_route_config['list_table'])) {
1672
-            return;
1673
-        } //not a list_table view so get out.
1674
-        //list table functions are per view specific (because some admin pages might have more than one listtable!)
1675
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1676
-            //user error msg
1677
-            $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1678
-            //developer error msg
1679
-            $error_msg .= '||' . sprintf(__('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.', 'event_espresso'),
1680
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1681
-            throw new EE_Error($error_msg);
1682
-        }
1683
-        //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1684
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1685
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1686
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1687
-        $this->_set_list_table_view();
1688
-        $this->_set_list_table_object();
1689
-    }
1690
-
1691
-
1692
-
1693
-    /**
1694
-     *        set current view for List Table
1695
-     *
1696
-     * @access public
1697
-     * @return array
1698
-     */
1699
-    protected function _set_list_table_view()
1700
-    {
1701
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1702
-        // looking at active items or dumpster diving ?
1703
-        if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1704
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1705
-        } else {
1706
-            $this->_view = sanitize_key($this->_req_data['status']);
1707
-        }
1708
-    }
1709
-
1710
-
1711
-
1712
-    /**
1713
-     * _set_list_table_object
1714
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1715
-     *
1716
-     * @throws \EE_Error
1717
-     */
1718
-    protected function _set_list_table_object()
1719
-    {
1720
-        if (isset($this->_route_config['list_table'])) {
1721
-            if ( ! class_exists($this->_route_config['list_table'])) {
1722
-                throw new EE_Error(
1723
-                        sprintf(
1724
-                                __(
1725
-                                        '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.',
1726
-                                        'event_espresso'
1727
-                                ),
1728
-                                $this->_route_config['list_table'],
1729
-                                get_class($this)
1730
-                        )
1731
-                );
1732
-            }
1733
-            $list_table = $this->_route_config['list_table'];
1734
-            $this->_list_table_object = new $list_table($this);
1735
-        }
1736
-    }
1737
-
1738
-
1739
-
1740
-    /**
1741
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1742
-     *
1743
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1744
-     *                                                    urls.  The array should be indexed by the view it is being
1745
-     *                                                    added to.
1746
-     * @return array
1747
-     */
1748
-    public function get_list_table_view_RLs($extra_query_args = array())
1749
-    {
1750
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1751
-        if (empty($this->_views)) {
1752
-            $this->_views = array();
1753
-        }
1754
-        // cycle thru views
1755
-        foreach ($this->_views as $key => $view) {
1756
-            $query_args = array();
1757
-            // check for current view
1758
-            $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1759
-            $query_args['action'] = $this->_req_action;
1760
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1761
-            $query_args['status'] = $view['slug'];
1762
-            //merge any other arguments sent in.
1763
-            if (isset($extra_query_args[$view['slug']])) {
1764
-                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1765
-            }
1766
-            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1767
-        }
1768
-        return $this->_views;
1769
-    }
1770
-
1771
-
1772
-
1773
-    /**
1774
-     * _entries_per_page_dropdown
1775
-     * generates a drop down box for selecting the number of visiable rows in an admin page list table
1776
-     *
1777
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1778
-     * @access protected
1779
-     * @param int $max_entries total number of rows in the table
1780
-     * @return string
1781
-     */
1782
-    protected function _entries_per_page_dropdown($max_entries = false)
1783
-    {
1784
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1785
-        $values = array(10, 25, 50, 100);
1786
-        $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1787
-        if ($max_entries) {
1788
-            $values[] = $max_entries;
1789
-            sort($values);
1790
-        }
1791
-        $entries_per_page_dropdown = '
143
+	// yes / no array for admin form fields
144
+	protected $_yes_no_values = array();
145
+
146
+	//some default things shared by all child classes
147
+	protected $_default_espresso_metaboxes;
148
+
149
+	/**
150
+	 *    EE_Registry Object
151
+	 *
152
+	 * @var    EE_Registry
153
+	 * @access    protected
154
+	 */
155
+	protected $EE = null;
156
+
157
+
158
+
159
+	/**
160
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
161
+	 *
162
+	 * @var boolean
163
+	 */
164
+	protected $_is_caf = false;
165
+
166
+
167
+
168
+	/**
169
+	 * @Constructor
170
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
171
+	 * @access public
172
+	 */
173
+	public function __construct($routing = true)
174
+	{
175
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
176
+			$this->_is_caf = true;
177
+		}
178
+		$this->_yes_no_values = array(
179
+				array('id' => true, 'text' => __('Yes', 'event_espresso')),
180
+				array('id' => false, 'text' => __('No', 'event_espresso')),
181
+		);
182
+		//set the _req_data property.
183
+		$this->_req_data = array_merge($_GET, $_POST);
184
+		//routing enabled?
185
+		$this->_routing = $routing;
186
+		//set initial page props (child method)
187
+		$this->_init_page_props();
188
+		//set global defaults
189
+		$this->_set_defaults();
190
+		//set early because incoming requests could be ajax related and we need to register those hooks.
191
+		$this->_global_ajax_hooks();
192
+		$this->_ajax_hooks();
193
+		//other_page_hooks have to be early too.
194
+		$this->_do_other_page_hooks();
195
+		//This just allows us to have extending classes do something specific
196
+		// before the parent constructor runs _page_setup().
197
+		if (method_exists($this, '_before_page_setup')) {
198
+			$this->_before_page_setup();
199
+		}
200
+		//set up page dependencies
201
+		$this->_page_setup();
202
+	}
203
+
204
+
205
+
206
+	/**
207
+	 * _init_page_props
208
+	 * Child classes use to set at least the following properties:
209
+	 * $page_slug.
210
+	 * $page_label.
211
+	 *
212
+	 * @abstract
213
+	 * @access protected
214
+	 * @return void
215
+	 */
216
+	abstract protected function _init_page_props();
217
+
218
+
219
+
220
+	/**
221
+	 * _ajax_hooks
222
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
223
+	 * Note: within the ajax callback methods.
224
+	 *
225
+	 * @abstract
226
+	 * @access protected
227
+	 * @return void
228
+	 */
229
+	abstract protected function _ajax_hooks();
230
+
231
+
232
+
233
+	/**
234
+	 * _define_page_props
235
+	 * child classes define page properties in here.  Must include at least:
236
+	 * $_admin_base_url = base_url for all admin pages
237
+	 * $_admin_page_title = default admin_page_title for admin pages
238
+	 * $_labels = array of default labels for various automatically generated elements:
239
+	 *    array(
240
+	 *        'buttons' => array(
241
+	 *            'add' => __('label for add new button'),
242
+	 *            'edit' => __('label for edit button'),
243
+	 *            'delete' => __('label for delete button')
244
+	 *            )
245
+	 *        )
246
+	 *
247
+	 * @abstract
248
+	 * @access protected
249
+	 * @return void
250
+	 */
251
+	abstract protected function _define_page_props();
252
+
253
+
254
+
255
+	/**
256
+	 * _set_page_routes
257
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
258
+	 * route. Here's the format
259
+	 * $this->_page_routes = array(
260
+	 *        'default' => array(
261
+	 *            'func' => '_default_method_handling_route',
262
+	 *            'args' => array('array','of','args'),
263
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
264
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
265
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
266
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
267
+	 *        ),
268
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
269
+	 *        )
270
+	 * )
271
+	 *
272
+	 * @abstract
273
+	 * @access protected
274
+	 * @return void
275
+	 */
276
+	abstract protected function _set_page_routes();
277
+
278
+
279
+
280
+	/**
281
+	 * _set_page_config
282
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
283
+	 * Format:
284
+	 * $this->_page_config = array(
285
+	 *        'default' => array(
286
+	 *            'labels' => array(
287
+	 *                'buttons' => array(
288
+	 *                    'add' => __('label for adding item'),
289
+	 *                    'edit' => __('label for editing item'),
290
+	 *                    'delete' => __('label for deleting item')
291
+	 *                ),
292
+	 *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
293
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
294
+	 *            'nav' => array(
295
+	 *                'label' => __('Label for Tab', 'event_espresso').
296
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
297
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
298
+	 *                'order' => 10, //required to indicate tab position.
299
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
300
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
301
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
302
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
303
+	 *            this flag to make sure the necessary js gets enqueued on page load.
304
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
305
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
306
+	 *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
307
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
308
+	 *                'tab_id' => array(
309
+	 *                    'title' => 'tab_title',
310
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
311
+	 *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
312
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
313
+	 *                    ),
314
+	 *                'tab2_id' => array(
315
+	 *                    'title' => 'tab2 title',
316
+	 *                    'filename' => 'file_name_2'
317
+	 *                    'callback' => 'callback_method_for_content',
318
+	 *                 ),
319
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
320
+	 *            'help_tour' => array(
321
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
322
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
323
+	 *            ),
324
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
325
+	 *            'require_nonce' to FALSE
326
+	 *            )
327
+	 * )
328
+	 *
329
+	 * @abstract
330
+	 * @access protected
331
+	 * @return void
332
+	 */
333
+	abstract protected function _set_page_config();
334
+
335
+
336
+
337
+
338
+
339
+	/** end sample help_tour methods **/
340
+	/**
341
+	 * _add_screen_options
342
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
343
+	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
344
+	 *
345
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
346
+	 *         see also WP_Screen object documents...
347
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
348
+	 * @abstract
349
+	 * @access protected
350
+	 * @return void
351
+	 */
352
+	abstract protected function _add_screen_options();
353
+
354
+
355
+
356
+	/**
357
+	 * _add_feature_pointers
358
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
359
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
360
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
361
+	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
362
+	 *
363
+	 * @link   http://eamann.com/tech/wordpress-portland/
364
+	 * @abstract
365
+	 * @access protected
366
+	 * @return void
367
+	 */
368
+	abstract protected function _add_feature_pointers();
369
+
370
+
371
+
372
+	/**
373
+	 * load_scripts_styles
374
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
375
+	 * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
376
+	 *
377
+	 * @abstract
378
+	 * @access public
379
+	 * @return void
380
+	 */
381
+	abstract public function load_scripts_styles();
382
+
383
+
384
+
385
+	/**
386
+	 * admin_init
387
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
388
+	 *
389
+	 * @abstract
390
+	 * @access public
391
+	 * @return void
392
+	 */
393
+	abstract public function admin_init();
394
+
395
+
396
+
397
+	/**
398
+	 * admin_notices
399
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
400
+	 *
401
+	 * @abstract
402
+	 * @access public
403
+	 * @return void
404
+	 */
405
+	abstract public function admin_notices();
406
+
407
+
408
+
409
+	/**
410
+	 * admin_footer_scripts
411
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
412
+	 *
413
+	 * @access public
414
+	 * @return void
415
+	 */
416
+	abstract public function admin_footer_scripts();
417
+
418
+
419
+
420
+	/**
421
+	 * admin_footer
422
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
423
+	 *
424
+	 * @access  public
425
+	 * @return void
426
+	 */
427
+	public function admin_footer()
428
+	{
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * _global_ajax_hooks
435
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
436
+	 * Note: within the ajax callback methods.
437
+	 *
438
+	 * @abstract
439
+	 * @access protected
440
+	 * @return void
441
+	 */
442
+	protected function _global_ajax_hooks()
443
+	{
444
+		//for lazy loading of metabox content
445
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
446
+	}
447
+
448
+
449
+
450
+	public function ajax_metabox_content()
451
+	{
452
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
453
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
454
+		self::cached_rss_display($contentid, $url);
455
+		wp_die();
456
+	}
457
+
458
+
459
+
460
+	/**
461
+	 * _page_setup
462
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
463
+	 *
464
+	 * @final
465
+	 * @access protected
466
+	 * @return void
467
+	 */
468
+	final protected function _page_setup()
469
+	{
470
+		//requires?
471
+		//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.
472
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
473
+		//next verify if we need to load anything...
474
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475
+		$this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476
+		global $ee_menu_slugs;
477
+		$ee_menu_slugs = (array)$ee_menu_slugs;
478
+		if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479
+			return;
480
+		}
481
+		// 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
482
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
483
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
484
+		}
485
+		// then set blank or -1 action values to 'default'
486
+		$this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
487
+		//if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
488
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
489
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
+		$this->_current_view = $this->_req_action;
492
+		$this->_req_nonce = $this->_req_action . '_nonce';
493
+		$this->_define_page_props();
494
+		$this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495
+		//default things
496
+		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
497
+		//set page configs
498
+		$this->_set_page_routes();
499
+		$this->_set_page_config();
500
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
501
+		if (isset($this->_req_data['wp_referer'])) {
502
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
503
+		}
504
+		//for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
505
+		if (method_exists($this, '_extend_page_config')) {
506
+			$this->_extend_page_config();
507
+		}
508
+		//for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
509
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
510
+			$this->_extend_page_config_for_cpt();
511
+		}
512
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
513
+		$this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
+		$this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
515
+		//if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
+			add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
518
+		}
519
+		//next route only if routing enabled
520
+		if ($this->_routing && ! defined('DOING_AJAX')) {
521
+			$this->_verify_routes();
522
+			//next let's just check user_access and kill if no access
523
+			$this->check_user_access();
524
+			if ($this->_is_UI_request) {
525
+				//admin_init stuff - global, all views for this page class, specific view
526
+				add_action('admin_init', array($this, 'admin_init'), 10);
527
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
529
+				}
530
+			} else {
531
+				//hijack regular WP loading and route admin request immediately
532
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
533
+				$this->route_admin_request();
534
+			}
535
+		}
536
+	}
537
+
538
+
539
+
540
+	/**
541
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
542
+	 *
543
+	 * @access private
544
+	 * @return void
545
+	 */
546
+	private function _do_other_page_hooks()
547
+	{
548
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
549
+		foreach ($registered_pages as $page) {
550
+			//now let's setup the file name and class that should be present
551
+			$classname = str_replace('.class.php', '', $page);
552
+			//autoloaders should take care of loading file
553
+			if ( ! class_exists($classname)) {
554
+				$error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555
+				$error_msg[] = $error_msg[0]
556
+							   . "\r\n"
557
+							   . sprintf( esc_html__('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',
558
+								'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
559
+				throw new EE_Error(implode('||', $error_msg));
560
+			}
561
+			$a = new ReflectionClass($classname);
562
+			//notice we are passing the instance of this class to the hook object.
563
+			$hookobj[] = $a->newInstance($this);
564
+		}
565
+	}
566
+
567
+
568
+
569
+	public function load_page_dependencies()
570
+	{
571
+		try {
572
+			$this->_load_page_dependencies();
573
+		} catch (EE_Error $e) {
574
+			$e->get_error();
575
+		}
576
+	}
577
+
578
+
579
+
580
+	/**
581
+	 * load_page_dependencies
582
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
583
+	 *
584
+	 * @access public
585
+	 * @return void
586
+	 */
587
+	protected function _load_page_dependencies()
588
+	{
589
+		//let's set the current_screen and screen options to override what WP set
590
+		$this->_current_screen = get_current_screen();
591
+		//load admin_notices - global, page class, and view specific
592
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
594
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
596
+		}
597
+		//load network admin_notices - global, page class, and view specific
598
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
601
+		}
602
+		//this will save any per_page screen options if they are present
603
+		$this->_set_per_page_screen_options();
604
+		//setup list table properties
605
+		$this->_set_list_table();
606
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
607
+		$this->_add_registered_meta_boxes();
608
+		$this->_add_screen_columns();
609
+		//add screen options - global, page child class, and view specific
610
+		$this->_add_global_screen_options();
611
+		$this->_add_screen_options();
612
+		if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
+			call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
614
+		}
615
+		//add help tab(s) and tours- set via page_config and qtips.
616
+		$this->_add_help_tour();
617
+		$this->_add_help_tabs();
618
+		$this->_add_qtips();
619
+		//add feature_pointers - global, page child class, and view specific
620
+		$this->_add_feature_pointers();
621
+		$this->_add_global_feature_pointers();
622
+		if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
+			call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
624
+		}
625
+		//enqueue scripts/styles - global, page class, and view specific
626
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
+		if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
+			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
630
+		}
631
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632
+		//admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
+		if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
+			add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
637
+		}
638
+		//admin footer scripts
639
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
641
+		if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
+			add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
643
+		}
644
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645
+		//targeted hook
646
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
647
+	}
648
+
649
+
650
+
651
+	/**
652
+	 * _set_defaults
653
+	 * This sets some global defaults for class properties.
654
+	 */
655
+	private function _set_defaults()
656
+	{
657
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
658
+		$this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
659
+		$this->default_nav_tab_name = 'overview';
660
+		//init template args
661
+		$this->_template_args = array(
662
+				'admin_page_header'  => '',
663
+				'admin_page_content' => '',
664
+				'post_body_content'  => '',
665
+				'before_list_table'  => '',
666
+				'after_list_table'   => '',
667
+		);
668
+	}
669
+
670
+
671
+
672
+	/**
673
+	 * route_admin_request
674
+	 *
675
+	 * @see    _route_admin_request()
676
+	 * @access public
677
+	 * @return void|exception error
678
+	 */
679
+	public function route_admin_request()
680
+	{
681
+		try {
682
+			$this->_route_admin_request();
683
+		} catch (EE_Error $e) {
684
+			$e->get_error();
685
+		}
686
+	}
687
+
688
+
689
+
690
+	public function set_wp_page_slug($wp_page_slug)
691
+	{
692
+		$this->_wp_page_slug = $wp_page_slug;
693
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
694
+		if (is_network_admin()) {
695
+			$this->_wp_page_slug .= '-network';
696
+		}
697
+	}
698
+
699
+
700
+
701
+	/**
702
+	 * _verify_routes
703
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
704
+	 *
705
+	 * @access protected
706
+	 * @return void
707
+	 */
708
+	protected function _verify_routes()
709
+	{
710
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
711
+		if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
712
+			return false;
713
+		}
714
+		$this->_route = false;
715
+		$func = false;
716
+		$args = array();
717
+		// check that the page_routes array is not empty
718
+		if (empty($this->_page_routes)) {
719
+			// user error msg
720
+			$error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721
+			// developer error msg
722
+			$error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723
+			throw new EE_Error($error_msg);
724
+		}
725
+		// and that the requested page route exists
726
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
727
+			$this->_route = $this->_page_routes[$this->_req_action];
728
+			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
729
+		} else {
730
+			// user error msg
731
+			$error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732
+			// developer error msg
733
+			$error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734
+			throw new EE_Error($error_msg);
735
+		}
736
+		// and that a default route exists
737
+		if ( ! array_key_exists('default', $this->_page_routes)) {
738
+			// user error msg
739
+			$error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740
+			// developer error msg
741
+			$error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742
+			throw new EE_Error($error_msg);
743
+		}
744
+		//first lets' catch if the UI request has EVER been set.
745
+		if ($this->_is_UI_request === null) {
746
+			//lets set if this is a UI request or not.
747
+			$this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
748
+			//wait a minute... we might have a noheader in the route array
749
+			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
750
+		}
751
+		$this->_set_current_labels();
752
+	}
753
+
754
+
755
+
756
+	/**
757
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
758
+	 *
759
+	 * @param  string $route the route name we're verifying
760
+	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
761
+	 */
762
+	protected function _verify_route($route)
763
+	{
764
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
765
+			return true;
766
+		} else {
767
+			// user error msg
768
+			$error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769
+			// developer error msg
770
+			$error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771
+			throw new EE_Error($error_msg);
772
+		}
773
+	}
774
+
775
+
776
+
777
+	/**
778
+	 * perform nonce verification
779
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
780
+	 *
781
+	 * @param  string $nonce     The nonce sent
782
+	 * @param  string $nonce_ref The nonce reference string (name0)
783
+	 * @return mixed (bool|die)
784
+	 */
785
+	protected function _verify_nonce($nonce, $nonce_ref)
786
+	{
787
+		// verify nonce against expected value
788
+		if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
789
+			// these are not the droids you are looking for !!!
790
+			$msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791
+			if (WP_DEBUG) {
792
+				$msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793
+			}
794
+			if ( ! defined('DOING_AJAX')) {
795
+				wp_die($msg);
796
+			} else {
797
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
798
+				$this->_return_json();
799
+			}
800
+		}
801
+	}
802
+
803
+
804
+
805
+	/**
806
+	 * _route_admin_request()
807
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
808
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
809
+	 * in the page routes and then will try to load the corresponding method.
810
+	 *
811
+	 * @access protected
812
+	 * @return void
813
+	 * @throws \EE_Error
814
+	 */
815
+	protected function _route_admin_request()
816
+	{
817
+		if ( ! $this->_is_UI_request) {
818
+			$this->_verify_routes();
819
+		}
820
+		$nonce_check = isset($this->_route_config['require_nonce'])
821
+			? $this->_route_config['require_nonce']
822
+			: true;
823
+		if ($this->_req_action !== 'default' && $nonce_check) {
824
+			// set nonce from post data
825
+			$nonce = isset($this->_req_data[$this->_req_nonce])
826
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
827
+				: '';
828
+			$this->_verify_nonce($nonce, $this->_req_nonce);
829
+		}
830
+		//set the nav_tabs array but ONLY if this is  UI_request
831
+		if ($this->_is_UI_request) {
832
+			$this->_set_nav_tabs();
833
+		}
834
+		// grab callback function
835
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
836
+		// check if callback has args
837
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
838
+		$error_msg = '';
839
+		// action right before calling route
840
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
841
+		if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
842
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
843
+		}
844
+		// right before calling the route, let's remove _wp_http_referer from the
845
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
846
+		$_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
847
+		if ( ! empty($func)) {
848
+			if (is_array($func)) {
849
+				list($class, $method) = $func;
850
+			} else if (strpos($func, '::') !== false) {
851
+				list($class, $method) = explode('::', $func);
852
+			} else {
853
+				$class = $this;
854
+				$method = $func;
855
+			}
856
+			if ( ! (is_object($class) && $class === $this)) {
857
+				// send along this admin page object for access by addons.
858
+				$args['admin_page_object'] = $this;
859
+			}
860
+
861
+			if (
862
+				//is it a method on a class that doesn't work?
863
+				(
864
+					(
865
+						method_exists($class, $method)
866
+						&& call_user_func_array(array($class, $method), $args) === false
867
+					)
868
+					&& (
869
+						//is it a standalone function that doesn't work?
870
+						function_exists($method)
871
+						&& call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
872
+					)
873
+				)
874
+				|| (
875
+					//is it neither a class method NOR a standalone function?
876
+					! method_exists($class, $method)
877
+					&& ! function_exists($method)
878
+				)
879
+			) {
880
+				// user error msg
881
+				$error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
882
+				// developer error msg
883
+				$error_msg .= '||';
884
+				$error_msg .= sprintf(
885
+					__(
886
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
887
+						'event_espresso'
888
+					),
889
+					$method
890
+				);
891
+			}
892
+			if ( ! empty($error_msg)) {
893
+				throw new EE_Error($error_msg);
894
+			}
895
+		}
896
+		//if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
897
+		//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.
898
+		if ($this->_is_UI_request === false
899
+			&& is_array($this->_route)
900
+			&& ! empty($this->_route['headers_sent_route'])
901
+		) {
902
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
903
+		}
904
+	}
905
+
906
+
907
+
908
+	/**
909
+	 * This method just allows the resetting of page properties in the case where a no headers
910
+	 * route redirects to a headers route in its route config.
911
+	 *
912
+	 * @since   4.3.0
913
+	 * @param  string $new_route New (non header) route to redirect to.
914
+	 * @return   void
915
+	 */
916
+	protected function _reset_routing_properties($new_route)
917
+	{
918
+		$this->_is_UI_request = true;
919
+		//now we set the current route to whatever the headers_sent_route is set at
920
+		$this->_req_data['action'] = $new_route;
921
+		//rerun page setup
922
+		$this->_page_setup();
923
+	}
924
+
925
+
926
+
927
+	/**
928
+	 * _add_query_arg
929
+	 * adds nonce to array of arguments then calls WP add_query_arg function
930
+	 *(internally just uses EEH_URL's function with the same name)
931
+	 *
932
+	 * @access public
933
+	 * @param array  $args
934
+	 * @param string $url
935
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
936
+	 *                                        url in an associative array indexed by the key 'wp_referer';
937
+	 *                                        Example usage:
938
+	 *                                        If the current page is:
939
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
940
+	 *                                        &action=default&event_id=20&month_range=March%202015
941
+	 *                                        &_wpnonce=5467821
942
+	 *                                        and you call:
943
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
944
+	 *                                        array(
945
+	 *                                        'action' => 'resend_something',
946
+	 *                                        'page=>espresso_registrations'
947
+	 *                                        ),
948
+	 *                                        $some_url,
949
+	 *                                        true
950
+	 *                                        );
951
+	 *                                        It will produce a url in this structure:
952
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
953
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
954
+	 *                                        month_range]=March%202015
955
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
956
+	 * @return string
957
+	 */
958
+	public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
959
+	{
960
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
961
+		if ($sticky) {
962
+			$request = $_REQUEST;
963
+			unset($request['_wp_http_referer']);
964
+			unset($request['wp_referer']);
965
+			foreach ($request as $key => $value) {
966
+				//do not add nonces
967
+				if (strpos($key, 'nonce') !== false) {
968
+					continue;
969
+				}
970
+				$args['wp_referer[' . $key . ']'] = $value;
971
+			}
972
+		}
973
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * This returns a generated link that will load the related help tab.
980
+	 *
981
+	 * @param  string $help_tab_id the id for the connected help tab
982
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
983
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
984
+	 * @uses EEH_Template::get_help_tab_link()
985
+	 * @return string              generated link
986
+	 */
987
+	protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
988
+	{
989
+		return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
990
+	}
991
+
992
+
993
+
994
+	/**
995
+	 * _add_help_tabs
996
+	 * Note child classes define their help tabs within the page_config array.
997
+	 *
998
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
999
+	 * @access protected
1000
+	 * @return void
1001
+	 */
1002
+	protected function _add_help_tabs()
1003
+	{
1004
+		$tour_buttons = '';
1005
+		if (isset($this->_page_config[$this->_req_action])) {
1006
+			$config = $this->_page_config[$this->_req_action];
1007
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1008
+			if (isset($this->_help_tour[$this->_req_action])) {
1009
+				$tb = array();
1010
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1011
+				foreach ($this->_help_tour['tours'] as $tour) {
1012
+					//if this is the end tour then we don't need to setup a button
1013
+					if ($tour instanceof EE_Help_Tour_final_stop) {
1014
+						continue;
1015
+					}
1016
+					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1017
+				}
1018
+				$tour_buttons .= implode('<br />', $tb);
1019
+				$tour_buttons .= '</div></div>';
1020
+			}
1021
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1022
+			if (is_array($config) && isset($config['help_sidebar'])) {
1023
+				//check that the callback given is valid
1024
+				if ( ! method_exists($this, $config['help_sidebar'])) {
1025
+					throw new EE_Error(sprintf(__('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',
1026
+							'event_espresso'), $config['help_sidebar'], get_class($this)));
1027
+				}
1028
+				$content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029
+				$content .= $tour_buttons; //add help tour buttons.
1030
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1031
+				$this->_current_screen->set_help_sidebar($content);
1032
+			}
1033
+			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1034
+			if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1035
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1036
+			}
1037
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1038
+			if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039
+				$_ht['id'] = $this->page_slug;
1040
+				$_ht['title'] = __('Help Tours', 'event_espresso');
1041
+				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1042
+				$this->_current_screen->add_help_tab($_ht);
1043
+			}/**/
1044
+			if ( ! isset($config['help_tabs'])) {
1045
+				return;
1046
+			} //no help tabs for this route
1047
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1048
+				//we're here so there ARE help tabs!
1049
+				//make sure we've got what we need
1050
+				if ( ! isset($cfg['title'])) {
1051
+					throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1052
+				}
1053
+				if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1054
+					throw new EE_Error(__('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',
1055
+							'event_espresso'));
1056
+				}
1057
+				//first priority goes to content.
1058
+				if ( ! empty($cfg['content'])) {
1059
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060
+					//second priority goes to filename
1061
+				} else if ( ! empty($cfg['filename'])) {
1062
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1063
+					//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)
1064
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1065
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066
+					if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067
+						EE_Error::add_error(sprintf(__('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',
1068
+								'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1069
+						return;
1070
+					}
1071
+					$template_args['admin_page_obj'] = $this;
1072
+					$content = EEH_Template::display_template($file_path, $template_args, true);
1073
+				} else {
1074
+					$content = '';
1075
+				}
1076
+				//check if callback is valid
1077
+				if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1078
+					EE_Error::add_error(sprintf(__('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.',
1079
+							'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1080
+					return;
1081
+				}
1082
+				//setup config array for help tab method
1083
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1084
+				$_ht = array(
1085
+						'id'       => $id,
1086
+						'title'    => $cfg['title'],
1087
+						'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1088
+						'content'  => $content,
1089
+				);
1090
+				$this->_current_screen->add_help_tab($_ht);
1091
+			}
1092
+		}
1093
+	}
1094
+
1095
+
1096
+
1097
+	/**
1098
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1099
+	 *
1100
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1101
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1102
+	 * @access protected
1103
+	 * @return void
1104
+	 */
1105
+	protected function _add_help_tour()
1106
+	{
1107
+		$tours = array();
1108
+		$this->_help_tour = array();
1109
+		//exit early if help tours are turned off globally
1110
+		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1111
+			return;
1112
+		}
1113
+		//loop through _page_config to find any help_tour defined
1114
+		foreach ($this->_page_config as $route => $config) {
1115
+			//we're only going to set things up for this route
1116
+			if ($route !== $this->_req_action) {
1117
+				continue;
1118
+			}
1119
+			if (isset($config['help_tour'])) {
1120
+				foreach ($config['help_tour'] as $tour) {
1121
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1122
+					//let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1124
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125
+					if ( ! is_readable($file_path)) {
1126
+						EE_Error::add_error(sprintf(__('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', 'event_espresso'),
1127
+								$file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1128
+						return;
1129
+					}
1130
+					require_once $file_path;
1131
+					if ( ! class_exists($tour)) {
1132
+						$error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
+						$error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('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.',
1134
+										'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135
+						throw new EE_Error(implode('||', $error_msg));
1136
+					}
1137
+					$a = new ReflectionClass($tour);
1138
+					$tour_obj = $a->newInstance($this->_is_caf);
1139
+					$tours[] = $tour_obj;
1140
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1141
+				}
1142
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1143
+				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1144
+				$tours[] = $end_stop_tour;
1145
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1146
+			}
1147
+		}
1148
+		if ( ! empty($tours)) {
1149
+			$this->_help_tour['tours'] = $tours;
1150
+		}
1151
+		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1152
+	}
1153
+
1154
+
1155
+
1156
+	/**
1157
+	 * This simply sets up any qtips that have been defined in the page config
1158
+	 *
1159
+	 * @access protected
1160
+	 * @return void
1161
+	 */
1162
+	protected function _add_qtips()
1163
+	{
1164
+		if (isset($this->_route_config['qtips'])) {
1165
+			$qtips = (array)$this->_route_config['qtips'];
1166
+			//load qtip loader
1167
+			$path = array(
1168
+					$this->_get_dir() . '/qtips/',
1169
+					EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1170
+			);
1171
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1172
+		}
1173
+	}
1174
+
1175
+
1176
+
1177
+	/**
1178
+	 * _set_nav_tabs
1179
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1180
+	 *
1181
+	 * @access protected
1182
+	 * @return void
1183
+	 */
1184
+	protected function _set_nav_tabs()
1185
+	{
1186
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1187
+		$i = 0;
1188
+		foreach ($this->_page_config as $slug => $config) {
1189
+			if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1190
+				continue;
1191
+			} //no nav tab for this config
1192
+			//check for persistent flag
1193
+			if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1194
+				continue;
1195
+			} //nav tab is only to appear when route requested.
1196
+			if ( ! $this->check_user_access($slug, true)) {
1197
+				continue;
1198
+			} //no nav tab becasue current user does not have access.
1199
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1200
+			$this->_nav_tabs[$slug] = array(
1201
+					'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202
+					'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
+					'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1204
+					'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205
+			);
1206
+			$i++;
1207
+		}
1208
+		//if $this->_nav_tabs is empty then lets set the default
1209
+		if (empty($this->_nav_tabs)) {
1210
+			$this->_nav_tabs[$this->default_nav_tab_name] = array(
1211
+					'url'       => $this->admin_base_url,
1212
+					'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1213
+					'css_class' => 'nav-tab-active',
1214
+					'order'     => 10,
1215
+			);
1216
+		}
1217
+		//now let's sort the tabs according to order
1218
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1219
+	}
1220
+
1221
+
1222
+
1223
+	/**
1224
+	 * _set_current_labels
1225
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1226
+	 *
1227
+	 * @access private
1228
+	 * @return void
1229
+	 */
1230
+	private function _set_current_labels()
1231
+	{
1232
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1233
+			foreach ($this->_route_config['labels'] as $label => $text) {
1234
+				if (is_array($text)) {
1235
+					foreach ($text as $sublabel => $subtext) {
1236
+						$this->_labels[$label][$sublabel] = $subtext;
1237
+					}
1238
+				} else {
1239
+					$this->_labels[$label] = $text;
1240
+				}
1241
+			}
1242
+		}
1243
+	}
1244
+
1245
+
1246
+
1247
+	/**
1248
+	 *        verifies user access for this admin page
1249
+	 *
1250
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1251
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1252
+	 * @return        BOOL|wp_die()
1253
+	 */
1254
+	public function check_user_access($route_to_check = '', $verify_only = false)
1255
+	{
1256
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1257
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1258
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1259
+				? $this->_page_routes[$route_to_check]['capability'] : null;
1260
+		if (empty($capability) && empty($route_to_check)) {
1261
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1262
+		} else {
1263
+			$capability = empty($capability) ? 'manage_options' : $capability;
1264
+		}
1265
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
+		if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267
+			if ($verify_only) {
1268
+				return false;
1269
+			} else {
1270
+				if ( is_user_logged_in() ) {
1271
+					wp_die(__('You do not have access to this route.', 'event_espresso'));
1272
+				} else {
1273
+					return false;
1274
+				}
1275
+			}
1276
+		}
1277
+		return true;
1278
+	}
1279
+
1280
+
1281
+
1282
+	/**
1283
+	 * admin_init_global
1284
+	 * This runs all the code that we want executed within the WP admin_init hook.
1285
+	 * This method executes for ALL EE Admin pages.
1286
+	 *
1287
+	 * @access public
1288
+	 * @return void
1289
+	 */
1290
+	public function admin_init_global()
1291
+	{
1292
+	}
1293
+
1294
+
1295
+
1296
+	/**
1297
+	 * wp_loaded_global
1298
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1299
+	 *
1300
+	 * @access public
1301
+	 * @return void
1302
+	 */
1303
+	public function wp_loaded()
1304
+	{
1305
+	}
1306
+
1307
+
1308
+
1309
+	/**
1310
+	 * admin_notices
1311
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1312
+	 *
1313
+	 * @access public
1314
+	 * @return void
1315
+	 */
1316
+	public function admin_notices_global()
1317
+	{
1318
+		$this->_display_no_javascript_warning();
1319
+		$this->_display_espresso_notices();
1320
+	}
1321
+
1322
+
1323
+
1324
+	public function network_admin_notices_global()
1325
+	{
1326
+		$this->_display_no_javascript_warning();
1327
+		$this->_display_espresso_notices();
1328
+	}
1329
+
1330
+
1331
+
1332
+	/**
1333
+	 * admin_footer_scripts_global
1334
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1335
+	 *
1336
+	 * @access public
1337
+	 * @return void
1338
+	 */
1339
+	public function admin_footer_scripts_global()
1340
+	{
1341
+		$this->_add_admin_page_ajax_loading_img();
1342
+		$this->_add_admin_page_overlay();
1343
+		//if metaboxes are present we need to add the nonce field
1344
+		if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1345
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1346
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1347
+		}
1348
+	}
1349
+
1350
+
1351
+
1352
+	/**
1353
+	 * admin_footer_global
1354
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1355
+	 *
1356
+	 * @access  public
1357
+	 * @return  void
1358
+	 */
1359
+	public function admin_footer_global()
1360
+	{
1361
+		//dialog container for dialog helper
1362
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1363
+		$d_cont .= '<div class="ee-notices"></div>';
1364
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365
+		$d_cont .= '</div>';
1366
+		echo $d_cont;
1367
+		//help tour stuff?
1368
+		if (isset($this->_help_tour[$this->_req_action])) {
1369
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370
+		}
1371
+		//current set timezone for timezone js
1372
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1373
+	}
1374
+
1375
+
1376
+
1377
+	/**
1378
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1379
+	 * For child classes:
1380
+	 * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1381
+	 * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1382
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1383
+	 *    'help_trigger_id' => array(
1384
+	 *        'title' => __('localized title for popup', 'event_espresso'),
1385
+	 *        'content' => __('localized content for popup', 'event_espresso')
1386
+	 *    )
1387
+	 * );
1388
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1389
+	 *
1390
+	 * @access protected
1391
+	 * @return string content
1392
+	 */
1393
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1394
+	{
1395
+		$content = '';
1396
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1398
+		//loop through the array and setup content
1399
+		foreach ($help_array as $trigger => $help) {
1400
+			//make sure the array is setup properly
1401
+			if ( ! isset($help['title']) || ! isset($help['content'])) {
1402
+				throw new EE_Error(__('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',
1403
+						'event_espresso'));
1404
+			}
1405
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1406
+			$template_args = array(
1407
+					'help_popup_id'      => $trigger,
1408
+					'help_popup_title'   => $help['title'],
1409
+					'help_popup_content' => $help['content'],
1410
+			);
1411
+			$content .= EEH_Template::display_template($template_path, $template_args, true);
1412
+		}
1413
+		if ($display) {
1414
+			echo $content;
1415
+		} else {
1416
+			return $content;
1417
+		}
1418
+	}
1419
+
1420
+
1421
+
1422
+	/**
1423
+	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1424
+	 *
1425
+	 * @access private
1426
+	 * @return array properly formatted array for help popup content
1427
+	 */
1428
+	private function _get_help_content()
1429
+	{
1430
+		//what is the method we're looking for?
1431
+		$method_name = '_help_popup_content_' . $this->_req_action;
1432
+		//if method doesn't exist let's get out.
1433
+		if ( ! method_exists($this, $method_name)) {
1434
+			return array();
1435
+		}
1436
+		//k we're good to go let's retrieve the help array
1437
+		$help_array = call_user_func(array($this, $method_name));
1438
+		//make sure we've got an array!
1439
+		if ( ! is_array($help_array)) {
1440
+			throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1441
+		}
1442
+		return $help_array;
1443
+	}
1444
+
1445
+
1446
+
1447
+	/**
1448
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1449
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1450
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1451
+	 *
1452
+	 * @access protected
1453
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1454
+	 * @param boolean $display    if false then we return the trigger string
1455
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1456
+	 * @return string
1457
+	 */
1458
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1459
+	{
1460
+		if (defined('DOING_AJAX')) {
1461
+			return;
1462
+		}
1463
+		//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
1464
+		$help_array = $this->_get_help_content();
1465
+		$help_content = '';
1466
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1467
+			$help_array[$trigger_id] = array(
1468
+					'title'   => __('Missing Content', 'event_espresso'),
1469
+					'content' => __('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.)',
1470
+							'event_espresso'),
1471
+			);
1472
+			$help_content = $this->_set_help_popup_content($help_array, false);
1473
+		}
1474
+		//let's setup the trigger
1475
+		$content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
+		$content = $content . $help_content;
1477
+		if ($display) {
1478
+			echo $content;
1479
+		} else {
1480
+			return $content;
1481
+		}
1482
+	}
1483
+
1484
+
1485
+
1486
+	/**
1487
+	 * _add_global_screen_options
1488
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1489
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1490
+	 *
1491
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1492
+	 *         see also WP_Screen object documents...
1493
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1494
+	 * @abstract
1495
+	 * @access private
1496
+	 * @return void
1497
+	 */
1498
+	private function _add_global_screen_options()
1499
+	{
1500
+	}
1501
+
1502
+
1503
+
1504
+	/**
1505
+	 * _add_global_feature_pointers
1506
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1507
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1508
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1509
+	 *
1510
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1511
+	 * @link   http://eamann.com/tech/wordpress-portland/
1512
+	 * @abstract
1513
+	 * @access protected
1514
+	 * @return void
1515
+	 */
1516
+	private function _add_global_feature_pointers()
1517
+	{
1518
+	}
1519
+
1520
+
1521
+
1522
+	/**
1523
+	 * load_global_scripts_styles
1524
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1525
+	 *
1526
+	 * @return void
1527
+	 */
1528
+	public function load_global_scripts_styles()
1529
+	{
1530
+		/** STYLES **/
1531
+		// add debugging styles
1532
+		if (WP_DEBUG) {
1533
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1534
+		}
1535
+		// register all styles
1536
+		wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538
+		//helpers styles
1539
+		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540
+		/** SCRIPTS **/
1541
+		//register all scripts
1542
+		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1543
+		wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1544
+		wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1545
+		add_filter('FHEE_load_joyride', '__return_true');
1546
+		//script for sorting tables
1547
+		wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1548
+		//script for parsing uri's
1549
+		wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1550
+		//and parsing associative serialized form elements
1551
+		wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1552
+		//helpers scripts
1553
+		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
+		wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
+		wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1556
+		wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1557
+		//google charts
1558
+		wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1559
+		// ENQUEUE ALL BASICS BY DEFAULT
1560
+		wp_enqueue_style('ee-admin-css');
1561
+		wp_enqueue_script('ee_admin_js');
1562
+		wp_enqueue_script('ee-accounting');
1563
+		wp_enqueue_script('jquery-validate');
1564
+		//taking care of metaboxes
1565
+		if (
1566
+			empty($this->_cpt_route)
1567
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1568
+		) {
1569
+			wp_enqueue_script('dashboard');
1570
+		}
1571
+		// LOCALIZED DATA
1572
+		//localize script for ajax lazy loading
1573
+		$lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1574
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1575
+		/**
1576
+		 * help tour stuff
1577
+		 */
1578
+		if ( ! empty($this->_help_tour)) {
1579
+			//register the js for kicking things off
1580
+			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1581
+			//setup tours for the js tour object
1582
+			foreach ($this->_help_tour['tours'] as $tour) {
1583
+				$tours[] = array(
1584
+						'id'      => $tour->get_slug(),
1585
+						'options' => $tour->get_options(),
1586
+				);
1587
+			}
1588
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1589
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1590
+		}
1591
+	}
1592
+
1593
+
1594
+
1595
+	/**
1596
+	 *        admin_footer_scripts_eei18n_js_strings
1597
+	 *
1598
+	 * @access        public
1599
+	 * @return        void
1600
+	 */
1601
+	public function admin_footer_scripts_eei18n_js_strings()
1602
+	{
1603
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1604
+		EE_Registry::$i18n_js_strings['confirm_delete'] = __('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!!!', 'event_espresso');
1605
+		EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1606
+		EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1607
+		EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1608
+		EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1609
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1610
+		EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1611
+		EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1612
+		EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1613
+		EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1614
+		EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1615
+		EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1616
+		EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1617
+		EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1618
+		EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1619
+		EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1620
+		EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1621
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1622
+		EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1623
+		EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1624
+		EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1625
+		EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1626
+		EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1627
+		EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1628
+		EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1629
+		EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1630
+		EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1631
+		EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1632
+		EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1633
+		EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1634
+		EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1635
+		EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1636
+		EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1637
+		EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1638
+		EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1639
+		EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1640
+		EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1641
+		EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1642
+		EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1643
+	}
1644
+
1645
+
1646
+
1647
+	/**
1648
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1649
+	 *
1650
+	 * @access        public
1651
+	 * @return        void
1652
+	 */
1653
+	public function add_xdebug_style()
1654
+	{
1655
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1656
+	}
1657
+
1658
+
1659
+	/************************/
1660
+	/** LIST TABLE METHODS **/
1661
+	/************************/
1662
+	/**
1663
+	 * this sets up the list table if the current view requires it.
1664
+	 *
1665
+	 * @access protected
1666
+	 * @return void
1667
+	 */
1668
+	protected function _set_list_table()
1669
+	{
1670
+		//first is this a list_table view?
1671
+		if ( ! isset($this->_route_config['list_table'])) {
1672
+			return;
1673
+		} //not a list_table view so get out.
1674
+		//list table functions are per view specific (because some admin pages might have more than one listtable!)
1675
+		if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1676
+			//user error msg
1677
+			$error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1678
+			//developer error msg
1679
+			$error_msg .= '||' . sprintf(__('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.', 'event_espresso'),
1680
+							$this->_req_action, '_set_list_table_views_' . $this->_req_action);
1681
+			throw new EE_Error($error_msg);
1682
+		}
1683
+		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1684
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1685
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1686
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1687
+		$this->_set_list_table_view();
1688
+		$this->_set_list_table_object();
1689
+	}
1690
+
1691
+
1692
+
1693
+	/**
1694
+	 *        set current view for List Table
1695
+	 *
1696
+	 * @access public
1697
+	 * @return array
1698
+	 */
1699
+	protected function _set_list_table_view()
1700
+	{
1701
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1702
+		// looking at active items or dumpster diving ?
1703
+		if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1704
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1705
+		} else {
1706
+			$this->_view = sanitize_key($this->_req_data['status']);
1707
+		}
1708
+	}
1709
+
1710
+
1711
+
1712
+	/**
1713
+	 * _set_list_table_object
1714
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1715
+	 *
1716
+	 * @throws \EE_Error
1717
+	 */
1718
+	protected function _set_list_table_object()
1719
+	{
1720
+		if (isset($this->_route_config['list_table'])) {
1721
+			if ( ! class_exists($this->_route_config['list_table'])) {
1722
+				throw new EE_Error(
1723
+						sprintf(
1724
+								__(
1725
+										'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.',
1726
+										'event_espresso'
1727
+								),
1728
+								$this->_route_config['list_table'],
1729
+								get_class($this)
1730
+						)
1731
+				);
1732
+			}
1733
+			$list_table = $this->_route_config['list_table'];
1734
+			$this->_list_table_object = new $list_table($this);
1735
+		}
1736
+	}
1737
+
1738
+
1739
+
1740
+	/**
1741
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1742
+	 *
1743
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1744
+	 *                                                    urls.  The array should be indexed by the view it is being
1745
+	 *                                                    added to.
1746
+	 * @return array
1747
+	 */
1748
+	public function get_list_table_view_RLs($extra_query_args = array())
1749
+	{
1750
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1751
+		if (empty($this->_views)) {
1752
+			$this->_views = array();
1753
+		}
1754
+		// cycle thru views
1755
+		foreach ($this->_views as $key => $view) {
1756
+			$query_args = array();
1757
+			// check for current view
1758
+			$this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1759
+			$query_args['action'] = $this->_req_action;
1760
+			$query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1761
+			$query_args['status'] = $view['slug'];
1762
+			//merge any other arguments sent in.
1763
+			if (isset($extra_query_args[$view['slug']])) {
1764
+				$query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1765
+			}
1766
+			$this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1767
+		}
1768
+		return $this->_views;
1769
+	}
1770
+
1771
+
1772
+
1773
+	/**
1774
+	 * _entries_per_page_dropdown
1775
+	 * generates a drop down box for selecting the number of visiable rows in an admin page list table
1776
+	 *
1777
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1778
+	 * @access protected
1779
+	 * @param int $max_entries total number of rows in the table
1780
+	 * @return string
1781
+	 */
1782
+	protected function _entries_per_page_dropdown($max_entries = false)
1783
+	{
1784
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1785
+		$values = array(10, 25, 50, 100);
1786
+		$per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1787
+		if ($max_entries) {
1788
+			$values[] = $max_entries;
1789
+			sort($values);
1790
+		}
1791
+		$entries_per_page_dropdown = '
1792 1792
 			<div id="entries-per-page-dv" class="alignleft actions">
1793 1793
 				<label class="hide-if-no-js">
1794 1794
 					Show
1795 1795
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1796
-        foreach ($values as $value) {
1797
-            if ($value < $max_entries) {
1798
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1799
-                $entries_per_page_dropdown .= '
1796
+		foreach ($values as $value) {
1797
+			if ($value < $max_entries) {
1798
+				$selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1799
+				$entries_per_page_dropdown .= '
1800 1800
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1801
-            }
1802
-        }
1803
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1804
-        $entries_per_page_dropdown .= '
1801
+			}
1802
+		}
1803
+		$selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1804
+		$entries_per_page_dropdown .= '
1805 1805
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1806
-        $entries_per_page_dropdown .= '
1806
+		$entries_per_page_dropdown .= '
1807 1807
 					</select>
1808 1808
 					entries
1809 1809
 				</label>
1810 1810
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
1811 1811
 			</div>
1812 1812
 		';
1813
-        return $entries_per_page_dropdown;
1814
-    }
1815
-
1816
-
1817
-
1818
-    /**
1819
-     *        _set_search_attributes
1820
-     *
1821
-     * @access        protected
1822
-     * @return        void
1823
-     */
1824
-    public function _set_search_attributes()
1825
-    {
1826
-        $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1827
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1828
-    }
1829
-
1830
-    /*** END LIST TABLE METHODS **/
1831
-    /*****************************/
1832
-    /**
1833
-     *        _add_registered_metaboxes
1834
-     *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1835
-     *
1836
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1837
-     * @access private
1838
-     * @return void
1839
-     */
1840
-    private function _add_registered_meta_boxes()
1841
-    {
1842
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1843
-        //we only add meta boxes if the page_route calls for it
1844
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1845
-            && is_array(
1846
-                    $this->_route_config['metaboxes']
1847
-            )
1848
-        ) {
1849
-            // this simply loops through the callbacks provided
1850
-            // and checks if there is a corresponding callback registered by the child
1851
-            // if there is then we go ahead and process the metabox loader.
1852
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1853
-                // first check for Closures
1854
-                if ($metabox_callback instanceof Closure) {
1855
-                    $result = $metabox_callback();
1856
-                } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1857
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1858
-                } else {
1859
-                    $result = call_user_func(array($this, &$metabox_callback));
1860
-                }
1861
-                if ($result === false) {
1862
-                    // user error msg
1863
-                    $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1864
-                    // developer error msg
1865
-                    $error_msg .= '||' . sprintf(
1866
-                                    __(
1867
-                                            '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.',
1868
-                                            'event_espresso'
1869
-                                    ),
1870
-                                    $metabox_callback
1871
-                            );
1872
-                    throw new EE_Error($error_msg);
1873
-                }
1874
-            }
1875
-        }
1876
-    }
1877
-
1878
-
1879
-
1880
-    /**
1881
-     * _add_screen_columns
1882
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1883
-     *
1884
-     * @access private
1885
-     * @return void
1886
-     */
1887
-    private function _add_screen_columns()
1888
-    {
1889
-        if (
1890
-                is_array($this->_route_config)
1891
-                && isset($this->_route_config['columns'])
1892
-                && is_array($this->_route_config['columns'])
1893
-                && count($this->_route_config['columns']) === 2
1894
-        ) {
1895
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1896
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1897
-            $screen_id = $this->_current_screen->id;
1898
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1899
-            $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1900
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1901
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
1902
-            $this->_template_args['screen'] = $this->_current_screen;
1903
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1904
-            //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1905
-            $this->_route_config['has_metaboxes'] = true;
1906
-        }
1907
-    }
1908
-
1909
-
1910
-
1911
-    /**********************************/
1912
-    /** GLOBALLY AVAILABLE METABOXES **/
1913
-    /**
1914
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1915
-     * loaded on.
1916
-     */
1917
-    private function _espresso_news_post_box()
1918
-    {
1919
-        $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1920
-        add_meta_box('espresso_news_post_box', $news_box_title, array(
1921
-                $this,
1922
-                'espresso_news_post_box',
1923
-        ), $this->_wp_page_slug, 'side');
1924
-    }
1925
-
1926
-
1927
-
1928
-    /**
1929
-     * Code for setting up espresso ratings request metabox.
1930
-     */
1931
-    protected function _espresso_ratings_request()
1932
-    {
1933
-        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1934
-            return '';
1935
-        }
1936
-        $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1937
-        add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1938
-                $this,
1939
-                'espresso_ratings_request',
1940
-        ), $this->_wp_page_slug, 'side');
1941
-    }
1942
-
1943
-
1944
-
1945
-    /**
1946
-     * Code for setting up espresso ratings request metabox content.
1947
-     */
1948
-    public function espresso_ratings_request()
1949
-    {
1950
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1951
-        EEH_Template::display_template($template_path, array());
1952
-    }
1953
-
1954
-
1955
-
1956
-    public static function cached_rss_display($rss_id, $url)
1957
-    {
1958
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1959
-        $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1960
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1961
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1962
-        $post = '</div>' . "\n";
1963
-        $cache_key = 'ee_rss_' . md5($rss_id);
1964
-        if (false != ($output = get_transient($cache_key))) {
1965
-            echo $pre . $output . $post;
1966
-            return true;
1967
-        }
1968
-        if ( ! $doing_ajax) {
1969
-            echo $pre . $loading . $post;
1970
-            return false;
1971
-        }
1972
-        ob_start();
1973
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1974
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1975
-        return true;
1976
-    }
1977
-
1978
-
1979
-
1980
-    public function espresso_news_post_box()
1981
-    {
1982
-        ?>
1813
+		return $entries_per_page_dropdown;
1814
+	}
1815
+
1816
+
1817
+
1818
+	/**
1819
+	 *        _set_search_attributes
1820
+	 *
1821
+	 * @access        protected
1822
+	 * @return        void
1823
+	 */
1824
+	public function _set_search_attributes()
1825
+	{
1826
+		$this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1827
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1828
+	}
1829
+
1830
+	/*** END LIST TABLE METHODS **/
1831
+	/*****************************/
1832
+	/**
1833
+	 *        _add_registered_metaboxes
1834
+	 *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1835
+	 *
1836
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1837
+	 * @access private
1838
+	 * @return void
1839
+	 */
1840
+	private function _add_registered_meta_boxes()
1841
+	{
1842
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1843
+		//we only add meta boxes if the page_route calls for it
1844
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1845
+			&& is_array(
1846
+					$this->_route_config['metaboxes']
1847
+			)
1848
+		) {
1849
+			// this simply loops through the callbacks provided
1850
+			// and checks if there is a corresponding callback registered by the child
1851
+			// if there is then we go ahead and process the metabox loader.
1852
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1853
+				// first check for Closures
1854
+				if ($metabox_callback instanceof Closure) {
1855
+					$result = $metabox_callback();
1856
+				} else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1857
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1858
+				} else {
1859
+					$result = call_user_func(array($this, &$metabox_callback));
1860
+				}
1861
+				if ($result === false) {
1862
+					// user error msg
1863
+					$error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1864
+					// developer error msg
1865
+					$error_msg .= '||' . sprintf(
1866
+									__(
1867
+											'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.',
1868
+											'event_espresso'
1869
+									),
1870
+									$metabox_callback
1871
+							);
1872
+					throw new EE_Error($error_msg);
1873
+				}
1874
+			}
1875
+		}
1876
+	}
1877
+
1878
+
1879
+
1880
+	/**
1881
+	 * _add_screen_columns
1882
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1883
+	 *
1884
+	 * @access private
1885
+	 * @return void
1886
+	 */
1887
+	private function _add_screen_columns()
1888
+	{
1889
+		if (
1890
+				is_array($this->_route_config)
1891
+				&& isset($this->_route_config['columns'])
1892
+				&& is_array($this->_route_config['columns'])
1893
+				&& count($this->_route_config['columns']) === 2
1894
+		) {
1895
+			add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1896
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1897
+			$screen_id = $this->_current_screen->id;
1898
+			$screen_columns = (int)get_user_option("screen_layout_$screen_id");
1899
+			$total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1900
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1901
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
1902
+			$this->_template_args['screen'] = $this->_current_screen;
1903
+			$this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1904
+			//finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1905
+			$this->_route_config['has_metaboxes'] = true;
1906
+		}
1907
+	}
1908
+
1909
+
1910
+
1911
+	/**********************************/
1912
+	/** GLOBALLY AVAILABLE METABOXES **/
1913
+	/**
1914
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1915
+	 * loaded on.
1916
+	 */
1917
+	private function _espresso_news_post_box()
1918
+	{
1919
+		$news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1920
+		add_meta_box('espresso_news_post_box', $news_box_title, array(
1921
+				$this,
1922
+				'espresso_news_post_box',
1923
+		), $this->_wp_page_slug, 'side');
1924
+	}
1925
+
1926
+
1927
+
1928
+	/**
1929
+	 * Code for setting up espresso ratings request metabox.
1930
+	 */
1931
+	protected function _espresso_ratings_request()
1932
+	{
1933
+		if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1934
+			return '';
1935
+		}
1936
+		$ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1937
+		add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1938
+				$this,
1939
+				'espresso_ratings_request',
1940
+		), $this->_wp_page_slug, 'side');
1941
+	}
1942
+
1943
+
1944
+
1945
+	/**
1946
+	 * Code for setting up espresso ratings request metabox content.
1947
+	 */
1948
+	public function espresso_ratings_request()
1949
+	{
1950
+		$template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1951
+		EEH_Template::display_template($template_path, array());
1952
+	}
1953
+
1954
+
1955
+
1956
+	public static function cached_rss_display($rss_id, $url)
1957
+	{
1958
+		$loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1959
+		$doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1960
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
1961
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1962
+		$post = '</div>' . "\n";
1963
+		$cache_key = 'ee_rss_' . md5($rss_id);
1964
+		if (false != ($output = get_transient($cache_key))) {
1965
+			echo $pre . $output . $post;
1966
+			return true;
1967
+		}
1968
+		if ( ! $doing_ajax) {
1969
+			echo $pre . $loading . $post;
1970
+			return false;
1971
+		}
1972
+		ob_start();
1973
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1974
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1975
+		return true;
1976
+	}
1977
+
1978
+
1979
+
1980
+	public function espresso_news_post_box()
1981
+	{
1982
+		?>
1983 1983
         <div class="padding">
1984 1984
             <div id="espresso_news_post_box_content" class="infolinks">
1985 1985
                 <?php
1986
-                // Get RSS Feed(s)
1987
-                $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1988
-                $url = urlencode($feed_url);
1989
-                self::cached_rss_display('espresso_news_post_box_content', $url);
1990
-                ?>
1986
+				// Get RSS Feed(s)
1987
+				$feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1988
+				$url = urlencode($feed_url);
1989
+				self::cached_rss_display('espresso_news_post_box_content', $url);
1990
+				?>
1991 1991
             </div>
1992 1992
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
1993 1993
         </div>
1994 1994
         <?php
1995
-    }
1996
-
1997
-
1998
-
1999
-    private function _espresso_links_post_box()
2000
-    {
2001
-        //Hiding until we actually have content to put in here...
2002
-        //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2003
-    }
2004
-
2005
-
2006
-
2007
-    public function espresso_links_post_box()
2008
-    {
2009
-        //Hiding until we actually have content to put in here...
2010
-        //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2011
-        //EEH_Template::display_template( $templatepath );
2012
-    }
2013
-
2014
-
2015
-
2016
-    protected function _espresso_sponsors_post_box()
2017
-    {
2018
-        $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2019
-        if ($show_sponsors) {
2020
-            add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2021
-        }
2022
-    }
2023
-
2024
-
2025
-
2026
-    public function espresso_sponsors_post_box()
2027
-    {
2028
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2029
-        EEH_Template::display_template($templatepath);
2030
-    }
2031
-
2032
-
2033
-
2034
-    private function _publish_post_box()
2035
-    {
2036
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2037
-        //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2038
-        if ( ! empty($this->_labels['publishbox'])) {
2039
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2040
-        } else {
2041
-            $box_label = __('Publish', 'event_espresso');
2042
-        }
2043
-        $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2044
-        add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2045
-    }
2046
-
2047
-
2048
-
2049
-    public function editor_overview()
2050
-    {
2051
-        //if we have extra content set let's add it in if not make sure its empty
2052
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2053
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2054
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2055
-    }
2056
-
2057
-
2058
-    /** end of globally available metaboxes section **/
2059
-    /*************************************************/
2060
-    /**
2061
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2062
-     * protected method.
2063
-     *
2064
-     * @see   $this->_set_publish_post_box_vars for param details
2065
-     * @since 4.6.0
2066
-     */
2067
-    public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2068
-    {
2069
-        $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2070
-    }
2071
-
2072
-
2073
-
2074
-    /**
2075
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2076
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2077
-     * save, and save and close buttons to work properly, then you will want to include a
2078
-     * values for the name and id arguments.
2079
-     *
2080
-     * @todo  Add in validation for name/id arguments.
2081
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2082
-     * @param    int     $id                      id attached to the item published
2083
-     * @param    string  $delete                  page route callback for the delete action
2084
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2085
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2086
-     * @throws \EE_Error
2087
-     */
2088
-    protected function _set_publish_post_box_vars(
2089
-            $name = '',
2090
-            $id = 0,
2091
-            $delete = '',
2092
-            $save_close_redirect_URL = '',
2093
-            $both_btns = true
2094
-    ) {
2095
-        // if Save & Close, use a custom redirect URL or default to the main page?
2096
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2097
-        // create the Save & Close and Save buttons
2098
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2099
-        //if we have extra content set let's add it in if not make sure its empty
2100
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2101
-        if ($delete && ! empty($id)) {
2102
-            //make sure we have a default if just true is sent.
2103
-            $delete = ! empty($delete) ? $delete : 'delete';
2104
-            $delete_link_args = array($name => $id);
2105
-            $delete = $this->get_action_link_or_button(
2106
-                    $delete,
2107
-                    $delete,
2108
-                    $delete_link_args,
2109
-                    'submitdelete deletion',
2110
-                    '',
2111
-                    false
2112
-            );
2113
-        }
2114
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2115
-        if ( ! empty($name) && ! empty($id)) {
2116
-            $hidden_field_arr[$name] = array(
2117
-                    'type'  => 'hidden',
2118
-                    'value' => $id,
2119
-            );
2120
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2121
-        } else {
2122
-            $hf = '';
2123
-        }
2124
-        // add hidden field
2125
-        $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2126
-    }
2127
-
2128
-
2129
-
2130
-    /**
2131
-     *        displays an error message to ppl who have javascript disabled
2132
-     *
2133
-     * @access        private
2134
-     * @return        string
2135
-     */
2136
-    private function _display_no_javascript_warning()
2137
-    {
2138
-        ?>
1995
+	}
1996
+
1997
+
1998
+
1999
+	private function _espresso_links_post_box()
2000
+	{
2001
+		//Hiding until we actually have content to put in here...
2002
+		//add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2003
+	}
2004
+
2005
+
2006
+
2007
+	public function espresso_links_post_box()
2008
+	{
2009
+		//Hiding until we actually have content to put in here...
2010
+		//$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2011
+		//EEH_Template::display_template( $templatepath );
2012
+	}
2013
+
2014
+
2015
+
2016
+	protected function _espresso_sponsors_post_box()
2017
+	{
2018
+		$show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2019
+		if ($show_sponsors) {
2020
+			add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2021
+		}
2022
+	}
2023
+
2024
+
2025
+
2026
+	public function espresso_sponsors_post_box()
2027
+	{
2028
+		$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2029
+		EEH_Template::display_template($templatepath);
2030
+	}
2031
+
2032
+
2033
+
2034
+	private function _publish_post_box()
2035
+	{
2036
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2037
+		//if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2038
+		if ( ! empty($this->_labels['publishbox'])) {
2039
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2040
+		} else {
2041
+			$box_label = __('Publish', 'event_espresso');
2042
+		}
2043
+		$box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2044
+		add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2045
+	}
2046
+
2047
+
2048
+
2049
+	public function editor_overview()
2050
+	{
2051
+		//if we have extra content set let's add it in if not make sure its empty
2052
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2053
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2054
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2055
+	}
2056
+
2057
+
2058
+	/** end of globally available metaboxes section **/
2059
+	/*************************************************/
2060
+	/**
2061
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2062
+	 * protected method.
2063
+	 *
2064
+	 * @see   $this->_set_publish_post_box_vars for param details
2065
+	 * @since 4.6.0
2066
+	 */
2067
+	public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2068
+	{
2069
+		$this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2070
+	}
2071
+
2072
+
2073
+
2074
+	/**
2075
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2076
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2077
+	 * save, and save and close buttons to work properly, then you will want to include a
2078
+	 * values for the name and id arguments.
2079
+	 *
2080
+	 * @todo  Add in validation for name/id arguments.
2081
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2082
+	 * @param    int     $id                      id attached to the item published
2083
+	 * @param    string  $delete                  page route callback for the delete action
2084
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2085
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2086
+	 * @throws \EE_Error
2087
+	 */
2088
+	protected function _set_publish_post_box_vars(
2089
+			$name = '',
2090
+			$id = 0,
2091
+			$delete = '',
2092
+			$save_close_redirect_URL = '',
2093
+			$both_btns = true
2094
+	) {
2095
+		// if Save & Close, use a custom redirect URL or default to the main page?
2096
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2097
+		// create the Save & Close and Save buttons
2098
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2099
+		//if we have extra content set let's add it in if not make sure its empty
2100
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2101
+		if ($delete && ! empty($id)) {
2102
+			//make sure we have a default if just true is sent.
2103
+			$delete = ! empty($delete) ? $delete : 'delete';
2104
+			$delete_link_args = array($name => $id);
2105
+			$delete = $this->get_action_link_or_button(
2106
+					$delete,
2107
+					$delete,
2108
+					$delete_link_args,
2109
+					'submitdelete deletion',
2110
+					'',
2111
+					false
2112
+			);
2113
+		}
2114
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2115
+		if ( ! empty($name) && ! empty($id)) {
2116
+			$hidden_field_arr[$name] = array(
2117
+					'type'  => 'hidden',
2118
+					'value' => $id,
2119
+			);
2120
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2121
+		} else {
2122
+			$hf = '';
2123
+		}
2124
+		// add hidden field
2125
+		$this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2126
+	}
2127
+
2128
+
2129
+
2130
+	/**
2131
+	 *        displays an error message to ppl who have javascript disabled
2132
+	 *
2133
+	 * @access        private
2134
+	 * @return        string
2135
+	 */
2136
+	private function _display_no_javascript_warning()
2137
+	{
2138
+		?>
2139 2139
         <noscript>
2140 2140
             <div id="no-js-message" class="error">
2141 2141
                 <p style="font-size:1.3em;">
@@ -2145,1267 +2145,1267 @@  discard block
 block discarded – undo
2145 2145
             </div>
2146 2146
         </noscript>
2147 2147
         <?php
2148
-    }
2148
+	}
2149 2149
 
2150 2150
 
2151 2151
 
2152
-    /**
2153
-     *        displays espresso success and/or error notices
2154
-     *
2155
-     * @access        private
2156
-     * @return        string
2157
-     */
2158
-    private function _display_espresso_notices()
2159
-    {
2160
-        $notices = $this->_get_transient(true);
2161
-        echo stripslashes($notices);
2162
-    }
2152
+	/**
2153
+	 *        displays espresso success and/or error notices
2154
+	 *
2155
+	 * @access        private
2156
+	 * @return        string
2157
+	 */
2158
+	private function _display_espresso_notices()
2159
+	{
2160
+		$notices = $this->_get_transient(true);
2161
+		echo stripslashes($notices);
2162
+	}
2163 2163
 
2164 2164
 
2165 2165
 
2166
-    /**
2167
-     *        spinny things pacify the masses
2168
-     *
2169
-     * @access private
2170
-     * @return string
2171
-     */
2172
-    protected function _add_admin_page_ajax_loading_img()
2173
-    {
2174
-        ?>
2166
+	/**
2167
+	 *        spinny things pacify the masses
2168
+	 *
2169
+	 * @access private
2170
+	 * @return string
2171
+	 */
2172
+	protected function _add_admin_page_ajax_loading_img()
2173
+	{
2174
+		?>
2175 2175
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2176 2176
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e('loading...', 'event_espresso'); ?></span>
2177 2177
         </div>
2178 2178
         <?php
2179
-    }
2179
+	}
2180 2180
 
2181 2181
 
2182 2182
 
2183
-    /**
2184
-     *        add admin page overlay for modal boxes
2185
-     *
2186
-     * @access private
2187
-     * @return string
2188
-     */
2189
-    protected function _add_admin_page_overlay()
2190
-    {
2191
-        ?>
2183
+	/**
2184
+	 *        add admin page overlay for modal boxes
2185
+	 *
2186
+	 * @access private
2187
+	 * @return string
2188
+	 */
2189
+	protected function _add_admin_page_overlay()
2190
+	{
2191
+		?>
2192 2192
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2193 2193
         <?php
2194
-    }
2195
-
2196
-
2197
-
2198
-    /**
2199
-     * facade for add_meta_box
2200
-     *
2201
-     * @param string  $action        where the metabox get's displayed
2202
-     * @param string  $title         Title of Metabox (output in metabox header)
2203
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2204
-     * @param array   $callback_args an array of args supplied for the metabox
2205
-     * @param string  $column        what metabox column
2206
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2207
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2208
-     */
2209
-    public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2210
-    {
2211
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2212
-        //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.
2213
-        if (empty($callback_args) && $create_func) {
2214
-            $callback_args = array(
2215
-                    'template_path' => $this->_template_path,
2216
-                    'template_args' => $this->_template_args,
2217
-            );
2218
-        }
2219
-        //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)
2220
-        $call_back_func = $create_func ? create_function('$post, $metabox',
2221
-                'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2222
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2223
-    }
2224
-
2225
-
2226
-
2227
-    /**
2228
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2229
-     *
2230
-     * @return [type] [description]
2231
-     */
2232
-    public function display_admin_page_with_metabox_columns()
2233
-    {
2234
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2235
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2236
-        //the final wrapper
2237
-        $this->admin_page_wrapper();
2238
-    }
2239
-
2240
-
2241
-
2242
-    /**
2243
-     *        generates  HTML wrapper for an admin details page
2244
-     *
2245
-     * @access public
2246
-     * @return void
2247
-     */
2248
-    public function display_admin_page_with_sidebar()
2249
-    {
2250
-        $this->_display_admin_page(true);
2251
-    }
2252
-
2253
-
2254
-
2255
-    /**
2256
-     *        generates  HTML wrapper for an admin details page (except no sidebar)
2257
-     *
2258
-     * @access public
2259
-     * @return void
2260
-     */
2261
-    public function display_admin_page_with_no_sidebar()
2262
-    {
2263
-        $this->_display_admin_page();
2264
-    }
2265
-
2266
-
2267
-
2268
-    /**
2269
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2270
-     *
2271
-     * @access public
2272
-     * @return void
2273
-     */
2274
-    public function display_about_admin_page()
2275
-    {
2276
-        $this->_display_admin_page(false, true);
2277
-    }
2278
-
2279
-
2280
-
2281
-    /**
2282
-     * display_admin_page
2283
-     * contains the code for actually displaying an admin page
2284
-     *
2285
-     * @access private
2286
-     * @param  boolean $sidebar true with sidebar, false without
2287
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2288
-     * @return void
2289
-     */
2290
-    private function _display_admin_page($sidebar = false, $about = false)
2291
-    {
2292
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2293
-        //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2294
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2295
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2296
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2297
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2298
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2299
-                ? 'poststuff'
2300
-                : 'espresso-default-admin';
2301
-        $template_path = $sidebar
2302
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2303
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2304
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2305
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2306
-        }
2307
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2308
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2309
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2310
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2311
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2312
-        // the final template wrapper
2313
-        $this->admin_page_wrapper($about);
2314
-    }
2315
-
2316
-
2317
-
2318
-    /**
2319
-     * This is used to display caf preview pages.
2320
-     *
2321
-     * @since 4.3.2
2322
-     * @param string $utm_campaign_source what is the key used for google analytics link
2323
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2324
-     * @return void
2325
-     * @throws \EE_Error
2326
-     */
2327
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2328
-    {
2329
-        //let's generate a default preview action button if there isn't one already present.
2330
-        $this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2331
-        $buy_now_url = add_query_arg(
2332
-                array(
2333
-                        'ee_ver'       => 'ee4',
2334
-                        'utm_source'   => 'ee4_plugin_admin',
2335
-                        'utm_medium'   => 'link',
2336
-                        'utm_campaign' => $utm_campaign_source,
2337
-                        'utm_content'  => 'buy_now_button',
2338
-                ),
2339
-                'http://eventespresso.com/pricing/'
2340
-        );
2341
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2342
-                ? $this->get_action_link_or_button(
2343
-                        '',
2344
-                        'buy_now',
2345
-                        array(),
2346
-                        'button-primary button-large',
2347
-                        $buy_now_url,
2348
-                        true
2349
-                )
2350
-                : $this->_template_args['preview_action_button'];
2351
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2352
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2353
-                $template_path,
2354
-                $this->_template_args,
2355
-                true
2356
-        );
2357
-        $this->_display_admin_page($display_sidebar);
2358
-    }
2359
-
2360
-
2361
-
2362
-    /**
2363
-     * display_admin_list_table_page_with_sidebar
2364
-     * generates HTML wrapper for an admin_page with list_table
2365
-     *
2366
-     * @access public
2367
-     * @return void
2368
-     */
2369
-    public function display_admin_list_table_page_with_sidebar()
2370
-    {
2371
-        $this->_display_admin_list_table_page(true);
2372
-    }
2373
-
2374
-
2375
-
2376
-    /**
2377
-     * display_admin_list_table_page_with_no_sidebar
2378
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2379
-     *
2380
-     * @access public
2381
-     * @return void
2382
-     */
2383
-    public function display_admin_list_table_page_with_no_sidebar()
2384
-    {
2385
-        $this->_display_admin_list_table_page();
2386
-    }
2387
-
2388
-
2389
-
2390
-    /**
2391
-     * generates html wrapper for an admin_list_table page
2392
-     *
2393
-     * @access private
2394
-     * @param boolean $sidebar whether to display with sidebar or not.
2395
-     * @return void
2396
-     */
2397
-    private function _display_admin_list_table_page($sidebar = false)
2398
-    {
2399
-        //setup search attributes
2400
-        $this->_set_search_attributes();
2401
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2402
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2403
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2404
-                ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2405
-                : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2406
-        $this->_template_args['list_table'] = $this->_list_table_object;
2407
-        $this->_template_args['current_route'] = $this->_req_action;
2408
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2409
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2410
-        if ( ! empty($ajax_sorting_callback)) {
2411
-            $sortable_list_table_form_fields = wp_nonce_field(
2412
-                    $ajax_sorting_callback . '_nonce',
2413
-                    $ajax_sorting_callback . '_nonce',
2414
-                    false,
2415
-                    false
2416
-            );
2417
-            //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2418
-            //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2419
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2420
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2421
-        } else {
2422
-            $sortable_list_table_form_fields = '';
2423
-        }
2424
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2425
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2426
-        $nonce_ref = $this->_req_action . '_nonce';
2427
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2428
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2429
-        //display message about search results?
2430
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2431
-                ? '<p class="ee-search-results">' . sprintf(
2432
-                        esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2433
-                        trim($this->_req_data['s'], '%')
2434
-                ) . '</p>'
2435
-                : '';
2436
-        // filter before_list_table template arg
2437
-        $this->_template_args['before_list_table'] = apply_filters(
2438
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2439
-            $this->_template_args['before_list_table'],
2440
-            $this->page_slug,
2441
-            $this->_req_data,
2442
-            $this->_req_action
2443
-        );
2444
-        // convert to array and filter again
2445
-        // arrays are easier to inject new items in a specific location,
2446
-        // but would not be backwards compatible, so we have to add a new filter
2447
-        $this->_template_args['before_list_table'] = implode(
2448
-            " \n",
2449
-            (array) apply_filters(
2450
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2451
-                (array) $this->_template_args['before_list_table'],
2452
-                $this->page_slug,
2453
-                $this->_req_data,
2454
-                $this->_req_action
2455
-            )
2456
-        );
2457
-        // filter after_list_table template arg
2458
-        $this->_template_args['after_list_table'] = apply_filters(
2459
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2460
-            $this->_template_args['after_list_table'],
2461
-            $this->page_slug,
2462
-            $this->_req_data,
2463
-            $this->_req_action
2464
-        );
2465
-        // convert to array and filter again
2466
-        // arrays are easier to inject new items in a specific location,
2467
-        // but would not be backwards compatible, so we have to add a new filter
2468
-        $this->_template_args['after_list_table'] = implode(
2469
-            " \n",
2470
-            (array) apply_filters(
2471
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2472
-                (array) $this->_template_args['after_list_table'],
2473
-                $this->page_slug,
2474
-                $this->_req_data,
2475
-                $this->_req_action
2476
-            )
2477
-        );
2478
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2479
-                $template_path,
2480
-                $this->_template_args,
2481
-                true
2482
-        );
2483
-        // the final template wrapper
2484
-        if ($sidebar) {
2485
-            $this->display_admin_page_with_sidebar();
2486
-        } else {
2487
-            $this->display_admin_page_with_no_sidebar();
2488
-        }
2489
-    }
2490
-
2491
-
2492
-
2493
-    /**
2494
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2495
-     * $items are expected in an array in the following format:
2496
-     * $legend_items = array(
2497
-     *        'item_id' => array(
2498
-     *            'icon' => 'http://url_to_icon_being_described.png',
2499
-     *            'desc' => __('localized description of item');
2500
-     *        )
2501
-     * );
2502
-     *
2503
-     * @param  array $items see above for format of array
2504
-     * @return string        html string of legend
2505
-     */
2506
-    protected function _display_legend($items)
2507
-    {
2508
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2509
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2510
-        return EEH_Template::display_template($legend_template, $this->_template_args, true);
2511
-    }
2512
-
2513
-
2514
-    /**
2515
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2516
-     * The returned json object is created from an array in the following format:
2517
-     * array(
2518
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2519
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
2520
-     *  'notices' => '', // - contains any EE_Error formatted notices
2521
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2522
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2523
-     *  specific template args that might be included in here)
2524
-     * )
2525
-     * The json object is populated by whatever is set in the $_template_args property.
2526
-     *
2527
-     * @param bool  $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2528
-     * @param array $notices_arguments  Use this to pass any additional args on to the _process_notices.
2529
-     * @return void
2530
-     */
2531
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
2532
-    {
2533
-        //make sure any EE_Error notices have been handled.
2534
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
2535
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2536
-        unset($this->_template_args['data']);
2537
-        $json = array(
2538
-                'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2539
-                'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2540
-                'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2541
-                'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2542
-                'notices'   => EE_Error::get_notices(),
2543
-                'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2544
-                'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2545
-                'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2546
-        );
2547
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2548
-        if (null === error_get_last() || ! headers_sent()) {
2549
-            header('Content-Type: application/json; charset=UTF-8');
2550
-        }
2551
-        echo wp_json_encode($json);
2552
-
2553
-        exit();
2554
-    }
2555
-
2556
-
2557
-
2558
-    /**
2559
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2560
-     *
2561
-     * @return void
2562
-     * @throws EE_Error
2563
-     */
2564
-    public function return_json()
2565
-    {
2566
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2567
-            $this->_return_json();
2568
-        } else {
2569
-            throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2570
-        }
2571
-    }
2572
-
2573
-
2574
-
2575
-    /**
2576
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2577
-     *
2578
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2579
-     * @access   public
2580
-     */
2581
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
2582
-    {
2583
-        $this->_hook_obj = $hook_obj;
2584
-    }
2585
-
2586
-
2587
-
2588
-    /**
2589
-     *        generates  HTML wrapper with Tabbed nav for an admin page
2590
-     *
2591
-     * @access public
2592
-     * @param  boolean $about whether to use the special about page wrapper or default.
2593
-     * @return void
2594
-     */
2595
-    public function admin_page_wrapper($about = false)
2596
-    {
2597
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2598
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
2599
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2600
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2601
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2602
-                isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2603
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2604
-                isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2605
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2606
-        // load settings page wrapper template
2607
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2608
-        //about page?
2609
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2610
-        if (defined('DOING_AJAX')) {
2611
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2612
-            $this->_return_json();
2613
-        } else {
2614
-            EEH_Template::display_template($template_path, $this->_template_args);
2615
-        }
2616
-    }
2617
-
2618
-
2619
-
2620
-    /**
2621
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2622
-     *
2623
-     * @return string html
2624
-     */
2625
-    protected function _get_main_nav_tabs()
2626
-    {
2627
-        //let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2628
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2629
-    }
2630
-
2631
-
2632
-
2633
-    /**
2634
-     *        sort nav tabs
2635
-     *
2636
-     * @access public
2637
-     * @param $a
2638
-     * @param $b
2639
-     * @return int
2640
-     */
2641
-    private function _sort_nav_tabs($a, $b)
2642
-    {
2643
-        if ($a['order'] == $b['order']) {
2644
-            return 0;
2645
-        }
2646
-        return ($a['order'] < $b['order']) ? -1 : 1;
2647
-    }
2648
-
2649
-
2650
-
2651
-    /**
2652
-     *    generates HTML for the forms used on admin pages
2653
-     *
2654
-     * @access protected
2655
-     * @param    array $input_vars - array of input field details
2656
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2657
-     * @return string
2658
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2659
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2660
-     */
2661
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2662
-    {
2663
-        $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2664
-        return $content;
2665
-    }
2666
-
2667
-
2668
-
2669
-    /**
2670
-     * generates the "Save" and "Save & Close" buttons for edit forms
2671
-     *
2672
-     * @access protected
2673
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2674
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2675
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2676
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2677
-     */
2678
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2679
-    {
2680
-        //make sure $text and $actions are in an array
2681
-        $text = (array)$text;
2682
-        $actions = (array)$actions;
2683
-        $referrer_url = empty($referrer) ? '' : $referrer;
2684
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2685
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2686
-        $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2687
-        $default_names = array('save', 'save_and_close');
2688
-        //add in a hidden index for the current page (so save and close redirects properly)
2689
-        $this->_template_args['save_buttons'] = $referrer_url;
2690
-        foreach ($button_text as $key => $button) {
2691
-            $ref = $default_names[$key];
2692
-            $id = $this->_current_view . '_' . $ref;
2693
-            $name = ! empty($actions) ? $actions[$key] : $ref;
2694
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2695
-            if ( ! $both) {
2696
-                break;
2697
-            }
2698
-        }
2699
-    }
2700
-
2701
-
2702
-
2703
-    /**
2704
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2705
-     *
2706
-     * @see   $this->_set_add_edit_form_tags() for details on params
2707
-     * @since 4.6.0
2708
-     * @param string $route
2709
-     * @param array  $additional_hidden_fields
2710
-     */
2711
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2712
-    {
2713
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2714
-    }
2715
-
2716
-
2717
-
2718
-    /**
2719
-     * set form open and close tags on add/edit pages.
2720
-     *
2721
-     * @access protected
2722
-     * @param string $route                    the route you want the form to direct to
2723
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2724
-     * @return void
2725
-     */
2726
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2727
-    {
2728
-        if (empty($route)) {
2729
-            $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2730
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2731
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2732
-        }
2733
-        // open form
2734
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2735
-        // add nonce
2736
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2737
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2738
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2739
-        // add REQUIRED form action
2740
-        $hidden_fields = array(
2741
-                'action' => array('type' => 'hidden', 'value' => $route),
2742
-        );
2743
-        // merge arrays
2744
-        $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2745
-        // generate form fields
2746
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2747
-        // add fields to form
2748
-        foreach ((array)$form_fields as $field_name => $form_field) {
2749
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2750
-        }
2751
-        // close form
2752
-        $this->_template_args['after_admin_page_content'] = '</form>';
2753
-    }
2754
-
2755
-
2756
-
2757
-    /**
2758
-     * Public Wrapper for _redirect_after_action() method since its
2759
-     * discovered it would be useful for external code to have access.
2760
-     *
2761
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
2762
-     * @since 4.5.0
2763
-     */
2764
-    public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2765
-    {
2766
-        $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2767
-    }
2768
-
2769
-
2770
-
2771
-    /**
2772
-     *    _redirect_after_action
2773
-     *
2774
-     * @param int    $success            - whether success was for two or more records, or just one, or none
2775
-     * @param string $what               - what the action was performed on
2776
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
2777
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2778
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2779
-     * @access protected
2780
-     * @return void
2781
-     */
2782
-    protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2783
-    {
2784
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2785
-        //class name for actions/filters.
2786
-        $classname = get_class($this);
2787
-        //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2788
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2789
-        $notices = EE_Error::get_notices(false);
2790
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
2791
-        if ( ! $override_overwrite || ! empty($notices['errors'])) {
2792
-            EE_Error::overwrite_success();
2793
-        }
2794
-        if ( ! empty($what) && ! empty($action_desc)) {
2795
-            // how many records affected ? more than one record ? or just one ?
2796
-            if ($success > 1 && empty($notices['errors'])) {
2797
-                // set plural msg
2798
-                EE_Error::add_success(
2799
-                        sprintf(
2800
-                                __('The "%s" have been successfully %s.', 'event_espresso'),
2801
-                                $what,
2802
-                                $action_desc
2803
-                        ),
2804
-                        __FILE__, __FUNCTION__, __LINE__
2805
-                );
2806
-            } else if ($success == 1 && empty($notices['errors'])) {
2807
-                // set singular msg
2808
-                EE_Error::add_success(
2809
-                        sprintf(
2810
-                                __('The "%s" has been successfully %s.', 'event_espresso'),
2811
-                                $what,
2812
-                                $action_desc
2813
-                        ),
2814
-                        __FILE__, __FUNCTION__, __LINE__
2815
-                );
2816
-            }
2817
-        }
2818
-        // check that $query_args isn't something crazy
2819
-        if ( ! is_array($query_args)) {
2820
-            $query_args = array();
2821
-        }
2822
-        /**
2823
-         * Allow injecting actions before the query_args are modified for possible different
2824
-         * redirections on save and close actions
2825
-         *
2826
-         * @since 4.2.0
2827
-         * @param array $query_args       The original query_args array coming into the
2828
-         *                                method.
2829
-         */
2830
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2831
-        //calculate where we're going (if we have a "save and close" button pushed)
2832
-        if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2833
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2834
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2835
-            // regenerate query args array from referrer URL
2836
-            parse_str($parsed_url['query'], $query_args);
2837
-            // correct page and action will be in the query args now
2838
-            $redirect_url = admin_url('admin.php');
2839
-        }
2840
-        //merge any default query_args set in _default_route_query_args property
2841
-        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2842
-            $args_to_merge = array();
2843
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
2844
-                //is there a wp_referer array in our _default_route_query_args property?
2845
-                if ($query_param == 'wp_referer') {
2846
-                    $query_value = (array)$query_value;
2847
-                    foreach ($query_value as $reference => $value) {
2848
-                        if (strpos($reference, 'nonce') !== false) {
2849
-                            continue;
2850
-                        }
2851
-                        //finally we will override any arguments in the referer with
2852
-                        //what might be set on the _default_route_query_args array.
2853
-                        if (isset($this->_default_route_query_args[$reference])) {
2854
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2855
-                        } else {
2856
-                            $args_to_merge[$reference] = urlencode($value);
2857
-                        }
2858
-                    }
2859
-                    continue;
2860
-                }
2861
-                $args_to_merge[$query_param] = $query_value;
2862
-            }
2863
-            //now let's merge these arguments but override with what was specifically sent in to the
2864
-            //redirect.
2865
-            $query_args = array_merge($args_to_merge, $query_args);
2866
-        }
2867
-        $this->_process_notices($query_args);
2868
-        // generate redirect url
2869
-        // if redirecting to anything other than the main page, add a nonce
2870
-        if (isset($query_args['action'])) {
2871
-            // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2872
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2873
-        }
2874
-        //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2875
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2876
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2877
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2878
-        if (defined('DOING_AJAX')) {
2879
-            $default_data = array(
2880
-                    'close'        => true,
2881
-                    'redirect_url' => $redirect_url,
2882
-                    'where'        => 'main',
2883
-                    'what'         => 'append',
2884
-            );
2885
-            $this->_template_args['success'] = $success;
2886
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2887
-            $this->_return_json();
2888
-        }
2889
-        wp_safe_redirect($redirect_url);
2890
-        exit();
2891
-    }
2892
-
2893
-
2894
-
2895
-    /**
2896
-     * process any notices before redirecting (or returning ajax request)
2897
-     * This method sets the $this->_template_args['notices'] attribute;
2898
-     *
2899
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
2900
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2901
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2902
-     * @return void
2903
-     */
2904
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2905
-    {
2906
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
2907
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2908
-            $notices = EE_Error::get_notices(false);
2909
-            if (empty($this->_template_args['success'])) {
2910
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2911
-            }
2912
-            if (empty($this->_template_args['errors'])) {
2913
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2914
-            }
2915
-            if (empty($this->_template_args['attention'])) {
2916
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2917
-            }
2918
-        }
2919
-        $this->_template_args['notices'] = EE_Error::get_notices();
2920
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2921
-        if ( ! defined('DOING_AJAX') || $sticky_notices) {
2922
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
2923
-            $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2924
-        }
2925
-    }
2926
-
2927
-
2928
-
2929
-    /**
2930
-     * get_action_link_or_button
2931
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
2932
-     *
2933
-     * @param string $action        use this to indicate which action the url is generated with.
2934
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2935
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2936
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2937
-     * @param string $base_url      If this is not provided
2938
-     *                              the _admin_base_url will be used as the default for the button base_url.
2939
-     *                              Otherwise this value will be used.
2940
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2941
-     * @return string
2942
-     * @throws \EE_Error
2943
-     */
2944
-    public function get_action_link_or_button(
2945
-            $action,
2946
-            $type = 'add',
2947
-            $extra_request = array(),
2948
-            $class = 'button-primary',
2949
-            $base_url = '',
2950
-            $exclude_nonce = false
2951
-    ) {
2952
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2953
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2954
-            throw new EE_Error(
2955
-                    sprintf(
2956
-                            __(
2957
-                                    'There is no page route for given action for the button.  This action was given: %s',
2958
-                                    'event_espresso'
2959
-                            ),
2960
-                            $action
2961
-                    )
2962
-            );
2963
-        }
2964
-        if ( ! isset($this->_labels['buttons'][$type])) {
2965
-            throw new EE_Error(
2966
-                    sprintf(
2967
-                            __(
2968
-                                    'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2969
-                                    'event_espresso'
2970
-                            ),
2971
-                            $type
2972
-                    )
2973
-            );
2974
-        }
2975
-        //finally check user access for this button.
2976
-        $has_access = $this->check_user_access($action, true);
2977
-        if ( ! $has_access) {
2978
-            return '';
2979
-        }
2980
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2981
-        $query_args = array(
2982
-                'action' => $action,
2983
-        );
2984
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2985
-        if ( ! empty($extra_request)) {
2986
-            $query_args = array_merge($extra_request, $query_args);
2987
-        }
2988
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2989
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2990
-    }
2991
-
2992
-
2993
-
2994
-    /**
2995
-     * _per_page_screen_option
2996
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
2997
-     *
2998
-     * @return void
2999
-     */
3000
-    protected function _per_page_screen_option()
3001
-    {
3002
-        $option = 'per_page';
3003
-        $args = array(
3004
-                'label'   => $this->_admin_page_title,
3005
-                'default' => 10,
3006
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3007
-        );
3008
-        //ONLY add the screen option if the user has access to it.
3009
-        if ($this->check_user_access($this->_current_view, true)) {
3010
-            add_screen_option($option, $args);
3011
-        }
3012
-    }
3013
-
3014
-
3015
-
3016
-    /**
3017
-     * set_per_page_screen_option
3018
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3019
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3020
-     *
3021
-     * @access private
3022
-     * @return void
3023
-     */
3024
-    private function _set_per_page_screen_options()
3025
-    {
3026
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3027
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3028
-            if ( ! $user = wp_get_current_user()) {
3029
-                return;
3030
-            }
3031
-            $option = $_POST['wp_screen_options']['option'];
3032
-            $value = $_POST['wp_screen_options']['value'];
3033
-            if ($option != sanitize_key($option)) {
3034
-                return;
3035
-            }
3036
-            $map_option = $option;
3037
-            $option = str_replace('-', '_', $option);
3038
-            switch ($map_option) {
3039
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3040
-                    $value = (int)$value;
3041
-                    if ($value < 1 || $value > 999) {
3042
-                        return;
3043
-                    }
3044
-                    break;
3045
-                default:
3046
-                    $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3047
-                    if (false === $value) {
3048
-                        return;
3049
-                    }
3050
-                    break;
3051
-            }
3052
-            update_user_meta($user->ID, $option, $value);
3053
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3054
-            exit;
3055
-        }
3056
-    }
3057
-
3058
-
3059
-
3060
-    /**
3061
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3062
-     *
3063
-     * @param array $data array that will be assigned to template args.
3064
-     */
3065
-    public function set_template_args($data)
3066
-    {
3067
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3068
-    }
3069
-
3070
-
3071
-
3072
-    /**
3073
-     * This makes available the WP transient system for temporarily moving data between routes
3074
-     *
3075
-     * @access protected
3076
-     * @param string $route             the route that should receive the transient
3077
-     * @param array  $data              the data that gets sent
3078
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3079
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3080
-     * @return void
3081
-     */
3082
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3083
-    {
3084
-        $user_id = get_current_user_id();
3085
-        if ( ! $skip_route_verify) {
3086
-            $this->_verify_route($route);
3087
-        }
3088
-        //now let's set the string for what kind of transient we're setting
3089
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3090
-        $data = $notices ? array('notices' => $data) : $data;
3091
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3092
-        $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3093
-        if ($existing) {
3094
-            $data = array_merge((array)$data, (array)$existing);
3095
-        }
3096
-        if (is_multisite() && is_network_admin()) {
3097
-            set_site_transient($transient, $data, 8);
3098
-        } else {
3099
-            set_transient($transient, $data, 8);
3100
-        }
3101
-    }
3102
-
3103
-
3104
-
3105
-    /**
3106
-     * this retrieves the temporary transient that has been set for moving data between routes.
3107
-     *
3108
-     * @param bool $notices true we get notices transient. False we just return normal route transient
3109
-     * @return mixed data
3110
-     */
3111
-    protected function _get_transient($notices = false, $route = false)
3112
-    {
3113
-        $user_id = get_current_user_id();
3114
-        $route = ! $route ? $this->_req_action : $route;
3115
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3116
-        $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3117
-        //delete transient after retrieval (just in case it hasn't expired);
3118
-        if (is_multisite() && is_network_admin()) {
3119
-            delete_site_transient($transient);
3120
-        } else {
3121
-            delete_transient($transient);
3122
-        }
3123
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3124
-    }
3125
-
3126
-
3127
-
3128
-    /**
3129
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3130
-     * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3131
-     *
3132
-     * @return void
3133
-     */
3134
-    protected function _transient_garbage_collection()
3135
-    {
3136
-        global $wpdb;
3137
-        //retrieve all existing transients
3138
-        $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3139
-        if ($results = $wpdb->get_results($query)) {
3140
-            foreach ($results as $result) {
3141
-                $transient = str_replace('_transient_', '', $result->option_name);
3142
-                get_transient($transient);
3143
-                if (is_multisite() && is_network_admin()) {
3144
-                    get_site_transient($transient);
3145
-                }
3146
-            }
3147
-        }
3148
-    }
3149
-
3150
-
3151
-
3152
-    /**
3153
-     * get_view
3154
-     *
3155
-     * @access public
3156
-     * @return string content of _view property
3157
-     */
3158
-    public function get_view()
3159
-    {
3160
-        return $this->_view;
3161
-    }
3162
-
3163
-
3164
-
3165
-    /**
3166
-     * getter for the protected $_views property
3167
-     *
3168
-     * @return array
3169
-     */
3170
-    public function get_views()
3171
-    {
3172
-        return $this->_views;
3173
-    }
3174
-
3175
-
3176
-
3177
-    /**
3178
-     * get_current_page
3179
-     *
3180
-     * @access public
3181
-     * @return string _current_page property value
3182
-     */
3183
-    public function get_current_page()
3184
-    {
3185
-        return $this->_current_page;
3186
-    }
3187
-
3188
-
3189
-
3190
-    /**
3191
-     * get_current_view
3192
-     *
3193
-     * @access public
3194
-     * @return string _current_view property value
3195
-     */
3196
-    public function get_current_view()
3197
-    {
3198
-        return $this->_current_view;
3199
-    }
3200
-
3201
-
3202
-
3203
-    /**
3204
-     * get_current_screen
3205
-     *
3206
-     * @access public
3207
-     * @return object The current WP_Screen object
3208
-     */
3209
-    public function get_current_screen()
3210
-    {
3211
-        return $this->_current_screen;
3212
-    }
3213
-
3214
-
3215
-
3216
-    /**
3217
-     * get_current_page_view_url
3218
-     *
3219
-     * @access public
3220
-     * @return string This returns the url for the current_page_view.
3221
-     */
3222
-    public function get_current_page_view_url()
3223
-    {
3224
-        return $this->_current_page_view_url;
3225
-    }
3226
-
3227
-
3228
-
3229
-    /**
3230
-     * just returns the _req_data property
3231
-     *
3232
-     * @return array
3233
-     */
3234
-    public function get_request_data()
3235
-    {
3236
-        return $this->_req_data;
3237
-    }
3238
-
3239
-
3240
-
3241
-    /**
3242
-     * returns the _req_data protected property
3243
-     *
3244
-     * @return string
3245
-     */
3246
-    public function get_req_action()
3247
-    {
3248
-        return $this->_req_action;
3249
-    }
3250
-
3251
-
3252
-
3253
-    /**
3254
-     * @return bool  value of $_is_caf property
3255
-     */
3256
-    public function is_caf()
3257
-    {
3258
-        return $this->_is_caf;
3259
-    }
3260
-
3261
-
3262
-
3263
-    /**
3264
-     * @return mixed
3265
-     */
3266
-    public function default_espresso_metaboxes()
3267
-    {
3268
-        return $this->_default_espresso_metaboxes;
3269
-    }
3270
-
3271
-
3272
-
3273
-    /**
3274
-     * @return mixed
3275
-     */
3276
-    public function admin_base_url()
3277
-    {
3278
-        return $this->_admin_base_url;
3279
-    }
3280
-
3281
-
3282
-
3283
-    /**
3284
-     * @return mixed
3285
-     */
3286
-    public function wp_page_slug()
3287
-    {
3288
-        return $this->_wp_page_slug;
3289
-    }
3290
-
3291
-
3292
-
3293
-    /**
3294
-     * updates  espresso configuration settings
3295
-     *
3296
-     * @access    protected
3297
-     * @param string                   $tab
3298
-     * @param EE_Config_Base|EE_Config $config
3299
-     * @param string                   $file file where error occurred
3300
-     * @param string                   $func function  where error occurred
3301
-     * @param string                   $line line no where error occurred
3302
-     * @return boolean
3303
-     */
3304
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3305
-    {
3306
-        //remove any options that are NOT going to be saved with the config settings.
3307
-        if (isset($config->core->ee_ueip_optin)) {
3308
-            $config->core->ee_ueip_has_notified = true;
3309
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3310
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3311
-            update_option('ee_ueip_has_notified', true);
3312
-        }
3313
-        // and save it (note we're also doing the network save here)
3314
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3315
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3316
-        if ($config_saved && $net_saved) {
3317
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3318
-            return true;
3319
-        } else {
3320
-            EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3321
-            return false;
3322
-        }
3323
-    }
3324
-
3325
-
3326
-
3327
-    /**
3328
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3329
-     *
3330
-     * @return array
3331
-     */
3332
-    public function get_yes_no_values()
3333
-    {
3334
-        return $this->_yes_no_values;
3335
-    }
3336
-
3337
-
3338
-
3339
-    protected function _get_dir()
3340
-    {
3341
-        $reflector = new ReflectionClass(get_class($this));
3342
-        return dirname($reflector->getFileName());
3343
-    }
3344
-
3345
-
3346
-
3347
-    /**
3348
-     * A helper for getting a "next link".
3349
-     *
3350
-     * @param string $url   The url to link to
3351
-     * @param string $class The class to use.
3352
-     * @return string
3353
-     */
3354
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3355
-    {
3356
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3357
-    }
3358
-
3359
-
3360
-
3361
-    /**
3362
-     * A helper for getting a "previous link".
3363
-     *
3364
-     * @param string $url   The url to link to
3365
-     * @param string $class The class to use.
3366
-     * @return string
3367
-     */
3368
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3369
-    {
3370
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3371
-    }
3372
-
3373
-
3374
-
3375
-
3376
-
3377
-
3378
-
3379
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3380
-    /**
3381
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller 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 _req_data
3382
-     * array.
3383
-     *
3384
-     * @return bool success/fail
3385
-     */
3386
-    protected function _process_resend_registration()
3387
-    {
3388
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3389
-        do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3390
-        return $this->_template_args['success'];
3391
-    }
3392
-
3393
-
3394
-
3395
-    /**
3396
-     * This automatically processes any payment message notifications when manual payment has been applied.
3397
-     *
3398
-     * @access protected
3399
-     * @param \EE_Payment $payment
3400
-     * @return bool success/fail
3401
-     */
3402
-    protected function _process_payment_notification(EE_Payment $payment)
3403
-    {
3404
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3405
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3406
-        $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3407
-        return $this->_template_args['success'];
3408
-    }
2194
+	}
2195
+
2196
+
2197
+
2198
+	/**
2199
+	 * facade for add_meta_box
2200
+	 *
2201
+	 * @param string  $action        where the metabox get's displayed
2202
+	 * @param string  $title         Title of Metabox (output in metabox header)
2203
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2204
+	 * @param array   $callback_args an array of args supplied for the metabox
2205
+	 * @param string  $column        what metabox column
2206
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2207
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2208
+	 */
2209
+	public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2210
+	{
2211
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2212
+		//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.
2213
+		if (empty($callback_args) && $create_func) {
2214
+			$callback_args = array(
2215
+					'template_path' => $this->_template_path,
2216
+					'template_args' => $this->_template_args,
2217
+			);
2218
+		}
2219
+		//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)
2220
+		$call_back_func = $create_func ? create_function('$post, $metabox',
2221
+				'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2222
+		add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2223
+	}
2224
+
2225
+
2226
+
2227
+	/**
2228
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2229
+	 *
2230
+	 * @return [type] [description]
2231
+	 */
2232
+	public function display_admin_page_with_metabox_columns()
2233
+	{
2234
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2235
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2236
+		//the final wrapper
2237
+		$this->admin_page_wrapper();
2238
+	}
2239
+
2240
+
2241
+
2242
+	/**
2243
+	 *        generates  HTML wrapper for an admin details page
2244
+	 *
2245
+	 * @access public
2246
+	 * @return void
2247
+	 */
2248
+	public function display_admin_page_with_sidebar()
2249
+	{
2250
+		$this->_display_admin_page(true);
2251
+	}
2252
+
2253
+
2254
+
2255
+	/**
2256
+	 *        generates  HTML wrapper for an admin details page (except no sidebar)
2257
+	 *
2258
+	 * @access public
2259
+	 * @return void
2260
+	 */
2261
+	public function display_admin_page_with_no_sidebar()
2262
+	{
2263
+		$this->_display_admin_page();
2264
+	}
2265
+
2266
+
2267
+
2268
+	/**
2269
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2270
+	 *
2271
+	 * @access public
2272
+	 * @return void
2273
+	 */
2274
+	public function display_about_admin_page()
2275
+	{
2276
+		$this->_display_admin_page(false, true);
2277
+	}
2278
+
2279
+
2280
+
2281
+	/**
2282
+	 * display_admin_page
2283
+	 * contains the code for actually displaying an admin page
2284
+	 *
2285
+	 * @access private
2286
+	 * @param  boolean $sidebar true with sidebar, false without
2287
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2288
+	 * @return void
2289
+	 */
2290
+	private function _display_admin_page($sidebar = false, $about = false)
2291
+	{
2292
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2293
+		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2294
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2295
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2296
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2297
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2298
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2299
+				? 'poststuff'
2300
+				: 'espresso-default-admin';
2301
+		$template_path = $sidebar
2302
+				? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2303
+				: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2304
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2305
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2306
+		}
2307
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2308
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2309
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2310
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2311
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2312
+		// the final template wrapper
2313
+		$this->admin_page_wrapper($about);
2314
+	}
2315
+
2316
+
2317
+
2318
+	/**
2319
+	 * This is used to display caf preview pages.
2320
+	 *
2321
+	 * @since 4.3.2
2322
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2323
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2324
+	 * @return void
2325
+	 * @throws \EE_Error
2326
+	 */
2327
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2328
+	{
2329
+		//let's generate a default preview action button if there isn't one already present.
2330
+		$this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2331
+		$buy_now_url = add_query_arg(
2332
+				array(
2333
+						'ee_ver'       => 'ee4',
2334
+						'utm_source'   => 'ee4_plugin_admin',
2335
+						'utm_medium'   => 'link',
2336
+						'utm_campaign' => $utm_campaign_source,
2337
+						'utm_content'  => 'buy_now_button',
2338
+				),
2339
+				'http://eventespresso.com/pricing/'
2340
+		);
2341
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2342
+				? $this->get_action_link_or_button(
2343
+						'',
2344
+						'buy_now',
2345
+						array(),
2346
+						'button-primary button-large',
2347
+						$buy_now_url,
2348
+						true
2349
+				)
2350
+				: $this->_template_args['preview_action_button'];
2351
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2352
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2353
+				$template_path,
2354
+				$this->_template_args,
2355
+				true
2356
+		);
2357
+		$this->_display_admin_page($display_sidebar);
2358
+	}
2359
+
2360
+
2361
+
2362
+	/**
2363
+	 * display_admin_list_table_page_with_sidebar
2364
+	 * generates HTML wrapper for an admin_page with list_table
2365
+	 *
2366
+	 * @access public
2367
+	 * @return void
2368
+	 */
2369
+	public function display_admin_list_table_page_with_sidebar()
2370
+	{
2371
+		$this->_display_admin_list_table_page(true);
2372
+	}
2373
+
2374
+
2375
+
2376
+	/**
2377
+	 * display_admin_list_table_page_with_no_sidebar
2378
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2379
+	 *
2380
+	 * @access public
2381
+	 * @return void
2382
+	 */
2383
+	public function display_admin_list_table_page_with_no_sidebar()
2384
+	{
2385
+		$this->_display_admin_list_table_page();
2386
+	}
2387
+
2388
+
2389
+
2390
+	/**
2391
+	 * generates html wrapper for an admin_list_table page
2392
+	 *
2393
+	 * @access private
2394
+	 * @param boolean $sidebar whether to display with sidebar or not.
2395
+	 * @return void
2396
+	 */
2397
+	private function _display_admin_list_table_page($sidebar = false)
2398
+	{
2399
+		//setup search attributes
2400
+		$this->_set_search_attributes();
2401
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2402
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2403
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2404
+				? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2405
+				: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2406
+		$this->_template_args['list_table'] = $this->_list_table_object;
2407
+		$this->_template_args['current_route'] = $this->_req_action;
2408
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2409
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2410
+		if ( ! empty($ajax_sorting_callback)) {
2411
+			$sortable_list_table_form_fields = wp_nonce_field(
2412
+					$ajax_sorting_callback . '_nonce',
2413
+					$ajax_sorting_callback . '_nonce',
2414
+					false,
2415
+					false
2416
+			);
2417
+			//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2418
+			//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2419
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2420
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2421
+		} else {
2422
+			$sortable_list_table_form_fields = '';
2423
+		}
2424
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2425
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2426
+		$nonce_ref = $this->_req_action . '_nonce';
2427
+		$hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2428
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2429
+		//display message about search results?
2430
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2431
+				? '<p class="ee-search-results">' . sprintf(
2432
+						esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2433
+						trim($this->_req_data['s'], '%')
2434
+				) . '</p>'
2435
+				: '';
2436
+		// filter before_list_table template arg
2437
+		$this->_template_args['before_list_table'] = apply_filters(
2438
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2439
+			$this->_template_args['before_list_table'],
2440
+			$this->page_slug,
2441
+			$this->_req_data,
2442
+			$this->_req_action
2443
+		);
2444
+		// convert to array and filter again
2445
+		// arrays are easier to inject new items in a specific location,
2446
+		// but would not be backwards compatible, so we have to add a new filter
2447
+		$this->_template_args['before_list_table'] = implode(
2448
+			" \n",
2449
+			(array) apply_filters(
2450
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2451
+				(array) $this->_template_args['before_list_table'],
2452
+				$this->page_slug,
2453
+				$this->_req_data,
2454
+				$this->_req_action
2455
+			)
2456
+		);
2457
+		// filter after_list_table template arg
2458
+		$this->_template_args['after_list_table'] = apply_filters(
2459
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2460
+			$this->_template_args['after_list_table'],
2461
+			$this->page_slug,
2462
+			$this->_req_data,
2463
+			$this->_req_action
2464
+		);
2465
+		// convert to array and filter again
2466
+		// arrays are easier to inject new items in a specific location,
2467
+		// but would not be backwards compatible, so we have to add a new filter
2468
+		$this->_template_args['after_list_table'] = implode(
2469
+			" \n",
2470
+			(array) apply_filters(
2471
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2472
+				(array) $this->_template_args['after_list_table'],
2473
+				$this->page_slug,
2474
+				$this->_req_data,
2475
+				$this->_req_action
2476
+			)
2477
+		);
2478
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2479
+				$template_path,
2480
+				$this->_template_args,
2481
+				true
2482
+		);
2483
+		// the final template wrapper
2484
+		if ($sidebar) {
2485
+			$this->display_admin_page_with_sidebar();
2486
+		} else {
2487
+			$this->display_admin_page_with_no_sidebar();
2488
+		}
2489
+	}
2490
+
2491
+
2492
+
2493
+	/**
2494
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2495
+	 * $items are expected in an array in the following format:
2496
+	 * $legend_items = array(
2497
+	 *        'item_id' => array(
2498
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2499
+	 *            'desc' => __('localized description of item');
2500
+	 *        )
2501
+	 * );
2502
+	 *
2503
+	 * @param  array $items see above for format of array
2504
+	 * @return string        html string of legend
2505
+	 */
2506
+	protected function _display_legend($items)
2507
+	{
2508
+		$this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2509
+		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2510
+		return EEH_Template::display_template($legend_template, $this->_template_args, true);
2511
+	}
2512
+
2513
+
2514
+	/**
2515
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2516
+	 * The returned json object is created from an array in the following format:
2517
+	 * array(
2518
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2519
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
2520
+	 *  'notices' => '', // - contains any EE_Error formatted notices
2521
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2522
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2523
+	 *  specific template args that might be included in here)
2524
+	 * )
2525
+	 * The json object is populated by whatever is set in the $_template_args property.
2526
+	 *
2527
+	 * @param bool  $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2528
+	 * @param array $notices_arguments  Use this to pass any additional args on to the _process_notices.
2529
+	 * @return void
2530
+	 */
2531
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
2532
+	{
2533
+		//make sure any EE_Error notices have been handled.
2534
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
2535
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2536
+		unset($this->_template_args['data']);
2537
+		$json = array(
2538
+				'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2539
+				'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2540
+				'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2541
+				'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2542
+				'notices'   => EE_Error::get_notices(),
2543
+				'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2544
+				'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2545
+				'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2546
+		);
2547
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2548
+		if (null === error_get_last() || ! headers_sent()) {
2549
+			header('Content-Type: application/json; charset=UTF-8');
2550
+		}
2551
+		echo wp_json_encode($json);
2552
+
2553
+		exit();
2554
+	}
2555
+
2556
+
2557
+
2558
+	/**
2559
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2560
+	 *
2561
+	 * @return void
2562
+	 * @throws EE_Error
2563
+	 */
2564
+	public function return_json()
2565
+	{
2566
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2567
+			$this->_return_json();
2568
+		} else {
2569
+			throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2570
+		}
2571
+	}
2572
+
2573
+
2574
+
2575
+	/**
2576
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2577
+	 *
2578
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2579
+	 * @access   public
2580
+	 */
2581
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
2582
+	{
2583
+		$this->_hook_obj = $hook_obj;
2584
+	}
2585
+
2586
+
2587
+
2588
+	/**
2589
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
2590
+	 *
2591
+	 * @access public
2592
+	 * @param  boolean $about whether to use the special about page wrapper or default.
2593
+	 * @return void
2594
+	 */
2595
+	public function admin_page_wrapper($about = false)
2596
+	{
2597
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2598
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
2599
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2600
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2601
+		$this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2602
+				isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2603
+		$this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2604
+				isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2605
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2606
+		// load settings page wrapper template
2607
+		$template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2608
+		//about page?
2609
+		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2610
+		if (defined('DOING_AJAX')) {
2611
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2612
+			$this->_return_json();
2613
+		} else {
2614
+			EEH_Template::display_template($template_path, $this->_template_args);
2615
+		}
2616
+	}
2617
+
2618
+
2619
+
2620
+	/**
2621
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2622
+	 *
2623
+	 * @return string html
2624
+	 */
2625
+	protected function _get_main_nav_tabs()
2626
+	{
2627
+		//let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2628
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2629
+	}
2630
+
2631
+
2632
+
2633
+	/**
2634
+	 *        sort nav tabs
2635
+	 *
2636
+	 * @access public
2637
+	 * @param $a
2638
+	 * @param $b
2639
+	 * @return int
2640
+	 */
2641
+	private function _sort_nav_tabs($a, $b)
2642
+	{
2643
+		if ($a['order'] == $b['order']) {
2644
+			return 0;
2645
+		}
2646
+		return ($a['order'] < $b['order']) ? -1 : 1;
2647
+	}
2648
+
2649
+
2650
+
2651
+	/**
2652
+	 *    generates HTML for the forms used on admin pages
2653
+	 *
2654
+	 * @access protected
2655
+	 * @param    array $input_vars - array of input field details
2656
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2657
+	 * @return string
2658
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2659
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2660
+	 */
2661
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2662
+	{
2663
+		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2664
+		return $content;
2665
+	}
2666
+
2667
+
2668
+
2669
+	/**
2670
+	 * generates the "Save" and "Save & Close" buttons for edit forms
2671
+	 *
2672
+	 * @access protected
2673
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2674
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2675
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2676
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2677
+	 */
2678
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2679
+	{
2680
+		//make sure $text and $actions are in an array
2681
+		$text = (array)$text;
2682
+		$actions = (array)$actions;
2683
+		$referrer_url = empty($referrer) ? '' : $referrer;
2684
+		$referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2685
+				: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2686
+		$button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2687
+		$default_names = array('save', 'save_and_close');
2688
+		//add in a hidden index for the current page (so save and close redirects properly)
2689
+		$this->_template_args['save_buttons'] = $referrer_url;
2690
+		foreach ($button_text as $key => $button) {
2691
+			$ref = $default_names[$key];
2692
+			$id = $this->_current_view . '_' . $ref;
2693
+			$name = ! empty($actions) ? $actions[$key] : $ref;
2694
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2695
+			if ( ! $both) {
2696
+				break;
2697
+			}
2698
+		}
2699
+	}
2700
+
2701
+
2702
+
2703
+	/**
2704
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2705
+	 *
2706
+	 * @see   $this->_set_add_edit_form_tags() for details on params
2707
+	 * @since 4.6.0
2708
+	 * @param string $route
2709
+	 * @param array  $additional_hidden_fields
2710
+	 */
2711
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2712
+	{
2713
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2714
+	}
2715
+
2716
+
2717
+
2718
+	/**
2719
+	 * set form open and close tags on add/edit pages.
2720
+	 *
2721
+	 * @access protected
2722
+	 * @param string $route                    the route you want the form to direct to
2723
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2724
+	 * @return void
2725
+	 */
2726
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2727
+	{
2728
+		if (empty($route)) {
2729
+			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2730
+			$dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2731
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2732
+		}
2733
+		// open form
2734
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2735
+		// add nonce
2736
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2737
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2738
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2739
+		// add REQUIRED form action
2740
+		$hidden_fields = array(
2741
+				'action' => array('type' => 'hidden', 'value' => $route),
2742
+		);
2743
+		// merge arrays
2744
+		$hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2745
+		// generate form fields
2746
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2747
+		// add fields to form
2748
+		foreach ((array)$form_fields as $field_name => $form_field) {
2749
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2750
+		}
2751
+		// close form
2752
+		$this->_template_args['after_admin_page_content'] = '</form>';
2753
+	}
2754
+
2755
+
2756
+
2757
+	/**
2758
+	 * Public Wrapper for _redirect_after_action() method since its
2759
+	 * discovered it would be useful for external code to have access.
2760
+	 *
2761
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
2762
+	 * @since 4.5.0
2763
+	 */
2764
+	public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2765
+	{
2766
+		$this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2767
+	}
2768
+
2769
+
2770
+
2771
+	/**
2772
+	 *    _redirect_after_action
2773
+	 *
2774
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
2775
+	 * @param string $what               - what the action was performed on
2776
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
2777
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2778
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2779
+	 * @access protected
2780
+	 * @return void
2781
+	 */
2782
+	protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2783
+	{
2784
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2785
+		//class name for actions/filters.
2786
+		$classname = get_class($this);
2787
+		//set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2788
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2789
+		$notices = EE_Error::get_notices(false);
2790
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
2791
+		if ( ! $override_overwrite || ! empty($notices['errors'])) {
2792
+			EE_Error::overwrite_success();
2793
+		}
2794
+		if ( ! empty($what) && ! empty($action_desc)) {
2795
+			// how many records affected ? more than one record ? or just one ?
2796
+			if ($success > 1 && empty($notices['errors'])) {
2797
+				// set plural msg
2798
+				EE_Error::add_success(
2799
+						sprintf(
2800
+								__('The "%s" have been successfully %s.', 'event_espresso'),
2801
+								$what,
2802
+								$action_desc
2803
+						),
2804
+						__FILE__, __FUNCTION__, __LINE__
2805
+				);
2806
+			} else if ($success == 1 && empty($notices['errors'])) {
2807
+				// set singular msg
2808
+				EE_Error::add_success(
2809
+						sprintf(
2810
+								__('The "%s" has been successfully %s.', 'event_espresso'),
2811
+								$what,
2812
+								$action_desc
2813
+						),
2814
+						__FILE__, __FUNCTION__, __LINE__
2815
+				);
2816
+			}
2817
+		}
2818
+		// check that $query_args isn't something crazy
2819
+		if ( ! is_array($query_args)) {
2820
+			$query_args = array();
2821
+		}
2822
+		/**
2823
+		 * Allow injecting actions before the query_args are modified for possible different
2824
+		 * redirections on save and close actions
2825
+		 *
2826
+		 * @since 4.2.0
2827
+		 * @param array $query_args       The original query_args array coming into the
2828
+		 *                                method.
2829
+		 */
2830
+		do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2831
+		//calculate where we're going (if we have a "save and close" button pushed)
2832
+		if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2833
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2834
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2835
+			// regenerate query args array from referrer URL
2836
+			parse_str($parsed_url['query'], $query_args);
2837
+			// correct page and action will be in the query args now
2838
+			$redirect_url = admin_url('admin.php');
2839
+		}
2840
+		//merge any default query_args set in _default_route_query_args property
2841
+		if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2842
+			$args_to_merge = array();
2843
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
2844
+				//is there a wp_referer array in our _default_route_query_args property?
2845
+				if ($query_param == 'wp_referer') {
2846
+					$query_value = (array)$query_value;
2847
+					foreach ($query_value as $reference => $value) {
2848
+						if (strpos($reference, 'nonce') !== false) {
2849
+							continue;
2850
+						}
2851
+						//finally we will override any arguments in the referer with
2852
+						//what might be set on the _default_route_query_args array.
2853
+						if (isset($this->_default_route_query_args[$reference])) {
2854
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2855
+						} else {
2856
+							$args_to_merge[$reference] = urlencode($value);
2857
+						}
2858
+					}
2859
+					continue;
2860
+				}
2861
+				$args_to_merge[$query_param] = $query_value;
2862
+			}
2863
+			//now let's merge these arguments but override with what was specifically sent in to the
2864
+			//redirect.
2865
+			$query_args = array_merge($args_to_merge, $query_args);
2866
+		}
2867
+		$this->_process_notices($query_args);
2868
+		// generate redirect url
2869
+		// if redirecting to anything other than the main page, add a nonce
2870
+		if (isset($query_args['action'])) {
2871
+			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2872
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2873
+		}
2874
+		//we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2875
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2876
+		$redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2877
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2878
+		if (defined('DOING_AJAX')) {
2879
+			$default_data = array(
2880
+					'close'        => true,
2881
+					'redirect_url' => $redirect_url,
2882
+					'where'        => 'main',
2883
+					'what'         => 'append',
2884
+			);
2885
+			$this->_template_args['success'] = $success;
2886
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2887
+			$this->_return_json();
2888
+		}
2889
+		wp_safe_redirect($redirect_url);
2890
+		exit();
2891
+	}
2892
+
2893
+
2894
+
2895
+	/**
2896
+	 * process any notices before redirecting (or returning ajax request)
2897
+	 * This method sets the $this->_template_args['notices'] attribute;
2898
+	 *
2899
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
2900
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2901
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2902
+	 * @return void
2903
+	 */
2904
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2905
+	{
2906
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
2907
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2908
+			$notices = EE_Error::get_notices(false);
2909
+			if (empty($this->_template_args['success'])) {
2910
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2911
+			}
2912
+			if (empty($this->_template_args['errors'])) {
2913
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2914
+			}
2915
+			if (empty($this->_template_args['attention'])) {
2916
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2917
+			}
2918
+		}
2919
+		$this->_template_args['notices'] = EE_Error::get_notices();
2920
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2921
+		if ( ! defined('DOING_AJAX') || $sticky_notices) {
2922
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
2923
+			$this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2924
+		}
2925
+	}
2926
+
2927
+
2928
+
2929
+	/**
2930
+	 * get_action_link_or_button
2931
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
2932
+	 *
2933
+	 * @param string $action        use this to indicate which action the url is generated with.
2934
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2935
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2936
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2937
+	 * @param string $base_url      If this is not provided
2938
+	 *                              the _admin_base_url will be used as the default for the button base_url.
2939
+	 *                              Otherwise this value will be used.
2940
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2941
+	 * @return string
2942
+	 * @throws \EE_Error
2943
+	 */
2944
+	public function get_action_link_or_button(
2945
+			$action,
2946
+			$type = 'add',
2947
+			$extra_request = array(),
2948
+			$class = 'button-primary',
2949
+			$base_url = '',
2950
+			$exclude_nonce = false
2951
+	) {
2952
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2953
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2954
+			throw new EE_Error(
2955
+					sprintf(
2956
+							__(
2957
+									'There is no page route for given action for the button.  This action was given: %s',
2958
+									'event_espresso'
2959
+							),
2960
+							$action
2961
+					)
2962
+			);
2963
+		}
2964
+		if ( ! isset($this->_labels['buttons'][$type])) {
2965
+			throw new EE_Error(
2966
+					sprintf(
2967
+							__(
2968
+									'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2969
+									'event_espresso'
2970
+							),
2971
+							$type
2972
+					)
2973
+			);
2974
+		}
2975
+		//finally check user access for this button.
2976
+		$has_access = $this->check_user_access($action, true);
2977
+		if ( ! $has_access) {
2978
+			return '';
2979
+		}
2980
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2981
+		$query_args = array(
2982
+				'action' => $action,
2983
+		);
2984
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2985
+		if ( ! empty($extra_request)) {
2986
+			$query_args = array_merge($extra_request, $query_args);
2987
+		}
2988
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2989
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2990
+	}
2991
+
2992
+
2993
+
2994
+	/**
2995
+	 * _per_page_screen_option
2996
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
2997
+	 *
2998
+	 * @return void
2999
+	 */
3000
+	protected function _per_page_screen_option()
3001
+	{
3002
+		$option = 'per_page';
3003
+		$args = array(
3004
+				'label'   => $this->_admin_page_title,
3005
+				'default' => 10,
3006
+				'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3007
+		);
3008
+		//ONLY add the screen option if the user has access to it.
3009
+		if ($this->check_user_access($this->_current_view, true)) {
3010
+			add_screen_option($option, $args);
3011
+		}
3012
+	}
3013
+
3014
+
3015
+
3016
+	/**
3017
+	 * set_per_page_screen_option
3018
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3019
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3020
+	 *
3021
+	 * @access private
3022
+	 * @return void
3023
+	 */
3024
+	private function _set_per_page_screen_options()
3025
+	{
3026
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3027
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3028
+			if ( ! $user = wp_get_current_user()) {
3029
+				return;
3030
+			}
3031
+			$option = $_POST['wp_screen_options']['option'];
3032
+			$value = $_POST['wp_screen_options']['value'];
3033
+			if ($option != sanitize_key($option)) {
3034
+				return;
3035
+			}
3036
+			$map_option = $option;
3037
+			$option = str_replace('-', '_', $option);
3038
+			switch ($map_option) {
3039
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3040
+					$value = (int)$value;
3041
+					if ($value < 1 || $value > 999) {
3042
+						return;
3043
+					}
3044
+					break;
3045
+				default:
3046
+					$value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3047
+					if (false === $value) {
3048
+						return;
3049
+					}
3050
+					break;
3051
+			}
3052
+			update_user_meta($user->ID, $option, $value);
3053
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3054
+			exit;
3055
+		}
3056
+	}
3057
+
3058
+
3059
+
3060
+	/**
3061
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3062
+	 *
3063
+	 * @param array $data array that will be assigned to template args.
3064
+	 */
3065
+	public function set_template_args($data)
3066
+	{
3067
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3068
+	}
3069
+
3070
+
3071
+
3072
+	/**
3073
+	 * This makes available the WP transient system for temporarily moving data between routes
3074
+	 *
3075
+	 * @access protected
3076
+	 * @param string $route             the route that should receive the transient
3077
+	 * @param array  $data              the data that gets sent
3078
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3079
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3080
+	 * @return void
3081
+	 */
3082
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3083
+	{
3084
+		$user_id = get_current_user_id();
3085
+		if ( ! $skip_route_verify) {
3086
+			$this->_verify_route($route);
3087
+		}
3088
+		//now let's set the string for what kind of transient we're setting
3089
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3090
+		$data = $notices ? array('notices' => $data) : $data;
3091
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3092
+		$existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3093
+		if ($existing) {
3094
+			$data = array_merge((array)$data, (array)$existing);
3095
+		}
3096
+		if (is_multisite() && is_network_admin()) {
3097
+			set_site_transient($transient, $data, 8);
3098
+		} else {
3099
+			set_transient($transient, $data, 8);
3100
+		}
3101
+	}
3102
+
3103
+
3104
+
3105
+	/**
3106
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3107
+	 *
3108
+	 * @param bool $notices true we get notices transient. False we just return normal route transient
3109
+	 * @return mixed data
3110
+	 */
3111
+	protected function _get_transient($notices = false, $route = false)
3112
+	{
3113
+		$user_id = get_current_user_id();
3114
+		$route = ! $route ? $this->_req_action : $route;
3115
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3116
+		$data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3117
+		//delete transient after retrieval (just in case it hasn't expired);
3118
+		if (is_multisite() && is_network_admin()) {
3119
+			delete_site_transient($transient);
3120
+		} else {
3121
+			delete_transient($transient);
3122
+		}
3123
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3124
+	}
3125
+
3126
+
3127
+
3128
+	/**
3129
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3130
+	 * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3131
+	 *
3132
+	 * @return void
3133
+	 */
3134
+	protected function _transient_garbage_collection()
3135
+	{
3136
+		global $wpdb;
3137
+		//retrieve all existing transients
3138
+		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3139
+		if ($results = $wpdb->get_results($query)) {
3140
+			foreach ($results as $result) {
3141
+				$transient = str_replace('_transient_', '', $result->option_name);
3142
+				get_transient($transient);
3143
+				if (is_multisite() && is_network_admin()) {
3144
+					get_site_transient($transient);
3145
+				}
3146
+			}
3147
+		}
3148
+	}
3149
+
3150
+
3151
+
3152
+	/**
3153
+	 * get_view
3154
+	 *
3155
+	 * @access public
3156
+	 * @return string content of _view property
3157
+	 */
3158
+	public function get_view()
3159
+	{
3160
+		return $this->_view;
3161
+	}
3162
+
3163
+
3164
+
3165
+	/**
3166
+	 * getter for the protected $_views property
3167
+	 *
3168
+	 * @return array
3169
+	 */
3170
+	public function get_views()
3171
+	{
3172
+		return $this->_views;
3173
+	}
3174
+
3175
+
3176
+
3177
+	/**
3178
+	 * get_current_page
3179
+	 *
3180
+	 * @access public
3181
+	 * @return string _current_page property value
3182
+	 */
3183
+	public function get_current_page()
3184
+	{
3185
+		return $this->_current_page;
3186
+	}
3187
+
3188
+
3189
+
3190
+	/**
3191
+	 * get_current_view
3192
+	 *
3193
+	 * @access public
3194
+	 * @return string _current_view property value
3195
+	 */
3196
+	public function get_current_view()
3197
+	{
3198
+		return $this->_current_view;
3199
+	}
3200
+
3201
+
3202
+
3203
+	/**
3204
+	 * get_current_screen
3205
+	 *
3206
+	 * @access public
3207
+	 * @return object The current WP_Screen object
3208
+	 */
3209
+	public function get_current_screen()
3210
+	{
3211
+		return $this->_current_screen;
3212
+	}
3213
+
3214
+
3215
+
3216
+	/**
3217
+	 * get_current_page_view_url
3218
+	 *
3219
+	 * @access public
3220
+	 * @return string This returns the url for the current_page_view.
3221
+	 */
3222
+	public function get_current_page_view_url()
3223
+	{
3224
+		return $this->_current_page_view_url;
3225
+	}
3226
+
3227
+
3228
+
3229
+	/**
3230
+	 * just returns the _req_data property
3231
+	 *
3232
+	 * @return array
3233
+	 */
3234
+	public function get_request_data()
3235
+	{
3236
+		return $this->_req_data;
3237
+	}
3238
+
3239
+
3240
+
3241
+	/**
3242
+	 * returns the _req_data protected property
3243
+	 *
3244
+	 * @return string
3245
+	 */
3246
+	public function get_req_action()
3247
+	{
3248
+		return $this->_req_action;
3249
+	}
3250
+
3251
+
3252
+
3253
+	/**
3254
+	 * @return bool  value of $_is_caf property
3255
+	 */
3256
+	public function is_caf()
3257
+	{
3258
+		return $this->_is_caf;
3259
+	}
3260
+
3261
+
3262
+
3263
+	/**
3264
+	 * @return mixed
3265
+	 */
3266
+	public function default_espresso_metaboxes()
3267
+	{
3268
+		return $this->_default_espresso_metaboxes;
3269
+	}
3270
+
3271
+
3272
+
3273
+	/**
3274
+	 * @return mixed
3275
+	 */
3276
+	public function admin_base_url()
3277
+	{
3278
+		return $this->_admin_base_url;
3279
+	}
3280
+
3281
+
3282
+
3283
+	/**
3284
+	 * @return mixed
3285
+	 */
3286
+	public function wp_page_slug()
3287
+	{
3288
+		return $this->_wp_page_slug;
3289
+	}
3290
+
3291
+
3292
+
3293
+	/**
3294
+	 * updates  espresso configuration settings
3295
+	 *
3296
+	 * @access    protected
3297
+	 * @param string                   $tab
3298
+	 * @param EE_Config_Base|EE_Config $config
3299
+	 * @param string                   $file file where error occurred
3300
+	 * @param string                   $func function  where error occurred
3301
+	 * @param string                   $line line no where error occurred
3302
+	 * @return boolean
3303
+	 */
3304
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3305
+	{
3306
+		//remove any options that are NOT going to be saved with the config settings.
3307
+		if (isset($config->core->ee_ueip_optin)) {
3308
+			$config->core->ee_ueip_has_notified = true;
3309
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3310
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3311
+			update_option('ee_ueip_has_notified', true);
3312
+		}
3313
+		// and save it (note we're also doing the network save here)
3314
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3315
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3316
+		if ($config_saved && $net_saved) {
3317
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3318
+			return true;
3319
+		} else {
3320
+			EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3321
+			return false;
3322
+		}
3323
+	}
3324
+
3325
+
3326
+
3327
+	/**
3328
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3329
+	 *
3330
+	 * @return array
3331
+	 */
3332
+	public function get_yes_no_values()
3333
+	{
3334
+		return $this->_yes_no_values;
3335
+	}
3336
+
3337
+
3338
+
3339
+	protected function _get_dir()
3340
+	{
3341
+		$reflector = new ReflectionClass(get_class($this));
3342
+		return dirname($reflector->getFileName());
3343
+	}
3344
+
3345
+
3346
+
3347
+	/**
3348
+	 * A helper for getting a "next link".
3349
+	 *
3350
+	 * @param string $url   The url to link to
3351
+	 * @param string $class The class to use.
3352
+	 * @return string
3353
+	 */
3354
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3355
+	{
3356
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3357
+	}
3358
+
3359
+
3360
+
3361
+	/**
3362
+	 * A helper for getting a "previous link".
3363
+	 *
3364
+	 * @param string $url   The url to link to
3365
+	 * @param string $class The class to use.
3366
+	 * @return string
3367
+	 */
3368
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3369
+	{
3370
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3371
+	}
3372
+
3373
+
3374
+
3375
+
3376
+
3377
+
3378
+
3379
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3380
+	/**
3381
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller 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 _req_data
3382
+	 * array.
3383
+	 *
3384
+	 * @return bool success/fail
3385
+	 */
3386
+	protected function _process_resend_registration()
3387
+	{
3388
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3389
+		do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3390
+		return $this->_template_args['success'];
3391
+	}
3392
+
3393
+
3394
+
3395
+	/**
3396
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3397
+	 *
3398
+	 * @access protected
3399
+	 * @param \EE_Payment $payment
3400
+	 * @return bool success/fail
3401
+	 */
3402
+	protected function _process_payment_notification(EE_Payment $payment)
3403
+	{
3404
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3405
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3406
+		$this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3407
+		return $this->_template_args['success'];
3408
+	}
3409 3409
 
3410 3410
 
3411 3411
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Indentation   +1407 added lines, -1407 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\services\shortcodes\ShortcodesManager;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -19,1412 +19,1412 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
24
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
25
-     */
26
-    const req_type_normal = 0;
27
-
28
-    /**
29
-     * Indicates this is a brand new installation of EE so we should install
30
-     * tables and default data etc
31
-     */
32
-    const req_type_new_activation = 1;
33
-
34
-    /**
35
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
36
-     * and we just exited maintenance mode). We MUST check the database is setup properly
37
-     * and that default data is setup too
38
-     */
39
-    const req_type_reactivation = 2;
40
-
41
-    /**
42
-     * indicates that EE has been upgraded since its previous request.
43
-     * We may have data migration scripts to call and will want to trigger maintenance mode
44
-     */
45
-    const req_type_upgrade = 3;
46
-
47
-    /**
48
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
49
-     */
50
-    const req_type_downgrade = 4;
51
-
52
-    /**
53
-     * @deprecated since version 4.6.0.dev.006
54
-     * Now whenever a new_activation is detected the request type is still just
55
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
56
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
57
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
58
-     * (Specifically, when the migration manager indicates migrations are finished
59
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
60
-     */
61
-    const req_type_activation_but_not_installed = 5;
62
-
63
-    /**
64
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
65
-     */
66
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
67
-
68
-
69
-    /**
70
-     *    instance of the EE_System object
71
-     *
72
-     * @var    $_instance
73
-     * @access    private
74
-     */
75
-    private static $_instance = null;
76
-
77
-    /**
78
-     * @type  EE_Registry $Registry
79
-     * @access    protected
80
-     */
81
-    protected $registry;
82
-
83
-    /**
84
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
85
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
86
-     *
87
-     * @var int
88
-     */
89
-    private $_req_type;
90
-
91
-    /**
92
-     * Whether or not there was a non-micro version change in EE core version during this request
93
-     *
94
-     * @var boolean
95
-     */
96
-    private $_major_version_change = false;
97
-
98
-
99
-
100
-    /**
101
-     * @singleton method used to instantiate class object
102
-     * @access    public
103
-     * @param  \EE_Registry $Registry
104
-     * @return \EE_System
105
-     */
106
-    public static function instance(EE_Registry $Registry = null)
107
-    {
108
-        // check if class object is instantiated
109
-        if ( ! self::$_instance instanceof EE_System) {
110
-            self::$_instance = new self($Registry);
111
-        }
112
-        return self::$_instance;
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * resets the instance and returns it
119
-     *
120
-     * @return EE_System
121
-     */
122
-    public static function reset()
123
-    {
124
-        self::$_instance->_req_type = null;
125
-        //make sure none of the old hooks are left hanging around
126
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
127
-        //we need to reset the migration manager in order for it to detect DMSs properly
128
-        EE_Data_Migration_Manager::reset();
129
-        self::instance()->detect_activations_or_upgrades();
130
-        self::instance()->perform_activations_upgrades_and_migrations();
131
-        return self::instance();
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     *    sets hooks for running rest of system
138
-     *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
139
-     *    starting EE Addons from any other point may lead to problems
140
-     *
141
-     * @access private
142
-     * @param  \EE_Registry $Registry
143
-     */
144
-    private function __construct(EE_Registry $Registry)
145
-    {
146
-        $this->registry = $Registry;
147
-        do_action('AHEE__EE_System__construct__begin', $this);
148
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
149
-        add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
150
-        // when an ee addon is activated, we want to call the core hook(s) again
151
-        // because the newly-activated addon didn't get a chance to run at all
152
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
153
-        // detect whether install or upgrade
154
-        add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
155
-            3);
156
-        // load EE_Config, EE_Textdomain, etc
157
-        add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
158
-        // load EE_Config, EE_Textdomain, etc
159
-        add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
160
-            array($this, 'register_shortcodes_modules_and_widgets'), 7);
161
-        // you wanna get going? I wanna get going... let's get going!
162
-        add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
163
-        //other housekeeping
164
-        //exclude EE critical pages from wp_list_pages
165
-        add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
166
-        // ALL EE Addons should use the following hook point to attach their initial setup too
167
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
168
-        do_action('AHEE__EE_System__construct__complete', $this);
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * load_espresso_addons
175
-     * allow addons to load first so that they can set hooks for running DMS's, etc
176
-     * this is hooked into both:
177
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
178
-     *        which runs during the WP 'plugins_loaded' action at priority 5
179
-     *    and the WP 'activate_plugin' hookpoint
180
-     *
181
-     * @access public
182
-     * @return void
183
-     */
184
-    public function load_espresso_addons()
185
-    {
186
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
187
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
188
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
189
-        //load and setup EE_Capabilities
190
-        $this->registry->load_core('Capabilities');
191
-        //caps need to be initialized on every request so that capability maps are set.
192
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
193
-        $this->registry->CAP->init_caps();
194
-        do_action('AHEE__EE_System__load_espresso_addons');
195
-        //if the WP API basic auth plugin isn't already loaded, load it now.
196
-        //We want it for mobile apps. Just include the entire plugin
197
-        //also, don't load the basic auth when a plugin is getting activated, because
198
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
199
-        //and causes a fatal error
200
-        if ( ! function_exists('json_basic_auth_handler')
201
-             && ! function_exists('json_basic_auth_error')
202
-             && ! (
203
-                isset($_GET['action'])
204
-                && in_array($_GET['action'], array('activate', 'activate-selected'))
205
-            )
206
-             && ! (
207
-                isset($_GET['activate'])
208
-                && $_GET['activate'] === 'true'
209
-            )
210
-        ) {
211
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
212
-        }
213
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
214
-    }
215
-
216
-
217
-
218
-    /**
219
-     * detect_activations_or_upgrades
220
-     * Checks for activation or upgrade of core first;
221
-     * then also checks if any registered addons have been activated or upgraded
222
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
223
-     * which runs during the WP 'plugins_loaded' action at priority 3
224
-     *
225
-     * @access public
226
-     * @return void
227
-     */
228
-    public function detect_activations_or_upgrades()
229
-    {
230
-        //first off: let's make sure to handle core
231
-        $this->detect_if_activation_or_upgrade();
232
-        foreach ($this->registry->addons as $addon) {
233
-            //detect teh request type for that addon
234
-            $addon->detect_activation_or_upgrade();
235
-        }
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * detect_if_activation_or_upgrade
242
-     * Takes care of detecting whether this is a brand new install or code upgrade,
243
-     * and either setting up the DB or setting up maintenance mode etc.
244
-     *
245
-     * @access public
246
-     * @return void
247
-     */
248
-    public function detect_if_activation_or_upgrade()
249
-    {
250
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
251
-        // load M-Mode class
252
-        $this->registry->load_core('Maintenance_Mode');
253
-        // check if db has been updated, or if its a brand-new installation
254
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
255
-        $request_type = $this->detect_req_type($espresso_db_update);
256
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
257
-        switch ($request_type) {
258
-            case EE_System::req_type_new_activation:
259
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
260
-                $this->_handle_core_version_change($espresso_db_update);
261
-                break;
262
-            case EE_System::req_type_reactivation:
263
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
264
-                $this->_handle_core_version_change($espresso_db_update);
265
-                break;
266
-            case EE_System::req_type_upgrade:
267
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
268
-                //migrations may be required now that we've upgraded
269
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
270
-                $this->_handle_core_version_change($espresso_db_update);
271
-                //				echo "done upgrade";die;
272
-                break;
273
-            case EE_System::req_type_downgrade:
274
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
275
-                //its possible migrations are no longer required
276
-                EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
277
-                $this->_handle_core_version_change($espresso_db_update);
278
-                break;
279
-            case EE_System::req_type_normal:
280
-            default:
281
-                //				$this->_maybe_redirect_to_ee_about();
282
-                break;
283
-        }
284
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * Updates the list of installed versions and sets hooks for
291
-     * initializing the database later during the request
292
-     *
293
-     * @param array $espresso_db_update
294
-     */
295
-    protected function _handle_core_version_change($espresso_db_update)
296
-    {
297
-        $this->update_list_of_installed_versions($espresso_db_update);
298
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
299
-        add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
300
-            array($this, 'initialize_db_if_no_migrations_required'));
301
-    }
302
-
303
-
304
-
305
-    /**
306
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
307
-     * information about what versions of EE have been installed and activated,
308
-     * NOT necessarily the state of the database
309
-     *
310
-     * @param null $espresso_db_update
311
-     * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
312
-     *           from the options table
313
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
314
-     */
315
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
316
-    {
317
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
318
-        if ( ! $espresso_db_update) {
319
-            $espresso_db_update = get_option('espresso_db_update');
320
-        }
321
-        // check that option is an array
322
-        if ( ! is_array($espresso_db_update)) {
323
-            // if option is FALSE, then it never existed
324
-            if ($espresso_db_update === false) {
325
-                // make $espresso_db_update an array and save option with autoload OFF
326
-                $espresso_db_update = array();
327
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
328
-            } else {
329
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
330
-                $espresso_db_update = array($espresso_db_update => array());
331
-                update_option('espresso_db_update', $espresso_db_update);
332
-            }
333
-        } else {
334
-            $corrected_db_update = array();
335
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
336
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
337
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
338
-                    //the key is an int, and the value IS NOT an array
339
-                    //so it must be numerically-indexed, where values are versions installed...
340
-                    //fix it!
341
-                    $version_string = $should_be_array;
342
-                    $corrected_db_update[$version_string] = array('unknown-date');
343
-                } else {
344
-                    //ok it checks out
345
-                    $corrected_db_update[$should_be_version_string] = $should_be_array;
346
-                }
347
-            }
348
-            $espresso_db_update = $corrected_db_update;
349
-            update_option('espresso_db_update', $espresso_db_update);
350
-        }
351
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
352
-        return $espresso_db_update;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * Does the traditional work of setting up the plugin's database and adding default data.
359
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
360
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
361
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
362
-     * so that it will be done when migrations are finished
363
-     *
364
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
365
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
366
-     *                                       This is a resource-intensive job
367
-     *                                       so we prefer to only do it when necessary
368
-     * @return void
369
-     */
370
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
371
-    {
372
-        $request_type = $this->detect_req_type();
373
-        //only initialize system if we're not in maintenance mode.
374
-        if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
375
-            update_option('ee_flush_rewrite_rules', true);
376
-            if ($verify_schema) {
377
-                EEH_Activation::initialize_db_and_folders();
378
-            }
379
-            EEH_Activation::initialize_db_content();
380
-            EEH_Activation::system_initialization();
381
-            if ($initialize_addons_too) {
382
-                $this->initialize_addons();
383
-            }
384
-        } else {
385
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
386
-        }
387
-        if ($request_type === EE_System::req_type_new_activation
388
-            || $request_type === EE_System::req_type_reactivation
389
-            || (
390
-                $request_type === EE_System::req_type_upgrade
391
-                && $this->is_major_version_change()
392
-            )
393
-        ) {
394
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
395
-        }
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     * Initializes the db for all registered addons
402
-     */
403
-    public function initialize_addons()
404
-    {
405
-        //foreach registered addon, make sure its db is up-to-date too
406
-        foreach ($this->registry->addons as $addon) {
407
-            $addon->initialize_db_if_no_migrations_required();
408
-        }
409
-    }
410
-
411
-
412
-
413
-    /**
414
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
415
-     *
416
-     * @param    array  $version_history
417
-     * @param    string $current_version_to_add version to be added to the version history
418
-     * @return    boolean success as to whether or not this option was changed
419
-     */
420
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
421
-    {
422
-        if ( ! $version_history) {
423
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
424
-        }
425
-        if ($current_version_to_add == null) {
426
-            $current_version_to_add = espresso_version();
427
-        }
428
-        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
429
-        // re-save
430
-        return update_option('espresso_db_update', $version_history);
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * Detects if the current version indicated in the has existed in the list of
437
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
438
-     *
439
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
440
-     *                                  If not supplied, fetches it from the options table.
441
-     *                                  Also, caches its result so later parts of the code can also know whether
442
-     *                                  there's been an update or not. This way we can add the current version to
443
-     *                                  espresso_db_update, but still know if this is a new install or not
444
-     * @return int one of the constants on EE_System::req_type_
445
-     */
446
-    public function detect_req_type($espresso_db_update = null)
447
-    {
448
-        if ($this->_req_type === null) {
449
-            $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
450
-                : $this->fix_espresso_db_upgrade_option();
451
-            $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
452
-                'ee_espresso_activation', espresso_version());
453
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
454
-        }
455
-        return $this->_req_type;
456
-    }
457
-
458
-
459
-
460
-    /**
461
-     * Returns whether or not there was a non-micro version change (ie, change in either
462
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
463
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
464
-     *
465
-     * @param $activation_history
466
-     * @return bool
467
-     */
468
-    protected function _detect_major_version_change($activation_history)
469
-    {
470
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
471
-        $previous_version_parts = explode('.', $previous_version);
472
-        $current_version_parts = explode('.', espresso_version());
473
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
474
-               && ($previous_version_parts[0] !== $current_version_parts[0]
475
-                   || $previous_version_parts[1] !== $current_version_parts[1]
476
-               );
477
-    }
478
-
479
-
480
-
481
-    /**
482
-     * Returns true if either the major or minor version of EE changed during this request.
483
-     * 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
484
-     *
485
-     * @return bool
486
-     */
487
-    public function is_major_version_change()
488
-    {
489
-        return $this->_major_version_change;
490
-    }
491
-
492
-
493
-
494
-    /**
495
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
496
-     * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
497
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
498
-     * just activated to (for core that will always be espresso_version())
499
-     *
500
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
501
-     *                                                 ee plugin. for core that's 'espresso_db_update'
502
-     * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
503
-     *                                                 indicate that this plugin was just activated
504
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
505
-     *                                                 espresso_version())
506
-     * @return int one of the constants on EE_System::req_type_*
507
-     */
508
-    public static function detect_req_type_given_activation_history(
509
-        $activation_history_for_addon,
510
-        $activation_indicator_option_name,
511
-        $version_to_upgrade_to
512
-    ) {
513
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
514
-        if ($activation_history_for_addon) {
515
-            //it exists, so this isn't a completely new install
516
-            //check if this version already in that list of previously installed versions
517
-            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
518
-                //it a version we haven't seen before
519
-                if ($version_is_higher === 1) {
520
-                    $req_type = EE_System::req_type_upgrade;
521
-                } else {
522
-                    $req_type = EE_System::req_type_downgrade;
523
-                }
524
-                delete_option($activation_indicator_option_name);
525
-            } else {
526
-                // its not an update. maybe a reactivation?
527
-                if (get_option($activation_indicator_option_name, false)) {
528
-                    if ($version_is_higher === -1) {
529
-                        $req_type = EE_System::req_type_downgrade;
530
-                    } elseif ($version_is_higher === 0) {
531
-                        //we've seen this version before, but it's an activation. must be a reactivation
532
-                        $req_type = EE_System::req_type_reactivation;
533
-                    } else {//$version_is_higher === 1
534
-                        $req_type = EE_System::req_type_upgrade;
535
-                    }
536
-                    delete_option($activation_indicator_option_name);
537
-                } else {
538
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
539
-                    if ($version_is_higher === -1) {
540
-                        $req_type = EE_System::req_type_downgrade;
541
-                    } elseif ($version_is_higher === 0) {
542
-                        //we've seen this version before and it's not an activation. its normal request
543
-                        $req_type = EE_System::req_type_normal;
544
-                    } else {//$version_is_higher === 1
545
-                        $req_type = EE_System::req_type_upgrade;
546
-                    }
547
-                }
548
-            }
549
-        } else {
550
-            //brand new install
551
-            $req_type = EE_System::req_type_new_activation;
552
-            delete_option($activation_indicator_option_name);
553
-        }
554
-        return $req_type;
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
561
-     * the $activation_history_for_addon
562
-     *
563
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
564
-     *                                             sometimes containing 'unknown-date'
565
-     * @param string $version_to_upgrade_to        (current version)
566
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
567
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
568
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
569
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
570
-     */
571
-    protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
572
-    {
573
-        //find the most recently-activated version
574
-        $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
575
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
576
-    }
577
-
578
-
579
-
580
-    /**
581
-     * Gets the most recently active version listed in the activation history,
582
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
583
-     *
584
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
585
-     *                                   sometimes containing 'unknown-date'
586
-     * @return string
587
-     */
588
-    protected static function _get_most_recently_active_version_from_activation_history($activation_history)
589
-    {
590
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
591
-        $most_recently_active_version = '0.0.0.dev.000';
592
-        if (is_array($activation_history)) {
593
-            foreach ($activation_history as $version => $times_activated) {
594
-                //check there is a record of when this version was activated. Otherwise,
595
-                //mark it as unknown
596
-                if ( ! $times_activated) {
597
-                    $times_activated = array('unknown-date');
598
-                }
599
-                if (is_string($times_activated)) {
600
-                    $times_activated = array($times_activated);
601
-                }
602
-                foreach ($times_activated as $an_activation) {
603
-                    if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
604
-                        $most_recently_active_version = $version;
605
-                        $most_recently_active_version_activation = $an_activation == 'unknown-date'
606
-                            ? '1970-01-01 00:00:00' : $an_activation;
607
-                    }
608
-                }
609
-            }
610
-        }
611
-        return $most_recently_active_version;
612
-    }
613
-
614
-
615
-
616
-    /**
617
-     * This redirects to the about EE page after activation
618
-     *
619
-     * @return void
620
-     */
621
-    public function redirect_to_about_ee()
622
-    {
623
-        $notices = EE_Error::get_notices(false);
624
-        //if current user is an admin and it's not an ajax or rest request
625
-        if (
626
-            ! (defined('DOING_AJAX') && DOING_AJAX)
627
-            && ! (defined('REST_REQUEST') && REST_REQUEST)
628
-            && ! isset($notices['errors'])
629
-            && apply_filters(
630
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
631
-                $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
632
-            )
633
-        ) {
634
-            $query_params = array('page' => 'espresso_about');
635
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
636
-                $query_params['new_activation'] = true;
637
-            }
638
-            if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
639
-                $query_params['reactivation'] = true;
640
-            }
641
-            $url = add_query_arg($query_params, admin_url('admin.php'));
642
-            wp_safe_redirect($url);
643
-            exit();
644
-        }
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * load_core_configuration
651
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
652
-     * which runs during the WP 'plugins_loaded' action at priority 5
653
-     *
654
-     * @return void
655
-     */
656
-    public function load_core_configuration()
657
-    {
658
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
659
-        $this->registry->load_core('EE_Load_Textdomain');
660
-        //load textdomain
661
-        EE_Load_Textdomain::load_textdomain();
662
-        // load and setup EE_Config and EE_Network_Config
663
-        $this->registry->load_core('Config');
664
-        $this->registry->load_core('Network_Config');
665
-        // setup autoloaders
666
-        // enable logging?
667
-        if ($this->registry->CFG->admin->use_full_logging) {
668
-            $this->registry->load_core('Log');
669
-        }
670
-        // check for activation errors
671
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
672
-        if ($activation_errors) {
673
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
674
-            update_option('ee_plugin_activation_errors', false);
675
-        }
676
-        // get model names
677
-        $this->_parse_model_names();
678
-        //load caf stuff a chance to play during the activation process too.
679
-        $this->_maybe_brew_regular();
680
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
681
-    }
682
-
683
-
684
-
685
-    /**
686
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
687
-     *
688
-     * @return void
689
-     */
690
-    private function _parse_model_names()
691
-    {
692
-        //get all the files in the EE_MODELS folder that end in .model.php
693
-        $models = glob(EE_MODELS . '*.model.php');
694
-        $model_names = array();
695
-        $non_abstract_db_models = array();
696
-        foreach ($models as $model) {
697
-            // get model classname
698
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
699
-            $short_name = str_replace('EEM_', '', $classname);
700
-            $reflectionClass = new ReflectionClass($classname);
701
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
702
-                $non_abstract_db_models[$short_name] = $classname;
703
-            }
704
-            $model_names[$short_name] = $classname;
705
-        }
706
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
707
-        $this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
708
-            $non_abstract_db_models);
709
-    }
710
-
711
-
712
-
713
-    /**
714
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
715
-     * that need to be setup before our EE_System launches.
716
-     *
717
-     * @return void
718
-     */
719
-    private function _maybe_brew_regular()
720
-    {
721
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
722
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
723
-        }
724
-    }
725
-
726
-
727
-
728
-    /**
729
-     * register_shortcodes_modules_and_widgets
730
-     * generate lists of shortcodes and modules, then verify paths and classes
731
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
732
-     * which runs during the WP 'plugins_loaded' action at priority 7
733
-     *
734
-     * @access public
735
-     * @return void
736
-     */
737
-    public function register_shortcodes_modules_and_widgets()
738
-    {
739
-        try {
740
-            // load, register, and add shortcodes the new way
741
-            new ShortcodesManager(
742
-            // and the old way, but we'll put it under control of the new system
743
-                EE_Config::getLegacyShortcodesManager()
744
-            );
745
-        } catch (Exception $exception) {
746
-            new ExceptionStackTraceDisplay($exception);
747
-        }
748
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
749
-        // check for addons using old hookpoint
750
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
751
-            $this->_incompatible_addon_error();
752
-        }
753
-    }
754
-
755
-
756
-
757
-    /**
758
-     * _incompatible_addon_error
759
-     *
760
-     * @access public
761
-     * @return void
762
-     */
763
-    private function _incompatible_addon_error()
764
-    {
765
-        // get array of classes hooking into here
766
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
767
-        if ( ! empty($class_names)) {
768
-            $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
769
-                'event_espresso');
770
-            $msg .= '<ul>';
771
-            foreach ($class_names as $class_name) {
772
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
-                        $class_name) . '</b></li>';
774
-            }
775
-            $msg .= '</ul>';
776
-            $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
777
-                'event_espresso');
778
-            // save list of incompatible addons to wp-options for later use
779
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
780
-            if (is_admin()) {
781
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
782
-            }
783
-        }
784
-    }
785
-
786
-
787
-
788
-    /**
789
-     * brew_espresso
790
-     * begins the process of setting hooks for initializing EE in the correct order
791
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
792
-     * which runs during the WP 'plugins_loaded' action at priority 9
793
-     *
794
-     * @return void
795
-     */
796
-    public function brew_espresso()
797
-    {
798
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
799
-        // load some final core systems
800
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
801
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
802
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
803
-        add_action('init', array($this, 'load_controllers'), 7);
804
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
805
-        add_action('init', array($this, 'initialize'), 10);
806
-        add_action('init', array($this, 'initialize_last'), 100);
807
-        add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
808
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
809
-            // pew pew pew
810
-            $this->registry->load_core('PUE');
811
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
812
-        }
813
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
814
-    }
815
-
816
-
817
-
818
-    /**
819
-     *    set_hooks_for_core
820
-     *
821
-     * @access public
822
-     * @return    void
823
-     */
824
-    public function set_hooks_for_core()
825
-    {
826
-        $this->_deactivate_incompatible_addons();
827
-        do_action('AHEE__EE_System__set_hooks_for_core');
828
-    }
829
-
830
-
831
-
832
-    /**
833
-     * Using the information gathered in EE_System::_incompatible_addon_error,
834
-     * deactivates any addons considered incompatible with the current version of EE
835
-     */
836
-    private function _deactivate_incompatible_addons()
837
-    {
838
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
839
-        if ( ! empty($incompatible_addons)) {
840
-            $active_plugins = get_option('active_plugins', array());
841
-            foreach ($active_plugins as $active_plugin) {
842
-                foreach ($incompatible_addons as $incompatible_addon) {
843
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
844
-                        unset($_GET['activate']);
845
-                        espresso_deactivate_plugin($active_plugin);
846
-                    }
847
-                }
848
-            }
849
-        }
850
-    }
851
-
852
-
853
-
854
-    /**
855
-     *    perform_activations_upgrades_and_migrations
856
-     *
857
-     * @access public
858
-     * @return    void
859
-     */
860
-    public function perform_activations_upgrades_and_migrations()
861
-    {
862
-        //first check if we had previously attempted to setup EE's directories but failed
863
-        if (EEH_Activation::upload_directories_incomplete()) {
864
-            EEH_Activation::create_upload_directories();
865
-        }
866
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     *    load_CPTs_and_session
873
-     *
874
-     * @access public
875
-     * @return    void
876
-     */
877
-    public function load_CPTs_and_session()
878
-    {
879
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
880
-        // register Custom Post Types
881
-        $this->registry->load_core('Register_CPTs');
882
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
883
-    }
884
-
885
-
886
-
887
-    /**
888
-     * load_controllers
889
-     * this is the best place to load any additional controllers that needs access to EE core.
890
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
891
-     * time
892
-     *
893
-     * @access public
894
-     * @return void
895
-     */
896
-    public function load_controllers()
897
-    {
898
-        do_action('AHEE__EE_System__load_controllers__start');
899
-        // let's get it started
900
-        if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
901
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
902
-            $this->registry->load_core('Front_Controller');
903
-        } else if ( ! EE_FRONT_AJAX) {
904
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
905
-            EE_Registry::instance()->load_core('Admin');
906
-        }
907
-        do_action('AHEE__EE_System__load_controllers__complete');
908
-    }
909
-
910
-
911
-
912
-    /**
913
-     * core_loaded_and_ready
914
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
915
-     *
916
-     * @access public
917
-     * @return void
918
-     */
919
-    public function core_loaded_and_ready()
920
-    {
921
-        $this->registry->load_core('Session');
922
-        do_action('AHEE__EE_System__core_loaded_and_ready');
923
-        // load_espresso_template_tags
924
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
925
-            require_once(EE_PUBLIC . 'template_tags.php');
926
-        }
927
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
928
-        $this->registry->create('EventEspresso\core\services\assets\Registry');
929
-        wp_enqueue_script('espresso_core');
930
-    }
931
-
932
-
933
-
934
-    /**
935
-     * initialize
936
-     * this is the best place to begin initializing client code
937
-     *
938
-     * @access public
939
-     * @return void
940
-     */
941
-    public function initialize()
942
-    {
943
-        do_action('AHEE__EE_System__initialize');
944
-    }
945
-
946
-
947
-
948
-    /**
949
-     * initialize_last
950
-     * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
951
-     * initialize has done so
952
-     *
953
-     * @access public
954
-     * @return void
955
-     */
956
-    public function initialize_last()
957
-    {
958
-        do_action('AHEE__EE_System__initialize_last');
959
-    }
960
-
961
-
962
-
963
-    /**
964
-     * set_hooks_for_shortcodes_modules_and_addons
965
-     * this is the best place for other systems to set callbacks for hooking into other parts of EE
966
-     * this happens at the very beginning of the wp_loaded hookpoint
967
-     *
968
-     * @access public
969
-     * @return void
970
-     */
971
-    public function set_hooks_for_shortcodes_modules_and_addons()
972
-    {
973
-        //		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * do_not_cache
980
-     * sets no cache headers and defines no cache constants for WP plugins
981
-     *
982
-     * @access public
983
-     * @return void
984
-     */
985
-    public static function do_not_cache()
986
-    {
987
-        // set no cache constants
988
-        if ( ! defined('DONOTCACHEPAGE')) {
989
-            define('DONOTCACHEPAGE', true);
990
-        }
991
-        if ( ! defined('DONOTCACHCEOBJECT')) {
992
-            define('DONOTCACHCEOBJECT', true);
993
-        }
994
-        if ( ! defined('DONOTCACHEDB')) {
995
-            define('DONOTCACHEDB', true);
996
-        }
997
-        // add no cache headers
998
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
999
-        // plus a little extra for nginx and Google Chrome
1000
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1001
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1002
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1003
-    }
1004
-
1005
-
1006
-
1007
-    /**
1008
-     *    extra_nocache_headers
1009
-     *
1010
-     * @access    public
1011
-     * @param $headers
1012
-     * @return    array
1013
-     */
1014
-    public static function extra_nocache_headers($headers)
1015
-    {
1016
-        // for NGINX
1017
-        $headers['X-Accel-Expires'] = 0;
1018
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1019
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1020
-        return $headers;
1021
-    }
1022
-
1023
-
1024
-
1025
-    /**
1026
-     *    nocache_headers
1027
-     *
1028
-     * @access    public
1029
-     * @return    void
1030
-     */
1031
-    public static function nocache_headers()
1032
-    {
1033
-        nocache_headers();
1034
-    }
1035
-
1036
-
1037
-
1038
-    /**
1039
-     *    espresso_toolbar_items
1040
-     *
1041
-     * @access public
1042
-     * @param  WP_Admin_Bar $admin_bar
1043
-     * @return void
1044
-     */
1045
-    public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1046
-    {
1047
-        // if in full M-Mode, or its an AJAX request, or user is NOT an admin
1048
-        if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1049
-            || defined('DOING_AJAX')
1050
-            || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1051
-        ) {
1052
-            return;
1053
-        }
1054
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1055
-        $menu_class = 'espresso_menu_item_class';
1056
-        //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1057
-        //because they're only defined in each of their respective constructors
1058
-        //and this might be a frontend request, in which case they aren't available
1059
-        $events_admin_url = admin_url("admin.php?page=espresso_events");
1060
-        $reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1061
-        $extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1062
-        //Top Level
1063
-        $admin_bar->add_menu(array(
1064
-            'id'    => 'espresso-toolbar',
1065
-            'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1066
-                       . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1067
-                       . '</span>',
1068
-            'href'  => $events_admin_url,
1069
-            'meta'  => array(
1070
-                'title' => __('Event Espresso', 'event_espresso'),
1071
-                'class' => $menu_class . 'first',
1072
-            ),
1073
-        ));
1074
-        //Events
1075
-        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1076
-            $admin_bar->add_menu(array(
1077
-                'id'     => 'espresso-toolbar-events',
1078
-                'parent' => 'espresso-toolbar',
1079
-                'title'  => __('Events', 'event_espresso'),
1080
-                'href'   => $events_admin_url,
1081
-                'meta'   => array(
1082
-                    'title'  => __('Events', 'event_espresso'),
1083
-                    'target' => '',
1084
-                    'class'  => $menu_class,
1085
-                ),
1086
-            ));
1087
-        }
1088
-        if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1089
-            //Events Add New
1090
-            $admin_bar->add_menu(array(
1091
-                'id'     => 'espresso-toolbar-events-new',
1092
-                'parent' => 'espresso-toolbar-events',
1093
-                'title'  => __('Add New', 'event_espresso'),
1094
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1095
-                'meta'   => array(
1096
-                    'title'  => __('Add New', 'event_espresso'),
1097
-                    'target' => '',
1098
-                    'class'  => $menu_class,
1099
-                ),
1100
-            ));
1101
-        }
1102
-        if (is_single() && (get_post_type() == 'espresso_events')) {
1103
-            //Current post
1104
-            global $post;
1105
-            if ($this->registry->CAP->current_user_can('ee_edit_event',
1106
-                'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1107
-            ) {
1108
-                //Events Edit Current Event
1109
-                $admin_bar->add_menu(array(
1110
-                    'id'     => 'espresso-toolbar-events-edit',
1111
-                    'parent' => 'espresso-toolbar-events',
1112
-                    'title'  => __('Edit Event', 'event_espresso'),
1113
-                    'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1114
-                        $events_admin_url),
1115
-                    'meta'   => array(
1116
-                        'title'  => __('Edit Event', 'event_espresso'),
1117
-                        'target' => '',
1118
-                        'class'  => $menu_class,
1119
-                    ),
1120
-                ));
1121
-            }
1122
-        }
1123
-        //Events View
1124
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1125
-            'ee_admin_bar_menu_espresso-toolbar-events-view')
1126
-        ) {
1127
-            $admin_bar->add_menu(array(
1128
-                'id'     => 'espresso-toolbar-events-view',
1129
-                'parent' => 'espresso-toolbar-events',
1130
-                'title'  => __('View', 'event_espresso'),
1131
-                'href'   => $events_admin_url,
1132
-                'meta'   => array(
1133
-                    'title'  => __('View', 'event_espresso'),
1134
-                    'target' => '',
1135
-                    'class'  => $menu_class,
1136
-                ),
1137
-            ));
1138
-        }
1139
-        if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1140
-            //Events View All
1141
-            $admin_bar->add_menu(array(
1142
-                'id'     => 'espresso-toolbar-events-all',
1143
-                'parent' => 'espresso-toolbar-events-view',
1144
-                'title'  => __('All', 'event_espresso'),
1145
-                'href'   => $events_admin_url,
1146
-                'meta'   => array(
1147
-                    'title'  => __('All', 'event_espresso'),
1148
-                    'target' => '',
1149
-                    'class'  => $menu_class,
1150
-                ),
1151
-            ));
1152
-        }
1153
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1154
-            'ee_admin_bar_menu_espresso-toolbar-events-today')
1155
-        ) {
1156
-            //Events View Today
1157
-            $admin_bar->add_menu(array(
1158
-                'id'     => 'espresso-toolbar-events-today',
1159
-                'parent' => 'espresso-toolbar-events-view',
1160
-                'title'  => __('Today', 'event_espresso'),
1161
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1162
-                    $events_admin_url),
1163
-                'meta'   => array(
1164
-                    'title'  => __('Today', 'event_espresso'),
1165
-                    'target' => '',
1166
-                    'class'  => $menu_class,
1167
-                ),
1168
-            ));
1169
-        }
1170
-        if ($this->registry->CAP->current_user_can('ee_read_events',
1171
-            'ee_admin_bar_menu_espresso-toolbar-events-month')
1172
-        ) {
1173
-            //Events View This Month
1174
-            $admin_bar->add_menu(array(
1175
-                'id'     => 'espresso-toolbar-events-month',
1176
-                'parent' => 'espresso-toolbar-events-view',
1177
-                'title'  => __('This Month', 'event_espresso'),
1178
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1179
-                    $events_admin_url),
1180
-                'meta'   => array(
1181
-                    'title'  => __('This Month', 'event_espresso'),
1182
-                    'target' => '',
1183
-                    'class'  => $menu_class,
1184
-                ),
1185
-            ));
1186
-        }
1187
-        //Registration Overview
1188
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1189
-            'ee_admin_bar_menu_espresso-toolbar-registrations')
1190
-        ) {
1191
-            $admin_bar->add_menu(array(
1192
-                'id'     => 'espresso-toolbar-registrations',
1193
-                'parent' => 'espresso-toolbar',
1194
-                'title'  => __('Registrations', 'event_espresso'),
1195
-                'href'   => $reg_admin_url,
1196
-                'meta'   => array(
1197
-                    'title'  => __('Registrations', 'event_espresso'),
1198
-                    'target' => '',
1199
-                    'class'  => $menu_class,
1200
-                ),
1201
-            ));
1202
-        }
1203
-        //Registration Overview Today
1204
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1205
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1206
-        ) {
1207
-            $admin_bar->add_menu(array(
1208
-                'id'     => 'espresso-toolbar-registrations-today',
1209
-                'parent' => 'espresso-toolbar-registrations',
1210
-                'title'  => __('Today', 'event_espresso'),
1211
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1212
-                    $reg_admin_url),
1213
-                'meta'   => array(
1214
-                    'title'  => __('Today', 'event_espresso'),
1215
-                    'target' => '',
1216
-                    'class'  => $menu_class,
1217
-                ),
1218
-            ));
1219
-        }
1220
-        //Registration Overview Today Completed
1221
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1222
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1223
-        ) {
1224
-            $admin_bar->add_menu(array(
1225
-                'id'     => 'espresso-toolbar-registrations-today-approved',
1226
-                'parent' => 'espresso-toolbar-registrations-today',
1227
-                'title'  => __('Approved', 'event_espresso'),
1228
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1229
-                    'action'      => 'default',
1230
-                    'status'      => 'today',
1231
-                    '_reg_status' => EEM_Registration::status_id_approved,
1232
-                ), $reg_admin_url),
1233
-                'meta'   => array(
1234
-                    'title'  => __('Approved', 'event_espresso'),
1235
-                    'target' => '',
1236
-                    'class'  => $menu_class,
1237
-                ),
1238
-            ));
1239
-        }
1240
-        //Registration Overview Today Pending\
1241
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1242
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1243
-        ) {
1244
-            $admin_bar->add_menu(array(
1245
-                'id'     => 'espresso-toolbar-registrations-today-pending',
1246
-                'parent' => 'espresso-toolbar-registrations-today',
1247
-                'title'  => __('Pending', 'event_espresso'),
1248
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1249
-                    'action'     => 'default',
1250
-                    'status'     => 'today',
1251
-                    'reg_status' => EEM_Registration::status_id_pending_payment,
1252
-                ), $reg_admin_url),
1253
-                'meta'   => array(
1254
-                    'title'  => __('Pending Payment', 'event_espresso'),
1255
-                    'target' => '',
1256
-                    'class'  => $menu_class,
1257
-                ),
1258
-            ));
1259
-        }
1260
-        //Registration Overview Today Incomplete
1261
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1262
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1263
-        ) {
1264
-            $admin_bar->add_menu(array(
1265
-                'id'     => 'espresso-toolbar-registrations-today-not-approved',
1266
-                'parent' => 'espresso-toolbar-registrations-today',
1267
-                'title'  => __('Not Approved', 'event_espresso'),
1268
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1269
-                    'action'      => 'default',
1270
-                    'status'      => 'today',
1271
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1272
-                ), $reg_admin_url),
1273
-                'meta'   => array(
1274
-                    'title'  => __('Not Approved', 'event_espresso'),
1275
-                    'target' => '',
1276
-                    'class'  => $menu_class,
1277
-                ),
1278
-            ));
1279
-        }
1280
-        //Registration Overview Today Incomplete
1281
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1282
-            'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1283
-        ) {
1284
-            $admin_bar->add_menu(array(
1285
-                'id'     => 'espresso-toolbar-registrations-today-cancelled',
1286
-                'parent' => 'espresso-toolbar-registrations-today',
1287
-                'title'  => __('Cancelled', 'event_espresso'),
1288
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1289
-                    'action'      => 'default',
1290
-                    'status'      => 'today',
1291
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1292
-                ), $reg_admin_url),
1293
-                'meta'   => array(
1294
-                    'title'  => __('Cancelled', 'event_espresso'),
1295
-                    'target' => '',
1296
-                    'class'  => $menu_class,
1297
-                ),
1298
-            ));
1299
-        }
1300
-        //Registration Overview This Month
1301
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1302
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1303
-        ) {
1304
-            $admin_bar->add_menu(array(
1305
-                'id'     => 'espresso-toolbar-registrations-month',
1306
-                'parent' => 'espresso-toolbar-registrations',
1307
-                'title'  => __('This Month', 'event_espresso'),
1308
-                'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1309
-                    $reg_admin_url),
1310
-                'meta'   => array(
1311
-                    'title'  => __('This Month', 'event_espresso'),
1312
-                    'target' => '',
1313
-                    'class'  => $menu_class,
1314
-                ),
1315
-            ));
1316
-        }
1317
-        //Registration Overview This Month Approved
1318
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1319
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1320
-        ) {
1321
-            $admin_bar->add_menu(array(
1322
-                'id'     => 'espresso-toolbar-registrations-month-approved',
1323
-                'parent' => 'espresso-toolbar-registrations-month',
1324
-                'title'  => __('Approved', 'event_espresso'),
1325
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1326
-                    'action'      => 'default',
1327
-                    'status'      => 'month',
1328
-                    '_reg_status' => EEM_Registration::status_id_approved,
1329
-                ), $reg_admin_url),
1330
-                'meta'   => array(
1331
-                    'title'  => __('Approved', 'event_espresso'),
1332
-                    'target' => '',
1333
-                    'class'  => $menu_class,
1334
-                ),
1335
-            ));
1336
-        }
1337
-        //Registration Overview This Month Pending
1338
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1339
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1340
-        ) {
1341
-            $admin_bar->add_menu(array(
1342
-                'id'     => 'espresso-toolbar-registrations-month-pending',
1343
-                'parent' => 'espresso-toolbar-registrations-month',
1344
-                'title'  => __('Pending', 'event_espresso'),
1345
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1346
-                    'action'      => 'default',
1347
-                    'status'      => 'month',
1348
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1349
-                ), $reg_admin_url),
1350
-                'meta'   => array(
1351
-                    'title'  => __('Pending', 'event_espresso'),
1352
-                    'target' => '',
1353
-                    'class'  => $menu_class,
1354
-                ),
1355
-            ));
1356
-        }
1357
-        //Registration Overview This Month Not Approved
1358
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1359
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1360
-        ) {
1361
-            $admin_bar->add_menu(array(
1362
-                'id'     => 'espresso-toolbar-registrations-month-not-approved',
1363
-                'parent' => 'espresso-toolbar-registrations-month',
1364
-                'title'  => __('Not Approved', 'event_espresso'),
1365
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1366
-                    'action'      => 'default',
1367
-                    'status'      => 'month',
1368
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1369
-                ), $reg_admin_url),
1370
-                'meta'   => array(
1371
-                    'title'  => __('Not Approved', 'event_espresso'),
1372
-                    'target' => '',
1373
-                    'class'  => $menu_class,
1374
-                ),
1375
-            ));
1376
-        }
1377
-        //Registration Overview This Month Cancelled
1378
-        if ($this->registry->CAP->current_user_can('ee_read_registrations',
1379
-            'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1380
-        ) {
1381
-            $admin_bar->add_menu(array(
1382
-                'id'     => 'espresso-toolbar-registrations-month-cancelled',
1383
-                'parent' => 'espresso-toolbar-registrations-month',
1384
-                'title'  => __('Cancelled', 'event_espresso'),
1385
-                'href'   => EEH_URL::add_query_args_and_nonce(array(
1386
-                    'action'      => 'default',
1387
-                    'status'      => 'month',
1388
-                    '_reg_status' => EEM_Registration::status_id_cancelled,
1389
-                ), $reg_admin_url),
1390
-                'meta'   => array(
1391
-                    'title'  => __('Cancelled', 'event_espresso'),
1392
-                    'target' => '',
1393
-                    'class'  => $menu_class,
1394
-                ),
1395
-            ));
1396
-        }
1397
-        //Extensions & Services
1398
-        if ($this->registry->CAP->current_user_can('ee_read_ee',
1399
-            'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1400
-        ) {
1401
-            $admin_bar->add_menu(array(
1402
-                'id'     => 'espresso-toolbar-extensions-and-services',
1403
-                'parent' => 'espresso-toolbar',
1404
-                'title'  => __('Extensions & Services', 'event_espresso'),
1405
-                'href'   => $extensions_admin_url,
1406
-                'meta'   => array(
1407
-                    'title'  => __('Extensions & Services', 'event_espresso'),
1408
-                    'target' => '',
1409
-                    'class'  => $menu_class,
1410
-                ),
1411
-            ));
1412
-        }
1413
-    }
1414
-
1415
-
1416
-
1417
-    /**
1418
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1419
-     * never returned with the function.
1420
-     *
1421
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1422
-     * @return array
1423
-     */
1424
-    public function remove_pages_from_wp_list_pages($exclude_array)
1425
-    {
1426
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1427
-    }
22
+	/**
23
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
24
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
25
+	 */
26
+	const req_type_normal = 0;
27
+
28
+	/**
29
+	 * Indicates this is a brand new installation of EE so we should install
30
+	 * tables and default data etc
31
+	 */
32
+	const req_type_new_activation = 1;
33
+
34
+	/**
35
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
36
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
37
+	 * and that default data is setup too
38
+	 */
39
+	const req_type_reactivation = 2;
40
+
41
+	/**
42
+	 * indicates that EE has been upgraded since its previous request.
43
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
44
+	 */
45
+	const req_type_upgrade = 3;
46
+
47
+	/**
48
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
49
+	 */
50
+	const req_type_downgrade = 4;
51
+
52
+	/**
53
+	 * @deprecated since version 4.6.0.dev.006
54
+	 * Now whenever a new_activation is detected the request type is still just
55
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
56
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
57
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
58
+	 * (Specifically, when the migration manager indicates migrations are finished
59
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
60
+	 */
61
+	const req_type_activation_but_not_installed = 5;
62
+
63
+	/**
64
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
65
+	 */
66
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
67
+
68
+
69
+	/**
70
+	 *    instance of the EE_System object
71
+	 *
72
+	 * @var    $_instance
73
+	 * @access    private
74
+	 */
75
+	private static $_instance = null;
76
+
77
+	/**
78
+	 * @type  EE_Registry $Registry
79
+	 * @access    protected
80
+	 */
81
+	protected $registry;
82
+
83
+	/**
84
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
85
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
86
+	 *
87
+	 * @var int
88
+	 */
89
+	private $_req_type;
90
+
91
+	/**
92
+	 * Whether or not there was a non-micro version change in EE core version during this request
93
+	 *
94
+	 * @var boolean
95
+	 */
96
+	private $_major_version_change = false;
97
+
98
+
99
+
100
+	/**
101
+	 * @singleton method used to instantiate class object
102
+	 * @access    public
103
+	 * @param  \EE_Registry $Registry
104
+	 * @return \EE_System
105
+	 */
106
+	public static function instance(EE_Registry $Registry = null)
107
+	{
108
+		// check if class object is instantiated
109
+		if ( ! self::$_instance instanceof EE_System) {
110
+			self::$_instance = new self($Registry);
111
+		}
112
+		return self::$_instance;
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * resets the instance and returns it
119
+	 *
120
+	 * @return EE_System
121
+	 */
122
+	public static function reset()
123
+	{
124
+		self::$_instance->_req_type = null;
125
+		//make sure none of the old hooks are left hanging around
126
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
127
+		//we need to reset the migration manager in order for it to detect DMSs properly
128
+		EE_Data_Migration_Manager::reset();
129
+		self::instance()->detect_activations_or_upgrades();
130
+		self::instance()->perform_activations_upgrades_and_migrations();
131
+		return self::instance();
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 *    sets hooks for running rest of system
138
+	 *    provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
139
+	 *    starting EE Addons from any other point may lead to problems
140
+	 *
141
+	 * @access private
142
+	 * @param  \EE_Registry $Registry
143
+	 */
144
+	private function __construct(EE_Registry $Registry)
145
+	{
146
+		$this->registry = $Registry;
147
+		do_action('AHEE__EE_System__construct__begin', $this);
148
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
149
+		add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons'));
150
+		// when an ee addon is activated, we want to call the core hook(s) again
151
+		// because the newly-activated addon didn't get a chance to run at all
152
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
153
+		// detect whether install or upgrade
154
+		add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'),
155
+			3);
156
+		// load EE_Config, EE_Textdomain, etc
157
+		add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5);
158
+		// load EE_Config, EE_Textdomain, etc
159
+		add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
160
+			array($this, 'register_shortcodes_modules_and_widgets'), 7);
161
+		// you wanna get going? I wanna get going... let's get going!
162
+		add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9);
163
+		//other housekeeping
164
+		//exclude EE critical pages from wp_list_pages
165
+		add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10);
166
+		// ALL EE Addons should use the following hook point to attach their initial setup too
167
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
168
+		do_action('AHEE__EE_System__construct__complete', $this);
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * load_espresso_addons
175
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
176
+	 * this is hooked into both:
177
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
178
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
179
+	 *    and the WP 'activate_plugin' hookpoint
180
+	 *
181
+	 * @access public
182
+	 * @return void
183
+	 */
184
+	public function load_espresso_addons()
185
+	{
186
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
187
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
188
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
189
+		//load and setup EE_Capabilities
190
+		$this->registry->load_core('Capabilities');
191
+		//caps need to be initialized on every request so that capability maps are set.
192
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
193
+		$this->registry->CAP->init_caps();
194
+		do_action('AHEE__EE_System__load_espresso_addons');
195
+		//if the WP API basic auth plugin isn't already loaded, load it now.
196
+		//We want it for mobile apps. Just include the entire plugin
197
+		//also, don't load the basic auth when a plugin is getting activated, because
198
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
199
+		//and causes a fatal error
200
+		if ( ! function_exists('json_basic_auth_handler')
201
+			 && ! function_exists('json_basic_auth_error')
202
+			 && ! (
203
+				isset($_GET['action'])
204
+				&& in_array($_GET['action'], array('activate', 'activate-selected'))
205
+			)
206
+			 && ! (
207
+				isset($_GET['activate'])
208
+				&& $_GET['activate'] === 'true'
209
+			)
210
+		) {
211
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
212
+		}
213
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
214
+	}
215
+
216
+
217
+
218
+	/**
219
+	 * detect_activations_or_upgrades
220
+	 * Checks for activation or upgrade of core first;
221
+	 * then also checks if any registered addons have been activated or upgraded
222
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
223
+	 * which runs during the WP 'plugins_loaded' action at priority 3
224
+	 *
225
+	 * @access public
226
+	 * @return void
227
+	 */
228
+	public function detect_activations_or_upgrades()
229
+	{
230
+		//first off: let's make sure to handle core
231
+		$this->detect_if_activation_or_upgrade();
232
+		foreach ($this->registry->addons as $addon) {
233
+			//detect teh request type for that addon
234
+			$addon->detect_activation_or_upgrade();
235
+		}
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * detect_if_activation_or_upgrade
242
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
243
+	 * and either setting up the DB or setting up maintenance mode etc.
244
+	 *
245
+	 * @access public
246
+	 * @return void
247
+	 */
248
+	public function detect_if_activation_or_upgrade()
249
+	{
250
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
251
+		// load M-Mode class
252
+		$this->registry->load_core('Maintenance_Mode');
253
+		// check if db has been updated, or if its a brand-new installation
254
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
255
+		$request_type = $this->detect_req_type($espresso_db_update);
256
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
257
+		switch ($request_type) {
258
+			case EE_System::req_type_new_activation:
259
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
260
+				$this->_handle_core_version_change($espresso_db_update);
261
+				break;
262
+			case EE_System::req_type_reactivation:
263
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
264
+				$this->_handle_core_version_change($espresso_db_update);
265
+				break;
266
+			case EE_System::req_type_upgrade:
267
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
268
+				//migrations may be required now that we've upgraded
269
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
270
+				$this->_handle_core_version_change($espresso_db_update);
271
+				//				echo "done upgrade";die;
272
+				break;
273
+			case EE_System::req_type_downgrade:
274
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
275
+				//its possible migrations are no longer required
276
+				EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
277
+				$this->_handle_core_version_change($espresso_db_update);
278
+				break;
279
+			case EE_System::req_type_normal:
280
+			default:
281
+				//				$this->_maybe_redirect_to_ee_about();
282
+				break;
283
+		}
284
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * Updates the list of installed versions and sets hooks for
291
+	 * initializing the database later during the request
292
+	 *
293
+	 * @param array $espresso_db_update
294
+	 */
295
+	protected function _handle_core_version_change($espresso_db_update)
296
+	{
297
+		$this->update_list_of_installed_versions($espresso_db_update);
298
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
299
+		add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations',
300
+			array($this, 'initialize_db_if_no_migrations_required'));
301
+	}
302
+
303
+
304
+
305
+	/**
306
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
307
+	 * information about what versions of EE have been installed and activated,
308
+	 * NOT necessarily the state of the database
309
+	 *
310
+	 * @param null $espresso_db_update
311
+	 * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it
312
+	 *           from the options table
313
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
314
+	 */
315
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
316
+	{
317
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
318
+		if ( ! $espresso_db_update) {
319
+			$espresso_db_update = get_option('espresso_db_update');
320
+		}
321
+		// check that option is an array
322
+		if ( ! is_array($espresso_db_update)) {
323
+			// if option is FALSE, then it never existed
324
+			if ($espresso_db_update === false) {
325
+				// make $espresso_db_update an array and save option with autoload OFF
326
+				$espresso_db_update = array();
327
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
328
+			} else {
329
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
330
+				$espresso_db_update = array($espresso_db_update => array());
331
+				update_option('espresso_db_update', $espresso_db_update);
332
+			}
333
+		} else {
334
+			$corrected_db_update = array();
335
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
336
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
337
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
338
+					//the key is an int, and the value IS NOT an array
339
+					//so it must be numerically-indexed, where values are versions installed...
340
+					//fix it!
341
+					$version_string = $should_be_array;
342
+					$corrected_db_update[$version_string] = array('unknown-date');
343
+				} else {
344
+					//ok it checks out
345
+					$corrected_db_update[$should_be_version_string] = $should_be_array;
346
+				}
347
+			}
348
+			$espresso_db_update = $corrected_db_update;
349
+			update_option('espresso_db_update', $espresso_db_update);
350
+		}
351
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
352
+		return $espresso_db_update;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * Does the traditional work of setting up the plugin's database and adding default data.
359
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
360
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
361
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
362
+	 * so that it will be done when migrations are finished
363
+	 *
364
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
365
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
366
+	 *                                       This is a resource-intensive job
367
+	 *                                       so we prefer to only do it when necessary
368
+	 * @return void
369
+	 */
370
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
371
+	{
372
+		$request_type = $this->detect_req_type();
373
+		//only initialize system if we're not in maintenance mode.
374
+		if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) {
375
+			update_option('ee_flush_rewrite_rules', true);
376
+			if ($verify_schema) {
377
+				EEH_Activation::initialize_db_and_folders();
378
+			}
379
+			EEH_Activation::initialize_db_content();
380
+			EEH_Activation::system_initialization();
381
+			if ($initialize_addons_too) {
382
+				$this->initialize_addons();
383
+			}
384
+		} else {
385
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
386
+		}
387
+		if ($request_type === EE_System::req_type_new_activation
388
+			|| $request_type === EE_System::req_type_reactivation
389
+			|| (
390
+				$request_type === EE_System::req_type_upgrade
391
+				&& $this->is_major_version_change()
392
+			)
393
+		) {
394
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
395
+		}
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 * Initializes the db for all registered addons
402
+	 */
403
+	public function initialize_addons()
404
+	{
405
+		//foreach registered addon, make sure its db is up-to-date too
406
+		foreach ($this->registry->addons as $addon) {
407
+			$addon->initialize_db_if_no_migrations_required();
408
+		}
409
+	}
410
+
411
+
412
+
413
+	/**
414
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
415
+	 *
416
+	 * @param    array  $version_history
417
+	 * @param    string $current_version_to_add version to be added to the version history
418
+	 * @return    boolean success as to whether or not this option was changed
419
+	 */
420
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
421
+	{
422
+		if ( ! $version_history) {
423
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
424
+		}
425
+		if ($current_version_to_add == null) {
426
+			$current_version_to_add = espresso_version();
427
+		}
428
+		$version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
429
+		// re-save
430
+		return update_option('espresso_db_update', $version_history);
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * Detects if the current version indicated in the has existed in the list of
437
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
438
+	 *
439
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
440
+	 *                                  If not supplied, fetches it from the options table.
441
+	 *                                  Also, caches its result so later parts of the code can also know whether
442
+	 *                                  there's been an update or not. This way we can add the current version to
443
+	 *                                  espresso_db_update, but still know if this is a new install or not
444
+	 * @return int one of the constants on EE_System::req_type_
445
+	 */
446
+	public function detect_req_type($espresso_db_update = null)
447
+	{
448
+		if ($this->_req_type === null) {
449
+			$espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update
450
+				: $this->fix_espresso_db_upgrade_option();
451
+			$this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update,
452
+				'ee_espresso_activation', espresso_version());
453
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
454
+		}
455
+		return $this->_req_type;
456
+	}
457
+
458
+
459
+
460
+	/**
461
+	 * Returns whether or not there was a non-micro version change (ie, change in either
462
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
463
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
464
+	 *
465
+	 * @param $activation_history
466
+	 * @return bool
467
+	 */
468
+	protected function _detect_major_version_change($activation_history)
469
+	{
470
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
471
+		$previous_version_parts = explode('.', $previous_version);
472
+		$current_version_parts = explode('.', espresso_version());
473
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
474
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
475
+				   || $previous_version_parts[1] !== $current_version_parts[1]
476
+			   );
477
+	}
478
+
479
+
480
+
481
+	/**
482
+	 * Returns true if either the major or minor version of EE changed during this request.
483
+	 * 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
484
+	 *
485
+	 * @return bool
486
+	 */
487
+	public function is_major_version_change()
488
+	{
489
+		return $this->_major_version_change;
490
+	}
491
+
492
+
493
+
494
+	/**
495
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
496
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily
497
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
498
+	 * just activated to (for core that will always be espresso_version())
499
+	 *
500
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
501
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
502
+	 * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to
503
+	 *                                                 indicate that this plugin was just activated
504
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
505
+	 *                                                 espresso_version())
506
+	 * @return int one of the constants on EE_System::req_type_*
507
+	 */
508
+	public static function detect_req_type_given_activation_history(
509
+		$activation_history_for_addon,
510
+		$activation_indicator_option_name,
511
+		$version_to_upgrade_to
512
+	) {
513
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
514
+		if ($activation_history_for_addon) {
515
+			//it exists, so this isn't a completely new install
516
+			//check if this version already in that list of previously installed versions
517
+			if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
518
+				//it a version we haven't seen before
519
+				if ($version_is_higher === 1) {
520
+					$req_type = EE_System::req_type_upgrade;
521
+				} else {
522
+					$req_type = EE_System::req_type_downgrade;
523
+				}
524
+				delete_option($activation_indicator_option_name);
525
+			} else {
526
+				// its not an update. maybe a reactivation?
527
+				if (get_option($activation_indicator_option_name, false)) {
528
+					if ($version_is_higher === -1) {
529
+						$req_type = EE_System::req_type_downgrade;
530
+					} elseif ($version_is_higher === 0) {
531
+						//we've seen this version before, but it's an activation. must be a reactivation
532
+						$req_type = EE_System::req_type_reactivation;
533
+					} else {//$version_is_higher === 1
534
+						$req_type = EE_System::req_type_upgrade;
535
+					}
536
+					delete_option($activation_indicator_option_name);
537
+				} else {
538
+					//we've seen this version before and the activation indicate doesn't show it was just activated
539
+					if ($version_is_higher === -1) {
540
+						$req_type = EE_System::req_type_downgrade;
541
+					} elseif ($version_is_higher === 0) {
542
+						//we've seen this version before and it's not an activation. its normal request
543
+						$req_type = EE_System::req_type_normal;
544
+					} else {//$version_is_higher === 1
545
+						$req_type = EE_System::req_type_upgrade;
546
+					}
547
+				}
548
+			}
549
+		} else {
550
+			//brand new install
551
+			$req_type = EE_System::req_type_new_activation;
552
+			delete_option($activation_indicator_option_name);
553
+		}
554
+		return $req_type;
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
561
+	 * the $activation_history_for_addon
562
+	 *
563
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
564
+	 *                                             sometimes containing 'unknown-date'
565
+	 * @param string $version_to_upgrade_to        (current version)
566
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
567
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
568
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
569
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
570
+	 */
571
+	protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
572
+	{
573
+		//find the most recently-activated version
574
+		$most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
575
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
576
+	}
577
+
578
+
579
+
580
+	/**
581
+	 * Gets the most recently active version listed in the activation history,
582
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
583
+	 *
584
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
585
+	 *                                   sometimes containing 'unknown-date'
586
+	 * @return string
587
+	 */
588
+	protected static function _get_most_recently_active_version_from_activation_history($activation_history)
589
+	{
590
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
591
+		$most_recently_active_version = '0.0.0.dev.000';
592
+		if (is_array($activation_history)) {
593
+			foreach ($activation_history as $version => $times_activated) {
594
+				//check there is a record of when this version was activated. Otherwise,
595
+				//mark it as unknown
596
+				if ( ! $times_activated) {
597
+					$times_activated = array('unknown-date');
598
+				}
599
+				if (is_string($times_activated)) {
600
+					$times_activated = array($times_activated);
601
+				}
602
+				foreach ($times_activated as $an_activation) {
603
+					if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) {
604
+						$most_recently_active_version = $version;
605
+						$most_recently_active_version_activation = $an_activation == 'unknown-date'
606
+							? '1970-01-01 00:00:00' : $an_activation;
607
+					}
608
+				}
609
+			}
610
+		}
611
+		return $most_recently_active_version;
612
+	}
613
+
614
+
615
+
616
+	/**
617
+	 * This redirects to the about EE page after activation
618
+	 *
619
+	 * @return void
620
+	 */
621
+	public function redirect_to_about_ee()
622
+	{
623
+		$notices = EE_Error::get_notices(false);
624
+		//if current user is an admin and it's not an ajax or rest request
625
+		if (
626
+			! (defined('DOING_AJAX') && DOING_AJAX)
627
+			&& ! (defined('REST_REQUEST') && REST_REQUEST)
628
+			&& ! isset($notices['errors'])
629
+			&& apply_filters(
630
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
631
+				$this->registry->CAP->current_user_can('manage_options', 'espresso_about_default')
632
+			)
633
+		) {
634
+			$query_params = array('page' => 'espresso_about');
635
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) {
636
+				$query_params['new_activation'] = true;
637
+			}
638
+			if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) {
639
+				$query_params['reactivation'] = true;
640
+			}
641
+			$url = add_query_arg($query_params, admin_url('admin.php'));
642
+			wp_safe_redirect($url);
643
+			exit();
644
+		}
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * load_core_configuration
651
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
652
+	 * which runs during the WP 'plugins_loaded' action at priority 5
653
+	 *
654
+	 * @return void
655
+	 */
656
+	public function load_core_configuration()
657
+	{
658
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
659
+		$this->registry->load_core('EE_Load_Textdomain');
660
+		//load textdomain
661
+		EE_Load_Textdomain::load_textdomain();
662
+		// load and setup EE_Config and EE_Network_Config
663
+		$this->registry->load_core('Config');
664
+		$this->registry->load_core('Network_Config');
665
+		// setup autoloaders
666
+		// enable logging?
667
+		if ($this->registry->CFG->admin->use_full_logging) {
668
+			$this->registry->load_core('Log');
669
+		}
670
+		// check for activation errors
671
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
672
+		if ($activation_errors) {
673
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
674
+			update_option('ee_plugin_activation_errors', false);
675
+		}
676
+		// get model names
677
+		$this->_parse_model_names();
678
+		//load caf stuff a chance to play during the activation process too.
679
+		$this->_maybe_brew_regular();
680
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
681
+	}
682
+
683
+
684
+
685
+	/**
686
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
687
+	 *
688
+	 * @return void
689
+	 */
690
+	private function _parse_model_names()
691
+	{
692
+		//get all the files in the EE_MODELS folder that end in .model.php
693
+		$models = glob(EE_MODELS . '*.model.php');
694
+		$model_names = array();
695
+		$non_abstract_db_models = array();
696
+		foreach ($models as $model) {
697
+			// get model classname
698
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
699
+			$short_name = str_replace('EEM_', '', $classname);
700
+			$reflectionClass = new ReflectionClass($classname);
701
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
702
+				$non_abstract_db_models[$short_name] = $classname;
703
+			}
704
+			$model_names[$short_name] = $classname;
705
+		}
706
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
707
+		$this->registry->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names',
708
+			$non_abstract_db_models);
709
+	}
710
+
711
+
712
+
713
+	/**
714
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
715
+	 * that need to be setup before our EE_System launches.
716
+	 *
717
+	 * @return void
718
+	 */
719
+	private function _maybe_brew_regular()
720
+	{
721
+		if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
722
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
723
+		}
724
+	}
725
+
726
+
727
+
728
+	/**
729
+	 * register_shortcodes_modules_and_widgets
730
+	 * generate lists of shortcodes and modules, then verify paths and classes
731
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
732
+	 * which runs during the WP 'plugins_loaded' action at priority 7
733
+	 *
734
+	 * @access public
735
+	 * @return void
736
+	 */
737
+	public function register_shortcodes_modules_and_widgets()
738
+	{
739
+		try {
740
+			// load, register, and add shortcodes the new way
741
+			new ShortcodesManager(
742
+			// and the old way, but we'll put it under control of the new system
743
+				EE_Config::getLegacyShortcodesManager()
744
+			);
745
+		} catch (Exception $exception) {
746
+			new ExceptionStackTraceDisplay($exception);
747
+		}
748
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
749
+		// check for addons using old hookpoint
750
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
751
+			$this->_incompatible_addon_error();
752
+		}
753
+	}
754
+
755
+
756
+
757
+	/**
758
+	 * _incompatible_addon_error
759
+	 *
760
+	 * @access public
761
+	 * @return void
762
+	 */
763
+	private function _incompatible_addon_error()
764
+	{
765
+		// get array of classes hooking into here
766
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons');
767
+		if ( ! empty($class_names)) {
768
+			$msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
769
+				'event_espresso');
770
+			$msg .= '<ul>';
771
+			foreach ($class_names as $class_name) {
772
+				$msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
+						$class_name) . '</b></li>';
774
+			}
775
+			$msg .= '</ul>';
776
+			$msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
777
+				'event_espresso');
778
+			// save list of incompatible addons to wp-options for later use
779
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
780
+			if (is_admin()) {
781
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
782
+			}
783
+		}
784
+	}
785
+
786
+
787
+
788
+	/**
789
+	 * brew_espresso
790
+	 * begins the process of setting hooks for initializing EE in the correct order
791
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint
792
+	 * which runs during the WP 'plugins_loaded' action at priority 9
793
+	 *
794
+	 * @return void
795
+	 */
796
+	public function brew_espresso()
797
+	{
798
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
799
+		// load some final core systems
800
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
801
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
802
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
803
+		add_action('init', array($this, 'load_controllers'), 7);
804
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
805
+		add_action('init', array($this, 'initialize'), 10);
806
+		add_action('init', array($this, 'initialize_last'), 100);
807
+		add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100);
808
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
809
+			// pew pew pew
810
+			$this->registry->load_core('PUE');
811
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
812
+		}
813
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
814
+	}
815
+
816
+
817
+
818
+	/**
819
+	 *    set_hooks_for_core
820
+	 *
821
+	 * @access public
822
+	 * @return    void
823
+	 */
824
+	public function set_hooks_for_core()
825
+	{
826
+		$this->_deactivate_incompatible_addons();
827
+		do_action('AHEE__EE_System__set_hooks_for_core');
828
+	}
829
+
830
+
831
+
832
+	/**
833
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
834
+	 * deactivates any addons considered incompatible with the current version of EE
835
+	 */
836
+	private function _deactivate_incompatible_addons()
837
+	{
838
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
839
+		if ( ! empty($incompatible_addons)) {
840
+			$active_plugins = get_option('active_plugins', array());
841
+			foreach ($active_plugins as $active_plugin) {
842
+				foreach ($incompatible_addons as $incompatible_addon) {
843
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
844
+						unset($_GET['activate']);
845
+						espresso_deactivate_plugin($active_plugin);
846
+					}
847
+				}
848
+			}
849
+		}
850
+	}
851
+
852
+
853
+
854
+	/**
855
+	 *    perform_activations_upgrades_and_migrations
856
+	 *
857
+	 * @access public
858
+	 * @return    void
859
+	 */
860
+	public function perform_activations_upgrades_and_migrations()
861
+	{
862
+		//first check if we had previously attempted to setup EE's directories but failed
863
+		if (EEH_Activation::upload_directories_incomplete()) {
864
+			EEH_Activation::create_upload_directories();
865
+		}
866
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 *    load_CPTs_and_session
873
+	 *
874
+	 * @access public
875
+	 * @return    void
876
+	 */
877
+	public function load_CPTs_and_session()
878
+	{
879
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
880
+		// register Custom Post Types
881
+		$this->registry->load_core('Register_CPTs');
882
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
883
+	}
884
+
885
+
886
+
887
+	/**
888
+	 * load_controllers
889
+	 * this is the best place to load any additional controllers that needs access to EE core.
890
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
891
+	 * time
892
+	 *
893
+	 * @access public
894
+	 * @return void
895
+	 */
896
+	public function load_controllers()
897
+	{
898
+		do_action('AHEE__EE_System__load_controllers__start');
899
+		// let's get it started
900
+		if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
901
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
902
+			$this->registry->load_core('Front_Controller');
903
+		} else if ( ! EE_FRONT_AJAX) {
904
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
905
+			EE_Registry::instance()->load_core('Admin');
906
+		}
907
+		do_action('AHEE__EE_System__load_controllers__complete');
908
+	}
909
+
910
+
911
+
912
+	/**
913
+	 * core_loaded_and_ready
914
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
915
+	 *
916
+	 * @access public
917
+	 * @return void
918
+	 */
919
+	public function core_loaded_and_ready()
920
+	{
921
+		$this->registry->load_core('Session');
922
+		do_action('AHEE__EE_System__core_loaded_and_ready');
923
+		// load_espresso_template_tags
924
+		if (is_readable(EE_PUBLIC . 'template_tags.php')) {
925
+			require_once(EE_PUBLIC . 'template_tags.php');
926
+		}
927
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
928
+		$this->registry->create('EventEspresso\core\services\assets\Registry');
929
+		wp_enqueue_script('espresso_core');
930
+	}
931
+
932
+
933
+
934
+	/**
935
+	 * initialize
936
+	 * this is the best place to begin initializing client code
937
+	 *
938
+	 * @access public
939
+	 * @return void
940
+	 */
941
+	public function initialize()
942
+	{
943
+		do_action('AHEE__EE_System__initialize');
944
+	}
945
+
946
+
947
+
948
+	/**
949
+	 * initialize_last
950
+	 * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to
951
+	 * initialize has done so
952
+	 *
953
+	 * @access public
954
+	 * @return void
955
+	 */
956
+	public function initialize_last()
957
+	{
958
+		do_action('AHEE__EE_System__initialize_last');
959
+	}
960
+
961
+
962
+
963
+	/**
964
+	 * set_hooks_for_shortcodes_modules_and_addons
965
+	 * this is the best place for other systems to set callbacks for hooking into other parts of EE
966
+	 * this happens at the very beginning of the wp_loaded hookpoint
967
+	 *
968
+	 * @access public
969
+	 * @return void
970
+	 */
971
+	public function set_hooks_for_shortcodes_modules_and_addons()
972
+	{
973
+		//		do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' );
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * do_not_cache
980
+	 * sets no cache headers and defines no cache constants for WP plugins
981
+	 *
982
+	 * @access public
983
+	 * @return void
984
+	 */
985
+	public static function do_not_cache()
986
+	{
987
+		// set no cache constants
988
+		if ( ! defined('DONOTCACHEPAGE')) {
989
+			define('DONOTCACHEPAGE', true);
990
+		}
991
+		if ( ! defined('DONOTCACHCEOBJECT')) {
992
+			define('DONOTCACHCEOBJECT', true);
993
+		}
994
+		if ( ! defined('DONOTCACHEDB')) {
995
+			define('DONOTCACHEDB', true);
996
+		}
997
+		// add no cache headers
998
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
999
+		// plus a little extra for nginx and Google Chrome
1000
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1001
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1002
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1003
+	}
1004
+
1005
+
1006
+
1007
+	/**
1008
+	 *    extra_nocache_headers
1009
+	 *
1010
+	 * @access    public
1011
+	 * @param $headers
1012
+	 * @return    array
1013
+	 */
1014
+	public static function extra_nocache_headers($headers)
1015
+	{
1016
+		// for NGINX
1017
+		$headers['X-Accel-Expires'] = 0;
1018
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1019
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1020
+		return $headers;
1021
+	}
1022
+
1023
+
1024
+
1025
+	/**
1026
+	 *    nocache_headers
1027
+	 *
1028
+	 * @access    public
1029
+	 * @return    void
1030
+	 */
1031
+	public static function nocache_headers()
1032
+	{
1033
+		nocache_headers();
1034
+	}
1035
+
1036
+
1037
+
1038
+	/**
1039
+	 *    espresso_toolbar_items
1040
+	 *
1041
+	 * @access public
1042
+	 * @param  WP_Admin_Bar $admin_bar
1043
+	 * @return void
1044
+	 */
1045
+	public function espresso_toolbar_items(WP_Admin_Bar $admin_bar)
1046
+	{
1047
+		// if in full M-Mode, or its an AJAX request, or user is NOT an admin
1048
+		if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance
1049
+			|| defined('DOING_AJAX')
1050
+			|| ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
1051
+		) {
1052
+			return;
1053
+		}
1054
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1055
+		$menu_class = 'espresso_menu_item_class';
1056
+		//we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
1057
+		//because they're only defined in each of their respective constructors
1058
+		//and this might be a frontend request, in which case they aren't available
1059
+		$events_admin_url = admin_url("admin.php?page=espresso_events");
1060
+		$reg_admin_url = admin_url("admin.php?page=espresso_registrations");
1061
+		$extensions_admin_url = admin_url("admin.php?page=espresso_packages");
1062
+		//Top Level
1063
+		$admin_bar->add_menu(array(
1064
+			'id'    => 'espresso-toolbar',
1065
+			'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
1066
+					   . _x('Event Espresso', 'admin bar menu group label', 'event_espresso')
1067
+					   . '</span>',
1068
+			'href'  => $events_admin_url,
1069
+			'meta'  => array(
1070
+				'title' => __('Event Espresso', 'event_espresso'),
1071
+				'class' => $menu_class . 'first',
1072
+			),
1073
+		));
1074
+		//Events
1075
+		if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) {
1076
+			$admin_bar->add_menu(array(
1077
+				'id'     => 'espresso-toolbar-events',
1078
+				'parent' => 'espresso-toolbar',
1079
+				'title'  => __('Events', 'event_espresso'),
1080
+				'href'   => $events_admin_url,
1081
+				'meta'   => array(
1082
+					'title'  => __('Events', 'event_espresso'),
1083
+					'target' => '',
1084
+					'class'  => $menu_class,
1085
+				),
1086
+			));
1087
+		}
1088
+		if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) {
1089
+			//Events Add New
1090
+			$admin_bar->add_menu(array(
1091
+				'id'     => 'espresso-toolbar-events-new',
1092
+				'parent' => 'espresso-toolbar-events',
1093
+				'title'  => __('Add New', 'event_espresso'),
1094
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url),
1095
+				'meta'   => array(
1096
+					'title'  => __('Add New', 'event_espresso'),
1097
+					'target' => '',
1098
+					'class'  => $menu_class,
1099
+				),
1100
+			));
1101
+		}
1102
+		if (is_single() && (get_post_type() == 'espresso_events')) {
1103
+			//Current post
1104
+			global $post;
1105
+			if ($this->registry->CAP->current_user_can('ee_edit_event',
1106
+				'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID)
1107
+			) {
1108
+				//Events Edit Current Event
1109
+				$admin_bar->add_menu(array(
1110
+					'id'     => 'espresso-toolbar-events-edit',
1111
+					'parent' => 'espresso-toolbar-events',
1112
+					'title'  => __('Edit Event', 'event_espresso'),
1113
+					'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID),
1114
+						$events_admin_url),
1115
+					'meta'   => array(
1116
+						'title'  => __('Edit Event', 'event_espresso'),
1117
+						'target' => '',
1118
+						'class'  => $menu_class,
1119
+					),
1120
+				));
1121
+			}
1122
+		}
1123
+		//Events View
1124
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1125
+			'ee_admin_bar_menu_espresso-toolbar-events-view')
1126
+		) {
1127
+			$admin_bar->add_menu(array(
1128
+				'id'     => 'espresso-toolbar-events-view',
1129
+				'parent' => 'espresso-toolbar-events',
1130
+				'title'  => __('View', 'event_espresso'),
1131
+				'href'   => $events_admin_url,
1132
+				'meta'   => array(
1133
+					'title'  => __('View', 'event_espresso'),
1134
+					'target' => '',
1135
+					'class'  => $menu_class,
1136
+				),
1137
+			));
1138
+		}
1139
+		if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) {
1140
+			//Events View All
1141
+			$admin_bar->add_menu(array(
1142
+				'id'     => 'espresso-toolbar-events-all',
1143
+				'parent' => 'espresso-toolbar-events-view',
1144
+				'title'  => __('All', 'event_espresso'),
1145
+				'href'   => $events_admin_url,
1146
+				'meta'   => array(
1147
+					'title'  => __('All', 'event_espresso'),
1148
+					'target' => '',
1149
+					'class'  => $menu_class,
1150
+				),
1151
+			));
1152
+		}
1153
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1154
+			'ee_admin_bar_menu_espresso-toolbar-events-today')
1155
+		) {
1156
+			//Events View Today
1157
+			$admin_bar->add_menu(array(
1158
+				'id'     => 'espresso-toolbar-events-today',
1159
+				'parent' => 'espresso-toolbar-events-view',
1160
+				'title'  => __('Today', 'event_espresso'),
1161
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1162
+					$events_admin_url),
1163
+				'meta'   => array(
1164
+					'title'  => __('Today', 'event_espresso'),
1165
+					'target' => '',
1166
+					'class'  => $menu_class,
1167
+				),
1168
+			));
1169
+		}
1170
+		if ($this->registry->CAP->current_user_can('ee_read_events',
1171
+			'ee_admin_bar_menu_espresso-toolbar-events-month')
1172
+		) {
1173
+			//Events View This Month
1174
+			$admin_bar->add_menu(array(
1175
+				'id'     => 'espresso-toolbar-events-month',
1176
+				'parent' => 'espresso-toolbar-events-view',
1177
+				'title'  => __('This Month', 'event_espresso'),
1178
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1179
+					$events_admin_url),
1180
+				'meta'   => array(
1181
+					'title'  => __('This Month', 'event_espresso'),
1182
+					'target' => '',
1183
+					'class'  => $menu_class,
1184
+				),
1185
+			));
1186
+		}
1187
+		//Registration Overview
1188
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1189
+			'ee_admin_bar_menu_espresso-toolbar-registrations')
1190
+		) {
1191
+			$admin_bar->add_menu(array(
1192
+				'id'     => 'espresso-toolbar-registrations',
1193
+				'parent' => 'espresso-toolbar',
1194
+				'title'  => __('Registrations', 'event_espresso'),
1195
+				'href'   => $reg_admin_url,
1196
+				'meta'   => array(
1197
+					'title'  => __('Registrations', 'event_espresso'),
1198
+					'target' => '',
1199
+					'class'  => $menu_class,
1200
+				),
1201
+			));
1202
+		}
1203
+		//Registration Overview Today
1204
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1205
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today')
1206
+		) {
1207
+			$admin_bar->add_menu(array(
1208
+				'id'     => 'espresso-toolbar-registrations-today',
1209
+				'parent' => 'espresso-toolbar-registrations',
1210
+				'title'  => __('Today', 'event_espresso'),
1211
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'),
1212
+					$reg_admin_url),
1213
+				'meta'   => array(
1214
+					'title'  => __('Today', 'event_espresso'),
1215
+					'target' => '',
1216
+					'class'  => $menu_class,
1217
+				),
1218
+			));
1219
+		}
1220
+		//Registration Overview Today Completed
1221
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1222
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved')
1223
+		) {
1224
+			$admin_bar->add_menu(array(
1225
+				'id'     => 'espresso-toolbar-registrations-today-approved',
1226
+				'parent' => 'espresso-toolbar-registrations-today',
1227
+				'title'  => __('Approved', 'event_espresso'),
1228
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1229
+					'action'      => 'default',
1230
+					'status'      => 'today',
1231
+					'_reg_status' => EEM_Registration::status_id_approved,
1232
+				), $reg_admin_url),
1233
+				'meta'   => array(
1234
+					'title'  => __('Approved', 'event_espresso'),
1235
+					'target' => '',
1236
+					'class'  => $menu_class,
1237
+				),
1238
+			));
1239
+		}
1240
+		//Registration Overview Today Pending\
1241
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1242
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending')
1243
+		) {
1244
+			$admin_bar->add_menu(array(
1245
+				'id'     => 'espresso-toolbar-registrations-today-pending',
1246
+				'parent' => 'espresso-toolbar-registrations-today',
1247
+				'title'  => __('Pending', 'event_espresso'),
1248
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1249
+					'action'     => 'default',
1250
+					'status'     => 'today',
1251
+					'reg_status' => EEM_Registration::status_id_pending_payment,
1252
+				), $reg_admin_url),
1253
+				'meta'   => array(
1254
+					'title'  => __('Pending Payment', 'event_espresso'),
1255
+					'target' => '',
1256
+					'class'  => $menu_class,
1257
+				),
1258
+			));
1259
+		}
1260
+		//Registration Overview Today Incomplete
1261
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1262
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved')
1263
+		) {
1264
+			$admin_bar->add_menu(array(
1265
+				'id'     => 'espresso-toolbar-registrations-today-not-approved',
1266
+				'parent' => 'espresso-toolbar-registrations-today',
1267
+				'title'  => __('Not Approved', 'event_espresso'),
1268
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1269
+					'action'      => 'default',
1270
+					'status'      => 'today',
1271
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1272
+				), $reg_admin_url),
1273
+				'meta'   => array(
1274
+					'title'  => __('Not Approved', 'event_espresso'),
1275
+					'target' => '',
1276
+					'class'  => $menu_class,
1277
+				),
1278
+			));
1279
+		}
1280
+		//Registration Overview Today Incomplete
1281
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1282
+			'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled')
1283
+		) {
1284
+			$admin_bar->add_menu(array(
1285
+				'id'     => 'espresso-toolbar-registrations-today-cancelled',
1286
+				'parent' => 'espresso-toolbar-registrations-today',
1287
+				'title'  => __('Cancelled', 'event_espresso'),
1288
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1289
+					'action'      => 'default',
1290
+					'status'      => 'today',
1291
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1292
+				), $reg_admin_url),
1293
+				'meta'   => array(
1294
+					'title'  => __('Cancelled', 'event_espresso'),
1295
+					'target' => '',
1296
+					'class'  => $menu_class,
1297
+				),
1298
+			));
1299
+		}
1300
+		//Registration Overview This Month
1301
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1302
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month')
1303
+		) {
1304
+			$admin_bar->add_menu(array(
1305
+				'id'     => 'espresso-toolbar-registrations-month',
1306
+				'parent' => 'espresso-toolbar-registrations',
1307
+				'title'  => __('This Month', 'event_espresso'),
1308
+				'href'   => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'),
1309
+					$reg_admin_url),
1310
+				'meta'   => array(
1311
+					'title'  => __('This Month', 'event_espresso'),
1312
+					'target' => '',
1313
+					'class'  => $menu_class,
1314
+				),
1315
+			));
1316
+		}
1317
+		//Registration Overview This Month Approved
1318
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1319
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved')
1320
+		) {
1321
+			$admin_bar->add_menu(array(
1322
+				'id'     => 'espresso-toolbar-registrations-month-approved',
1323
+				'parent' => 'espresso-toolbar-registrations-month',
1324
+				'title'  => __('Approved', 'event_espresso'),
1325
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1326
+					'action'      => 'default',
1327
+					'status'      => 'month',
1328
+					'_reg_status' => EEM_Registration::status_id_approved,
1329
+				), $reg_admin_url),
1330
+				'meta'   => array(
1331
+					'title'  => __('Approved', 'event_espresso'),
1332
+					'target' => '',
1333
+					'class'  => $menu_class,
1334
+				),
1335
+			));
1336
+		}
1337
+		//Registration Overview This Month Pending
1338
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1339
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending')
1340
+		) {
1341
+			$admin_bar->add_menu(array(
1342
+				'id'     => 'espresso-toolbar-registrations-month-pending',
1343
+				'parent' => 'espresso-toolbar-registrations-month',
1344
+				'title'  => __('Pending', 'event_espresso'),
1345
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1346
+					'action'      => 'default',
1347
+					'status'      => 'month',
1348
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1349
+				), $reg_admin_url),
1350
+				'meta'   => array(
1351
+					'title'  => __('Pending', 'event_espresso'),
1352
+					'target' => '',
1353
+					'class'  => $menu_class,
1354
+				),
1355
+			));
1356
+		}
1357
+		//Registration Overview This Month Not Approved
1358
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1359
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved')
1360
+		) {
1361
+			$admin_bar->add_menu(array(
1362
+				'id'     => 'espresso-toolbar-registrations-month-not-approved',
1363
+				'parent' => 'espresso-toolbar-registrations-month',
1364
+				'title'  => __('Not Approved', 'event_espresso'),
1365
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1366
+					'action'      => 'default',
1367
+					'status'      => 'month',
1368
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1369
+				), $reg_admin_url),
1370
+				'meta'   => array(
1371
+					'title'  => __('Not Approved', 'event_espresso'),
1372
+					'target' => '',
1373
+					'class'  => $menu_class,
1374
+				),
1375
+			));
1376
+		}
1377
+		//Registration Overview This Month Cancelled
1378
+		if ($this->registry->CAP->current_user_can('ee_read_registrations',
1379
+			'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled')
1380
+		) {
1381
+			$admin_bar->add_menu(array(
1382
+				'id'     => 'espresso-toolbar-registrations-month-cancelled',
1383
+				'parent' => 'espresso-toolbar-registrations-month',
1384
+				'title'  => __('Cancelled', 'event_espresso'),
1385
+				'href'   => EEH_URL::add_query_args_and_nonce(array(
1386
+					'action'      => 'default',
1387
+					'status'      => 'month',
1388
+					'_reg_status' => EEM_Registration::status_id_cancelled,
1389
+				), $reg_admin_url),
1390
+				'meta'   => array(
1391
+					'title'  => __('Cancelled', 'event_espresso'),
1392
+					'target' => '',
1393
+					'class'  => $menu_class,
1394
+				),
1395
+			));
1396
+		}
1397
+		//Extensions & Services
1398
+		if ($this->registry->CAP->current_user_can('ee_read_ee',
1399
+			'ee_admin_bar_menu_espresso-toolbar-extensions-and-services')
1400
+		) {
1401
+			$admin_bar->add_menu(array(
1402
+				'id'     => 'espresso-toolbar-extensions-and-services',
1403
+				'parent' => 'espresso-toolbar',
1404
+				'title'  => __('Extensions & Services', 'event_espresso'),
1405
+				'href'   => $extensions_admin_url,
1406
+				'meta'   => array(
1407
+					'title'  => __('Extensions & Services', 'event_espresso'),
1408
+					'target' => '',
1409
+					'class'  => $menu_class,
1410
+				),
1411
+			));
1412
+		}
1413
+	}
1414
+
1415
+
1416
+
1417
+	/**
1418
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1419
+	 * never returned with the function.
1420
+	 *
1421
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1422
+	 * @return array
1423
+	 */
1424
+	public function remove_pages_from_wp_list_pages($exclude_array)
1425
+	{
1426
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1427
+	}
1428 1428
 
1429 1429
 
1430 1430
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
     {
186 186
         // set autoloaders for all of the classes implementing EEI_Plugin_API
187 187
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
188
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
188
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
189 189
         //load and setup EE_Capabilities
190 190
         $this->registry->load_core('Capabilities');
191 191
         //caps need to be initialized on every request so that capability maps are set.
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
                 && $_GET['activate'] === 'true'
209 209
             )
210 210
         ) {
211
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
211
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
212 212
         }
213 213
         do_action('AHEE__EE_System__load_espresso_addons__complete');
214 214
     }
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
     private function _parse_model_names()
691 691
     {
692 692
         //get all the files in the EE_MODELS folder that end in .model.php
693
-        $models = glob(EE_MODELS . '*.model.php');
693
+        $models = glob(EE_MODELS.'*.model.php');
694 694
         $model_names = array();
695 695
         $non_abstract_db_models = array();
696 696
         foreach ($models as $model) {
@@ -718,8 +718,8 @@  discard block
 block discarded – undo
718 718
      */
719 719
     private function _maybe_brew_regular()
720 720
     {
721
-        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
722
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
721
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
722
+            require_once EE_CAFF_PATH.'brewing_regular.php';
723 723
         }
724 724
     }
725 725
 
@@ -769,8 +769,8 @@  discard block
 block discarded – undo
769 769
                 'event_espresso');
770 770
             $msg .= '<ul>';
771 771
             foreach ($class_names as $class_name) {
772
-                $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
-                        $class_name) . '</b></li>';
772
+                $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
773
+                        $class_name).'</b></li>';
774 774
             }
775 775
             $msg .= '</ul>';
776 776
             $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
@@ -921,8 +921,8 @@  discard block
 block discarded – undo
921 921
         $this->registry->load_core('Session');
922 922
         do_action('AHEE__EE_System__core_loaded_and_ready');
923 923
         // load_espresso_template_tags
924
-        if (is_readable(EE_PUBLIC . 'template_tags.php')) {
925
-            require_once(EE_PUBLIC . 'template_tags.php');
924
+        if (is_readable(EE_PUBLIC.'template_tags.php')) {
925
+            require_once(EE_PUBLIC.'template_tags.php');
926 926
         }
927 927
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
928 928
         $this->registry->create('EventEspresso\core\services\assets\Registry');
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
             'href'  => $events_admin_url,
1069 1069
             'meta'  => array(
1070 1070
                 'title' => __('Event Espresso', 'event_espresso'),
1071
-                'class' => $menu_class . 'first',
1071
+                'class' => $menu_class.'first',
1072 1072
             ),
1073 1073
         ));
1074 1074
         //Events
Please login to merge, or discard this patch.
core/EE_Session.core.php 1 patch
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\exceptions\InvalidSessionDataException;
3 3
 use EventEspresso\core\services\cache\CacheStorageInterface;
4 4
 
5
-if (!defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
5
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
6 6
 /**
7 7
  *
8 8
  * EE_Session class
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	  * array for defining default session vars
109 109
 	  * @var array
110 110
 	  */
111
-	 private $_default_session_vars = array (
111
+	 private $_default_session_vars = array(
112 112
         'id'            => null,
113 113
         'user_id'       => null,
114 114
         'ip_address'    => null,
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
 		// check if class object is instantiated
137 137
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
138 138
 		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
139
-		if ( ! self::$_instance instanceof EE_Session && apply_filters( 'FHEE_load_EE_Session', true ) ) {
140
-			self::$_instance = new self($cache_storage, $encryption );
139
+		if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
140
+			self::$_instance = new self($cache_storage, $encryption);
141 141
 		}
142 142
 		return self::$_instance;
143 143
 	}
@@ -152,15 +152,15 @@  discard block
 block discarded – undo
152 152
 	  * @throws \EE_Error
153 153
 	  * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
154 154
 	  */
155
-	 protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null ) {
155
+	 protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null) {
156 156
 
157 157
 		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
158
-		if ( ! apply_filters( 'FHEE_load_EE_Session', true ) ) {
158
+		if ( ! apply_filters('FHEE_load_EE_Session', true)) {
159 159
 			return;
160 160
 		}
161
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
162
-		if ( ! defined( 'ESPRESSO_SESSION' ) ) {
163
-			define( 'ESPRESSO_SESSION', true );
161
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
162
+		if ( ! defined('ESPRESSO_SESSION')) {
163
+			define('ESPRESSO_SESSION', true);
164 164
 		}
165 165
 		// default session lifespan in seconds
166 166
 		$this->_lifespan = apply_filters(
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 		 * 		}
175 175
 		 */
176 176
 		// retrieve session options from db
177
-		$session_settings = (array) get_option( 'ee_session_settings', array() );
178
-		if ( ! empty( $session_settings )) {
177
+		$session_settings = (array) get_option('ee_session_settings', array());
178
+		if ( ! empty($session_settings)) {
179 179
 			// cycle though existing session options
180
-			foreach ( $session_settings as $var_name => $session_setting ) {
180
+			foreach ($session_settings as $var_name => $session_setting) {
181 181
 				// set values for class properties
182
-				$var_name = '_' . $var_name;
182
+				$var_name = '_'.$var_name;
183 183
 				$this->{$var_name} = $session_setting;
184 184
 			}
185 185
 		}
@@ -190,15 +190,15 @@  discard block
 block discarded – undo
190 190
         // encrypt data via: $this->encryption->encrypt();
191 191
         $this->encryption = $encryption;
192 192
 		// filter hook allows outside functions/classes/plugins to change default empty cart
193
-		$extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() );
194
-		array_merge( $this->_default_session_vars, $extra_default_session_vars );
193
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
194
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
195 195
 		// apply default session vars
196 196
 		$this->_set_defaults();
197 197
          add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
198 198
          // check request for 'clear_session' param
199
-		add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' ));
199
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
200 200
 		// once everything is all said and done,
201
-		add_action( 'shutdown', array( $this, 'update' ), 100 );
201
+		add_action('shutdown', array($this, 'update'), 100);
202 202
          $this->configure_garbage_collection_filters();
203 203
 	}
204 204
 
@@ -286,11 +286,11 @@  discard block
 block discarded – undo
286 286
 	 */
287 287
 	private function _set_defaults() {
288 288
 		// set some defaults
289
-		foreach ( $this->_default_session_vars as $key => $default_var ) {
290
-			if ( is_array( $default_var )) {
291
-				$this->_session_data[ $key ] = array();
289
+		foreach ($this->_default_session_vars as $key => $default_var) {
290
+			if (is_array($default_var)) {
291
+				$this->_session_data[$key] = array();
292 292
 			} else {
293
-				$this->_session_data[ $key ] = '';
293
+				$this->_session_data[$key] = '';
294 294
 			}
295 295
 		}
296 296
 	}
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	  * @param \EE_Checkout $checkout
346 346
 	  * @return bool
347 347
 	  */
348
-	 public function set_checkout( EE_Checkout $checkout ) {
348
+	 public function set_checkout(EE_Checkout $checkout) {
349 349
 		 $this->_session_data['checkout'] = $checkout;
350 350
 		 return TRUE;
351 351
 	 }
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
 	  * @return bool
379 379
 	  * @throws \EE_Error
380 380
 	  */
381
-	 public function set_transaction( EE_Transaction $transaction ) {
381
+	 public function set_transaction(EE_Transaction $transaction) {
382 382
 		 // first remove the session from the transaction before we save the transaction in the session
383
-		 $transaction->set_txn_session_data( NULL );
383
+		 $transaction->set_txn_session_data(NULL);
384 384
 		 $this->_session_data['transaction'] = $transaction;
385 385
 		 return TRUE;
386 386
 	 }
@@ -416,15 +416,15 @@  discard block
 block discarded – undo
416 416
 	  * @param bool $reset_cache
417 417
 	  * @return    array
418 418
 	  */
419
-	public function get_session_data( $key = NULL, $reset_cache = FALSE ) {
420
-		if ( $reset_cache ) {
419
+	public function get_session_data($key = NULL, $reset_cache = FALSE) {
420
+		if ($reset_cache) {
421 421
 			$this->reset_cart();
422 422
 			$this->reset_checkout();
423 423
 			$this->reset_transaction();
424 424
 		}
425
-		 if ( ! empty( $key ))  {
426
-			return  isset( $this->_session_data[ $key ] ) ? $this->_session_data[ $key ] : NULL;
427
-		}  else  {
425
+		 if ( ! empty($key)) {
426
+			return  isset($this->_session_data[$key]) ? $this->_session_data[$key] : NULL;
427
+		} else {
428 428
 			return $this->_session_data;
429 429
 		}
430 430
 	}
@@ -437,20 +437,20 @@  discard block
 block discarded – undo
437 437
 	  * @param 	array $data
438 438
 	  * @return 	TRUE on success, FALSE on fail
439 439
 	  */
440
-	public function set_session_data( $data ) {
440
+	public function set_session_data($data) {
441 441
 
442 442
 		// nothing ??? bad data ??? go home!
443
-		if ( empty( $data ) || ! is_array( $data )) {
444
-			EE_Error::add_error( __( 'No session data or invalid session data was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
443
+		if (empty($data) || ! is_array($data)) {
444
+			EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
445 445
 			return FALSE;
446 446
 		}
447 447
 
448
-		foreach ( $data as $key =>$value ) {
449
-			if ( isset( $this->_default_session_vars[ $key ] )) {
450
-				EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $key ), __FILE__, __FUNCTION__, __LINE__ );
448
+		foreach ($data as $key =>$value) {
449
+			if (isset($this->_default_session_vars[$key])) {
450
+				EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
451 451
 				return FALSE;
452 452
 			} else {
453
-				$this->_session_data[ $key ] = $value;
453
+				$this->_session_data[$key] = $value;
454 454
 			}
455 455
 		}
456 456
 
@@ -468,9 +468,9 @@  discard block
 block discarded – undo
468 468
 	  * @throws \EE_Error
469 469
 	  */
470 470
 	private function _espresso_session() {
471
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
471
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
472 472
 		// check that session has started
473
-		if ( session_id() === '' ) {
473
+		if (session_id() === '') {
474 474
 			//starts a new session if one doesn't already exist, or re-initiates an existing one
475 475
 			session_start();
476 476
 		}
@@ -479,39 +479,39 @@  discard block
 block discarded – undo
479 479
 		// and the visitors IP
480 480
 		$this->_ip_address = $this->_visitor_ip();
481 481
 		// set the "user agent"
482
-		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE;
482
+		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : FALSE;
483 483
 		// now let's retrieve what's in the db
484 484
         $session_data = $this->_retrieve_session_data();
485
-        if (! empty($session_data)) {
485
+        if ( ! empty($session_data)) {
486 486
             // get the current time in UTC
487
-			$this->_time = isset( $this->_time ) ? $this->_time : time();
487
+			$this->_time = isset($this->_time) ? $this->_time : time();
488 488
 			// and reset the session expiration
489
-			$this->_expiration = isset( $session_data['expiration'] )
489
+			$this->_expiration = isset($session_data['expiration'])
490 490
 				? $session_data['expiration']
491 491
 				: $this->_time + $this->_lifespan;
492 492
 		} else {
493 493
             // set initial site access time and the session expiration
494 494
 			$this->_set_init_access_and_expiration();
495 495
 			// set referer
496
-			$this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] )
497
-				? esc_attr( $_SERVER['HTTP_REFERER'] )
496
+			$this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER'])
497
+				? esc_attr($_SERVER['HTTP_REFERER'])
498 498
 				: '';
499 499
 			// no previous session = go back and create one (on top of the data above)
500 500
 			return FALSE;
501 501
 		}
502 502
         // now the user agent
503
-		if ( $session_data['user_agent'] !== $this->_user_agent ) {
503
+		if ($session_data['user_agent'] !== $this->_user_agent) {
504 504
 			return FALSE;
505 505
 		}
506 506
 		// wait a minute... how old are you?
507
-		if ( $this->_time > $this->_expiration ) {
507
+		if ($this->_time > $this->_expiration) {
508 508
 			// yer too old fer me!
509 509
             $this->_expired = true;
510 510
 			// wipe out everything that isn't a default session datum
511
-			$this->clear_session( __CLASS__, __FUNCTION__ );
511
+			$this->clear_session(__CLASS__, __FUNCTION__);
512 512
 		}
513 513
 		// make event espresso session data available to plugin
514
-		$this->_session_data = array_merge( $this->_session_data, $session_data );
514
+		$this->_session_data = array_merge($this->_session_data, $session_data);
515 515
 		return TRUE;
516 516
 
517 517
 	}
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
       */
528 528
      protected function _retrieve_session_data()
529 529
      {
530
-         $ssn_key = EE_Session::session_id_prefix . $this->_sid;
530
+         $ssn_key = EE_Session::session_id_prefix.$this->_sid;
531 531
          try {
532 532
              // we're using WP's Transient API to store session data using the PHP session ID as the option name
533 533
              $session_data = $this->cache_storage->get($ssn_key, false);
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
              }
537 537
              if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
538 538
                  $hash_check = $this->cache_storage->get(
539
-                     EE_Session::hash_check_prefix . $this->_sid,
539
+                     EE_Session::hash_check_prefix.$this->_sid,
540 540
                      false
541 541
                  );
542 542
                  if ($hash_check && $hash_check !== md5($session_data)) {
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
                                  'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
547 547
                                  'event_espresso'
548 548
                              ),
549
-                             EE_Session::session_id_prefix . $this->_sid
549
+                             EE_Session::session_id_prefix.$this->_sid
550 550
                          ),
551 551
                          __FILE__, __FUNCTION__, __LINE__
552 552
                      );
@@ -558,17 +558,17 @@  discard block
 block discarded – undo
558 558
              $row = $wpdb->get_row(
559 559
                  $wpdb->prepare(
560 560
                      "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
561
-                     '_transient_' . $ssn_key
561
+                     '_transient_'.$ssn_key
562 562
                  )
563 563
              );
564 564
              $session_data = is_object($row) ? $row->option_value : null;
565 565
              if ($session_data) {
566 566
                  $session_data = preg_replace_callback(
567 567
                      '!s:(d+):"(.*?)";!',
568
-                     function ($match) {
568
+                     function($match) {
569 569
                          return $match[1] === strlen($match[2])
570 570
                              ? $match[0]
571
-                             : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
571
+                             : 's:'.strlen($match[2]).':"'.$match[2].'";';
572 572
                      },
573 573
                      $session_data
574 574
                  );
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
                      'event_espresso'
590 590
                  );
591 591
                  $msg .= WP_DEBUG
592
-                     ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
592
+                     ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
593 593
                      : '';
594 594
                  throw new InvalidSessionDataException($msg, 0, $e);
595 595
              }
@@ -602,11 +602,11 @@  discard block
 block discarded – undo
602 602
                  'event_espresso'
603 603
              );
604 604
              $msg .= WP_DEBUG
605
-                 ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
605
+                 ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
606 606
                  : '';
607 607
 	         throw new InvalidSessionDataException($msg);
608 608
          }
609
-	     if ( isset($session_data['transaction'] ) && absint($session_data['transaction'] ) !== 0 ) {
609
+	     if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
610 610
              $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
611 611
                  $session_data['transaction']
612 612
 	         );
@@ -627,12 +627,12 @@  discard block
 block discarded – undo
627 627
 	  */
628 628
 	protected function _generate_session_id() {
629 629
 		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
630
-		if ( isset( $_REQUEST[ 'EESID' ] ) ) {
631
-			$session_id = sanitize_text_field( $_REQUEST[ 'EESID' ] );
630
+		if (isset($_REQUEST['EESID'])) {
631
+			$session_id = sanitize_text_field($_REQUEST['EESID']);
632 632
 		} else {
633
-			$session_id = md5( session_id() . get_current_blog_id() . $this->_get_sid_salt() );
633
+			$session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt());
634 634
 		}
635
-		return apply_filters( 'FHEE__EE_Session___generate_session_id__session_id', $session_id );
635
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
636 636
 	}
637 637
 
638 638
 
@@ -644,20 +644,20 @@  discard block
 block discarded – undo
644 644
 	  */
645 645
 	protected function _get_sid_salt() {
646 646
 		// was session id salt already saved to db ?
647
-		if ( empty( $this->_sid_salt ) ) {
647
+		if (empty($this->_sid_salt)) {
648 648
 			// no?  then maybe use WP defined constant
649
-			if ( defined( 'AUTH_SALT' ) ) {
649
+			if (defined('AUTH_SALT')) {
650 650
 				$this->_sid_salt = AUTH_SALT;
651 651
 			}
652 652
 			// if salt doesn't exist or is too short
653
-			if ( strlen( $this->_sid_salt ) < 32 ) {
653
+			if (strlen($this->_sid_salt) < 32) {
654 654
 				// create a new one
655
-				$this->_sid_salt = wp_generate_password( 64 );
655
+				$this->_sid_salt = wp_generate_password(64);
656 656
 			}
657 657
 			// and save it as a permanent session setting
658
-			$session_settings = get_option( 'ee_session_settings' );
659
-			$session_settings[ 'sid_salt' ] = $this->_sid_salt;
660
-			update_option( 'ee_session_settings', $session_settings );
658
+			$session_settings = get_option('ee_session_settings');
659
+			$session_settings['sid_salt'] = $this->_sid_salt;
660
+			update_option('ee_session_settings', $session_settings);
661 661
 		}
662 662
 		return $this->_sid_salt;
663 663
 	}
@@ -686,19 +686,19 @@  discard block
 block discarded – undo
686 686
       * @return TRUE on success, FALSE on fail
687 687
       * @throws \EE_Error
688 688
       */
689
-	public function update( $new_session = FALSE ) {
690
-		$this->_session_data = isset( $this->_session_data )
691
-			&& is_array( $this->_session_data )
692
-			&& isset( $this->_session_data['id'])
689
+	public function update($new_session = FALSE) {
690
+		$this->_session_data = isset($this->_session_data)
691
+			&& is_array($this->_session_data)
692
+			&& isset($this->_session_data['id'])
693 693
 			? $this->_session_data
694 694
 			: array();
695
-		if ( empty( $this->_session_data )) {
695
+		if (empty($this->_session_data)) {
696 696
 			$this->_set_defaults();
697 697
 		}
698 698
 		$session_data = array();
699
-		foreach ( $this->_session_data as $key => $value ) {
699
+		foreach ($this->_session_data as $key => $value) {
700 700
 
701
-			switch( $key ) {
701
+			switch ($key) {
702 702
 
703 703
 				case 'id' :
704 704
 					// session ID
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 				break;
717 717
 
718 718
 				case 'init_access' :
719
-					$session_data['init_access'] = absint( $value );
719
+					$session_data['init_access'] = absint($value);
720 720
 				break;
721 721
 
722 722
 				case 'last_access' :
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 
727 727
 				case 'expiration' :
728 728
 					// when the session expires
729
-					$session_data['expiration'] = ! empty( $this->_expiration )
729
+					$session_data['expiration'] = ! empty($this->_expiration)
730 730
 						? $this->_expiration
731 731
 						: $session_data['init_access'] + $this->_lifespan;
732 732
 				break;
@@ -738,11 +738,11 @@  discard block
 block discarded – undo
738 738
 
739 739
 				case 'pages_visited' :
740 740
 					$page_visit = $this->_get_page_visit();
741
-					if ( $page_visit ) {
741
+					if ($page_visit) {
742 742
 						// set pages visited where the first will be the http referrer
743
-						$this->_session_data[ 'pages_visited' ][ $this->_time ] = $page_visit;
743
+						$this->_session_data['pages_visited'][$this->_time] = $page_visit;
744 744
 						// we'll only save the last 10 page visits.
745
-						$session_data[ 'pages_visited' ] = array_slice( $this->_session_data['pages_visited'], -10 );
745
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
746 746
 					}
747 747
 				break;
748 748
 
@@ -756,9 +756,9 @@  discard block
 block discarded – undo
756 756
 
757 757
 		$this->_session_data = $session_data;
758 758
 		// creating a new session does not require saving to the db just yet
759
-		if ( ! $new_session ) {
759
+		if ( ! $new_session) {
760 760
 			// ready? let's save
761
-			if ( $this->_save_session_to_db() ) {
761
+			if ($this->_save_session_to_db()) {
762 762
 				return TRUE;
763 763
 			} else {
764 764
 				return FALSE;
@@ -778,9 +778,9 @@  discard block
 block discarded – undo
778 778
       * @throws \EE_Error
779 779
       */
780 780
 	private function _create_espresso_session( ) {
781
-		do_action( 'AHEE_log', __CLASS__, __FUNCTION__, '' );
781
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
782 782
 		// use the update function for now with $new_session arg set to TRUE
783
-		return  $this->update( TRUE ) ? TRUE : FALSE;
783
+		return  $this->update(TRUE) ? TRUE : FALSE;
784 784
 	}
785 785
 
786 786
 
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
                 EE_Registry::instance()->REQ->front_ajax
801 801
                 || (
802 802
                     // OR an admin request that is NOT AJAX
803
-					! ( defined( 'DOING_AJAX' ) && DOING_AJAX )
803
+					! (defined('DOING_AJAX') && DOING_AJAX)
804 804
                     && is_admin()
805 805
 				)
806 806
                 || (
@@ -813,8 +813,8 @@  discard block
 block discarded – undo
813 813
 			return false;
814 814
 		}
815 815
 		$transaction = $this->transaction();
816
-		if ( $transaction instanceof EE_Transaction ) {
817
-			if ( ! $transaction->ID() ) {
816
+		if ($transaction instanceof EE_Transaction) {
817
+			if ( ! $transaction->ID()) {
818 818
 				$transaction->save();
819 819
 			}
820 820
 			$this->_session_data['transaction'] = $transaction->ID();
@@ -823,19 +823,19 @@  discard block
 block discarded – undo
823 823
 		$session_data = serialize($this->_session_data);
824 824
 		// do we need to also encode it to avoid corrupted data when saved to the db?
825 825
 		$session_data = $this->_use_encryption
826
-            ? $this->encryption->base64_string_encode( $session_data )
826
+            ? $this->encryption->base64_string_encode($session_data)
827 827
             : $session_data;
828 828
 		// maybe save hash check
829
-		if ( apply_filters( 'FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG ) ) {
829
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
830 830
             $this->cache_storage->add(
831
-                EE_Session::hash_check_prefix . $this->_sid,
831
+                EE_Session::hash_check_prefix.$this->_sid,
832 832
                 md5($session_data),
833 833
                 $this->_lifespan
834 834
             );
835 835
         }
836 836
         // we're using the Transient API for storing session data,
837 837
         return $this->cache_storage->add(
838
-            EE_Session::session_id_prefix . $this->_sid,
838
+            EE_Session::session_id_prefix.$this->_sid,
839 839
             $session_data,
840 840
             $this->_lifespan
841 841
         );
@@ -864,10 +864,10 @@  discard block
 block discarded – undo
864 864
 			'HTTP_FORWARDED',
865 865
 			'REMOTE_ADDR'
866 866
 		);
867
-		foreach ( $server_keys as $key ){
868
-			if ( isset( $_SERVER[ $key ] )) {
869
-				foreach ( array_map( 'trim', explode( ',', $_SERVER[ $key ] )) as $ip ) {
870
-					if ( $ip === '127.0.0.1' || filter_var( $ip, FILTER_VALIDATE_IP ) !== FALSE ) {
867
+		foreach ($server_keys as $key) {
868
+			if (isset($_SERVER[$key])) {
869
+				foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
870
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== FALSE) {
871 871
 						$visitor_ip = $ip;
872 872
 					}
873 873
 				}
@@ -886,32 +886,32 @@  discard block
 block discarded – undo
886 886
 	 *			@return string
887 887
 	 */
888 888
 	public function _get_page_visit() {
889
-		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
889
+		$page_visit = home_url('/').'wp-admin/admin-ajax.php';
890 890
 		// check for request url
891
-		if ( isset( $_SERVER['REQUEST_URI'] )) {
891
+		if (isset($_SERVER['REQUEST_URI'])) {
892 892
 			$http_host = '';
893 893
 			$page_id = '?';
894 894
 			$e_reg = '';
895
-			$request_uri = esc_url( $_SERVER['REQUEST_URI'] );
896
-			$ru_bits = explode( '?', $request_uri );
895
+			$request_uri = esc_url($_SERVER['REQUEST_URI']);
896
+			$ru_bits = explode('?', $request_uri);
897 897
 			$request_uri = $ru_bits[0];
898 898
 			// check for and grab host as well
899
-			if ( isset( $_SERVER['HTTP_HOST'] )) {
900
-				$http_host = esc_url( $_SERVER['HTTP_HOST'] );
899
+			if (isset($_SERVER['HTTP_HOST'])) {
900
+				$http_host = esc_url($_SERVER['HTTP_HOST']);
901 901
 			}
902 902
 			// check for page_id in SERVER REQUEST
903
-			if ( isset( $_REQUEST['page_id'] )) {
903
+			if (isset($_REQUEST['page_id'])) {
904 904
 				// rebuild $e_reg without any of the extra parameters
905
-				$page_id = '?page_id=' . esc_attr( $_REQUEST['page_id'] ) . '&amp;';
905
+				$page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&amp;';
906 906
 			}
907 907
 			// check for $e_reg in SERVER REQUEST
908
-			if ( isset( $_REQUEST['ee'] )) {
908
+			if (isset($_REQUEST['ee'])) {
909 909
 				// rebuild $e_reg without any of the extra parameters
910
-				$e_reg = 'ee=' . esc_attr( $_REQUEST['ee'] );
910
+				$e_reg = 'ee='.esc_attr($_REQUEST['ee']);
911 911
 			}
912
-			$page_visit = rtrim( $http_host . $request_uri . $page_id . $e_reg, '?' );
912
+			$page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?');
913 913
 		}
914
-		return $page_visit !== home_url( '/wp-admin/admin-ajax.php' ) ? $page_visit : '';
914
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
915 915
 
916 916
 	}
917 917
 
@@ -941,14 +941,14 @@  discard block
 block discarded – undo
941 941
       * @return void
942 942
       * @throws \EE_Error
943 943
       */
944
-	public function clear_session( $class = '', $function = '' ) {
944
+	public function clear_session($class = '', $function = '') {
945 945
 		//echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
946
-        do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' .  $function . '()' );
946
+        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
947 947
 		$this->reset_cart();
948 948
 		$this->reset_checkout();
949 949
 		$this->reset_transaction();
950 950
 		// wipe out everything that isn't a default session datum
951
-		$this->reset_data( array_keys( $this->_session_data ));
951
+		$this->reset_data(array_keys($this->_session_data));
952 952
 		// reset initial site access time and the session expiration
953 953
 		$this->_set_init_access_and_expiration();
954 954
 		$this->_save_session_to_db();
@@ -963,42 +963,42 @@  discard block
 block discarded – undo
963 963
 	  * @param bool  $show_all_notices
964 964
 	  * @return TRUE on success, FALSE on fail
965 965
 	  */
966
-	public function reset_data( $data_to_reset = array(), $show_all_notices = FALSE ) {
966
+	public function reset_data($data_to_reset = array(), $show_all_notices = FALSE) {
967 967
 		// if $data_to_reset is not in an array, then put it in one
968
-		if ( ! is_array( $data_to_reset ) ) {
969
-			$data_to_reset = array ( $data_to_reset );
968
+		if ( ! is_array($data_to_reset)) {
969
+			$data_to_reset = array($data_to_reset);
970 970
 		}
971 971
 		// nothing ??? go home!
972
-		if ( empty( $data_to_reset )) {
973
-			EE_Error::add_error( __( 'No session data could be reset, because no session var name was provided.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
972
+		if (empty($data_to_reset)) {
973
+			EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
974 974
 			return FALSE;
975 975
 		}
976 976
 		$return_value = TRUE;
977 977
 		// since $data_to_reset is an array, cycle through the values
978
-		foreach ( $data_to_reset as $reset ) {
978
+		foreach ($data_to_reset as $reset) {
979 979
 
980 980
 			// first check to make sure it is a valid session var
981
-			if ( isset( $this->_session_data[ $reset ] )) {
981
+			if (isset($this->_session_data[$reset])) {
982 982
 				// then check to make sure it is not a default var
983
-				if ( ! array_key_exists( $reset, $this->_default_session_vars )) {
983
+				if ( ! array_key_exists($reset, $this->_default_session_vars)) {
984 984
 					// remove session var
985
-					unset( $this->_session_data[ $reset ] );
986
-					if ( $show_all_notices ) {
987
-						EE_Error::add_success( sprintf( __( 'The session variable %s was removed.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
985
+					unset($this->_session_data[$reset]);
986
+					if ($show_all_notices) {
987
+						EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
988 988
 					}
989
-					$return_value = !isset($return_value) ? TRUE : $return_value;
989
+					$return_value = ! isset($return_value) ? TRUE : $return_value;
990 990
 
991 991
 				} else {
992 992
 					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
993
-					if ( $show_all_notices ) {
994
-						EE_Error::add_error( sprintf( __( 'Sorry! %s is a default session datum and can not be reset.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
993
+					if ($show_all_notices) {
994
+						EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
995 995
 					}
996 996
 					$return_value = FALSE;
997 997
 				}
998 998
 
999
-			} else if ( $show_all_notices ) {
999
+			} else if ($show_all_notices) {
1000 1000
 				// oops! that session var does not exist!
1001
-				EE_Error::add_error( sprintf( __( 'The session item provided, %s, is invalid or does not exist.', 'event_espresso' ), $reset ), __FILE__, __FUNCTION__, __LINE__ );
1001
+				EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1002 1002
 				$return_value = FALSE;
1003 1003
 			}
1004 1004
 
@@ -1017,8 +1017,8 @@  discard block
 block discarded – undo
1017 1017
       * @throws \EE_Error
1018 1018
       */
1019 1019
 	public function wp_loaded() {
1020
-		if ( isset(  EE_Registry::instance()->REQ ) && EE_Registry::instance()->REQ->is_set( 'clear_session' )) {
1021
-			$this->clear_session( __CLASS__, __FUNCTION__ );
1020
+		if (isset(EE_Registry::instance()->REQ) && EE_Registry::instance()->REQ->is_set('clear_session')) {
1021
+			$this->clear_session(__CLASS__, __FUNCTION__);
1022 1022
 		}
1023 1023
 	}
1024 1024
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
              // or use that for the new transient cleanup query limit
1055 1055
              add_filter(
1056 1056
                  'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1057
-                 function () use ($expired_session_transient_delete_query_limit) {
1057
+                 function() use ($expired_session_transient_delete_query_limit) {
1058 1058
                      return $expired_session_transient_delete_query_limit;
1059 1059
                  }
1060 1060
              );
@@ -1068,34 +1068,34 @@  discard block
 block discarded – undo
1068 1068
 	  * @param $data1
1069 1069
 	  * @return string
1070 1070
 	  */
1071
-	 private function find_serialize_error( $data1 ) {
1071
+	 private function find_serialize_error($data1) {
1072 1072
 		$error = '<pre>';
1073 1073
 		 $data2 = preg_replace_callback(
1074 1074
 			 '!s:(\d+):"(.*?)";!',
1075
-			 function ( $match ) {
1076
-				 return ( $match[1] === strlen( $match[2] ) )
1075
+			 function($match) {
1076
+				 return ($match[1] === strlen($match[2]))
1077 1077
 					 ? $match[0]
1078 1078
 					 : 's:'
1079
-					   . strlen( $match[2] )
1079
+					   . strlen($match[2])
1080 1080
 					   . ':"'
1081 1081
 					   . $match[2]
1082 1082
 					   . '";';
1083 1083
 			 },
1084 1084
 			 $data1
1085 1085
 		 );
1086
-		$max = ( strlen( $data1 ) > strlen( $data2 ) ) ? strlen( $data1 ) : strlen( $data2 );
1087
-		$error .= $data1 . PHP_EOL;
1088
-		$error .= $data2 . PHP_EOL;
1089
-		for ( $i = 0; $i < $max; $i++ ) {
1090
-			if ( @$data1[ $i ] !== @$data2[ $i ] ) {
1091
-				$error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1092
-				$error .= "\t-> ORD number " . ord( @$data1[ $i ] ) . ' != ' . ord( @$data2[ $i ] ) . PHP_EOL;
1093
-				$error .= "\t-> Line Number = $i" . PHP_EOL;
1094
-				$start = ( $i - 20 );
1095
-				$start = ( $start < 0 ) ? 0 : $start;
1086
+		$max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1087
+		$error .= $data1.PHP_EOL;
1088
+		$error .= $data2.PHP_EOL;
1089
+		for ($i = 0; $i < $max; $i++) {
1090
+			if (@$data1[$i] !== @$data2[$i]) {
1091
+				$error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL;
1092
+				$error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL;
1093
+				$error .= "\t-> Line Number = $i".PHP_EOL;
1094
+				$start = ($i - 20);
1095
+				$start = ($start < 0) ? 0 : $start;
1096 1096
 				$length = 40;
1097 1097
 				$point = $max - $i;
1098
-				if ( $point < 20 ) {
1098
+				if ($point < 20) {
1099 1099
 					$rlength = 1;
1100 1100
 					$rpoint = -$point;
1101 1101
 				} else {
@@ -1104,16 +1104,16 @@  discard block
 block discarded – undo
1104 1104
 				}
1105 1105
 				$error .= "\t-> Section Data1  = ";
1106 1106
 				$error .= substr_replace(
1107
-					substr( $data1, $start, $length ),
1108
-					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1107
+					substr($data1, $start, $length),
1108
+					"<b style=\"color:green\">{$data1[$i]}</b>",
1109 1109
 					$rpoint,
1110 1110
 					$rlength
1111 1111
 				);
1112 1112
 				$error .= PHP_EOL;
1113 1113
 				$error .= "\t-> Section Data2  = ";
1114 1114
 				$error .= substr_replace(
1115
-					substr( $data2, $start, $length ),
1116
-					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1115
+					substr($data2, $start, $length),
1116
+					"<b style=\"color:red\">{$data2[$i]}</b>",
1117 1117
 					$rpoint,
1118 1118
 					$rlength
1119 1119
 				);
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoTicketSelector.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@
 block discarded – undo
77 77
         extract($attributes, EXTR_OVERWRITE);
78 78
         $event_id = isset($event_id) ? $event_id : 0;
79 79
         $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
80
-        if (! $event instanceof EE_Event) {
80
+        if ( ! $event instanceof EE_Event) {
81 81
             new ExceptionStackTraceDisplay(
82 82
                 new InvalidArgumentException(
83 83
                     sprintf(
Please login to merge, or discard this patch.
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -24,82 +24,82 @@
 block discarded – undo
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     * the actual shortcode tag that gets registered with WordPress
29
-     *
30
-     * @return string
31
-     */
32
-    public function getTag()
33
-    {
34
-        return 'ESPRESSO_TICKET_SELECTOR';
35
-    }
36
-
37
-
38
-
39
-    /**
40
-     * the time in seconds to cache the results of the processShortcode() method
41
-     * 0 means the processShortcode() results will NOT be cached at all
42
-     *
43
-     * @return int
44
-     */
45
-    public function cacheExpiration()
46
-    {
47
-        return 0;
48
-    }
49
-
50
-
51
-    /**
52
-     * a place for adding any initialization code that needs to run prior to wp_header().
53
-     * this may be required for shortcodes that utilize a corresponding module,
54
-     * and need to enqueue assets for that module
55
-     *
56
-     * @return void
57
-     */
58
-    public function initializeShortcode()
59
-    {
60
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
61
-        $this->shortcodeHasBeenInitialized();
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * callback that runs when the shortcode is encountered in post content.
68
-     * IMPORTANT !!!
69
-     * remember that shortcode content should be RETURNED and NOT echoed out
70
-     *
71
-     * @param array $attributes
72
-     * @return string
73
-     * @throws InvalidArgumentException
74
-     */
75
-    public function processShortcode($attributes = array())
76
-    {
77
-        extract($attributes, EXTR_OVERWRITE);
78
-        $event_id = isset($event_id) ? $event_id : 0;
79
-        $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
80
-        if (! $event instanceof EE_Event) {
81
-            new ExceptionStackTraceDisplay(
82
-                new InvalidArgumentException(
83
-                    sprintf(
84
-                        esc_html__(
85
-                            'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that it\'s value corresponds to a valid Event ID.',
86
-                            'event_espresso'
87
-                        ),
88
-                        $this->getTag(),
89
-                        $event_id,
90
-                        'event_id',
91
-                        '<br />'
92
-                    )
93
-                )
94
-            );
95
-            return '';
96
-        }
97
-        ob_start();
98
-        do_action('AHEE_event_details_before_post', $event_id);
99
-        espresso_ticket_selector($event);
100
-        do_action('AHEE_event_details_after_post');
101
-        return ob_get_clean();
102
-    }
27
+	/**
28
+	 * the actual shortcode tag that gets registered with WordPress
29
+	 *
30
+	 * @return string
31
+	 */
32
+	public function getTag()
33
+	{
34
+		return 'ESPRESSO_TICKET_SELECTOR';
35
+	}
36
+
37
+
38
+
39
+	/**
40
+	 * the time in seconds to cache the results of the processShortcode() method
41
+	 * 0 means the processShortcode() results will NOT be cached at all
42
+	 *
43
+	 * @return int
44
+	 */
45
+	public function cacheExpiration()
46
+	{
47
+		return 0;
48
+	}
49
+
50
+
51
+	/**
52
+	 * a place for adding any initialization code that needs to run prior to wp_header().
53
+	 * this may be required for shortcodes that utilize a corresponding module,
54
+	 * and need to enqueue assets for that module
55
+	 *
56
+	 * @return void
57
+	 */
58
+	public function initializeShortcode()
59
+	{
60
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
61
+		$this->shortcodeHasBeenInitialized();
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * callback that runs when the shortcode is encountered in post content.
68
+	 * IMPORTANT !!!
69
+	 * remember that shortcode content should be RETURNED and NOT echoed out
70
+	 *
71
+	 * @param array $attributes
72
+	 * @return string
73
+	 * @throws InvalidArgumentException
74
+	 */
75
+	public function processShortcode($attributes = array())
76
+	{
77
+		extract($attributes, EXTR_OVERWRITE);
78
+		$event_id = isset($event_id) ? $event_id : 0;
79
+		$event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
80
+		if (! $event instanceof EE_Event) {
81
+			new ExceptionStackTraceDisplay(
82
+				new InvalidArgumentException(
83
+					sprintf(
84
+						esc_html__(
85
+							'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that it\'s value corresponds to a valid Event ID.',
86
+							'event_espresso'
87
+						),
88
+						$this->getTag(),
89
+						$event_id,
90
+						'event_id',
91
+						'<br />'
92
+					)
93
+				)
94
+			);
95
+			return '';
96
+		}
97
+		ob_start();
98
+		do_action('AHEE_event_details_before_post', $event_id);
99
+		espresso_ticket_selector($event);
100
+		do_action('AHEE_event_details_after_post');
101
+		return ob_get_clean();
102
+	}
103 103
 
104 104
 
105 105
 }
Please login to merge, or discard this patch.
core/domain/services/session/SessionIdentifierInterface.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@
 block discarded – undo
5 5
 interface SessionIdentifierInterface
6 6
 {
7 7
 
8
-    /**
9
-     * @return    string
10
-     */
11
-    public function id();
8
+	/**
9
+	 * @return    string
10
+	 */
11
+	public function id();
12 12
 
13 13
 }
14 14
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/collections/CollectionLoader.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -199,13 +199,13 @@  discard block
 block discarded – undo
199 199
 			);
200 200
 			return CollectionLoader::ENTITY_ADDED;
201 201
 		}
202
-        do_action(
203
-            'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
204
-            $this,
205
-            $this->collection_details->collectionName(),
206
-            $this->collection_details
207
-        );
208
-        return CollectionLoader::ENTITY_NOT_ADDED;
202
+		do_action(
203
+			'FHEE__CollectionLoader__addEntityToCollection__entity_not_added',
204
+			$this,
205
+			$this->collection_details->collectionName(),
206
+			$this->collection_details
207
+		);
208
+		return CollectionLoader::ENTITY_NOT_ADDED;
209 209
 	}
210 210
 
211 211
 
@@ -220,37 +220,37 @@  discard block
 block discarded – undo
220 220
 	 * @throws \EventEspresso\core\exceptions\InvalidEntityException
221 221
 	 */
222 222
 	protected function setIdentifier( $entity, $identifier ) {
223
-	    switch($this->collection_details->identifierType()) {
224
-	        // every unique object gets added to the collection, but not duplicates of the exact same object
225
-            case CollectionDetails::ID_OBJECT_HASH :
226
-                $identifier = spl_object_hash($entity);
227
-                break;
228
-            // only one entity per class can be added to collection, like a singleton
229
-            case CollectionDetails::ID_CLASS_NAME :
230
-                $identifier = get_class($entity);
231
-                break;
232
-            // objects added to the collection based on entity callback, so the entity itself decides
233
-            case CollectionDetails::ID_CALLBACK_METHOD :
234
-                $identifier_callback = $this->collection_details->identifierCallback();
235
-                if ( ! method_exists($entity, $identifier_callback)) {
236
-                    throw new InvalidEntityException(
237
-                        $entity,
238
-                        $this->collection_details->getCollectionInterface(),
239
-                        sprintf(
240
-                            __(
241
-                                'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
223
+		switch($this->collection_details->identifierType()) {
224
+			// every unique object gets added to the collection, but not duplicates of the exact same object
225
+			case CollectionDetails::ID_OBJECT_HASH :
226
+				$identifier = spl_object_hash($entity);
227
+				break;
228
+			// only one entity per class can be added to collection, like a singleton
229
+			case CollectionDetails::ID_CLASS_NAME :
230
+				$identifier = get_class($entity);
231
+				break;
232
+			// objects added to the collection based on entity callback, so the entity itself decides
233
+			case CollectionDetails::ID_CALLBACK_METHOD :
234
+				$identifier_callback = $this->collection_details->identifierCallback();
235
+				if ( ! method_exists($entity, $identifier_callback)) {
236
+					throw new InvalidEntityException(
237
+						$entity,
238
+						$this->collection_details->getCollectionInterface(),
239
+						sprintf(
240
+							__(
241
+								'The current collection is configured to use a method named "%1$s" when setting or retrieving objects. The supplied entity is an instance
242 242
                                 of "%2$s", but does not contain this method.',
243
-                                'event_espresso'
244
-                            ),
245
-                            $identifier_callback,
246
-                            get_class($entity)
247
-                        )
248
-                    );
249
-                }
250
-                $identifier = $entity->{$identifier_callback}();
251
-                break;
252
-
253
-        }
243
+								'event_espresso'
244
+							),
245
+							$identifier_callback,
246
+							get_class($entity)
247
+						)
248
+					);
249
+				}
250
+				$identifier = $entity->{$identifier_callback}();
251
+				break;
252
+
253
+		}
254 254
 		return apply_filters(
255 255
 			'FHEE__CollectionLoader__addEntityToCollection__identifier',
256 256
 			$identifier,
Please login to merge, or discard this patch.
core/services/cache/BasicCacheManager.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         // with these parameters
141 141
         $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL);
142 142
         // then md5 the above to control it's length, add all of our prefixes, and truncate
143
-        return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182);
143
+        return substr($this->cachePrefix().$id_prefix.'-'.md5($cache_id), 0, 182);
144 144
     }
145 145
 
146 146
 
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
         return '
171 171
 <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;">
172 172
     <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px">
173
-        <b>' . $type . '</b><span style="color:#999"> : </span>
174
-        <span>' . $cache_id . '</span>
175
-        <span style="margin-left:2em;">' . __FILE__ . '</span>
173
+        <b>' . $type.'</b><span style="color:#999"> : </span>
174
+        <span>' . $cache_id.'</span>
175
+        <span style="margin-left:2em;">' . __FILE__.'</span>
176 176
     </p>
177 177
 </div>';
178 178
     }
Please login to merge, or discard this patch.
Indentation   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -19,140 +19,140 @@  discard block
 block discarded – undo
19 19
 class BasicCacheManager implements CacheManagerInterface
20 20
 {
21 21
 
22
-    /**
23
-     * @type string
24
-     */
25
-    const CACHE_PREFIX = 'ee_cache_';
26
-
27
-
28
-    /**
29
-     * @var CacheStorageInterface $cache_storage
30
-     */
31
-    private $cache_storage;
32
-
33
-
34
-
35
-    /**
36
-     * BasicCacheManager constructor.
37
-     *
38
-     * @param CacheStorageInterface      $cache_storage [required]
39
-     */
40
-    public function __construct(CacheStorageInterface $cache_storage)
41
-    {
42
-        $this->cache_storage = $cache_storage;
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * returns a string that will be prepended to all cache identifiers
49
-     *
50
-     * @return string
51
-     */
52
-    public function cachePrefix()
53
-    {
54
-        return BasicCacheManager::CACHE_PREFIX;
55
-    }
56
-
57
-
58
-
59
-    /**
60
-     * @param string  $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types.
61
-     *                           May also be helpful to include an additional specific identifier,
62
-     *                           such as a post ID as part of the $id_prefix so that individual caches
63
-     *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
64
-     *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
65
-     * @param string  $cache_id  [required] Additional identifying details that make this cache unique.
66
-     *                           It is advisable to use some of the actual data
67
-     *                           that is used to generate the content being cached,
68
-     *                           in order to guarantee that the cache id is unique for that content.
69
-     *                           The cache id will be md5'd before usage to make it more db friendly,
70
-     *                           and the entire cache id string will be truncated to 190 characters.
71
-     * @param Closure $callback  [required] since the point of caching is to avoid generating content when not
72
-     *                           necessary,
73
-     *                           we wrap our content creation in a Closure so that it is not executed until needed.
74
-     * @param int     $expiration
75
-     * @return Closure|mixed
76
-     */
77
-    public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS)
78
-    {
79
-        $content = '';
80
-        $expiration = absint(
81
-            apply_filters(
82
-                'FHEE__CacheManager__get__cache_expiration',
83
-                $expiration,
84
-                $id_prefix,
85
-                $cache_id
86
-            )
87
-        );
88
-        $cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id);
89
-        // is caching enabled for this content ?
90
-        if ($expiration) {
91
-            $content = $this->cache_storage->get($cache_id);
92
-        }
93
-        // any existing content ?
94
-        if (empty($content)) {
95
-            // nope! let's generate some new stuff
96
-            $content = $callback();
97
-            // save the new content if caching is enabled
98
-            if ($expiration) {
99
-                $this->cache_storage->add($cache_id, $content, $expiration);
100
-                if (EE_DEBUG) {
101
-                    $content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE');
102
-                }
103
-            }
104
-        } else {
105
-            if (EE_DEBUG) {
106
-                $content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT');
107
-            }
108
-        }
109
-        return $content;
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * Generates a unique identifier string for the cache
116
-     *
117
-     * @param string $id_prefix  [required] see BasicCacheManager::get()
118
-     * @param string $cache_id   [required] see BasicCacheManager::get()
119
-     * @return string
120
-     */
121
-    private function generateCacheIdentifier($id_prefix, $cache_id)
122
-    {
123
-        // let's make the cached content unique for this "page"
124
-        $cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL);
125
-        // with these parameters
126
-        $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL);
127
-        // then md5 the above to control it's length, add all of our prefixes, and truncate
128
-        return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182);
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @param array|string $cache_id [required] Could be an ID prefix affecting many caches
135
-     *                               or a specific ID targeting a single cache item
136
-     * @return void
137
-     */
138
-    public function clear($cache_id)
139
-    {
140
-        // ensure incoming arg is in an array
141
-        $cache_id = is_array($cache_id) ? $cache_id : array($cache_id);
142
-        // delete corresponding transients for the supplied id prefix
143
-        $this->cache_storage->deleteMany($cache_id);
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * @param array|string $cache_id [required] Could be an ID prefix affecting many caches
150
-     *                               or a specific ID targeting a single cache item
151
-     * @param string       $type
152
-     * @return string
153
-     */
154
-    private function displayCacheNotice($cache_id, $type) {
155
-        return '
22
+	/**
23
+	 * @type string
24
+	 */
25
+	const CACHE_PREFIX = 'ee_cache_';
26
+
27
+
28
+	/**
29
+	 * @var CacheStorageInterface $cache_storage
30
+	 */
31
+	private $cache_storage;
32
+
33
+
34
+
35
+	/**
36
+	 * BasicCacheManager constructor.
37
+	 *
38
+	 * @param CacheStorageInterface      $cache_storage [required]
39
+	 */
40
+	public function __construct(CacheStorageInterface $cache_storage)
41
+	{
42
+		$this->cache_storage = $cache_storage;
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * returns a string that will be prepended to all cache identifiers
49
+	 *
50
+	 * @return string
51
+	 */
52
+	public function cachePrefix()
53
+	{
54
+		return BasicCacheManager::CACHE_PREFIX;
55
+	}
56
+
57
+
58
+
59
+	/**
60
+	 * @param string  $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types.
61
+	 *                           May also be helpful to include an additional specific identifier,
62
+	 *                           such as a post ID as part of the $id_prefix so that individual caches
63
+	 *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
64
+	 *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
65
+	 * @param string  $cache_id  [required] Additional identifying details that make this cache unique.
66
+	 *                           It is advisable to use some of the actual data
67
+	 *                           that is used to generate the content being cached,
68
+	 *                           in order to guarantee that the cache id is unique for that content.
69
+	 *                           The cache id will be md5'd before usage to make it more db friendly,
70
+	 *                           and the entire cache id string will be truncated to 190 characters.
71
+	 * @param Closure $callback  [required] since the point of caching is to avoid generating content when not
72
+	 *                           necessary,
73
+	 *                           we wrap our content creation in a Closure so that it is not executed until needed.
74
+	 * @param int     $expiration
75
+	 * @return Closure|mixed
76
+	 */
77
+	public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS)
78
+	{
79
+		$content = '';
80
+		$expiration = absint(
81
+			apply_filters(
82
+				'FHEE__CacheManager__get__cache_expiration',
83
+				$expiration,
84
+				$id_prefix,
85
+				$cache_id
86
+			)
87
+		);
88
+		$cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id);
89
+		// is caching enabled for this content ?
90
+		if ($expiration) {
91
+			$content = $this->cache_storage->get($cache_id);
92
+		}
93
+		// any existing content ?
94
+		if (empty($content)) {
95
+			// nope! let's generate some new stuff
96
+			$content = $callback();
97
+			// save the new content if caching is enabled
98
+			if ($expiration) {
99
+				$this->cache_storage->add($cache_id, $content, $expiration);
100
+				if (EE_DEBUG) {
101
+					$content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE');
102
+				}
103
+			}
104
+		} else {
105
+			if (EE_DEBUG) {
106
+				$content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT');
107
+			}
108
+		}
109
+		return $content;
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * Generates a unique identifier string for the cache
116
+	 *
117
+	 * @param string $id_prefix  [required] see BasicCacheManager::get()
118
+	 * @param string $cache_id   [required] see BasicCacheManager::get()
119
+	 * @return string
120
+	 */
121
+	private function generateCacheIdentifier($id_prefix, $cache_id)
122
+	{
123
+		// let's make the cached content unique for this "page"
124
+		$cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL);
125
+		// with these parameters
126
+		$cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL);
127
+		// then md5 the above to control it's length, add all of our prefixes, and truncate
128
+		return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182);
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @param array|string $cache_id [required] Could be an ID prefix affecting many caches
135
+	 *                               or a specific ID targeting a single cache item
136
+	 * @return void
137
+	 */
138
+	public function clear($cache_id)
139
+	{
140
+		// ensure incoming arg is in an array
141
+		$cache_id = is_array($cache_id) ? $cache_id : array($cache_id);
142
+		// delete corresponding transients for the supplied id prefix
143
+		$this->cache_storage->deleteMany($cache_id);
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * @param array|string $cache_id [required] Could be an ID prefix affecting many caches
150
+	 *                               or a specific ID targeting a single cache item
151
+	 * @param string       $type
152
+	 * @return string
153
+	 */
154
+	private function displayCacheNotice($cache_id, $type) {
155
+		return '
156 156
 <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;">
157 157
     <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px">
158 158
         <b>' . $type . '</b><span style="color:#999"> : </span>
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         <span style="margin-left:2em;">' . __FILE__ . '</span>
161 161
     </p>
162 162
 </div>';
163
-    }
163
+	}
164 164
 
165 165
 }
166 166
 // End of file BasicCacheManager.php
Please login to merge, or discard this patch.
core/services/cache/PostRelatedCacheManager.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -18,93 +18,93 @@
 block discarded – undo
18 18
 class PostRelatedCacheManager extends BasicCacheManager
19 19
 {
20 20
 
21
-    /**
22
-     * @type string
23
-     */
24
-    const POST_CACHE_PREFIX = 'ee_cache_post_';
25
-
26
-    /**
27
-     * wp-option option_name for tracking post related cache
28
-     *
29
-     * @type string
30
-     */
31
-    const POST_CACHE_OPTIONS_KEY = 'ee_post_cache';
32
-
33
-
34
-
35
-    /**
36
-     * PostRelatedCacheManager constructor.
37
-     *
38
-     * @param CacheStorageInterface      $cache_storage
39
-     * @param SessionIdentifierInterface $session
40
-     */
41
-    public function __construct(CacheStorageInterface $cache_storage, SessionIdentifierInterface $session)
42
-    {
43
-        parent::__construct($cache_storage, $session);
44
-        add_action('save_post', array($this, 'clearPostRelatedCache'));
45
-    }
46
-
47
-
48
-
49
-    /**
50
-     * returns a string that will be prepended to all cache identifiers
51
-     *
52
-     * @return string
53
-     */
54
-    public function cachePrefix()
55
-    {
56
-        return PostRelatedCacheManager::POST_CACHE_PREFIX;
57
-    }
58
-
59
-
60
-
61
-    /**
62
-     * If you are caching content that pertains to a Post of any type,
63
-     * then it is recommended to pass the post id and cache id prefix to this method
64
-     * so that it can be added to the post related cache tracking.
65
-     * Then, whenever that post is updated, the cache will automatically be deleted,
66
-     * which helps to ensure that outdated cache content will not be served
67
-     *
68
-     * @param int    $post_ID    [required]
69
-     * @param string $id_prefix  [required] Appended to all cache IDs. Can be helpful in finding specific cache types.
70
-     *                           May also be helpful to include an additional specific identifier,
71
-     *                           such as a post ID as part of the $id_prefix so that individual caches
72
-     *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
73
-     *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
74
-     */
75
-    public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix)
76
-    {
77
-        $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
78
-        // if post is not already being tracked
79
-        if ( ! isset($post_related_cache[$post_ID])) {
80
-            // add array to add cache ids to
81
-            $post_related_cache[$post_ID] = array();
82
-        }
83
-        // add cache id to be tracked
84
-        $post_related_cache[$post_ID][] = $id_prefix;
85
-        update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
86
-    }
87
-
88
-
89
-
90
-    /**
91
-     * callback hooked into the WordPress "save_post" action
92
-     * deletes any cache content associated with the post
93
-     *
94
-     * @param int $post_ID [required]
95
-     */
96
-    public function clearPostRelatedCache($post_ID)
97
-    {
98
-        $post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
99
-        // if post is not being tracked
100
-        if ( ! isset($post_related_cache[$post_ID])) {
101
-            return;
102
-        }
103
-        // get cache id prefixes for post, and delete their corresponding transients
104
-        $this->clear($post_related_cache[$post_ID]);
105
-        unset($post_related_cache[$post_ID]);
106
-        update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
107
-    }
21
+	/**
22
+	 * @type string
23
+	 */
24
+	const POST_CACHE_PREFIX = 'ee_cache_post_';
25
+
26
+	/**
27
+	 * wp-option option_name for tracking post related cache
28
+	 *
29
+	 * @type string
30
+	 */
31
+	const POST_CACHE_OPTIONS_KEY = 'ee_post_cache';
32
+
33
+
34
+
35
+	/**
36
+	 * PostRelatedCacheManager constructor.
37
+	 *
38
+	 * @param CacheStorageInterface      $cache_storage
39
+	 * @param SessionIdentifierInterface $session
40
+	 */
41
+	public function __construct(CacheStorageInterface $cache_storage, SessionIdentifierInterface $session)
42
+	{
43
+		parent::__construct($cache_storage, $session);
44
+		add_action('save_post', array($this, 'clearPostRelatedCache'));
45
+	}
46
+
47
+
48
+
49
+	/**
50
+	 * returns a string that will be prepended to all cache identifiers
51
+	 *
52
+	 * @return string
53
+	 */
54
+	public function cachePrefix()
55
+	{
56
+		return PostRelatedCacheManager::POST_CACHE_PREFIX;
57
+	}
58
+
59
+
60
+
61
+	/**
62
+	 * If you are caching content that pertains to a Post of any type,
63
+	 * then it is recommended to pass the post id and cache id prefix to this method
64
+	 * so that it can be added to the post related cache tracking.
65
+	 * Then, whenever that post is updated, the cache will automatically be deleted,
66
+	 * which helps to ensure that outdated cache content will not be served
67
+	 *
68
+	 * @param int    $post_ID    [required]
69
+	 * @param string $id_prefix  [required] Appended to all cache IDs. Can be helpful in finding specific cache types.
70
+	 *                           May also be helpful to include an additional specific identifier,
71
+	 *                           such as a post ID as part of the $id_prefix so that individual caches
72
+	 *                           can be found and/or cleared. ex: "venue-28", or "shortcode-156".
73
+	 *                           BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id.
74
+	 */
75
+	public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix)
76
+	{
77
+		$post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
78
+		// if post is not already being tracked
79
+		if ( ! isset($post_related_cache[$post_ID])) {
80
+			// add array to add cache ids to
81
+			$post_related_cache[$post_ID] = array();
82
+		}
83
+		// add cache id to be tracked
84
+		$post_related_cache[$post_ID][] = $id_prefix;
85
+		update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
86
+	}
87
+
88
+
89
+
90
+	/**
91
+	 * callback hooked into the WordPress "save_post" action
92
+	 * deletes any cache content associated with the post
93
+	 *
94
+	 * @param int $post_ID [required]
95
+	 */
96
+	public function clearPostRelatedCache($post_ID)
97
+	{
98
+		$post_related_cache = (array)get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array());
99
+		// if post is not being tracked
100
+		if ( ! isset($post_related_cache[$post_ID])) {
101
+			return;
102
+		}
103
+		// get cache id prefixes for post, and delete their corresponding transients
104
+		$this->clear($post_related_cache[$post_ID]);
105
+		unset($post_related_cache[$post_ID]);
106
+		update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache);
107
+	}
108 108
 
109 109
 
110 110
 }
Please login to merge, or discard this patch.
core/services/shortcodes/EspressoShortcode.php 1 patch
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -21,219 +21,219 @@
 block discarded – undo
21 21
 abstract class EspressoShortcode implements ShortcodeInterface
22 22
 {
23 23
 
24
-    /**
25
-     * transient prefix
26
-     *
27
-     * @type string
28
-     */
29
-    const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
30
-
31
-    /**
32
-     * @var PostRelatedCacheManager $cache_manager
33
-     */
34
-    private $cache_manager;
35
-
36
-    /**
37
-     * true if ShortcodeInterface::initializeShortcode() has been called
38
-     * if false, then that will get called before processing
39
-     *
40
-     * @var boolean $initialized
41
-     */
42
-    private $initialized = false;
43
-
44
-
45
-
46
-    /**
47
-     * EspressoShortcode constructor
48
-     *
49
-     * @param PostRelatedCacheManager $cache_manager
50
-     */
51
-    public function __construct(PostRelatedCacheManager $cache_manager)
52
-    {
53
-        $this->cache_manager = $cache_manager;
54
-    }
55
-
56
-
57
-
58
-    /**
59
-     * @return void
60
-     */
61
-    public function shortcodeHasBeenInitialized()
62
-    {
63
-        $this->initialized = true;
64
-    }
65
-
66
-
67
-
68
-    /**
69
-     * enqueues scripts then processes the shortcode
70
-     *
71
-     * @param array $attributes
72
-     * @return string
73
-     * @throws EE_Error
74
-     */
75
-    final public function processShortcodeCallback($attributes = array())
76
-    {
77
-        if ($this instanceof EnqueueAssetsInterface) {
78
-            if (is_admin()) {
79
-                $this->enqueueAdminScripts();
80
-            } else {
81
-                $this->enqueueScripts();
82
-            }
83
-        }
84
-        return $this->shortcodeContent(
85
-            $this->sanitizeAttributes((array)$attributes)
86
-        );
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     * If shortcode caching is enabled for the shortcode,
93
-     * and cached results exist, then that will be returned
94
-     * else new content will be generated.
95
-     * If caching is enabled, then the new content will be cached for later.
96
-     *
97
-     * @param array $attributes
98
-     * @return mixed|string
99
-     * @throws EE_Error
100
-     */
101
-    private function shortcodeContent(array $attributes)
102
-    {
103
-        $shortcode = $this;
104
-        $post_ID = $this->currentPostID();
105
-        // something like "SC_EVENTS-123"
106
-        $cache_ID = $this->shortcodeCacheID($post_ID);
107
-        $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
108
-        return $this->cache_manager->get(
109
-            $cache_ID,
110
-            // serialized attributes
111
-            wp_json_encode($attributes),
112
-            // Closure for generating content if cache is expired
113
-            function () use ($shortcode, $attributes) {
114
-                if($shortcode->initialized === false){
115
-                    $shortcode->initializeShortcode();
116
-                }
117
-                return $shortcode->processShortcode($attributes);
118
-            },
119
-            // filterable cache expiration set by each shortcode
120
-            apply_filters(
121
-                'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
122
-                $this->cacheExpiration(),
123
-                $this->getTag(),
124
-                $this
125
-            )
126
-        );
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * @return int
133
-     * @throws EE_Error
134
-     */
135
-    private function currentPostID()
136
-    {
137
-        // try to get EE_Event any way we can
138
-        $event = EEH_Event_View::get_event();
139
-        // then get some kind of ID
140
-        if ($event instanceof \EE_Event) {
141
-            $post_ID = $event->ID();
142
-        } else {
143
-            global $post;
144
-            $post_ID = $post->ID;
145
-        }
146
-        return $post_ID;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * @param int $post_ID
153
-     * @return string
154
-     * @throws EE_Error
155
-     */
156
-    private function shortcodeCacheID($post_ID)
157
-    {
158
-        $tag = str_replace('ESPRESSO_', '', $this->getTag());
159
-        return "SC_{$tag}-{$post_ID}";
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * array for defining custom attribute sanitization callbacks,
166
-     * where keys match keys in your attributes array,
167
-     * and values represent the sanitization function you wish to be applied to that attribute.
168
-     * So for example, if you had an integer attribute named "event_id"
169
-     * that you wanted to be sanitized using absint(),
170
-     * then you would return the following:
171
-     *      array('event_id' => 'absint')
172
-     * Entering 'skip_sanitization' for the callback value
173
-     * means that no sanitization will be applied
174
-     * on the assumption that the attribute
175
-     * will be sanitized at some point... right?
176
-     * You wouldn't pass around unsanitized attributes would you?
177
-     * That would be very Tom Foolery of you!!!
178
-     *
179
-     * @return array
180
-     */
181
-    protected function customAttributeSanitizationMap()
182
-    {
183
-        return array();
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * Performs basic sanitization on shortcode attributes
190
-     * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
191
-     * most attributes will by default be sanitized using the sanitize_text_field() function.
192
-     * This can be overridden using the customAttributeSanitizationMap() method (see above),
193
-     * all other attributes would be sanitized using the defaults in the switch statement below
194
-     *
195
-     * @param array $attributes
196
-     * @return array
197
-     */
198
-    private function sanitizeAttributes(array $attributes)
199
-    {
200
-        $custom_sanitization = $this->customAttributeSanitizationMap();
201
-        foreach ($attributes as $key => $value) {
202
-            // is a custom sanitization callback specified ?
203
-            if (isset($custom_sanitization[$key])) {
204
-                $callback = $custom_sanitization[$key];
205
-                if ($callback === 'skip_sanitization') {
206
-                    $attributes[$key] = $value;
207
-                    continue;
208
-                }
209
-                if (function_exists($callback)) {
210
-                    $attributes[$key] = $callback($value);
211
-                    continue;
212
-                }
213
-            }
214
-            switch (true) {
215
-                case $value === null :
216
-                case is_int($value) :
217
-                case is_float($value) :
218
-                    // typical booleans
219
-                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
220
-                    $attributes[$key] = $value;
221
-                    break;
222
-                case is_string($value) :
223
-                    $attributes[$key] = sanitize_text_field($value);
224
-                    break;
225
-                case is_array($value) :
226
-                    $attributes[$key] = $this->sanitizeAttributes($value);
227
-                    break;
228
-                default :
229
-                    // only remaining data types are Object and Resource
230
-                    // which are not allowed as shortcode attributes
231
-                    $attributes[$key] = null;
232
-                    break;
233
-            }
234
-        }
235
-        return $attributes;
236
-    }
24
+	/**
25
+	 * transient prefix
26
+	 *
27
+	 * @type string
28
+	 */
29
+	const CACHE_TRANSIENT_PREFIX = 'ee_sc_';
30
+
31
+	/**
32
+	 * @var PostRelatedCacheManager $cache_manager
33
+	 */
34
+	private $cache_manager;
35
+
36
+	/**
37
+	 * true if ShortcodeInterface::initializeShortcode() has been called
38
+	 * if false, then that will get called before processing
39
+	 *
40
+	 * @var boolean $initialized
41
+	 */
42
+	private $initialized = false;
43
+
44
+
45
+
46
+	/**
47
+	 * EspressoShortcode constructor
48
+	 *
49
+	 * @param PostRelatedCacheManager $cache_manager
50
+	 */
51
+	public function __construct(PostRelatedCacheManager $cache_manager)
52
+	{
53
+		$this->cache_manager = $cache_manager;
54
+	}
55
+
56
+
57
+
58
+	/**
59
+	 * @return void
60
+	 */
61
+	public function shortcodeHasBeenInitialized()
62
+	{
63
+		$this->initialized = true;
64
+	}
65
+
66
+
67
+
68
+	/**
69
+	 * enqueues scripts then processes the shortcode
70
+	 *
71
+	 * @param array $attributes
72
+	 * @return string
73
+	 * @throws EE_Error
74
+	 */
75
+	final public function processShortcodeCallback($attributes = array())
76
+	{
77
+		if ($this instanceof EnqueueAssetsInterface) {
78
+			if (is_admin()) {
79
+				$this->enqueueAdminScripts();
80
+			} else {
81
+				$this->enqueueScripts();
82
+			}
83
+		}
84
+		return $this->shortcodeContent(
85
+			$this->sanitizeAttributes((array)$attributes)
86
+		);
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 * If shortcode caching is enabled for the shortcode,
93
+	 * and cached results exist, then that will be returned
94
+	 * else new content will be generated.
95
+	 * If caching is enabled, then the new content will be cached for later.
96
+	 *
97
+	 * @param array $attributes
98
+	 * @return mixed|string
99
+	 * @throws EE_Error
100
+	 */
101
+	private function shortcodeContent(array $attributes)
102
+	{
103
+		$shortcode = $this;
104
+		$post_ID = $this->currentPostID();
105
+		// something like "SC_EVENTS-123"
106
+		$cache_ID = $this->shortcodeCacheID($post_ID);
107
+		$this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID);
108
+		return $this->cache_manager->get(
109
+			$cache_ID,
110
+			// serialized attributes
111
+			wp_json_encode($attributes),
112
+			// Closure for generating content if cache is expired
113
+			function () use ($shortcode, $attributes) {
114
+				if($shortcode->initialized === false){
115
+					$shortcode->initializeShortcode();
116
+				}
117
+				return $shortcode->processShortcode($attributes);
118
+			},
119
+			// filterable cache expiration set by each shortcode
120
+			apply_filters(
121
+				'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration',
122
+				$this->cacheExpiration(),
123
+				$this->getTag(),
124
+				$this
125
+			)
126
+		);
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * @return int
133
+	 * @throws EE_Error
134
+	 */
135
+	private function currentPostID()
136
+	{
137
+		// try to get EE_Event any way we can
138
+		$event = EEH_Event_View::get_event();
139
+		// then get some kind of ID
140
+		if ($event instanceof \EE_Event) {
141
+			$post_ID = $event->ID();
142
+		} else {
143
+			global $post;
144
+			$post_ID = $post->ID;
145
+		}
146
+		return $post_ID;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * @param int $post_ID
153
+	 * @return string
154
+	 * @throws EE_Error
155
+	 */
156
+	private function shortcodeCacheID($post_ID)
157
+	{
158
+		$tag = str_replace('ESPRESSO_', '', $this->getTag());
159
+		return "SC_{$tag}-{$post_ID}";
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * array for defining custom attribute sanitization callbacks,
166
+	 * where keys match keys in your attributes array,
167
+	 * and values represent the sanitization function you wish to be applied to that attribute.
168
+	 * So for example, if you had an integer attribute named "event_id"
169
+	 * that you wanted to be sanitized using absint(),
170
+	 * then you would return the following:
171
+	 *      array('event_id' => 'absint')
172
+	 * Entering 'skip_sanitization' for the callback value
173
+	 * means that no sanitization will be applied
174
+	 * on the assumption that the attribute
175
+	 * will be sanitized at some point... right?
176
+	 * You wouldn't pass around unsanitized attributes would you?
177
+	 * That would be very Tom Foolery of you!!!
178
+	 *
179
+	 * @return array
180
+	 */
181
+	protected function customAttributeSanitizationMap()
182
+	{
183
+		return array();
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * Performs basic sanitization on shortcode attributes
190
+	 * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
191
+	 * most attributes will by default be sanitized using the sanitize_text_field() function.
192
+	 * This can be overridden using the customAttributeSanitizationMap() method (see above),
193
+	 * all other attributes would be sanitized using the defaults in the switch statement below
194
+	 *
195
+	 * @param array $attributes
196
+	 * @return array
197
+	 */
198
+	private function sanitizeAttributes(array $attributes)
199
+	{
200
+		$custom_sanitization = $this->customAttributeSanitizationMap();
201
+		foreach ($attributes as $key => $value) {
202
+			// is a custom sanitization callback specified ?
203
+			if (isset($custom_sanitization[$key])) {
204
+				$callback = $custom_sanitization[$key];
205
+				if ($callback === 'skip_sanitization') {
206
+					$attributes[$key] = $value;
207
+					continue;
208
+				}
209
+				if (function_exists($callback)) {
210
+					$attributes[$key] = $callback($value);
211
+					continue;
212
+				}
213
+			}
214
+			switch (true) {
215
+				case $value === null :
216
+				case is_int($value) :
217
+				case is_float($value) :
218
+					// typical booleans
219
+				case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
220
+					$attributes[$key] = $value;
221
+					break;
222
+				case is_string($value) :
223
+					$attributes[$key] = sanitize_text_field($value);
224
+					break;
225
+				case is_array($value) :
226
+					$attributes[$key] = $this->sanitizeAttributes($value);
227
+					break;
228
+				default :
229
+					// only remaining data types are Object and Resource
230
+					// which are not allowed as shortcode attributes
231
+					$attributes[$key] = null;
232
+					break;
233
+			}
234
+		}
235
+		return $attributes;
236
+	}
237 237
 
238 238
 
239 239
 
Please login to merge, or discard this patch.