Completed
Branch FET-10304-welcome-to-vue (2869cd)
by
unknown
12:52
created
core/admin/EE_Admin_Page.core.php 2 patches
Indentation   +3273 added lines, -3273 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,2119 +28,2119 @@  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 clases do something specific before the parent constructor runs _page_setup.
196
-        if (method_exists($this, '_before_page_setup')) {
197
-            $this->_before_page_setup();
198
-        }
199
-        //set up page dependencies
200
-        $this->_page_setup();
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * _init_page_props
207
-     * Child classes use to set at least the following properties:
208
-     * $page_slug.
209
-     * $page_label.
210
-     *
211
-     * @abstract
212
-     * @access protected
213
-     * @return void
214
-     */
215
-    abstract protected function _init_page_props();
216
-
217
-
218
-
219
-    /**
220
-     * _ajax_hooks
221
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
222
-     * Note: within the ajax callback methods.
223
-     *
224
-     * @abstract
225
-     * @access protected
226
-     * @return void
227
-     */
228
-    abstract protected function _ajax_hooks();
229
-
230
-
231
-
232
-    /**
233
-     * _define_page_props
234
-     * child classes define page properties in here.  Must include at least:
235
-     * $_admin_base_url = base_url for all admin pages
236
-     * $_admin_page_title = default admin_page_title for admin pages
237
-     * $_labels = array of default labels for various automatically generated elements:
238
-     *    array(
239
-     *        'buttons' => array(
240
-     *            'add' => __('label for add new button'),
241
-     *            'edit' => __('label for edit button'),
242
-     *            'delete' => __('label for delete button')
243
-     *            )
244
-     *        )
245
-     *
246
-     * @abstract
247
-     * @access protected
248
-     * @return void
249
-     */
250
-    abstract protected function _define_page_props();
251
-
252
-
253
-
254
-    /**
255
-     * _set_page_routes
256
-     * 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'
257
-     * route. Here's the format
258
-     * $this->_page_routes = array(
259
-     *        'default' => array(
260
-     *            'func' => '_default_method_handling_route',
261
-     *            'args' => array('array','of','args'),
262
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
263
-     *            '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.
264
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
265
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
266
-     *        ),
267
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
268
-     *        )
269
-     * )
270
-     *
271
-     * @abstract
272
-     * @access protected
273
-     * @return void
274
-     */
275
-    abstract protected function _set_page_routes();
276
-
277
-
278
-
279
-    /**
280
-     * _set_page_config
281
-     * 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.
282
-     * Format:
283
-     * $this->_page_config = array(
284
-     *        'default' => array(
285
-     *            'labels' => array(
286
-     *                'buttons' => array(
287
-     *                    'add' => __('label for adding item'),
288
-     *                    'edit' => __('label for editing item'),
289
-     *                    'delete' => __('label for deleting item')
290
-     *                ),
291
-     *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
292
-     *            ), //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
293
-     *            'nav' => array(
294
-     *                'label' => __('Label for Tab', 'event_espresso').
295
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
296
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
297
-     *                'order' => 10, //required to indicate tab position.
298
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
299
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
300
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
301
-     *            '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
302
-     *            this flag to make sure the necessary js gets enqueued on page load.
303
-     *            '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.
304
-     *            '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
305
-     *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
306
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
307
-     *                'tab_id' => array(
308
-     *                    'title' => 'tab_title',
309
-     *                    '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
310
-     *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
311
-     *                    '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
312
-     *                    ),
313
-     *                'tab2_id' => array(
314
-     *                    'title' => 'tab2 title',
315
-     *                    'filename' => 'file_name_2'
316
-     *                    'callback' => 'callback_method_for_content',
317
-     *                 ),
318
-     *            '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/
319
-     *            'help_tour' => array(
320
-     *                '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
321
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
322
-     *            ),
323
-     *            '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
324
-     *            'require_nonce' to FALSE
325
-     *            )
326
-     * )
327
-     *
328
-     * @abstract
329
-     * @access protected
330
-     * @return void
331
-     */
332
-    abstract protected function _set_page_config();
333
-
334
-
335
-
336
-
337
-
338
-    /** end sample help_tour methods **/
339
-    /**
340
-     * _add_screen_options
341
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
342
-     * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
343
-     *
344
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
345
-     *         see also WP_Screen object documents...
346
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
347
-     * @abstract
348
-     * @access protected
349
-     * @return void
350
-     */
351
-    abstract protected function _add_screen_options();
352
-
353
-
354
-
355
-    /**
356
-     * _add_feature_pointers
357
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
358
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
359
-     * Note: this is just a placeholder for now.  Implementation will come down the road
360
-     * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
361
-     *
362
-     * @link   http://eamann.com/tech/wordpress-portland/
363
-     * @abstract
364
-     * @access protected
365
-     * @return void
366
-     */
367
-    abstract protected function _add_feature_pointers();
368
-
369
-
370
-
371
-    /**
372
-     * load_scripts_styles
373
-     * 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
374
-     * 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)
375
-     *
376
-     * @abstract
377
-     * @access public
378
-     * @return void
379
-     */
380
-    abstract public function load_scripts_styles();
381
-
382
-
383
-
384
-    /**
385
-     * admin_init
386
-     * 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.
387
-     *
388
-     * @abstract
389
-     * @access public
390
-     * @return void
391
-     */
392
-    abstract public function admin_init();
393
-
394
-
395
-
396
-    /**
397
-     * admin_notices
398
-     * 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.
399
-     *
400
-     * @abstract
401
-     * @access public
402
-     * @return void
403
-     */
404
-    abstract public function admin_notices();
405
-
406
-
407
-
408
-    /**
409
-     * admin_footer_scripts
410
-     * 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.
411
-     *
412
-     * @access public
413
-     * @return void
414
-     */
415
-    abstract public function admin_footer_scripts();
416
-
417
-
418
-
419
-    /**
420
-     * admin_footer
421
-     * 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.
422
-     *
423
-     * @access  public
424
-     * @return void
425
-     */
426
-    public function admin_footer()
427
-    {
428
-    }
429
-
430
-
431
-
432
-    /**
433
-     * _global_ajax_hooks
434
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
435
-     * Note: within the ajax callback methods.
436
-     *
437
-     * @abstract
438
-     * @access protected
439
-     * @return void
440
-     */
441
-    protected function _global_ajax_hooks()
442
-    {
443
-        //for lazy loading of metabox content
444
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
445
-    }
446
-
447
-
448
-
449
-    public function ajax_metabox_content()
450
-    {
451
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
452
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
453
-        self::cached_rss_display($contentid, $url);
454
-        wp_die();
455
-    }
456
-
457
-
458
-
459
-    /**
460
-     * _page_setup
461
-     * 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.
462
-     *
463
-     * @final
464
-     * @access protected
465
-     * @return void
466
-     */
467
-    final protected function _page_setup()
468
-    {
469
-        //requires?
470
-        //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.
471
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
472
-        //next verify if we need to load anything...
473
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
474
-        $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
475
-        global $ee_menu_slugs;
476
-        $ee_menu_slugs = (array)$ee_menu_slugs;
477
-        if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
478
-            return false;
479
-        }
480
-        // 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
481
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
482
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
483
-        }
484
-        // then set blank or -1 action values to 'default'
485
-        $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';
486
-        //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.
487
-        $this->_req_action = $this->_req_action == 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
488
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
489
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
490
-        $this->_current_view = $this->_req_action;
491
-        $this->_req_nonce = $this->_req_action . '_nonce';
492
-        $this->_define_page_props();
493
-        $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
494
-        //default things
495
-        $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
496
-        //set page configs
497
-        $this->_set_page_routes();
498
-        $this->_set_page_config();
499
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
500
-        if (isset($this->_req_data['wp_referer'])) {
501
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
502
-        }
503
-        //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
504
-        if (method_exists($this, '_extend_page_config')) {
505
-            $this->_extend_page_config();
506
-        }
507
-        //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.
508
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
509
-            $this->_extend_page_config_for_cpt();
510
-        }
511
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
512
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
513
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
514
-        //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
515
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
516
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
517
-        }
518
-        //next route only if routing enabled
519
-        if ($this->_routing && ! defined('DOING_AJAX')) {
520
-            $this->_verify_routes();
521
-            //next let's just check user_access and kill if no access
522
-            $this->check_user_access();
523
-            if ($this->_is_UI_request) {
524
-                //admin_init stuff - global, all views for this page class, specific view
525
-                add_action('admin_init', array($this, 'admin_init'), 10);
526
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
527
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
528
-                }
529
-            } else {
530
-                //hijack regular WP loading and route admin request immediately
531
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
532
-                $this->route_admin_request();
533
-            }
534
-        }
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
541
-     *
542
-     * @access private
543
-     * @return void
544
-     */
545
-    private function _do_other_page_hooks()
546
-    {
547
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
548
-        foreach ($registered_pages as $page) {
549
-            //now let's setup the file name and class that should be present
550
-            $classname = str_replace('.class.php', '', $page);
551
-            //autoloaders should take care of loading file
552
-            if ( ! class_exists($classname)) {
553
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
554
-                $error_msg[] = $error_msg[0]
555
-                               . "\r\n"
556
-                               . 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',
557
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
558
-                throw new EE_Error(implode('||', $error_msg));
559
-            }
560
-            $a = new ReflectionClass($classname);
561
-            //notice we are passing the instance of this class to the hook object.
562
-            $hookobj[] = $a->newInstance($this);
563
-        }
564
-    }
565
-
566
-
567
-
568
-    public function load_page_dependencies()
569
-    {
570
-        try {
571
-            $this->_load_page_dependencies();
572
-        } catch (EE_Error $e) {
573
-            $e->get_error();
574
-        }
575
-    }
576
-
577
-
578
-
579
-    /**
580
-     * load_page_dependencies
581
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
582
-     *
583
-     * @access public
584
-     * @return void
585
-     */
586
-    protected function _load_page_dependencies()
587
-    {
588
-        //let's set the current_screen and screen options to override what WP set
589
-        $this->_current_screen = get_current_screen();
590
-        //load admin_notices - global, page class, and view specific
591
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
592
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
593
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
594
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
595
-        }
596
-        //load network admin_notices - global, page class, and view specific
597
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
598
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
599
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
600
-        }
601
-        //this will save any per_page screen options if they are present
602
-        $this->_set_per_page_screen_options();
603
-        //setup list table properties
604
-        $this->_set_list_table();
605
-        // 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.
606
-        $this->_add_registered_meta_boxes();
607
-        $this->_add_screen_columns();
608
-        //add screen options - global, page child class, and view specific
609
-        $this->_add_global_screen_options();
610
-        $this->_add_screen_options();
611
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
612
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
613
-        }
614
-        //add help tab(s) and tours- set via page_config and qtips.
615
-        $this->_add_help_tour();
616
-        $this->_add_help_tabs();
617
-        $this->_add_qtips();
618
-        //add feature_pointers - global, page child class, and view specific
619
-        $this->_add_feature_pointers();
620
-        $this->_add_global_feature_pointers();
621
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
622
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
623
-        }
624
-        //enqueue scripts/styles - global, page class, and view specific
625
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
626
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
627
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
628
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
629
-        }
630
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
631
-        //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
632
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
633
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
634
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
635
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
636
-        }
637
-        //admin footer scripts
638
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
639
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
640
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
641
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
642
-        }
643
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
644
-        //targeted hook
645
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
646
-    }
647
-
648
-
649
-
650
-    /**
651
-     * _set_defaults
652
-     * This sets some global defaults for class properties.
653
-     */
654
-    private function _set_defaults()
655
-    {
656
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
657
-        $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
658
-        $this->default_nav_tab_name = 'overview';
659
-        //init template args
660
-        $this->_template_args = array(
661
-                'admin_page_header'  => '',
662
-                'admin_page_content' => '',
663
-                'post_body_content'  => '',
664
-                'before_list_table'  => '',
665
-                'after_list_table'   => '',
666
-        );
667
-    }
668
-
669
-
670
-
671
-    /**
672
-     * route_admin_request
673
-     *
674
-     * @see    _route_admin_request()
675
-     * @access public
676
-     * @return void|exception error
677
-     */
678
-    public function route_admin_request()
679
-    {
680
-        try {
681
-            $this->_route_admin_request();
682
-        } catch (EE_Error $e) {
683
-            $e->get_error();
684
-        }
685
-    }
686
-
687
-
688
-
689
-    public function set_wp_page_slug($wp_page_slug)
690
-    {
691
-        $this->_wp_page_slug = $wp_page_slug;
692
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
693
-        if (is_network_admin()) {
694
-            $this->_wp_page_slug .= '-network';
695
-        }
696
-    }
697
-
698
-
699
-
700
-    /**
701
-     * _verify_routes
702
-     * 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.
703
-     *
704
-     * @access protected
705
-     * @return void
706
-     */
707
-    protected function _verify_routes()
708
-    {
709
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
710
-        if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
711
-            return false;
712
-        }
713
-        $this->_route = false;
714
-        $func = false;
715
-        $args = array();
716
-        // check that the page_routes array is not empty
717
-        if (empty($this->_page_routes)) {
718
-            // user error msg
719
-            $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
720
-            // developer error msg
721
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
722
-            throw new EE_Error($error_msg);
723
-        }
724
-        // and that the requested page route exists
725
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
726
-            $this->_route = $this->_page_routes[$this->_req_action];
727
-            $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
728
-        } else {
729
-            // user error msg
730
-            $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
731
-            // developer error msg
732
-            $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);
733
-            throw new EE_Error($error_msg);
734
-        }
735
-        // and that a default route exists
736
-        if ( ! array_key_exists('default', $this->_page_routes)) {
737
-            // user error msg
738
-            $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
739
-            // developer error msg
740
-            $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');
741
-            throw new EE_Error($error_msg);
742
-        }
743
-        //first lets' catch if the UI request has EVER been set.
744
-        if ($this->_is_UI_request === null) {
745
-            //lets set if this is a UI request or not.
746
-            $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
747
-            //wait a minute... we might have a noheader in the route array
748
-            $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
749
-        }
750
-        $this->_set_current_labels();
751
-    }
752
-
753
-
754
-
755
-    /**
756
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
757
-     *
758
-     * @param  string $route the route name we're verifying
759
-     * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
760
-     */
761
-    protected function _verify_route($route)
762
-    {
763
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
764
-            return true;
765
-        } else {
766
-            // user error msg
767
-            $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
768
-            // developer error msg
769
-            $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);
770
-            throw new EE_Error($error_msg);
771
-        }
772
-    }
773
-
774
-
775
-
776
-    /**
777
-     * perform nonce verification
778
-     * 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!)
779
-     *
780
-     * @param  string $nonce     The nonce sent
781
-     * @param  string $nonce_ref The nonce reference string (name0)
782
-     * @return mixed (bool|die)
783
-     */
784
-    protected function _verify_nonce($nonce, $nonce_ref)
785
-    {
786
-        // verify nonce against expected value
787
-        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
788
-            // these are not the droids you are looking for !!!
789
-            $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
790
-            if (WP_DEBUG) {
791
-                $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__);
792
-            }
793
-            if ( ! defined('DOING_AJAX')) {
794
-                wp_die($msg);
795
-            } else {
796
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
797
-                $this->_return_json();
798
-            }
799
-        }
800
-    }
801
-
802
-
803
-
804
-    /**
805
-     * _route_admin_request()
806
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
807
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
808
-     * in the page routes and then will try to load the corresponding method.
809
-     *
810
-     * @access protected
811
-     * @return void
812
-     * @throws \EE_Error
813
-     */
814
-    protected function _route_admin_request()
815
-    {
816
-        if ( ! $this->_is_UI_request) {
817
-            $this->_verify_routes();
818
-        }
819
-        $nonce_check = isset($this->_route_config['require_nonce'])
820
-            ? $this->_route_config['require_nonce']
821
-            : true;
822
-        if ($this->_req_action !== 'default' && $nonce_check) {
823
-            // set nonce from post data
824
-            $nonce = isset($this->_req_data[$this->_req_nonce])
825
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
826
-                : '';
827
-            $this->_verify_nonce($nonce, $this->_req_nonce);
828
-        }
829
-        //set the nav_tabs array but ONLY if this is  UI_request
830
-        if ($this->_is_UI_request) {
831
-            $this->_set_nav_tabs();
832
-        }
833
-        // grab callback function
834
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
835
-        // check if callback has args
836
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
837
-        $error_msg = '';
838
-        // action right before calling route
839
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
840
-        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
841
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
842
-        }
843
-        // right before calling the route, let's remove _wp_http_referer from the
844
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
845
-        $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
846
-        if ( ! empty($func)) {
847
-            if (is_array($func)) {
848
-                list($class, $method) = $func;
849
-            } else if (strpos($func, '::') !== false) {
850
-                list($class, $method) = explode('::', $func);
851
-            } else {
852
-                $class = $this;
853
-                $method = $func;
854
-            }
855
-            if ( ! (is_object($class) && $class === $this)) {
856
-                // send along this admin page object for access by addons.
857
-                $args['admin_page_object'] = $this;
858
-            }
859
-
860
-            if (
861
-                //is it a method on a class that doesn't work?
862
-                (
863
-                    (
864
-                        method_exists($class, $method)
865
-                        && call_user_func_array(array($class, $method), $args) === false
866
-                    )
867
-                    && (
868
-                        //is it a standalone function that doesn't work?
869
-                        function_exists($method)
870
-                        && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
871
-                    )
872
-                )
873
-                || (
874
-                    //is it neither a class method NOR a standalone function?
875
-                    ! method_exists($class, $method)
876
-                    && ! function_exists($method)
877
-                )
878
-            ) {
879
-                // user error msg
880
-                $error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
881
-                // developer error msg
882
-                $error_msg .= '||';
883
-                $error_msg .= sprintf(
884
-                    __(
885
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
886
-                        'event_espresso'
887
-                    ),
888
-                    $method
889
-                );
890
-            }
891
-            if ( ! empty($error_msg)) {
892
-                throw new EE_Error($error_msg);
893
-            }
894
-        }
895
-        //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.
896
-        //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.
897
-        if ($this->_is_UI_request === false
898
-            && is_array($this->_route)
899
-            && ! empty($this->_route['headers_sent_route'])
900
-        ) {
901
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
902
-        }
903
-    }
904
-
905
-
906
-
907
-    /**
908
-     * This method just allows the resetting of page properties in the case where a no headers
909
-     * route redirects to a headers route in its route config.
910
-     *
911
-     * @since   4.3.0
912
-     * @param  string $new_route New (non header) route to redirect to.
913
-     * @return   void
914
-     */
915
-    protected function _reset_routing_properties($new_route)
916
-    {
917
-        $this->_is_UI_request = true;
918
-        //now we set the current route to whatever the headers_sent_route is set at
919
-        $this->_req_data['action'] = $new_route;
920
-        //rerun page setup
921
-        $this->_page_setup();
922
-    }
923
-
924
-
925
-
926
-    /**
927
-     * _add_query_arg
928
-     * adds nonce to array of arguments then calls WP add_query_arg function
929
-     *(internally just uses EEH_URL's function with the same name)
930
-     *
931
-     * @access public
932
-     * @param array  $args
933
-     * @param string $url
934
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
935
-     *                                        url in an associative array indexed by the key 'wp_referer';
936
-     *                                        Example usage:
937
-     *                                        If the current page is:
938
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
939
-     *                                        &action=default&event_id=20&month_range=March%202015
940
-     *                                        &_wpnonce=5467821
941
-     *                                        and you call:
942
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
943
-     *                                        array(
944
-     *                                        'action' => 'resend_something',
945
-     *                                        'page=>espresso_registrations'
946
-     *                                        ),
947
-     *                                        $some_url,
948
-     *                                        true
949
-     *                                        );
950
-     *                                        It will produce a url in this structure:
951
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
952
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
953
-     *                                        month_range]=March%202015
954
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
955
-     * @return string
956
-     */
957
-    public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
958
-    {
959
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
960
-        if ($sticky) {
961
-            $request = $_REQUEST;
962
-            unset($request['_wp_http_referer']);
963
-            unset($request['wp_referer']);
964
-            foreach ($request as $key => $value) {
965
-                //do not add nonces
966
-                if (strpos($key, 'nonce') !== false) {
967
-                    continue;
968
-                }
969
-                $args['wp_referer[' . $key . ']'] = $value;
970
-            }
971
-        }
972
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
973
-    }
974
-
975
-
976
-
977
-    /**
978
-     * This returns a generated link that will load the related help tab.
979
-     *
980
-     * @param  string $help_tab_id the id for the connected help tab
981
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
982
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
983
-     * @uses EEH_Template::get_help_tab_link()
984
-     * @return string              generated link
985
-     */
986
-    protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
987
-    {
988
-        return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
989
-    }
990
-
991
-
992
-
993
-    /**
994
-     * _add_help_tabs
995
-     * Note child classes define their help tabs within the page_config array.
996
-     *
997
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
998
-     * @access protected
999
-     * @return void
1000
-     */
1001
-    protected function _add_help_tabs()
1002
-    {
1003
-        $tour_buttons = '';
1004
-        if (isset($this->_page_config[$this->_req_action])) {
1005
-            $config = $this->_page_config[$this->_req_action];
1006
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1007
-            if (isset($this->_help_tour[$this->_req_action])) {
1008
-                $tb = array();
1009
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1010
-                foreach ($this->_help_tour['tours'] as $tour) {
1011
-                    //if this is the end tour then we don't need to setup a button
1012
-                    if ($tour instanceof EE_Help_Tour_final_stop) {
1013
-                        continue;
1014
-                    }
1015
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1016
-                }
1017
-                $tour_buttons .= implode('<br />', $tb);
1018
-                $tour_buttons .= '</div></div>';
1019
-            }
1020
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1021
-            if (is_array($config) && isset($config['help_sidebar'])) {
1022
-                //check that the callback given is valid
1023
-                if ( ! method_exists($this, $config['help_sidebar'])) {
1024
-                    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',
1025
-                            'event_espresso'), $config['help_sidebar'], get_class($this)));
1026
-                }
1027
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1028
-                $content .= $tour_buttons; //add help tour buttons.
1029
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1030
-                $this->_current_screen->set_help_sidebar($content);
1031
-            }
1032
-            //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1033
-            if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1034
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1035
-            }
1036
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1037
-            if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1038
-                $_ht['id'] = $this->page_slug;
1039
-                $_ht['title'] = __('Help Tours', 'event_espresso');
1040
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1041
-                $this->_current_screen->add_help_tab($_ht);
1042
-            }/**/
1043
-            if ( ! isset($config['help_tabs'])) {
1044
-                return;
1045
-            } //no help tabs for this route
1046
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1047
-                //we're here so there ARE help tabs!
1048
-                //make sure we've got what we need
1049
-                if ( ! isset($cfg['title'])) {
1050
-                    throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1051
-                }
1052
-                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1053
-                    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',
1054
-                            'event_espresso'));
1055
-                }
1056
-                //first priority goes to content.
1057
-                if ( ! empty($cfg['content'])) {
1058
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1059
-                    //second priority goes to filename
1060
-                } else if ( ! empty($cfg['filename'])) {
1061
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1062
-                    //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)
1063
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1064
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1065
-                    if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1066
-                        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',
1067
-                                'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1068
-                        return;
1069
-                    }
1070
-                    $template_args['admin_page_obj'] = $this;
1071
-                    $content = EEH_Template::display_template($file_path, $template_args, true);
1072
-                } else {
1073
-                    $content = '';
1074
-                }
1075
-                //check if callback is valid
1076
-                if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1077
-                    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.',
1078
-                            'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1079
-                    return;
1080
-                }
1081
-                //setup config array for help tab method
1082
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1083
-                $_ht = array(
1084
-                        'id'       => $id,
1085
-                        'title'    => $cfg['title'],
1086
-                        'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1087
-                        'content'  => $content,
1088
-                );
1089
-                $this->_current_screen->add_help_tab($_ht);
1090
-            }
1091
-        }
1092
-    }
1093
-
1094
-
1095
-
1096
-    /**
1097
-     * 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
1098
-     *
1099
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1100
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1101
-     * @access protected
1102
-     * @return void
1103
-     */
1104
-    protected function _add_help_tour()
1105
-    {
1106
-        $tours = array();
1107
-        $this->_help_tour = array();
1108
-        //exit early if help tours are turned off globally
1109
-        if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1110
-            return;
1111
-        }
1112
-        //loop through _page_config to find any help_tour defined
1113
-        foreach ($this->_page_config as $route => $config) {
1114
-            //we're only going to set things up for this route
1115
-            if ($route !== $this->_req_action) {
1116
-                continue;
1117
-            }
1118
-            if (isset($config['help_tour'])) {
1119
-                foreach ($config['help_tour'] as $tour) {
1120
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1121
-                    //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
1122
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1123
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1124
-                    if ( ! is_readable($file_path)) {
1125
-                        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'),
1126
-                                $file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1127
-                        return;
1128
-                    }
1129
-                    require_once $file_path;
1130
-                    if ( ! class_exists($tour)) {
1131
-                        $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1132
-                        $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.',
1133
-                                        'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1134
-                        throw new EE_Error(implode('||', $error_msg));
1135
-                    }
1136
-                    $a = new ReflectionClass($tour);
1137
-                    $tour_obj = $a->newInstance($this->_is_caf);
1138
-                    $tours[] = $tour_obj;
1139
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1140
-                }
1141
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1142
-                $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1143
-                $tours[] = $end_stop_tour;
1144
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1145
-            }
1146
-        }
1147
-        if ( ! empty($tours)) {
1148
-            $this->_help_tour['tours'] = $tours;
1149
-        }
1150
-        //thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1151
-    }
1152
-
1153
-
1154
-
1155
-    /**
1156
-     * This simply sets up any qtips that have been defined in the page config
1157
-     *
1158
-     * @access protected
1159
-     * @return void
1160
-     */
1161
-    protected function _add_qtips()
1162
-    {
1163
-        if (isset($this->_route_config['qtips'])) {
1164
-            $qtips = (array)$this->_route_config['qtips'];
1165
-            //load qtip loader
1166
-            $path = array(
1167
-                    $this->_get_dir() . '/qtips/',
1168
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1169
-            );
1170
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1171
-        }
1172
-    }
1173
-
1174
-
1175
-
1176
-    /**
1177
-     * _set_nav_tabs
1178
-     * 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.
1179
-     *
1180
-     * @access protected
1181
-     * @return void
1182
-     */
1183
-    protected function _set_nav_tabs()
1184
-    {
1185
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1186
-        $i = 0;
1187
-        foreach ($this->_page_config as $slug => $config) {
1188
-            if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1189
-                continue;
1190
-            } //no nav tab for this config
1191
-            //check for persistent flag
1192
-            if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1193
-                continue;
1194
-            } //nav tab is only to appear when route requested.
1195
-            if ( ! $this->check_user_access($slug, true)) {
1196
-                continue;
1197
-            } //no nav tab becasue current user does not have access.
1198
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1199
-            $this->_nav_tabs[$slug] = array(
1200
-                    'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1201
-                    'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1202
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1203
-                    'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1204
-            );
1205
-            $i++;
1206
-        }
1207
-        //if $this->_nav_tabs is empty then lets set the default
1208
-        if (empty($this->_nav_tabs)) {
1209
-            $this->_nav_tabs[$this->default_nav_tab_name] = array(
1210
-                    'url'       => $this->admin_base_url,
1211
-                    'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1212
-                    'css_class' => 'nav-tab-active',
1213
-                    'order'     => 10,
1214
-            );
1215
-        }
1216
-        //now let's sort the tabs according to order
1217
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1218
-    }
1219
-
1220
-
1221
-
1222
-    /**
1223
-     * _set_current_labels
1224
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1225
-     *
1226
-     * @access private
1227
-     * @return void
1228
-     */
1229
-    private function _set_current_labels()
1230
-    {
1231
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1232
-            foreach ($this->_route_config['labels'] as $label => $text) {
1233
-                if (is_array($text)) {
1234
-                    foreach ($text as $sublabel => $subtext) {
1235
-                        $this->_labels[$label][$sublabel] = $subtext;
1236
-                    }
1237
-                } else {
1238
-                    $this->_labels[$label] = $text;
1239
-                }
1240
-            }
1241
-        }
1242
-    }
1243
-
1244
-
1245
-
1246
-    /**
1247
-     *        verifies user access for this admin page
1248
-     *
1249
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1250
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1251
-     * @return        BOOL|wp_die()
1252
-     */
1253
-    public function check_user_access($route_to_check = '', $verify_only = false)
1254
-    {
1255
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1256
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1257
-        $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'])
1258
-                ? $this->_page_routes[$route_to_check]['capability'] : null;
1259
-        if (empty($capability) && empty($route_to_check)) {
1260
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1261
-        } else {
1262
-            $capability = empty($capability) ? 'manage_options' : $capability;
1263
-        }
1264
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1265
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1266
-            if ($verify_only) {
1267
-                return false;
1268
-            } else {
1269
-                if ( is_user_logged_in() ) {
1270
-                    wp_die(__('You do not have access to this route.', 'event_espresso'));
1271
-                } else {
1272
-                    return false;
1273
-                }
1274
-            }
1275
-        }
1276
-        return true;
1277
-    }
1278
-
1279
-
1280
-
1281
-    /**
1282
-     * admin_init_global
1283
-     * This runs all the code that we want executed within the WP admin_init hook.
1284
-     * This method executes for ALL EE Admin pages.
1285
-     *
1286
-     * @access public
1287
-     * @return void
1288
-     */
1289
-    public function admin_init_global()
1290
-    {
1291
-    }
1292
-
1293
-
1294
-
1295
-    /**
1296
-     * wp_loaded_global
1297
-     * 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
1298
-     *
1299
-     * @access public
1300
-     * @return void
1301
-     */
1302
-    public function wp_loaded()
1303
-    {
1304
-    }
1305
-
1306
-
1307
-
1308
-    /**
1309
-     * admin_notices
1310
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1311
-     *
1312
-     * @access public
1313
-     * @return void
1314
-     */
1315
-    public function admin_notices_global()
1316
-    {
1317
-        $this->_display_no_javascript_warning();
1318
-        $this->_display_espresso_notices();
1319
-    }
1320
-
1321
-
1322
-
1323
-    public function network_admin_notices_global()
1324
-    {
1325
-        $this->_display_no_javascript_warning();
1326
-        $this->_display_espresso_notices();
1327
-    }
1328
-
1329
-
1330
-
1331
-    /**
1332
-     * admin_footer_scripts_global
1333
-     * 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.
1334
-     *
1335
-     * @access public
1336
-     * @return void
1337
-     */
1338
-    public function admin_footer_scripts_global()
1339
-    {
1340
-        $this->_add_admin_page_ajax_loading_img();
1341
-        $this->_add_admin_page_overlay();
1342
-        //if metaboxes are present we need to add the nonce field
1343
-        if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1344
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1345
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1346
-        }
1347
-    }
1348
-
1349
-
1350
-
1351
-    /**
1352
-     * admin_footer_global
1353
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1354
-     *
1355
-     * @access  public
1356
-     * @return  void
1357
-     */
1358
-    public function admin_footer_global()
1359
-    {
1360
-        //dialog container for dialog helper
1361
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1362
-        $d_cont .= '<div class="ee-notices"></div>';
1363
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1364
-        $d_cont .= '</div>';
1365
-        echo $d_cont;
1366
-        //help tour stuff?
1367
-        if (isset($this->_help_tour[$this->_req_action])) {
1368
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1369
-        }
1370
-        //current set timezone for timezone js
1371
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1372
-    }
1373
-
1374
-
1375
-
1376
-    /**
1377
-     * 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.
1378
-     * For child classes:
1379
-     * 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
1380
-     * 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
1381
-     * '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(
1382
-     *    'help_trigger_id' => array(
1383
-     *        'title' => __('localized title for popup', 'event_espresso'),
1384
-     *        'content' => __('localized content for popup', 'event_espresso')
1385
-     *    )
1386
-     * );
1387
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1388
-     *
1389
-     * @access protected
1390
-     * @return string content
1391
-     */
1392
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1393
-    {
1394
-        $content = '';
1395
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1396
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1397
-        //loop through the array and setup content
1398
-        foreach ($help_array as $trigger => $help) {
1399
-            //make sure the array is setup properly
1400
-            if ( ! isset($help['title']) || ! isset($help['content'])) {
1401
-                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',
1402
-                        'event_espresso'));
1403
-            }
1404
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1405
-            $template_args = array(
1406
-                    'help_popup_id'      => $trigger,
1407
-                    'help_popup_title'   => $help['title'],
1408
-                    'help_popup_content' => $help['content'],
1409
-            );
1410
-            $content .= EEH_Template::display_template($template_path, $template_args, true);
1411
-        }
1412
-        if ($display) {
1413
-            echo $content;
1414
-        } else {
1415
-            return $content;
1416
-        }
1417
-    }
1418
-
1419
-
1420
-
1421
-    /**
1422
-     * All this does is retrive the help content array if set by the EE_Admin_Page child
1423
-     *
1424
-     * @access private
1425
-     * @return array properly formatted array for help popup content
1426
-     */
1427
-    private function _get_help_content()
1428
-    {
1429
-        //what is the method we're looking for?
1430
-        $method_name = '_help_popup_content_' . $this->_req_action;
1431
-        //if method doesn't exist let's get out.
1432
-        if ( ! method_exists($this, $method_name)) {
1433
-            return array();
1434
-        }
1435
-        //k we're good to go let's retrieve the help array
1436
-        $help_array = call_user_func(array($this, $method_name));
1437
-        //make sure we've got an array!
1438
-        if ( ! is_array($help_array)) {
1439
-            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'));
1440
-        }
1441
-        return $help_array;
1442
-    }
1443
-
1444
-
1445
-
1446
-    /**
1447
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1448
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1449
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1450
-     *
1451
-     * @access protected
1452
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1453
-     * @param boolean $display    if false then we return the trigger string
1454
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1455
-     * @return string
1456
-     */
1457
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1458
-    {
1459
-        if (defined('DOING_AJAX')) {
1460
-            return;
1461
-        }
1462
-        //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
1463
-        $help_array = $this->_get_help_content();
1464
-        $help_content = '';
1465
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1466
-            $help_array[$trigger_id] = array(
1467
-                    'title'   => __('Missing Content', 'event_espresso'),
1468
-                    '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.)',
1469
-                            'event_espresso'),
1470
-            );
1471
-            $help_content = $this->_set_help_popup_content($help_array, false);
1472
-        }
1473
-        //let's setup the trigger
1474
-        $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>';
1475
-        $content = $content . $help_content;
1476
-        if ($display) {
1477
-            echo $content;
1478
-        } else {
1479
-            return $content;
1480
-        }
1481
-    }
1482
-
1483
-
1484
-
1485
-    /**
1486
-     * _add_global_screen_options
1487
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1488
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1489
-     *
1490
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1491
-     *         see also WP_Screen object documents...
1492
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1493
-     * @abstract
1494
-     * @access private
1495
-     * @return void
1496
-     */
1497
-    private function _add_global_screen_options()
1498
-    {
1499
-    }
1500
-
1501
-
1502
-
1503
-    /**
1504
-     * _add_global_feature_pointers
1505
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1506
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1507
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1508
-     *
1509
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1510
-     * @link   http://eamann.com/tech/wordpress-portland/
1511
-     * @abstract
1512
-     * @access protected
1513
-     * @return void
1514
-     */
1515
-    private function _add_global_feature_pointers()
1516
-    {
1517
-    }
1518
-
1519
-
1520
-
1521
-    /**
1522
-     * load_global_scripts_styles
1523
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1524
-     *
1525
-     * @return void
1526
-     */
1527
-    public function load_global_scripts_styles()
1528
-    {
1529
-        /** STYLES **/
1530
-        // add debugging styles
1531
-        if (WP_DEBUG) {
1532
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1533
-        }
1534
-        //register all styles
1535
-        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);
1536
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1537
-        //helpers styles
1538
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1539
-        //enqueue global styles
1540
-        wp_enqueue_style('ee-admin-css');
1541
-        /** SCRIPTS **/
1542
-        //register all scripts
1543
-        wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1544
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1545
-        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);
1546
-        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);
1547
-        // register jQuery Validate - see /includes/functions/wp_hooks.php
1548
-        add_filter('FHEE_load_jquery_validate', '__return_true');
1549
-        add_filter('FHEE_load_joyride', '__return_true');
1550
-        //script for sorting tables
1551
-        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);
1552
-        //script for parsing uri's
1553
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1554
-        //and parsing associative serialized form elements
1555
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1556
-        //helpers scripts
1557
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1558
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1559
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1560
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1561
-        //google charts
1562
-        wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1563
-        //enqueue global scripts
1564
-        //taking care of metaboxes
1565
-        if ((isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) && empty($this->_cpt_route)) {
1566
-            wp_enqueue_script('dashboard');
1567
-        }
1568
-        //enqueue thickbox for ee help popups.  default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups
1569
-        if ( ! isset($this->_route_config['has_help_popups']) || (isset($this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'])) {
1570
-            wp_enqueue_script('ee_admin_js');
1571
-            wp_enqueue_style('ee-admin-css');
1572
-        }
1573
-        //localize script for ajax lazy loading
1574
-        $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1575
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1576
-        /**
1577
-         * help tour stuff
1578
-         */
1579
-        if ( ! empty($this->_help_tour)) {
1580
-            //register the js for kicking things off
1581
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1582
-            //setup tours for the js tour object
1583
-            foreach ($this->_help_tour['tours'] as $tour) {
1584
-                $tours[] = array(
1585
-                        'id'      => $tour->get_slug(),
1586
-                        'options' => $tour->get_options(),
1587
-                );
1588
-            }
1589
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1590
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1591
-        }
1592
-    }
1593
-
1594
-
1595
-
1596
-    /**
1597
-     *        admin_footer_scripts_eei18n_js_strings
1598
-     *
1599
-     * @access        public
1600
-     * @return        void
1601
-     */
1602
-    public function admin_footer_scripts_eei18n_js_strings()
1603
-    {
1604
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1605
-        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');
1606
-        EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1607
-        EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1608
-        EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1609
-        EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1610
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1611
-        EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1612
-        EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1613
-        EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1614
-        EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1615
-        EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1616
-        EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1617
-        EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1618
-        EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1619
-        EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1620
-        EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1621
-        EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1622
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1623
-        EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1624
-        EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1625
-        EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1626
-        EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1627
-        EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1628
-        EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1629
-        EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1630
-        EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1631
-        EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1632
-        EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1633
-        EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1634
-        EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1635
-        EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1636
-        EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1637
-        EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1638
-        EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1639
-        EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1640
-        EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1641
-        EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1642
-        EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1643
-        EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1644
-        //setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance
1645
-        //admin page when in maintenance mode and ee_admin_js is not loaded then.  This works everywhere else because
1646
-        //espresso_core is listed as a dependency of ee_admin_js.
1647
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
1648
-    }
1649
-
1650
-
1651
-
1652
-    /**
1653
-     *        load enhanced xdebug styles for ppl with failing eyesight
1654
-     *
1655
-     * @access        public
1656
-     * @return        void
1657
-     */
1658
-    public function add_xdebug_style()
1659
-    {
1660
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1661
-    }
1662
-
1663
-
1664
-    /************************/
1665
-    /** LIST TABLE METHODS **/
1666
-    /************************/
1667
-    /**
1668
-     * this sets up the list table if the current view requires it.
1669
-     *
1670
-     * @access protected
1671
-     * @return void
1672
-     */
1673
-    protected function _set_list_table()
1674
-    {
1675
-        //first is this a list_table view?
1676
-        if ( ! isset($this->_route_config['list_table'])) {
1677
-            return;
1678
-        } //not a list_table view so get out.
1679
-        //list table functions are per view specific (because some admin pages might have more than one listtable!)
1680
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1681
-            //user error msg
1682
-            $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1683
-            //developer error msg
1684
-            $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'),
1685
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1686
-            throw new EE_Error($error_msg);
1687
-        }
1688
-        //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1689
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1690
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1691
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1692
-        $this->_set_list_table_view();
1693
-        $this->_set_list_table_object();
1694
-    }
1695
-
1696
-
1697
-
1698
-    /**
1699
-     *        set current view for List Table
1700
-     *
1701
-     * @access public
1702
-     * @return array
1703
-     */
1704
-    protected function _set_list_table_view()
1705
-    {
1706
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1707
-        // looking at active items or dumpster diving ?
1708
-        if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1709
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1710
-        } else {
1711
-            $this->_view = sanitize_key($this->_req_data['status']);
1712
-        }
1713
-    }
1714
-
1715
-
1716
-
1717
-    /**
1718
-     * _set_list_table_object
1719
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1720
-     *
1721
-     * @throws \EE_Error
1722
-     */
1723
-    protected function _set_list_table_object()
1724
-    {
1725
-        if (isset($this->_route_config['list_table'])) {
1726
-            if ( ! class_exists($this->_route_config['list_table'])) {
1727
-                throw new EE_Error(
1728
-                        sprintf(
1729
-                                __(
1730
-                                        '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.',
1731
-                                        'event_espresso'
1732
-                                ),
1733
-                                $this->_route_config['list_table'],
1734
-                                get_class($this)
1735
-                        )
1736
-                );
1737
-            }
1738
-            $list_table = $this->_route_config['list_table'];
1739
-            $this->_list_table_object = new $list_table($this);
1740
-        }
1741
-    }
1742
-
1743
-
1744
-
1745
-    /**
1746
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1747
-     *
1748
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1749
-     *                                                    urls.  The array should be indexed by the view it is being
1750
-     *                                                    added to.
1751
-     * @return array
1752
-     */
1753
-    public function get_list_table_view_RLs($extra_query_args = array())
1754
-    {
1755
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1756
-        if (empty($this->_views)) {
1757
-            $this->_views = array();
1758
-        }
1759
-        // cycle thru views
1760
-        foreach ($this->_views as $key => $view) {
1761
-            $query_args = array();
1762
-            // check for current view
1763
-            $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1764
-            $query_args['action'] = $this->_req_action;
1765
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1766
-            $query_args['status'] = $view['slug'];
1767
-            //merge any other arguments sent in.
1768
-            if (isset($extra_query_args[$view['slug']])) {
1769
-                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1770
-            }
1771
-            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1772
-        }
1773
-        return $this->_views;
1774
-    }
1775
-
1776
-
1777
-
1778
-    /**
1779
-     * _entries_per_page_dropdown
1780
-     * generates a drop down box for selecting the number of visiable rows in an admin page list table
1781
-     *
1782
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1783
-     * @access protected
1784
-     * @param int $max_entries total number of rows in the table
1785
-     * @return string
1786
-     */
1787
-    protected function _entries_per_page_dropdown($max_entries = false)
1788
-    {
1789
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1790
-        $values = array(10, 25, 50, 100);
1791
-        $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1792
-        if ($max_entries) {
1793
-            $values[] = $max_entries;
1794
-            sort($values);
1795
-        }
1796
-        $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 clases do something specific before the parent constructor runs _page_setup.
196
+		if (method_exists($this, '_before_page_setup')) {
197
+			$this->_before_page_setup();
198
+		}
199
+		//set up page dependencies
200
+		$this->_page_setup();
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * _init_page_props
207
+	 * Child classes use to set at least the following properties:
208
+	 * $page_slug.
209
+	 * $page_label.
210
+	 *
211
+	 * @abstract
212
+	 * @access protected
213
+	 * @return void
214
+	 */
215
+	abstract protected function _init_page_props();
216
+
217
+
218
+
219
+	/**
220
+	 * _ajax_hooks
221
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
222
+	 * Note: within the ajax callback methods.
223
+	 *
224
+	 * @abstract
225
+	 * @access protected
226
+	 * @return void
227
+	 */
228
+	abstract protected function _ajax_hooks();
229
+
230
+
231
+
232
+	/**
233
+	 * _define_page_props
234
+	 * child classes define page properties in here.  Must include at least:
235
+	 * $_admin_base_url = base_url for all admin pages
236
+	 * $_admin_page_title = default admin_page_title for admin pages
237
+	 * $_labels = array of default labels for various automatically generated elements:
238
+	 *    array(
239
+	 *        'buttons' => array(
240
+	 *            'add' => __('label for add new button'),
241
+	 *            'edit' => __('label for edit button'),
242
+	 *            'delete' => __('label for delete button')
243
+	 *            )
244
+	 *        )
245
+	 *
246
+	 * @abstract
247
+	 * @access protected
248
+	 * @return void
249
+	 */
250
+	abstract protected function _define_page_props();
251
+
252
+
253
+
254
+	/**
255
+	 * _set_page_routes
256
+	 * 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'
257
+	 * route. Here's the format
258
+	 * $this->_page_routes = array(
259
+	 *        'default' => array(
260
+	 *            'func' => '_default_method_handling_route',
261
+	 *            'args' => array('array','of','args'),
262
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
263
+	 *            '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.
264
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
265
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
266
+	 *        ),
267
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
268
+	 *        )
269
+	 * )
270
+	 *
271
+	 * @abstract
272
+	 * @access protected
273
+	 * @return void
274
+	 */
275
+	abstract protected function _set_page_routes();
276
+
277
+
278
+
279
+	/**
280
+	 * _set_page_config
281
+	 * 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.
282
+	 * Format:
283
+	 * $this->_page_config = array(
284
+	 *        'default' => array(
285
+	 *            'labels' => array(
286
+	 *                'buttons' => array(
287
+	 *                    'add' => __('label for adding item'),
288
+	 *                    'edit' => __('label for editing item'),
289
+	 *                    'delete' => __('label for deleting item')
290
+	 *                ),
291
+	 *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
292
+	 *            ), //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
293
+	 *            'nav' => array(
294
+	 *                'label' => __('Label for Tab', 'event_espresso').
295
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
296
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
297
+	 *                'order' => 10, //required to indicate tab position.
298
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
299
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
300
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
301
+	 *            '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
302
+	 *            this flag to make sure the necessary js gets enqueued on page load.
303
+	 *            '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.
304
+	 *            '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
305
+	 *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
306
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
307
+	 *                'tab_id' => array(
308
+	 *                    'title' => 'tab_title',
309
+	 *                    '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
310
+	 *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
311
+	 *                    '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
312
+	 *                    ),
313
+	 *                'tab2_id' => array(
314
+	 *                    'title' => 'tab2 title',
315
+	 *                    'filename' => 'file_name_2'
316
+	 *                    'callback' => 'callback_method_for_content',
317
+	 *                 ),
318
+	 *            '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/
319
+	 *            'help_tour' => array(
320
+	 *                '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
321
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
322
+	 *            ),
323
+	 *            '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
324
+	 *            'require_nonce' to FALSE
325
+	 *            )
326
+	 * )
327
+	 *
328
+	 * @abstract
329
+	 * @access protected
330
+	 * @return void
331
+	 */
332
+	abstract protected function _set_page_config();
333
+
334
+
335
+
336
+
337
+
338
+	/** end sample help_tour methods **/
339
+	/**
340
+	 * _add_screen_options
341
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
342
+	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
343
+	 *
344
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
345
+	 *         see also WP_Screen object documents...
346
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
347
+	 * @abstract
348
+	 * @access protected
349
+	 * @return void
350
+	 */
351
+	abstract protected function _add_screen_options();
352
+
353
+
354
+
355
+	/**
356
+	 * _add_feature_pointers
357
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
358
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
359
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
360
+	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
361
+	 *
362
+	 * @link   http://eamann.com/tech/wordpress-portland/
363
+	 * @abstract
364
+	 * @access protected
365
+	 * @return void
366
+	 */
367
+	abstract protected function _add_feature_pointers();
368
+
369
+
370
+
371
+	/**
372
+	 * load_scripts_styles
373
+	 * 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
374
+	 * 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)
375
+	 *
376
+	 * @abstract
377
+	 * @access public
378
+	 * @return void
379
+	 */
380
+	abstract public function load_scripts_styles();
381
+
382
+
383
+
384
+	/**
385
+	 * admin_init
386
+	 * 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.
387
+	 *
388
+	 * @abstract
389
+	 * @access public
390
+	 * @return void
391
+	 */
392
+	abstract public function admin_init();
393
+
394
+
395
+
396
+	/**
397
+	 * admin_notices
398
+	 * 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.
399
+	 *
400
+	 * @abstract
401
+	 * @access public
402
+	 * @return void
403
+	 */
404
+	abstract public function admin_notices();
405
+
406
+
407
+
408
+	/**
409
+	 * admin_footer_scripts
410
+	 * 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.
411
+	 *
412
+	 * @access public
413
+	 * @return void
414
+	 */
415
+	abstract public function admin_footer_scripts();
416
+
417
+
418
+
419
+	/**
420
+	 * admin_footer
421
+	 * 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.
422
+	 *
423
+	 * @access  public
424
+	 * @return void
425
+	 */
426
+	public function admin_footer()
427
+	{
428
+	}
429
+
430
+
431
+
432
+	/**
433
+	 * _global_ajax_hooks
434
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
435
+	 * Note: within the ajax callback methods.
436
+	 *
437
+	 * @abstract
438
+	 * @access protected
439
+	 * @return void
440
+	 */
441
+	protected function _global_ajax_hooks()
442
+	{
443
+		//for lazy loading of metabox content
444
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
445
+	}
446
+
447
+
448
+
449
+	public function ajax_metabox_content()
450
+	{
451
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
452
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
453
+		self::cached_rss_display($contentid, $url);
454
+		wp_die();
455
+	}
456
+
457
+
458
+
459
+	/**
460
+	 * _page_setup
461
+	 * 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.
462
+	 *
463
+	 * @final
464
+	 * @access protected
465
+	 * @return void
466
+	 */
467
+	final protected function _page_setup()
468
+	{
469
+		//requires?
470
+		//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.
471
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
472
+		//next verify if we need to load anything...
473
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
474
+		$this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
475
+		global $ee_menu_slugs;
476
+		$ee_menu_slugs = (array)$ee_menu_slugs;
477
+		if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
478
+			return false;
479
+		}
480
+		// 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
481
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
482
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
483
+		}
484
+		// then set blank or -1 action values to 'default'
485
+		$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';
486
+		//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.
487
+		$this->_req_action = $this->_req_action == 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
488
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
489
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
490
+		$this->_current_view = $this->_req_action;
491
+		$this->_req_nonce = $this->_req_action . '_nonce';
492
+		$this->_define_page_props();
493
+		$this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
494
+		//default things
495
+		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
496
+		//set page configs
497
+		$this->_set_page_routes();
498
+		$this->_set_page_config();
499
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
500
+		if (isset($this->_req_data['wp_referer'])) {
501
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
502
+		}
503
+		//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
504
+		if (method_exists($this, '_extend_page_config')) {
505
+			$this->_extend_page_config();
506
+		}
507
+		//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.
508
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
509
+			$this->_extend_page_config_for_cpt();
510
+		}
511
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
512
+		$this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
513
+		$this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
514
+		//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
515
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
516
+			add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
517
+		}
518
+		//next route only if routing enabled
519
+		if ($this->_routing && ! defined('DOING_AJAX')) {
520
+			$this->_verify_routes();
521
+			//next let's just check user_access and kill if no access
522
+			$this->check_user_access();
523
+			if ($this->_is_UI_request) {
524
+				//admin_init stuff - global, all views for this page class, specific view
525
+				add_action('admin_init', array($this, 'admin_init'), 10);
526
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
527
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
528
+				}
529
+			} else {
530
+				//hijack regular WP loading and route admin request immediately
531
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
532
+				$this->route_admin_request();
533
+			}
534
+		}
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
541
+	 *
542
+	 * @access private
543
+	 * @return void
544
+	 */
545
+	private function _do_other_page_hooks()
546
+	{
547
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
548
+		foreach ($registered_pages as $page) {
549
+			//now let's setup the file name and class that should be present
550
+			$classname = str_replace('.class.php', '', $page);
551
+			//autoloaders should take care of loading file
552
+			if ( ! class_exists($classname)) {
553
+				$error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
554
+				$error_msg[] = $error_msg[0]
555
+							   . "\r\n"
556
+							   . 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',
557
+								'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
558
+				throw new EE_Error(implode('||', $error_msg));
559
+			}
560
+			$a = new ReflectionClass($classname);
561
+			//notice we are passing the instance of this class to the hook object.
562
+			$hookobj[] = $a->newInstance($this);
563
+		}
564
+	}
565
+
566
+
567
+
568
+	public function load_page_dependencies()
569
+	{
570
+		try {
571
+			$this->_load_page_dependencies();
572
+		} catch (EE_Error $e) {
573
+			$e->get_error();
574
+		}
575
+	}
576
+
577
+
578
+
579
+	/**
580
+	 * load_page_dependencies
581
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
582
+	 *
583
+	 * @access public
584
+	 * @return void
585
+	 */
586
+	protected function _load_page_dependencies()
587
+	{
588
+		//let's set the current_screen and screen options to override what WP set
589
+		$this->_current_screen = get_current_screen();
590
+		//load admin_notices - global, page class, and view specific
591
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
592
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
593
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
594
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
595
+		}
596
+		//load network admin_notices - global, page class, and view specific
597
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
598
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
599
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
600
+		}
601
+		//this will save any per_page screen options if they are present
602
+		$this->_set_per_page_screen_options();
603
+		//setup list table properties
604
+		$this->_set_list_table();
605
+		// 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.
606
+		$this->_add_registered_meta_boxes();
607
+		$this->_add_screen_columns();
608
+		//add screen options - global, page child class, and view specific
609
+		$this->_add_global_screen_options();
610
+		$this->_add_screen_options();
611
+		if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
612
+			call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
613
+		}
614
+		//add help tab(s) and tours- set via page_config and qtips.
615
+		$this->_add_help_tour();
616
+		$this->_add_help_tabs();
617
+		$this->_add_qtips();
618
+		//add feature_pointers - global, page child class, and view specific
619
+		$this->_add_feature_pointers();
620
+		$this->_add_global_feature_pointers();
621
+		if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
622
+			call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
623
+		}
624
+		//enqueue scripts/styles - global, page class, and view specific
625
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
626
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
627
+		if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
628
+			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
629
+		}
630
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
631
+		//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
632
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
633
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
634
+		if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
635
+			add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
636
+		}
637
+		//admin footer scripts
638
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
639
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
640
+		if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
641
+			add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
642
+		}
643
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
644
+		//targeted hook
645
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
646
+	}
647
+
648
+
649
+
650
+	/**
651
+	 * _set_defaults
652
+	 * This sets some global defaults for class properties.
653
+	 */
654
+	private function _set_defaults()
655
+	{
656
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
657
+		$this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
658
+		$this->default_nav_tab_name = 'overview';
659
+		//init template args
660
+		$this->_template_args = array(
661
+				'admin_page_header'  => '',
662
+				'admin_page_content' => '',
663
+				'post_body_content'  => '',
664
+				'before_list_table'  => '',
665
+				'after_list_table'   => '',
666
+		);
667
+	}
668
+
669
+
670
+
671
+	/**
672
+	 * route_admin_request
673
+	 *
674
+	 * @see    _route_admin_request()
675
+	 * @access public
676
+	 * @return void|exception error
677
+	 */
678
+	public function route_admin_request()
679
+	{
680
+		try {
681
+			$this->_route_admin_request();
682
+		} catch (EE_Error $e) {
683
+			$e->get_error();
684
+		}
685
+	}
686
+
687
+
688
+
689
+	public function set_wp_page_slug($wp_page_slug)
690
+	{
691
+		$this->_wp_page_slug = $wp_page_slug;
692
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
693
+		if (is_network_admin()) {
694
+			$this->_wp_page_slug .= '-network';
695
+		}
696
+	}
697
+
698
+
699
+
700
+	/**
701
+	 * _verify_routes
702
+	 * 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.
703
+	 *
704
+	 * @access protected
705
+	 * @return void
706
+	 */
707
+	protected function _verify_routes()
708
+	{
709
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
710
+		if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
711
+			return false;
712
+		}
713
+		$this->_route = false;
714
+		$func = false;
715
+		$args = array();
716
+		// check that the page_routes array is not empty
717
+		if (empty($this->_page_routes)) {
718
+			// user error msg
719
+			$error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
720
+			// developer error msg
721
+			$error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
722
+			throw new EE_Error($error_msg);
723
+		}
724
+		// and that the requested page route exists
725
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
726
+			$this->_route = $this->_page_routes[$this->_req_action];
727
+			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
728
+		} else {
729
+			// user error msg
730
+			$error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
731
+			// developer error msg
732
+			$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);
733
+			throw new EE_Error($error_msg);
734
+		}
735
+		// and that a default route exists
736
+		if ( ! array_key_exists('default', $this->_page_routes)) {
737
+			// user error msg
738
+			$error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
739
+			// developer error msg
740
+			$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');
741
+			throw new EE_Error($error_msg);
742
+		}
743
+		//first lets' catch if the UI request has EVER been set.
744
+		if ($this->_is_UI_request === null) {
745
+			//lets set if this is a UI request or not.
746
+			$this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
747
+			//wait a minute... we might have a noheader in the route array
748
+			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
749
+		}
750
+		$this->_set_current_labels();
751
+	}
752
+
753
+
754
+
755
+	/**
756
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
757
+	 *
758
+	 * @param  string $route the route name we're verifying
759
+	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
760
+	 */
761
+	protected function _verify_route($route)
762
+	{
763
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
764
+			return true;
765
+		} else {
766
+			// user error msg
767
+			$error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
768
+			// developer error msg
769
+			$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);
770
+			throw new EE_Error($error_msg);
771
+		}
772
+	}
773
+
774
+
775
+
776
+	/**
777
+	 * perform nonce verification
778
+	 * 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!)
779
+	 *
780
+	 * @param  string $nonce     The nonce sent
781
+	 * @param  string $nonce_ref The nonce reference string (name0)
782
+	 * @return mixed (bool|die)
783
+	 */
784
+	protected function _verify_nonce($nonce, $nonce_ref)
785
+	{
786
+		// verify nonce against expected value
787
+		if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
788
+			// these are not the droids you are looking for !!!
789
+			$msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
790
+			if (WP_DEBUG) {
791
+				$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__);
792
+			}
793
+			if ( ! defined('DOING_AJAX')) {
794
+				wp_die($msg);
795
+			} else {
796
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
797
+				$this->_return_json();
798
+			}
799
+		}
800
+	}
801
+
802
+
803
+
804
+	/**
805
+	 * _route_admin_request()
806
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
807
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
808
+	 * in the page routes and then will try to load the corresponding method.
809
+	 *
810
+	 * @access protected
811
+	 * @return void
812
+	 * @throws \EE_Error
813
+	 */
814
+	protected function _route_admin_request()
815
+	{
816
+		if ( ! $this->_is_UI_request) {
817
+			$this->_verify_routes();
818
+		}
819
+		$nonce_check = isset($this->_route_config['require_nonce'])
820
+			? $this->_route_config['require_nonce']
821
+			: true;
822
+		if ($this->_req_action !== 'default' && $nonce_check) {
823
+			// set nonce from post data
824
+			$nonce = isset($this->_req_data[$this->_req_nonce])
825
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
826
+				: '';
827
+			$this->_verify_nonce($nonce, $this->_req_nonce);
828
+		}
829
+		//set the nav_tabs array but ONLY if this is  UI_request
830
+		if ($this->_is_UI_request) {
831
+			$this->_set_nav_tabs();
832
+		}
833
+		// grab callback function
834
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
835
+		// check if callback has args
836
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
837
+		$error_msg = '';
838
+		// action right before calling route
839
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
840
+		if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
841
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
842
+		}
843
+		// right before calling the route, let's remove _wp_http_referer from the
844
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
845
+		$_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
846
+		if ( ! empty($func)) {
847
+			if (is_array($func)) {
848
+				list($class, $method) = $func;
849
+			} else if (strpos($func, '::') !== false) {
850
+				list($class, $method) = explode('::', $func);
851
+			} else {
852
+				$class = $this;
853
+				$method = $func;
854
+			}
855
+			if ( ! (is_object($class) && $class === $this)) {
856
+				// send along this admin page object for access by addons.
857
+				$args['admin_page_object'] = $this;
858
+			}
859
+
860
+			if (
861
+				//is it a method on a class that doesn't work?
862
+				(
863
+					(
864
+						method_exists($class, $method)
865
+						&& call_user_func_array(array($class, $method), $args) === false
866
+					)
867
+					&& (
868
+						//is it a standalone function that doesn't work?
869
+						function_exists($method)
870
+						&& call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
871
+					)
872
+				)
873
+				|| (
874
+					//is it neither a class method NOR a standalone function?
875
+					! method_exists($class, $method)
876
+					&& ! function_exists($method)
877
+				)
878
+			) {
879
+				// user error msg
880
+				$error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
881
+				// developer error msg
882
+				$error_msg .= '||';
883
+				$error_msg .= sprintf(
884
+					__(
885
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
886
+						'event_espresso'
887
+					),
888
+					$method
889
+				);
890
+			}
891
+			if ( ! empty($error_msg)) {
892
+				throw new EE_Error($error_msg);
893
+			}
894
+		}
895
+		//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.
896
+		//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.
897
+		if ($this->_is_UI_request === false
898
+			&& is_array($this->_route)
899
+			&& ! empty($this->_route['headers_sent_route'])
900
+		) {
901
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
902
+		}
903
+	}
904
+
905
+
906
+
907
+	/**
908
+	 * This method just allows the resetting of page properties in the case where a no headers
909
+	 * route redirects to a headers route in its route config.
910
+	 *
911
+	 * @since   4.3.0
912
+	 * @param  string $new_route New (non header) route to redirect to.
913
+	 * @return   void
914
+	 */
915
+	protected function _reset_routing_properties($new_route)
916
+	{
917
+		$this->_is_UI_request = true;
918
+		//now we set the current route to whatever the headers_sent_route is set at
919
+		$this->_req_data['action'] = $new_route;
920
+		//rerun page setup
921
+		$this->_page_setup();
922
+	}
923
+
924
+
925
+
926
+	/**
927
+	 * _add_query_arg
928
+	 * adds nonce to array of arguments then calls WP add_query_arg function
929
+	 *(internally just uses EEH_URL's function with the same name)
930
+	 *
931
+	 * @access public
932
+	 * @param array  $args
933
+	 * @param string $url
934
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
935
+	 *                                        url in an associative array indexed by the key 'wp_referer';
936
+	 *                                        Example usage:
937
+	 *                                        If the current page is:
938
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
939
+	 *                                        &action=default&event_id=20&month_range=March%202015
940
+	 *                                        &_wpnonce=5467821
941
+	 *                                        and you call:
942
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
943
+	 *                                        array(
944
+	 *                                        'action' => 'resend_something',
945
+	 *                                        'page=>espresso_registrations'
946
+	 *                                        ),
947
+	 *                                        $some_url,
948
+	 *                                        true
949
+	 *                                        );
950
+	 *                                        It will produce a url in this structure:
951
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
952
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
953
+	 *                                        month_range]=March%202015
954
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
955
+	 * @return string
956
+	 */
957
+	public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
958
+	{
959
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
960
+		if ($sticky) {
961
+			$request = $_REQUEST;
962
+			unset($request['_wp_http_referer']);
963
+			unset($request['wp_referer']);
964
+			foreach ($request as $key => $value) {
965
+				//do not add nonces
966
+				if (strpos($key, 'nonce') !== false) {
967
+					continue;
968
+				}
969
+				$args['wp_referer[' . $key . ']'] = $value;
970
+			}
971
+		}
972
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
973
+	}
974
+
975
+
976
+
977
+	/**
978
+	 * This returns a generated link that will load the related help tab.
979
+	 *
980
+	 * @param  string $help_tab_id the id for the connected help tab
981
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
982
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
983
+	 * @uses EEH_Template::get_help_tab_link()
984
+	 * @return string              generated link
985
+	 */
986
+	protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
987
+	{
988
+		return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
989
+	}
990
+
991
+
992
+
993
+	/**
994
+	 * _add_help_tabs
995
+	 * Note child classes define their help tabs within the page_config array.
996
+	 *
997
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
998
+	 * @access protected
999
+	 * @return void
1000
+	 */
1001
+	protected function _add_help_tabs()
1002
+	{
1003
+		$tour_buttons = '';
1004
+		if (isset($this->_page_config[$this->_req_action])) {
1005
+			$config = $this->_page_config[$this->_req_action];
1006
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1007
+			if (isset($this->_help_tour[$this->_req_action])) {
1008
+				$tb = array();
1009
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1010
+				foreach ($this->_help_tour['tours'] as $tour) {
1011
+					//if this is the end tour then we don't need to setup a button
1012
+					if ($tour instanceof EE_Help_Tour_final_stop) {
1013
+						continue;
1014
+					}
1015
+					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1016
+				}
1017
+				$tour_buttons .= implode('<br />', $tb);
1018
+				$tour_buttons .= '</div></div>';
1019
+			}
1020
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1021
+			if (is_array($config) && isset($config['help_sidebar'])) {
1022
+				//check that the callback given is valid
1023
+				if ( ! method_exists($this, $config['help_sidebar'])) {
1024
+					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',
1025
+							'event_espresso'), $config['help_sidebar'], get_class($this)));
1026
+				}
1027
+				$content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1028
+				$content .= $tour_buttons; //add help tour buttons.
1029
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1030
+				$this->_current_screen->set_help_sidebar($content);
1031
+			}
1032
+			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1033
+			if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1034
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1035
+			}
1036
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1037
+			if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1038
+				$_ht['id'] = $this->page_slug;
1039
+				$_ht['title'] = __('Help Tours', 'event_espresso');
1040
+				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1041
+				$this->_current_screen->add_help_tab($_ht);
1042
+			}/**/
1043
+			if ( ! isset($config['help_tabs'])) {
1044
+				return;
1045
+			} //no help tabs for this route
1046
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1047
+				//we're here so there ARE help tabs!
1048
+				//make sure we've got what we need
1049
+				if ( ! isset($cfg['title'])) {
1050
+					throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1051
+				}
1052
+				if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1053
+					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',
1054
+							'event_espresso'));
1055
+				}
1056
+				//first priority goes to content.
1057
+				if ( ! empty($cfg['content'])) {
1058
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1059
+					//second priority goes to filename
1060
+				} else if ( ! empty($cfg['filename'])) {
1061
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1062
+					//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)
1063
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1064
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1065
+					if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1066
+						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',
1067
+								'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1068
+						return;
1069
+					}
1070
+					$template_args['admin_page_obj'] = $this;
1071
+					$content = EEH_Template::display_template($file_path, $template_args, true);
1072
+				} else {
1073
+					$content = '';
1074
+				}
1075
+				//check if callback is valid
1076
+				if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1077
+					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.',
1078
+							'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1079
+					return;
1080
+				}
1081
+				//setup config array for help tab method
1082
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1083
+				$_ht = array(
1084
+						'id'       => $id,
1085
+						'title'    => $cfg['title'],
1086
+						'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1087
+						'content'  => $content,
1088
+				);
1089
+				$this->_current_screen->add_help_tab($_ht);
1090
+			}
1091
+		}
1092
+	}
1093
+
1094
+
1095
+
1096
+	/**
1097
+	 * 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
1098
+	 *
1099
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1100
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1101
+	 * @access protected
1102
+	 * @return void
1103
+	 */
1104
+	protected function _add_help_tour()
1105
+	{
1106
+		$tours = array();
1107
+		$this->_help_tour = array();
1108
+		//exit early if help tours are turned off globally
1109
+		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1110
+			return;
1111
+		}
1112
+		//loop through _page_config to find any help_tour defined
1113
+		foreach ($this->_page_config as $route => $config) {
1114
+			//we're only going to set things up for this route
1115
+			if ($route !== $this->_req_action) {
1116
+				continue;
1117
+			}
1118
+			if (isset($config['help_tour'])) {
1119
+				foreach ($config['help_tour'] as $tour) {
1120
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1121
+					//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
1122
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1123
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1124
+					if ( ! is_readable($file_path)) {
1125
+						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'),
1126
+								$file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1127
+						return;
1128
+					}
1129
+					require_once $file_path;
1130
+					if ( ! class_exists($tour)) {
1131
+						$error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1132
+						$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.',
1133
+										'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1134
+						throw new EE_Error(implode('||', $error_msg));
1135
+					}
1136
+					$a = new ReflectionClass($tour);
1137
+					$tour_obj = $a->newInstance($this->_is_caf);
1138
+					$tours[] = $tour_obj;
1139
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1140
+				}
1141
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1142
+				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1143
+				$tours[] = $end_stop_tour;
1144
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1145
+			}
1146
+		}
1147
+		if ( ! empty($tours)) {
1148
+			$this->_help_tour['tours'] = $tours;
1149
+		}
1150
+		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1151
+	}
1152
+
1153
+
1154
+
1155
+	/**
1156
+	 * This simply sets up any qtips that have been defined in the page config
1157
+	 *
1158
+	 * @access protected
1159
+	 * @return void
1160
+	 */
1161
+	protected function _add_qtips()
1162
+	{
1163
+		if (isset($this->_route_config['qtips'])) {
1164
+			$qtips = (array)$this->_route_config['qtips'];
1165
+			//load qtip loader
1166
+			$path = array(
1167
+					$this->_get_dir() . '/qtips/',
1168
+					EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1169
+			);
1170
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1171
+		}
1172
+	}
1173
+
1174
+
1175
+
1176
+	/**
1177
+	 * _set_nav_tabs
1178
+	 * 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.
1179
+	 *
1180
+	 * @access protected
1181
+	 * @return void
1182
+	 */
1183
+	protected function _set_nav_tabs()
1184
+	{
1185
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1186
+		$i = 0;
1187
+		foreach ($this->_page_config as $slug => $config) {
1188
+			if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1189
+				continue;
1190
+			} //no nav tab for this config
1191
+			//check for persistent flag
1192
+			if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1193
+				continue;
1194
+			} //nav tab is only to appear when route requested.
1195
+			if ( ! $this->check_user_access($slug, true)) {
1196
+				continue;
1197
+			} //no nav tab becasue current user does not have access.
1198
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1199
+			$this->_nav_tabs[$slug] = array(
1200
+					'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1201
+					'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1202
+					'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1203
+					'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1204
+			);
1205
+			$i++;
1206
+		}
1207
+		//if $this->_nav_tabs is empty then lets set the default
1208
+		if (empty($this->_nav_tabs)) {
1209
+			$this->_nav_tabs[$this->default_nav_tab_name] = array(
1210
+					'url'       => $this->admin_base_url,
1211
+					'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1212
+					'css_class' => 'nav-tab-active',
1213
+					'order'     => 10,
1214
+			);
1215
+		}
1216
+		//now let's sort the tabs according to order
1217
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1218
+	}
1219
+
1220
+
1221
+
1222
+	/**
1223
+	 * _set_current_labels
1224
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1225
+	 *
1226
+	 * @access private
1227
+	 * @return void
1228
+	 */
1229
+	private function _set_current_labels()
1230
+	{
1231
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1232
+			foreach ($this->_route_config['labels'] as $label => $text) {
1233
+				if (is_array($text)) {
1234
+					foreach ($text as $sublabel => $subtext) {
1235
+						$this->_labels[$label][$sublabel] = $subtext;
1236
+					}
1237
+				} else {
1238
+					$this->_labels[$label] = $text;
1239
+				}
1240
+			}
1241
+		}
1242
+	}
1243
+
1244
+
1245
+
1246
+	/**
1247
+	 *        verifies user access for this admin page
1248
+	 *
1249
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1250
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1251
+	 * @return        BOOL|wp_die()
1252
+	 */
1253
+	public function check_user_access($route_to_check = '', $verify_only = false)
1254
+	{
1255
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1256
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1257
+		$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'])
1258
+				? $this->_page_routes[$route_to_check]['capability'] : null;
1259
+		if (empty($capability) && empty($route_to_check)) {
1260
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1261
+		} else {
1262
+			$capability = empty($capability) ? 'manage_options' : $capability;
1263
+		}
1264
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1265
+		if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1266
+			if ($verify_only) {
1267
+				return false;
1268
+			} else {
1269
+				if ( is_user_logged_in() ) {
1270
+					wp_die(__('You do not have access to this route.', 'event_espresso'));
1271
+				} else {
1272
+					return false;
1273
+				}
1274
+			}
1275
+		}
1276
+		return true;
1277
+	}
1278
+
1279
+
1280
+
1281
+	/**
1282
+	 * admin_init_global
1283
+	 * This runs all the code that we want executed within the WP admin_init hook.
1284
+	 * This method executes for ALL EE Admin pages.
1285
+	 *
1286
+	 * @access public
1287
+	 * @return void
1288
+	 */
1289
+	public function admin_init_global()
1290
+	{
1291
+	}
1292
+
1293
+
1294
+
1295
+	/**
1296
+	 * wp_loaded_global
1297
+	 * 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
1298
+	 *
1299
+	 * @access public
1300
+	 * @return void
1301
+	 */
1302
+	public function wp_loaded()
1303
+	{
1304
+	}
1305
+
1306
+
1307
+
1308
+	/**
1309
+	 * admin_notices
1310
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1311
+	 *
1312
+	 * @access public
1313
+	 * @return void
1314
+	 */
1315
+	public function admin_notices_global()
1316
+	{
1317
+		$this->_display_no_javascript_warning();
1318
+		$this->_display_espresso_notices();
1319
+	}
1320
+
1321
+
1322
+
1323
+	public function network_admin_notices_global()
1324
+	{
1325
+		$this->_display_no_javascript_warning();
1326
+		$this->_display_espresso_notices();
1327
+	}
1328
+
1329
+
1330
+
1331
+	/**
1332
+	 * admin_footer_scripts_global
1333
+	 * 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.
1334
+	 *
1335
+	 * @access public
1336
+	 * @return void
1337
+	 */
1338
+	public function admin_footer_scripts_global()
1339
+	{
1340
+		$this->_add_admin_page_ajax_loading_img();
1341
+		$this->_add_admin_page_overlay();
1342
+		//if metaboxes are present we need to add the nonce field
1343
+		if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1344
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1345
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1346
+		}
1347
+	}
1348
+
1349
+
1350
+
1351
+	/**
1352
+	 * admin_footer_global
1353
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1354
+	 *
1355
+	 * @access  public
1356
+	 * @return  void
1357
+	 */
1358
+	public function admin_footer_global()
1359
+	{
1360
+		//dialog container for dialog helper
1361
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1362
+		$d_cont .= '<div class="ee-notices"></div>';
1363
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1364
+		$d_cont .= '</div>';
1365
+		echo $d_cont;
1366
+		//help tour stuff?
1367
+		if (isset($this->_help_tour[$this->_req_action])) {
1368
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1369
+		}
1370
+		//current set timezone for timezone js
1371
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1372
+	}
1373
+
1374
+
1375
+
1376
+	/**
1377
+	 * 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.
1378
+	 * For child classes:
1379
+	 * 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
1380
+	 * 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
1381
+	 * '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(
1382
+	 *    'help_trigger_id' => array(
1383
+	 *        'title' => __('localized title for popup', 'event_espresso'),
1384
+	 *        'content' => __('localized content for popup', 'event_espresso')
1385
+	 *    )
1386
+	 * );
1387
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1388
+	 *
1389
+	 * @access protected
1390
+	 * @return string content
1391
+	 */
1392
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1393
+	{
1394
+		$content = '';
1395
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1396
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1397
+		//loop through the array and setup content
1398
+		foreach ($help_array as $trigger => $help) {
1399
+			//make sure the array is setup properly
1400
+			if ( ! isset($help['title']) || ! isset($help['content'])) {
1401
+				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',
1402
+						'event_espresso'));
1403
+			}
1404
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1405
+			$template_args = array(
1406
+					'help_popup_id'      => $trigger,
1407
+					'help_popup_title'   => $help['title'],
1408
+					'help_popup_content' => $help['content'],
1409
+			);
1410
+			$content .= EEH_Template::display_template($template_path, $template_args, true);
1411
+		}
1412
+		if ($display) {
1413
+			echo $content;
1414
+		} else {
1415
+			return $content;
1416
+		}
1417
+	}
1418
+
1419
+
1420
+
1421
+	/**
1422
+	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1423
+	 *
1424
+	 * @access private
1425
+	 * @return array properly formatted array for help popup content
1426
+	 */
1427
+	private function _get_help_content()
1428
+	{
1429
+		//what is the method we're looking for?
1430
+		$method_name = '_help_popup_content_' . $this->_req_action;
1431
+		//if method doesn't exist let's get out.
1432
+		if ( ! method_exists($this, $method_name)) {
1433
+			return array();
1434
+		}
1435
+		//k we're good to go let's retrieve the help array
1436
+		$help_array = call_user_func(array($this, $method_name));
1437
+		//make sure we've got an array!
1438
+		if ( ! is_array($help_array)) {
1439
+			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'));
1440
+		}
1441
+		return $help_array;
1442
+	}
1443
+
1444
+
1445
+
1446
+	/**
1447
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1448
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1449
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1450
+	 *
1451
+	 * @access protected
1452
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1453
+	 * @param boolean $display    if false then we return the trigger string
1454
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1455
+	 * @return string
1456
+	 */
1457
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1458
+	{
1459
+		if (defined('DOING_AJAX')) {
1460
+			return;
1461
+		}
1462
+		//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
1463
+		$help_array = $this->_get_help_content();
1464
+		$help_content = '';
1465
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1466
+			$help_array[$trigger_id] = array(
1467
+					'title'   => __('Missing Content', 'event_espresso'),
1468
+					'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.)',
1469
+							'event_espresso'),
1470
+			);
1471
+			$help_content = $this->_set_help_popup_content($help_array, false);
1472
+		}
1473
+		//let's setup the trigger
1474
+		$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>';
1475
+		$content = $content . $help_content;
1476
+		if ($display) {
1477
+			echo $content;
1478
+		} else {
1479
+			return $content;
1480
+		}
1481
+	}
1482
+
1483
+
1484
+
1485
+	/**
1486
+	 * _add_global_screen_options
1487
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1488
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1489
+	 *
1490
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1491
+	 *         see also WP_Screen object documents...
1492
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1493
+	 * @abstract
1494
+	 * @access private
1495
+	 * @return void
1496
+	 */
1497
+	private function _add_global_screen_options()
1498
+	{
1499
+	}
1500
+
1501
+
1502
+
1503
+	/**
1504
+	 * _add_global_feature_pointers
1505
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1506
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1507
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1508
+	 *
1509
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1510
+	 * @link   http://eamann.com/tech/wordpress-portland/
1511
+	 * @abstract
1512
+	 * @access protected
1513
+	 * @return void
1514
+	 */
1515
+	private function _add_global_feature_pointers()
1516
+	{
1517
+	}
1518
+
1519
+
1520
+
1521
+	/**
1522
+	 * load_global_scripts_styles
1523
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1524
+	 *
1525
+	 * @return void
1526
+	 */
1527
+	public function load_global_scripts_styles()
1528
+	{
1529
+		/** STYLES **/
1530
+		// add debugging styles
1531
+		if (WP_DEBUG) {
1532
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1533
+		}
1534
+		//register all styles
1535
+		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);
1536
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1537
+		//helpers styles
1538
+		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1539
+		//enqueue global styles
1540
+		wp_enqueue_style('ee-admin-css');
1541
+		/** SCRIPTS **/
1542
+		//register all scripts
1543
+		wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1544
+		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1545
+		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);
1546
+		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);
1547
+		// register jQuery Validate - see /includes/functions/wp_hooks.php
1548
+		add_filter('FHEE_load_jquery_validate', '__return_true');
1549
+		add_filter('FHEE_load_joyride', '__return_true');
1550
+		//script for sorting tables
1551
+		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);
1552
+		//script for parsing uri's
1553
+		wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1554
+		//and parsing associative serialized form elements
1555
+		wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1556
+		//helpers scripts
1557
+		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1558
+		wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1559
+		wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1560
+		wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1561
+		//google charts
1562
+		wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1563
+		//enqueue global scripts
1564
+		//taking care of metaboxes
1565
+		if ((isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) && empty($this->_cpt_route)) {
1566
+			wp_enqueue_script('dashboard');
1567
+		}
1568
+		//enqueue thickbox for ee help popups.  default is to enqueue unless its explicitly set to false since we're assuming all EE pages will have popups
1569
+		if ( ! isset($this->_route_config['has_help_popups']) || (isset($this->_route_config['has_help_popups']) && $this->_route_config['has_help_popups'])) {
1570
+			wp_enqueue_script('ee_admin_js');
1571
+			wp_enqueue_style('ee-admin-css');
1572
+		}
1573
+		//localize script for ajax lazy loading
1574
+		$lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1575
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1576
+		/**
1577
+		 * help tour stuff
1578
+		 */
1579
+		if ( ! empty($this->_help_tour)) {
1580
+			//register the js for kicking things off
1581
+			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1582
+			//setup tours for the js tour object
1583
+			foreach ($this->_help_tour['tours'] as $tour) {
1584
+				$tours[] = array(
1585
+						'id'      => $tour->get_slug(),
1586
+						'options' => $tour->get_options(),
1587
+				);
1588
+			}
1589
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1590
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1591
+		}
1592
+	}
1593
+
1594
+
1595
+
1596
+	/**
1597
+	 *        admin_footer_scripts_eei18n_js_strings
1598
+	 *
1599
+	 * @access        public
1600
+	 * @return        void
1601
+	 */
1602
+	public function admin_footer_scripts_eei18n_js_strings()
1603
+	{
1604
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1605
+		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');
1606
+		EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1607
+		EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1608
+		EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1609
+		EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1610
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1611
+		EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1612
+		EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1613
+		EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1614
+		EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1615
+		EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1616
+		EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1617
+		EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1618
+		EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1619
+		EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1620
+		EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1621
+		EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1622
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1623
+		EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1624
+		EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1625
+		EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1626
+		EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1627
+		EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1628
+		EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1629
+		EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1630
+		EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1631
+		EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1632
+		EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1633
+		EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1634
+		EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1635
+		EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1636
+		EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1637
+		EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1638
+		EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1639
+		EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1640
+		EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1641
+		EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1642
+		EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1643
+		EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1644
+		//setting on espresso_core instead of ee_admin_js because espresso_core is enqueued by the maintenance
1645
+		//admin page when in maintenance mode and ee_admin_js is not loaded then.  This works everywhere else because
1646
+		//espresso_core is listed as a dependency of ee_admin_js.
1647
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
1648
+	}
1649
+
1650
+
1651
+
1652
+	/**
1653
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1654
+	 *
1655
+	 * @access        public
1656
+	 * @return        void
1657
+	 */
1658
+	public function add_xdebug_style()
1659
+	{
1660
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1661
+	}
1662
+
1663
+
1664
+	/************************/
1665
+	/** LIST TABLE METHODS **/
1666
+	/************************/
1667
+	/**
1668
+	 * this sets up the list table if the current view requires it.
1669
+	 *
1670
+	 * @access protected
1671
+	 * @return void
1672
+	 */
1673
+	protected function _set_list_table()
1674
+	{
1675
+		//first is this a list_table view?
1676
+		if ( ! isset($this->_route_config['list_table'])) {
1677
+			return;
1678
+		} //not a list_table view so get out.
1679
+		//list table functions are per view specific (because some admin pages might have more than one listtable!)
1680
+		if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1681
+			//user error msg
1682
+			$error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1683
+			//developer error msg
1684
+			$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'),
1685
+							$this->_req_action, '_set_list_table_views_' . $this->_req_action);
1686
+			throw new EE_Error($error_msg);
1687
+		}
1688
+		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1689
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1690
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1691
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1692
+		$this->_set_list_table_view();
1693
+		$this->_set_list_table_object();
1694
+	}
1695
+
1696
+
1697
+
1698
+	/**
1699
+	 *        set current view for List Table
1700
+	 *
1701
+	 * @access public
1702
+	 * @return array
1703
+	 */
1704
+	protected function _set_list_table_view()
1705
+	{
1706
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1707
+		// looking at active items or dumpster diving ?
1708
+		if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1709
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1710
+		} else {
1711
+			$this->_view = sanitize_key($this->_req_data['status']);
1712
+		}
1713
+	}
1714
+
1715
+
1716
+
1717
+	/**
1718
+	 * _set_list_table_object
1719
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1720
+	 *
1721
+	 * @throws \EE_Error
1722
+	 */
1723
+	protected function _set_list_table_object()
1724
+	{
1725
+		if (isset($this->_route_config['list_table'])) {
1726
+			if ( ! class_exists($this->_route_config['list_table'])) {
1727
+				throw new EE_Error(
1728
+						sprintf(
1729
+								__(
1730
+										'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.',
1731
+										'event_espresso'
1732
+								),
1733
+								$this->_route_config['list_table'],
1734
+								get_class($this)
1735
+						)
1736
+				);
1737
+			}
1738
+			$list_table = $this->_route_config['list_table'];
1739
+			$this->_list_table_object = new $list_table($this);
1740
+		}
1741
+	}
1742
+
1743
+
1744
+
1745
+	/**
1746
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1747
+	 *
1748
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1749
+	 *                                                    urls.  The array should be indexed by the view it is being
1750
+	 *                                                    added to.
1751
+	 * @return array
1752
+	 */
1753
+	public function get_list_table_view_RLs($extra_query_args = array())
1754
+	{
1755
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1756
+		if (empty($this->_views)) {
1757
+			$this->_views = array();
1758
+		}
1759
+		// cycle thru views
1760
+		foreach ($this->_views as $key => $view) {
1761
+			$query_args = array();
1762
+			// check for current view
1763
+			$this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1764
+			$query_args['action'] = $this->_req_action;
1765
+			$query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1766
+			$query_args['status'] = $view['slug'];
1767
+			//merge any other arguments sent in.
1768
+			if (isset($extra_query_args[$view['slug']])) {
1769
+				$query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1770
+			}
1771
+			$this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1772
+		}
1773
+		return $this->_views;
1774
+	}
1775
+
1776
+
1777
+
1778
+	/**
1779
+	 * _entries_per_page_dropdown
1780
+	 * generates a drop down box for selecting the number of visiable rows in an admin page list table
1781
+	 *
1782
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1783
+	 * @access protected
1784
+	 * @param int $max_entries total number of rows in the table
1785
+	 * @return string
1786
+	 */
1787
+	protected function _entries_per_page_dropdown($max_entries = false)
1788
+	{
1789
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1790
+		$values = array(10, 25, 50, 100);
1791
+		$per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1792
+		if ($max_entries) {
1793
+			$values[] = $max_entries;
1794
+			sort($values);
1795
+		}
1796
+		$entries_per_page_dropdown = '
1797 1797
 			<div id="entries-per-page-dv" class="alignleft actions">
1798 1798
 				<label class="hide-if-no-js">
1799 1799
 					Show
1800 1800
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1801
-        foreach ($values as $value) {
1802
-            if ($value < $max_entries) {
1803
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1804
-                $entries_per_page_dropdown .= '
1801
+		foreach ($values as $value) {
1802
+			if ($value < $max_entries) {
1803
+				$selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1804
+				$entries_per_page_dropdown .= '
1805 1805
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1806
-            }
1807
-        }
1808
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1809
-        $entries_per_page_dropdown .= '
1806
+			}
1807
+		}
1808
+		$selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1809
+		$entries_per_page_dropdown .= '
1810 1810
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1811
-        $entries_per_page_dropdown .= '
1811
+		$entries_per_page_dropdown .= '
1812 1812
 					</select>
1813 1813
 					entries
1814 1814
 				</label>
1815 1815
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
1816 1816
 			</div>
1817 1817
 		';
1818
-        return $entries_per_page_dropdown;
1819
-    }
1820
-
1821
-
1822
-
1823
-    /**
1824
-     *        _set_search_attributes
1825
-     *
1826
-     * @access        protected
1827
-     * @return        void
1828
-     */
1829
-    public function _set_search_attributes()
1830
-    {
1831
-        $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1832
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1833
-    }
1834
-
1835
-    /*** END LIST TABLE METHODS **/
1836
-    /*****************************/
1837
-    /**
1838
-     *        _add_registered_metaboxes
1839
-     *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1840
-     *
1841
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1842
-     * @access private
1843
-     * @return void
1844
-     */
1845
-    private function _add_registered_meta_boxes()
1846
-    {
1847
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1848
-        //we only add meta boxes if the page_route calls for it
1849
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1850
-            && is_array(
1851
-                    $this->_route_config['metaboxes']
1852
-            )
1853
-        ) {
1854
-            // this simply loops through the callbacks provided
1855
-            // and checks if there is a corresponding callback registered by the child
1856
-            // if there is then we go ahead and process the metabox loader.
1857
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1858
-                // first check for Closures
1859
-                if ($metabox_callback instanceof Closure) {
1860
-                    $result = $metabox_callback();
1861
-                } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1862
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1863
-                } else {
1864
-                    $result = call_user_func(array($this, &$metabox_callback));
1865
-                }
1866
-                if ($result === false) {
1867
-                    // user error msg
1868
-                    $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1869
-                    // developer error msg
1870
-                    $error_msg .= '||' . sprintf(
1871
-                                    __(
1872
-                                            '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.',
1873
-                                            'event_espresso'
1874
-                                    ),
1875
-                                    $metabox_callback
1876
-                            );
1877
-                    throw new EE_Error($error_msg);
1878
-                }
1879
-            }
1880
-        }
1881
-    }
1882
-
1883
-
1884
-
1885
-    /**
1886
-     * _add_screen_columns
1887
-     * 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.
1888
-     *
1889
-     * @access private
1890
-     * @return void
1891
-     */
1892
-    private function _add_screen_columns()
1893
-    {
1894
-        if (
1895
-                is_array($this->_route_config)
1896
-                && isset($this->_route_config['columns'])
1897
-                && is_array($this->_route_config['columns'])
1898
-                && count($this->_route_config['columns']) === 2
1899
-        ) {
1900
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1901
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1902
-            $screen_id = $this->_current_screen->id;
1903
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1904
-            $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1905
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1906
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
1907
-            $this->_template_args['screen'] = $this->_current_screen;
1908
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1909
-            //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.
1910
-            $this->_route_config['has_metaboxes'] = true;
1911
-        }
1912
-    }
1913
-
1914
-
1915
-
1916
-    /**********************************/
1917
-    /** GLOBALLY AVAILABLE METABOXES **/
1918
-    /**
1919
-     * 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
1920
-     * loaded on.
1921
-     */
1922
-    private function _espresso_news_post_box()
1923
-    {
1924
-        $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1925
-        add_meta_box('espresso_news_post_box', $news_box_title, array(
1926
-                $this,
1927
-                'espresso_news_post_box',
1928
-        ), $this->_wp_page_slug, 'side');
1929
-    }
1930
-
1931
-
1932
-
1933
-    /**
1934
-     * Code for setting up espresso ratings request metabox.
1935
-     */
1936
-    protected function _espresso_ratings_request()
1937
-    {
1938
-        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1939
-            return '';
1940
-        }
1941
-        $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1942
-        add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1943
-                $this,
1944
-                'espresso_ratings_request',
1945
-        ), $this->_wp_page_slug, 'side');
1946
-    }
1947
-
1948
-
1949
-
1950
-    /**
1951
-     * Code for setting up espresso ratings request metabox content.
1952
-     */
1953
-    public function espresso_ratings_request()
1954
-    {
1955
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1956
-        EEH_Template::display_template($template_path, array());
1957
-    }
1958
-
1959
-
1960
-
1961
-    public static function cached_rss_display($rss_id, $url)
1962
-    {
1963
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1964
-        $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1965
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1966
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1967
-        $post = '</div>' . "\n";
1968
-        $cache_key = 'ee_rss_' . md5($rss_id);
1969
-        if (false != ($output = get_transient($cache_key))) {
1970
-            echo $pre . $output . $post;
1971
-            return true;
1972
-        }
1973
-        if ( ! $doing_ajax) {
1974
-            echo $pre . $loading . $post;
1975
-            return false;
1976
-        }
1977
-        ob_start();
1978
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1979
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1980
-        return true;
1981
-    }
1982
-
1983
-
1984
-
1985
-    public function espresso_news_post_box()
1986
-    {
1987
-        ?>
1818
+		return $entries_per_page_dropdown;
1819
+	}
1820
+
1821
+
1822
+
1823
+	/**
1824
+	 *        _set_search_attributes
1825
+	 *
1826
+	 * @access        protected
1827
+	 * @return        void
1828
+	 */
1829
+	public function _set_search_attributes()
1830
+	{
1831
+		$this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1832
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1833
+	}
1834
+
1835
+	/*** END LIST TABLE METHODS **/
1836
+	/*****************************/
1837
+	/**
1838
+	 *        _add_registered_metaboxes
1839
+	 *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1840
+	 *
1841
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1842
+	 * @access private
1843
+	 * @return void
1844
+	 */
1845
+	private function _add_registered_meta_boxes()
1846
+	{
1847
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1848
+		//we only add meta boxes if the page_route calls for it
1849
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1850
+			&& is_array(
1851
+					$this->_route_config['metaboxes']
1852
+			)
1853
+		) {
1854
+			// this simply loops through the callbacks provided
1855
+			// and checks if there is a corresponding callback registered by the child
1856
+			// if there is then we go ahead and process the metabox loader.
1857
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1858
+				// first check for Closures
1859
+				if ($metabox_callback instanceof Closure) {
1860
+					$result = $metabox_callback();
1861
+				} else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1862
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1863
+				} else {
1864
+					$result = call_user_func(array($this, &$metabox_callback));
1865
+				}
1866
+				if ($result === false) {
1867
+					// user error msg
1868
+					$error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1869
+					// developer error msg
1870
+					$error_msg .= '||' . sprintf(
1871
+									__(
1872
+											'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.',
1873
+											'event_espresso'
1874
+									),
1875
+									$metabox_callback
1876
+							);
1877
+					throw new EE_Error($error_msg);
1878
+				}
1879
+			}
1880
+		}
1881
+	}
1882
+
1883
+
1884
+
1885
+	/**
1886
+	 * _add_screen_columns
1887
+	 * 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.
1888
+	 *
1889
+	 * @access private
1890
+	 * @return void
1891
+	 */
1892
+	private function _add_screen_columns()
1893
+	{
1894
+		if (
1895
+				is_array($this->_route_config)
1896
+				&& isset($this->_route_config['columns'])
1897
+				&& is_array($this->_route_config['columns'])
1898
+				&& count($this->_route_config['columns']) === 2
1899
+		) {
1900
+			add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1901
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1902
+			$screen_id = $this->_current_screen->id;
1903
+			$screen_columns = (int)get_user_option("screen_layout_$screen_id");
1904
+			$total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1905
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1906
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
1907
+			$this->_template_args['screen'] = $this->_current_screen;
1908
+			$this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1909
+			//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.
1910
+			$this->_route_config['has_metaboxes'] = true;
1911
+		}
1912
+	}
1913
+
1914
+
1915
+
1916
+	/**********************************/
1917
+	/** GLOBALLY AVAILABLE METABOXES **/
1918
+	/**
1919
+	 * 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
1920
+	 * loaded on.
1921
+	 */
1922
+	private function _espresso_news_post_box()
1923
+	{
1924
+		$news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1925
+		add_meta_box('espresso_news_post_box', $news_box_title, array(
1926
+				$this,
1927
+				'espresso_news_post_box',
1928
+		), $this->_wp_page_slug, 'side');
1929
+	}
1930
+
1931
+
1932
+
1933
+	/**
1934
+	 * Code for setting up espresso ratings request metabox.
1935
+	 */
1936
+	protected function _espresso_ratings_request()
1937
+	{
1938
+		if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1939
+			return '';
1940
+		}
1941
+		$ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1942
+		add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1943
+				$this,
1944
+				'espresso_ratings_request',
1945
+		), $this->_wp_page_slug, 'side');
1946
+	}
1947
+
1948
+
1949
+
1950
+	/**
1951
+	 * Code for setting up espresso ratings request metabox content.
1952
+	 */
1953
+	public function espresso_ratings_request()
1954
+	{
1955
+		$template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1956
+		EEH_Template::display_template($template_path, array());
1957
+	}
1958
+
1959
+
1960
+
1961
+	public static function cached_rss_display($rss_id, $url)
1962
+	{
1963
+		$loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1964
+		$doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1965
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
1966
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1967
+		$post = '</div>' . "\n";
1968
+		$cache_key = 'ee_rss_' . md5($rss_id);
1969
+		if (false != ($output = get_transient($cache_key))) {
1970
+			echo $pre . $output . $post;
1971
+			return true;
1972
+		}
1973
+		if ( ! $doing_ajax) {
1974
+			echo $pre . $loading . $post;
1975
+			return false;
1976
+		}
1977
+		ob_start();
1978
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1979
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1980
+		return true;
1981
+	}
1982
+
1983
+
1984
+
1985
+	public function espresso_news_post_box()
1986
+	{
1987
+		?>
1988 1988
         <div class="padding">
1989 1989
             <div id="espresso_news_post_box_content" class="infolinks">
1990 1990
                 <?php
1991
-                // Get RSS Feed(s)
1992
-                $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1993
-                $url = urlencode($feed_url);
1994
-                self::cached_rss_display('espresso_news_post_box_content', $url);
1995
-                ?>
1991
+				// Get RSS Feed(s)
1992
+				$feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1993
+				$url = urlencode($feed_url);
1994
+				self::cached_rss_display('espresso_news_post_box_content', $url);
1995
+				?>
1996 1996
             </div>
1997 1997
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
1998 1998
         </div>
1999 1999
         <?php
2000
-    }
2001
-
2002
-
2003
-
2004
-    private function _espresso_links_post_box()
2005
-    {
2006
-        //Hiding until we actually have content to put in here...
2007
-        //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2008
-    }
2009
-
2010
-
2011
-
2012
-    public function espresso_links_post_box()
2013
-    {
2014
-        //Hiding until we actually have content to put in here...
2015
-        //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2016
-        //EEH_Template::display_template( $templatepath );
2017
-    }
2018
-
2019
-
2020
-
2021
-    protected function _espresso_sponsors_post_box()
2022
-    {
2023
-        $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2024
-        if ($show_sponsors) {
2025
-            add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2026
-        }
2027
-    }
2028
-
2029
-
2030
-
2031
-    public function espresso_sponsors_post_box()
2032
-    {
2033
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2034
-        EEH_Template::display_template($templatepath);
2035
-    }
2036
-
2037
-
2038
-
2039
-    private function _publish_post_box()
2040
-    {
2041
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2042
-        //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)
2043
-        if ( ! empty($this->_labels['publishbox'])) {
2044
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2045
-        } else {
2046
-            $box_label = __('Publish', 'event_espresso');
2047
-        }
2048
-        $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2049
-        add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2050
-    }
2051
-
2052
-
2053
-
2054
-    public function editor_overview()
2055
-    {
2056
-        //if we have extra content set let's add it in if not make sure its empty
2057
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2058
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2059
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2060
-    }
2061
-
2062
-
2063
-    /** end of globally available metaboxes section **/
2064
-    /*************************************************/
2065
-    /**
2066
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2067
-     * protected method.
2068
-     *
2069
-     * @see   $this->_set_publish_post_box_vars for param details
2070
-     * @since 4.6.0
2071
-     */
2072
-    public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2073
-    {
2074
-        $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2075
-    }
2076
-
2077
-
2078
-
2079
-    /**
2080
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2081
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2082
-     * save, and save and close buttons to work properly, then you will want to include a
2083
-     * values for the name and id arguments.
2084
-     *
2085
-     * @todo  Add in validation for name/id arguments.
2086
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2087
-     * @param    int     $id                      id attached to the item published
2088
-     * @param    string  $delete                  page route callback for the delete action
2089
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2090
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2091
-     * @throws \EE_Error
2092
-     */
2093
-    protected function _set_publish_post_box_vars(
2094
-            $name = '',
2095
-            $id = 0,
2096
-            $delete = '',
2097
-            $save_close_redirect_URL = '',
2098
-            $both_btns = true
2099
-    ) {
2100
-        // if Save & Close, use a custom redirect URL or default to the main page?
2101
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2102
-        // create the Save & Close and Save buttons
2103
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2104
-        //if we have extra content set let's add it in if not make sure its empty
2105
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2106
-        if ($delete && ! empty($id)) {
2107
-            //make sure we have a default if just true is sent.
2108
-            $delete = ! empty($delete) ? $delete : 'delete';
2109
-            $delete_link_args = array($name => $id);
2110
-            $delete = $this->get_action_link_or_button(
2111
-                    $delete,
2112
-                    $delete,
2113
-                    $delete_link_args,
2114
-                    'submitdelete deletion',
2115
-                    '',
2116
-                    false
2117
-            );
2118
-        }
2119
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2120
-        if ( ! empty($name) && ! empty($id)) {
2121
-            $hidden_field_arr[$name] = array(
2122
-                    'type'  => 'hidden',
2123
-                    'value' => $id,
2124
-            );
2125
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2126
-        } else {
2127
-            $hf = '';
2128
-        }
2129
-        // add hidden field
2130
-        $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2131
-    }
2132
-
2133
-
2134
-
2135
-    /**
2136
-     *        displays an error message to ppl who have javascript disabled
2137
-     *
2138
-     * @access        private
2139
-     * @return        string
2140
-     */
2141
-    private function _display_no_javascript_warning()
2142
-    {
2143
-        ?>
2000
+	}
2001
+
2002
+
2003
+
2004
+	private function _espresso_links_post_box()
2005
+	{
2006
+		//Hiding until we actually have content to put in here...
2007
+		//add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2008
+	}
2009
+
2010
+
2011
+
2012
+	public function espresso_links_post_box()
2013
+	{
2014
+		//Hiding until we actually have content to put in here...
2015
+		//$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2016
+		//EEH_Template::display_template( $templatepath );
2017
+	}
2018
+
2019
+
2020
+
2021
+	protected function _espresso_sponsors_post_box()
2022
+	{
2023
+		$show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2024
+		if ($show_sponsors) {
2025
+			add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2026
+		}
2027
+	}
2028
+
2029
+
2030
+
2031
+	public function espresso_sponsors_post_box()
2032
+	{
2033
+		$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2034
+		EEH_Template::display_template($templatepath);
2035
+	}
2036
+
2037
+
2038
+
2039
+	private function _publish_post_box()
2040
+	{
2041
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2042
+		//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)
2043
+		if ( ! empty($this->_labels['publishbox'])) {
2044
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2045
+		} else {
2046
+			$box_label = __('Publish', 'event_espresso');
2047
+		}
2048
+		$box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2049
+		add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2050
+	}
2051
+
2052
+
2053
+
2054
+	public function editor_overview()
2055
+	{
2056
+		//if we have extra content set let's add it in if not make sure its empty
2057
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2058
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2059
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2060
+	}
2061
+
2062
+
2063
+	/** end of globally available metaboxes section **/
2064
+	/*************************************************/
2065
+	/**
2066
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2067
+	 * protected method.
2068
+	 *
2069
+	 * @see   $this->_set_publish_post_box_vars for param details
2070
+	 * @since 4.6.0
2071
+	 */
2072
+	public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2073
+	{
2074
+		$this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2075
+	}
2076
+
2077
+
2078
+
2079
+	/**
2080
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2081
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2082
+	 * save, and save and close buttons to work properly, then you will want to include a
2083
+	 * values for the name and id arguments.
2084
+	 *
2085
+	 * @todo  Add in validation for name/id arguments.
2086
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2087
+	 * @param    int     $id                      id attached to the item published
2088
+	 * @param    string  $delete                  page route callback for the delete action
2089
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2090
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2091
+	 * @throws \EE_Error
2092
+	 */
2093
+	protected function _set_publish_post_box_vars(
2094
+			$name = '',
2095
+			$id = 0,
2096
+			$delete = '',
2097
+			$save_close_redirect_URL = '',
2098
+			$both_btns = true
2099
+	) {
2100
+		// if Save & Close, use a custom redirect URL or default to the main page?
2101
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2102
+		// create the Save & Close and Save buttons
2103
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2104
+		//if we have extra content set let's add it in if not make sure its empty
2105
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2106
+		if ($delete && ! empty($id)) {
2107
+			//make sure we have a default if just true is sent.
2108
+			$delete = ! empty($delete) ? $delete : 'delete';
2109
+			$delete_link_args = array($name => $id);
2110
+			$delete = $this->get_action_link_or_button(
2111
+					$delete,
2112
+					$delete,
2113
+					$delete_link_args,
2114
+					'submitdelete deletion',
2115
+					'',
2116
+					false
2117
+			);
2118
+		}
2119
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2120
+		if ( ! empty($name) && ! empty($id)) {
2121
+			$hidden_field_arr[$name] = array(
2122
+					'type'  => 'hidden',
2123
+					'value' => $id,
2124
+			);
2125
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2126
+		} else {
2127
+			$hf = '';
2128
+		}
2129
+		// add hidden field
2130
+		$this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2131
+	}
2132
+
2133
+
2134
+
2135
+	/**
2136
+	 *        displays an error message to ppl who have javascript disabled
2137
+	 *
2138
+	 * @access        private
2139
+	 * @return        string
2140
+	 */
2141
+	private function _display_no_javascript_warning()
2142
+	{
2143
+		?>
2144 2144
         <noscript>
2145 2145
             <div id="no-js-message" class="error">
2146 2146
                 <p style="font-size:1.3em;">
@@ -2150,1236 +2150,1236 @@  discard block
 block discarded – undo
2150 2150
             </div>
2151 2151
         </noscript>
2152 2152
         <?php
2153
-    }
2153
+	}
2154 2154
 
2155 2155
 
2156 2156
 
2157
-    /**
2158
-     *        displays espresso success and/or error notices
2159
-     *
2160
-     * @access        private
2161
-     * @return        string
2162
-     */
2163
-    private function _display_espresso_notices()
2164
-    {
2165
-        $notices = $this->_get_transient(true);
2166
-        echo stripslashes($notices);
2167
-    }
2157
+	/**
2158
+	 *        displays espresso success and/or error notices
2159
+	 *
2160
+	 * @access        private
2161
+	 * @return        string
2162
+	 */
2163
+	private function _display_espresso_notices()
2164
+	{
2165
+		$notices = $this->_get_transient(true);
2166
+		echo stripslashes($notices);
2167
+	}
2168 2168
 
2169 2169
 
2170 2170
 
2171
-    /**
2172
-     *        spinny things pacify the masses
2173
-     *
2174
-     * @access private
2175
-     * @return string
2176
-     */
2177
-    protected function _add_admin_page_ajax_loading_img()
2178
-    {
2179
-        ?>
2171
+	/**
2172
+	 *        spinny things pacify the masses
2173
+	 *
2174
+	 * @access private
2175
+	 * @return string
2176
+	 */
2177
+	protected function _add_admin_page_ajax_loading_img()
2178
+	{
2179
+		?>
2180 2180
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2181 2181
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e('loading...', 'event_espresso'); ?></span>
2182 2182
         </div>
2183 2183
         <?php
2184
-    }
2184
+	}
2185 2185
 
2186 2186
 
2187 2187
 
2188
-    /**
2189
-     *        add admin page overlay for modal boxes
2190
-     *
2191
-     * @access private
2192
-     * @return string
2193
-     */
2194
-    protected function _add_admin_page_overlay()
2195
-    {
2196
-        ?>
2188
+	/**
2189
+	 *        add admin page overlay for modal boxes
2190
+	 *
2191
+	 * @access private
2192
+	 * @return string
2193
+	 */
2194
+	protected function _add_admin_page_overlay()
2195
+	{
2196
+		?>
2197 2197
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2198 2198
         <?php
2199
-    }
2200
-
2201
-
2202
-
2203
-    /**
2204
-     * facade for add_meta_box
2205
-     *
2206
-     * @param string  $action        where the metabox get's displayed
2207
-     * @param string  $title         Title of Metabox (output in metabox header)
2208
-     * @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.
2209
-     * @param array   $callback_args an array of args supplied for the metabox
2210
-     * @param string  $column        what metabox column
2211
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2212
-     * @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.
2213
-     */
2214
-    public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2215
-    {
2216
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2217
-        //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.
2218
-        if (empty($callback_args) && $create_func) {
2219
-            $callback_args = array(
2220
-                    'template_path' => $this->_template_path,
2221
-                    'template_args' => $this->_template_args,
2222
-            );
2223
-        }
2224
-        //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)
2225
-        $call_back_func = $create_func ? create_function('$post, $metabox',
2226
-                'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2227
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2228
-    }
2229
-
2230
-
2231
-
2232
-    /**
2233
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2234
-     *
2235
-     * @return [type] [description]
2236
-     */
2237
-    public function display_admin_page_with_metabox_columns()
2238
-    {
2239
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2240
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2241
-        //the final wrapper
2242
-        $this->admin_page_wrapper();
2243
-    }
2244
-
2245
-
2246
-
2247
-    /**
2248
-     *        generates  HTML wrapper for an admin details page
2249
-     *
2250
-     * @access public
2251
-     * @return void
2252
-     */
2253
-    public function display_admin_page_with_sidebar()
2254
-    {
2255
-        $this->_display_admin_page(true);
2256
-    }
2257
-
2258
-
2259
-
2260
-    /**
2261
-     *        generates  HTML wrapper for an admin details page (except no sidebar)
2262
-     *
2263
-     * @access public
2264
-     * @return void
2265
-     */
2266
-    public function display_admin_page_with_no_sidebar()
2267
-    {
2268
-        $this->_display_admin_page();
2269
-    }
2270
-
2271
-
2272
-
2273
-    /**
2274
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2275
-     *
2276
-     * @access public
2277
-     * @return void
2278
-     */
2279
-    public function display_about_admin_page()
2280
-    {
2281
-        $this->_display_admin_page(false, true);
2282
-    }
2283
-
2284
-
2285
-
2286
-    /**
2287
-     * display_admin_page
2288
-     * contains the code for actually displaying an admin page
2289
-     *
2290
-     * @access private
2291
-     * @param  boolean $sidebar true with sidebar, false without
2292
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2293
-     * @return void
2294
-     */
2295
-    private function _display_admin_page($sidebar = false, $about = false)
2296
-    {
2297
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2298
-        //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2299
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2300
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2301
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2302
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2303
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2304
-                ? 'poststuff'
2305
-                : 'espresso-default-admin';
2306
-        $template_path = $sidebar
2307
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2308
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2309
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2310
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2311
-        }
2312
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2313
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2314
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2315
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2316
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2317
-        // the final template wrapper
2318
-        $this->admin_page_wrapper($about);
2319
-    }
2320
-
2321
-
2322
-
2323
-    /**
2324
-     * This is used to display caf preview pages.
2325
-     *
2326
-     * @since 4.3.2
2327
-     * @param string $utm_campaign_source what is the key used for google analytics link
2328
-     * @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.
2329
-     * @return void
2330
-     * @throws \EE_Error
2331
-     */
2332
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2333
-    {
2334
-        //let's generate a default preview action button if there isn't one already present.
2335
-        $this->_labels['buttons']['buy_now'] = __('Upgrade Now', 'event_espresso');
2336
-        $buy_now_url = add_query_arg(
2337
-                array(
2338
-                        'ee_ver'       => 'ee4',
2339
-                        'utm_source'   => 'ee4_plugin_admin',
2340
-                        'utm_medium'   => 'link',
2341
-                        'utm_campaign' => $utm_campaign_source,
2342
-                        'utm_content'  => 'buy_now_button',
2343
-                ),
2344
-                'http://eventespresso.com/pricing/'
2345
-        );
2346
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2347
-                ? $this->get_action_link_or_button(
2348
-                        '',
2349
-                        'buy_now',
2350
-                        array(),
2351
-                        'button-primary button-large',
2352
-                        $buy_now_url,
2353
-                        true
2354
-                )
2355
-                : $this->_template_args['preview_action_button'];
2356
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2357
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2358
-                $template_path,
2359
-                $this->_template_args,
2360
-                true
2361
-        );
2362
-        $this->_display_admin_page($display_sidebar);
2363
-    }
2364
-
2365
-
2366
-
2367
-    /**
2368
-     * display_admin_list_table_page_with_sidebar
2369
-     * generates HTML wrapper for an admin_page with list_table
2370
-     *
2371
-     * @access public
2372
-     * @return void
2373
-     */
2374
-    public function display_admin_list_table_page_with_sidebar()
2375
-    {
2376
-        $this->_display_admin_list_table_page(true);
2377
-    }
2378
-
2379
-
2380
-
2381
-    /**
2382
-     * display_admin_list_table_page_with_no_sidebar
2383
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2384
-     *
2385
-     * @access public
2386
-     * @return void
2387
-     */
2388
-    public function display_admin_list_table_page_with_no_sidebar()
2389
-    {
2390
-        $this->_display_admin_list_table_page();
2391
-    }
2392
-
2393
-
2394
-
2395
-    /**
2396
-     * generates html wrapper for an admin_list_table page
2397
-     *
2398
-     * @access private
2399
-     * @param boolean $sidebar whether to display with sidebar or not.
2400
-     * @return void
2401
-     */
2402
-    private function _display_admin_list_table_page($sidebar = false)
2403
-    {
2404
-        //setup search attributes
2405
-        $this->_set_search_attributes();
2406
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2407
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2408
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2409
-                ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2410
-                : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2411
-        $this->_template_args['list_table'] = $this->_list_table_object;
2412
-        $this->_template_args['current_route'] = $this->_req_action;
2413
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2414
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2415
-        if ( ! empty($ajax_sorting_callback)) {
2416
-            $sortable_list_table_form_fields = wp_nonce_field(
2417
-                    $ajax_sorting_callback . '_nonce',
2418
-                    $ajax_sorting_callback . '_nonce',
2419
-                    false,
2420
-                    false
2421
-            );
2422
-            //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2423
-            //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2424
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2425
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2426
-        } else {
2427
-            $sortable_list_table_form_fields = '';
2428
-        }
2429
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2430
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2431
-        $nonce_ref = $this->_req_action . '_nonce';
2432
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2433
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2434
-        //display message about search results?
2435
-        $this->_template_args['before_list_table'] .= apply_filters(
2436
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2437
-                ! empty($this->_req_data['s'])
2438
-                        ? '<p class="ee-search-results">'
2439
-                            . sprintf(
2440
-                                esc_html__(
2441
-                                        'Displaying search results for the search string: %1$s',
2442
-                                        'event_espresso'
2443
-                                ),
2444
-                                '<strong><em>' . trim( $this->_req_data['s'], '%' ) . '</em></strong>'
2445
-                            )
2446
-                            . '</p>'
2447
-                        : '',
2448
-                $this->page_slug,
2449
-                $this->_req_data,
2450
-                $this->_req_action
2451
-        );
2452
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2453
-                $template_path,
2454
-                $this->_template_args,
2455
-                true
2456
-        );
2457
-        // the final template wrapper
2458
-        if ($sidebar) {
2459
-            $this->display_admin_page_with_sidebar();
2460
-        } else {
2461
-            $this->display_admin_page_with_no_sidebar();
2462
-        }
2463
-    }
2464
-
2465
-
2466
-
2467
-    /**
2468
-     * 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.
2469
-     * $items are expected in an array in the following format:
2470
-     * $legend_items = array(
2471
-     *        'item_id' => array(
2472
-     *            'icon' => 'http://url_to_icon_being_described.png',
2473
-     *            'desc' => __('localized description of item');
2474
-     *        )
2475
-     * );
2476
-     *
2477
-     * @param  array $items see above for format of array
2478
-     * @return string        html string of legend
2479
-     */
2480
-    protected function _display_legend($items)
2481
-    {
2482
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2483
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2484
-        return EEH_Template::display_template($legend_template, $this->_template_args, true);
2485
-    }
2486
-
2487
-
2488
-
2489
-    /**
2490
-     * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2491
-     *
2492
-     * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2493
-     *                             The returned json object is created from an array in the following format:
2494
-     *                             array(
2495
-     *                             'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2496
-     *                             'success' => FALSE, //(default FALSE) - contains any special success message.
2497
-     *                             'notices' => '', // - contains any EE_Error formatted notices
2498
-     *                             'content' => 'string can be html', //this is a string of formatted content (can be html)
2499
-     *                             '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
2500
-     *                             specific template args that might be included in here)
2501
-     *                             )
2502
-     *                             The json object is populated by whatever is set in the $_template_args property.
2503
-     * @return void
2504
-     */
2505
-    protected function _return_json($sticky_notices = false)
2506
-    {
2507
-        //make sure any EE_Error notices have been handled.
2508
-        $this->_process_notices(array(), true, $sticky_notices);
2509
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2510
-        unset($this->_template_args['data']);
2511
-        $json = array(
2512
-                'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2513
-                'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2514
-                'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2515
-                'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2516
-                'notices'   => EE_Error::get_notices(),
2517
-                'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2518
-                'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2519
-                'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2520
-        );
2521
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2522
-        if (null === error_get_last() || ! headers_sent()) {
2523
-            header('Content-Type: application/json; charset=UTF-8');
2524
-        }
2525
-        echo wp_json_encode($json);
2526
-
2527
-        exit();
2528
-    }
2529
-
2530
-
2531
-
2532
-    /**
2533
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2534
-     *
2535
-     * @return void
2536
-     * @throws EE_Error
2537
-     */
2538
-    public function return_json()
2539
-    {
2540
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2541
-            $this->_return_json();
2542
-        } else {
2543
-            throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2544
-        }
2545
-    }
2546
-
2547
-
2548
-
2549
-    /**
2550
-     * 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.
2551
-     *
2552
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2553
-     * @access   public
2554
-     */
2555
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
2556
-    {
2557
-        $this->_hook_obj = $hook_obj;
2558
-    }
2559
-
2560
-
2561
-
2562
-    /**
2563
-     *        generates  HTML wrapper with Tabbed nav for an admin page
2564
-     *
2565
-     * @access public
2566
-     * @param  boolean $about whether to use the special about page wrapper or default.
2567
-     * @return void
2568
-     */
2569
-    public function admin_page_wrapper($about = false)
2570
-    {
2571
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2572
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
2573
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2574
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2575
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2576
-                isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2577
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2578
-                isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2579
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2580
-        // load settings page wrapper template
2581
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2582
-        //about page?
2583
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2584
-        if (defined('DOING_AJAX')) {
2585
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2586
-            $this->_return_json();
2587
-        } else {
2588
-            EEH_Template::display_template($template_path, $this->_template_args);
2589
-        }
2590
-    }
2591
-
2592
-
2593
-
2594
-    /**
2595
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2596
-     *
2597
-     * @return string html
2598
-     */
2599
-    protected function _get_main_nav_tabs()
2600
-    {
2601
-        //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)
2602
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2603
-    }
2604
-
2605
-
2606
-
2607
-    /**
2608
-     *        sort nav tabs
2609
-     *
2610
-     * @access public
2611
-     * @param $a
2612
-     * @param $b
2613
-     * @return int
2614
-     */
2615
-    private function _sort_nav_tabs($a, $b)
2616
-    {
2617
-        if ($a['order'] == $b['order']) {
2618
-            return 0;
2619
-        }
2620
-        return ($a['order'] < $b['order']) ? -1 : 1;
2621
-    }
2622
-
2623
-
2624
-
2625
-    /**
2626
-     *    generates HTML for the forms used on admin pages
2627
-     *
2628
-     * @access protected
2629
-     * @param    array $input_vars - array of input field details
2630
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2631
-     * @return string
2632
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2633
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2634
-     */
2635
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2636
-    {
2637
-        $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2638
-        return $content;
2639
-    }
2640
-
2641
-
2642
-
2643
-    /**
2644
-     * generates the "Save" and "Save & Close" buttons for edit forms
2645
-     *
2646
-     * @access protected
2647
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2648
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2649
-     * @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.
2650
-     * @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).
2651
-     */
2652
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2653
-    {
2654
-        //make sure $text and $actions are in an array
2655
-        $text = (array)$text;
2656
-        $actions = (array)$actions;
2657
-        $referrer_url = empty($referrer) ? '' : $referrer;
2658
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2659
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2660
-        $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2661
-        $default_names = array('save', 'save_and_close');
2662
-        //add in a hidden index for the current page (so save and close redirects properly)
2663
-        $this->_template_args['save_buttons'] = $referrer_url;
2664
-        foreach ($button_text as $key => $button) {
2665
-            $ref = $default_names[$key];
2666
-            $id = $this->_current_view . '_' . $ref;
2667
-            $name = ! empty($actions) ? $actions[$key] : $ref;
2668
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2669
-            if ( ! $both) {
2670
-                break;
2671
-            }
2672
-        }
2673
-    }
2674
-
2675
-
2676
-
2677
-    /**
2678
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2679
-     *
2680
-     * @see   $this->_set_add_edit_form_tags() for details on params
2681
-     * @since 4.6.0
2682
-     * @param string $route
2683
-     * @param array  $additional_hidden_fields
2684
-     */
2685
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2686
-    {
2687
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2688
-    }
2689
-
2690
-
2691
-
2692
-    /**
2693
-     * set form open and close tags on add/edit pages.
2694
-     *
2695
-     * @access protected
2696
-     * @param string $route                    the route you want the form to direct to
2697
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2698
-     * @return void
2699
-     */
2700
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2701
-    {
2702
-        if (empty($route)) {
2703
-            $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2704
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2705
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2706
-        }
2707
-        // open form
2708
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2709
-        // add nonce
2710
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2711
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2712
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2713
-        // add REQUIRED form action
2714
-        $hidden_fields = array(
2715
-                'action' => array('type' => 'hidden', 'value' => $route),
2716
-        );
2717
-        // merge arrays
2718
-        $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2719
-        // generate form fields
2720
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2721
-        // add fields to form
2722
-        foreach ((array)$form_fields as $field_name => $form_field) {
2723
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2724
-        }
2725
-        // close form
2726
-        $this->_template_args['after_admin_page_content'] = '</form>';
2727
-    }
2728
-
2729
-
2730
-
2731
-    /**
2732
-     * Public Wrapper for _redirect_after_action() method since its
2733
-     * discovered it would be useful for external code to have access.
2734
-     *
2735
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
2736
-     * @since 4.5.0
2737
-     */
2738
-    public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2739
-    {
2740
-        $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2741
-    }
2742
-
2743
-
2744
-
2745
-    /**
2746
-     *    _redirect_after_action
2747
-     *
2748
-     * @param int    $success            - whether success was for two or more records, or just one, or none
2749
-     * @param string $what               - what the action was performed on
2750
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
2751
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2752
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2753
-     * @access protected
2754
-     * @return void
2755
-     */
2756
-    protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2757
-    {
2758
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2759
-        //class name for actions/filters.
2760
-        $classname = get_class($this);
2761
-        //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
2762
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2763
-        $notices = EE_Error::get_notices(false);
2764
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
2765
-        if ( ! $override_overwrite || ! empty($notices['errors'])) {
2766
-            EE_Error::overwrite_success();
2767
-        }
2768
-        if ( ! empty($what) && ! empty($action_desc)) {
2769
-            // how many records affected ? more than one record ? or just one ?
2770
-            if ($success > 1 && empty($notices['errors'])) {
2771
-                // set plural msg
2772
-                EE_Error::add_success(
2773
-                        sprintf(
2774
-                                __('The "%s" have been successfully %s.', 'event_espresso'),
2775
-                                $what,
2776
-                                $action_desc
2777
-                        ),
2778
-                        __FILE__, __FUNCTION__, __LINE__
2779
-                );
2780
-            } else if ($success == 1 && empty($notices['errors'])) {
2781
-                // set singular msg
2782
-                EE_Error::add_success(
2783
-                        sprintf(
2784
-                                __('The "%s" has been successfully %s.', 'event_espresso'),
2785
-                                $what,
2786
-                                $action_desc
2787
-                        ),
2788
-                        __FILE__, __FUNCTION__, __LINE__
2789
-                );
2790
-            }
2791
-        }
2792
-        // check that $query_args isn't something crazy
2793
-        if ( ! is_array($query_args)) {
2794
-            $query_args = array();
2795
-        }
2796
-        /**
2797
-         * Allow injecting actions before the query_args are modified for possible different
2798
-         * redirections on save and close actions
2799
-         *
2800
-         * @since 4.2.0
2801
-         * @param array $query_args       The original query_args array coming into the
2802
-         *                                method.
2803
-         */
2804
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2805
-        //calculate where we're going (if we have a "save and close" button pushed)
2806
-        if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2807
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2808
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2809
-            // regenerate query args array from referrer URL
2810
-            parse_str($parsed_url['query'], $query_args);
2811
-            // correct page and action will be in the query args now
2812
-            $redirect_url = admin_url('admin.php');
2813
-        }
2814
-        //merge any default query_args set in _default_route_query_args property
2815
-        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2816
-            $args_to_merge = array();
2817
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
2818
-                //is there a wp_referer array in our _default_route_query_args property?
2819
-                if ($query_param == 'wp_referer') {
2820
-                    $query_value = (array)$query_value;
2821
-                    foreach ($query_value as $reference => $value) {
2822
-                        if (strpos($reference, 'nonce') !== false) {
2823
-                            continue;
2824
-                        }
2825
-                        //finally we will override any arguments in the referer with
2826
-                        //what might be set on the _default_route_query_args array.
2827
-                        if (isset($this->_default_route_query_args[$reference])) {
2828
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2829
-                        } else {
2830
-                            $args_to_merge[$reference] = urlencode($value);
2831
-                        }
2832
-                    }
2833
-                    continue;
2834
-                }
2835
-                $args_to_merge[$query_param] = $query_value;
2836
-            }
2837
-            //now let's merge these arguments but override with what was specifically sent in to the
2838
-            //redirect.
2839
-            $query_args = array_merge($args_to_merge, $query_args);
2840
-        }
2841
-        $this->_process_notices($query_args);
2842
-        // generate redirect url
2843
-        // if redirecting to anything other than the main page, add a nonce
2844
-        if (isset($query_args['action'])) {
2845
-            // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2846
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2847
-        }
2848
-        //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).
2849
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2850
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2851
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2852
-        if (defined('DOING_AJAX')) {
2853
-            $default_data = array(
2854
-                    'close'        => true,
2855
-                    'redirect_url' => $redirect_url,
2856
-                    'where'        => 'main',
2857
-                    'what'         => 'append',
2858
-            );
2859
-            $this->_template_args['success'] = $success;
2860
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2861
-            $this->_return_json();
2862
-        }
2863
-        wp_safe_redirect($redirect_url);
2864
-        exit();
2865
-    }
2866
-
2867
-
2868
-
2869
-    /**
2870
-     * process any notices before redirecting (or returning ajax request)
2871
-     * This method sets the $this->_template_args['notices'] attribute;
2872
-     *
2873
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
2874
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2875
-     * @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.
2876
-     * @return void
2877
-     */
2878
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2879
-    {
2880
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
2881
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2882
-            $notices = EE_Error::get_notices(false);
2883
-            if (empty($this->_template_args['success'])) {
2884
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2885
-            }
2886
-            if (empty($this->_template_args['errors'])) {
2887
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2888
-            }
2889
-            if (empty($this->_template_args['attention'])) {
2890
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2891
-            }
2892
-        }
2893
-        $this->_template_args['notices'] = EE_Error::get_notices();
2894
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2895
-        if ( ! defined('DOING_AJAX') || $sticky_notices) {
2896
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
2897
-            $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2898
-        }
2899
-    }
2900
-
2901
-
2902
-
2903
-    /**
2904
-     * get_action_link_or_button
2905
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
2906
-     *
2907
-     * @param string $action        use this to indicate which action the url is generated with.
2908
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2909
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2910
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2911
-     * @param string $base_url      If this is not provided
2912
-     *                              the _admin_base_url will be used as the default for the button base_url.
2913
-     *                              Otherwise this value will be used.
2914
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2915
-     * @return string
2916
-     * @throws \EE_Error
2917
-     */
2918
-    public function get_action_link_or_button(
2919
-            $action,
2920
-            $type = 'add',
2921
-            $extra_request = array(),
2922
-            $class = 'button-primary',
2923
-            $base_url = '',
2924
-            $exclude_nonce = false
2925
-    ) {
2926
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2927
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2928
-            throw new EE_Error(
2929
-                    sprintf(
2930
-                            __(
2931
-                                    'There is no page route for given action for the button.  This action was given: %s',
2932
-                                    'event_espresso'
2933
-                            ),
2934
-                            $action
2935
-                    )
2936
-            );
2937
-        }
2938
-        if ( ! isset($this->_labels['buttons'][$type])) {
2939
-            throw new EE_Error(
2940
-                    sprintf(
2941
-                            __(
2942
-                                    'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2943
-                                    'event_espresso'
2944
-                            ),
2945
-                            $type
2946
-                    )
2947
-            );
2948
-        }
2949
-        //finally check user access for this button.
2950
-        $has_access = $this->check_user_access($action, true);
2951
-        if ( ! $has_access) {
2952
-            return '';
2953
-        }
2954
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2955
-        $query_args = array(
2956
-                'action' => $action,
2957
-        );
2958
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2959
-        if ( ! empty($extra_request)) {
2960
-            $query_args = array_merge($extra_request, $query_args);
2961
-        }
2962
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2963
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2964
-    }
2965
-
2966
-
2967
-
2968
-    /**
2969
-     * _per_page_screen_option
2970
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
2971
-     *
2972
-     * @return void
2973
-     */
2974
-    protected function _per_page_screen_option()
2975
-    {
2976
-        $option = 'per_page';
2977
-        $args = array(
2978
-                'label'   => $this->_admin_page_title,
2979
-                'default' => 10,
2980
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
2981
-        );
2982
-        //ONLY add the screen option if the user has access to it.
2983
-        if ($this->check_user_access($this->_current_view, true)) {
2984
-            add_screen_option($option, $args);
2985
-        }
2986
-    }
2987
-
2988
-
2989
-
2990
-    /**
2991
-     * set_per_page_screen_option
2992
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
2993
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
2994
-     *
2995
-     * @access private
2996
-     * @return void
2997
-     */
2998
-    private function _set_per_page_screen_options()
2999
-    {
3000
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3001
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3002
-            if ( ! $user = wp_get_current_user()) {
3003
-                return;
3004
-            }
3005
-            $option = $_POST['wp_screen_options']['option'];
3006
-            $value = $_POST['wp_screen_options']['value'];
3007
-            if ($option != sanitize_key($option)) {
3008
-                return;
3009
-            }
3010
-            $map_option = $option;
3011
-            $option = str_replace('-', '_', $option);
3012
-            switch ($map_option) {
3013
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3014
-                    $value = (int)$value;
3015
-                    if ($value < 1 || $value > 999) {
3016
-                        return;
3017
-                    }
3018
-                    break;
3019
-                default:
3020
-                    $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3021
-                    if (false === $value) {
3022
-                        return;
3023
-                    }
3024
-                    break;
3025
-            }
3026
-            update_user_meta($user->ID, $option, $value);
3027
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3028
-            exit;
3029
-        }
3030
-    }
3031
-
3032
-
3033
-
3034
-    /**
3035
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3036
-     *
3037
-     * @param array $data array that will be assigned to template args.
3038
-     */
3039
-    public function set_template_args($data)
3040
-    {
3041
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3042
-    }
3043
-
3044
-
3045
-
3046
-    /**
3047
-     * This makes available the WP transient system for temporarily moving data between routes
3048
-     *
3049
-     * @access protected
3050
-     * @param string $route             the route that should receive the transient
3051
-     * @param array  $data              the data that gets sent
3052
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3053
-     * @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.
3054
-     * @return void
3055
-     */
3056
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3057
-    {
3058
-        $user_id = get_current_user_id();
3059
-        if ( ! $skip_route_verify) {
3060
-            $this->_verify_route($route);
3061
-        }
3062
-        //now let's set the string for what kind of transient we're setting
3063
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3064
-        $data = $notices ? array('notices' => $data) : $data;
3065
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3066
-        $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3067
-        if ($existing) {
3068
-            $data = array_merge((array)$data, (array)$existing);
3069
-        }
3070
-        if (is_multisite() && is_network_admin()) {
3071
-            set_site_transient($transient, $data, 8);
3072
-        } else {
3073
-            set_transient($transient, $data, 8);
3074
-        }
3075
-    }
3076
-
3077
-
3078
-
3079
-    /**
3080
-     * this retrieves the temporary transient that has been set for moving data between routes.
3081
-     *
3082
-     * @param bool $notices true we get notices transient. False we just return normal route transient
3083
-     * @return mixed data
3084
-     */
3085
-    protected function _get_transient($notices = false, $route = false)
3086
-    {
3087
-        $user_id = get_current_user_id();
3088
-        $route = ! $route ? $this->_req_action : $route;
3089
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3090
-        $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3091
-        //delete transient after retrieval (just in case it hasn't expired);
3092
-        if (is_multisite() && is_network_admin()) {
3093
-            delete_site_transient($transient);
3094
-        } else {
3095
-            delete_transient($transient);
3096
-        }
3097
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3098
-    }
3099
-
3100
-
3101
-
3102
-    /**
3103
-     * 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.
3104
-     * 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.)
3105
-     *
3106
-     * @return void
3107
-     */
3108
-    protected function _transient_garbage_collection()
3109
-    {
3110
-        global $wpdb;
3111
-        //retrieve all existing transients
3112
-        $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3113
-        if ($results = $wpdb->get_results($query)) {
3114
-            foreach ($results as $result) {
3115
-                $transient = str_replace('_transient_', '', $result->option_name);
3116
-                get_transient($transient);
3117
-                if (is_multisite() && is_network_admin()) {
3118
-                    get_site_transient($transient);
3119
-                }
3120
-            }
3121
-        }
3122
-    }
3123
-
3124
-
3125
-
3126
-    /**
3127
-     * get_view
3128
-     *
3129
-     * @access public
3130
-     * @return string content of _view property
3131
-     */
3132
-    public function get_view()
3133
-    {
3134
-        return $this->_view;
3135
-    }
3136
-
3137
-
3138
-
3139
-    /**
3140
-     * getter for the protected $_views property
3141
-     *
3142
-     * @return array
3143
-     */
3144
-    public function get_views()
3145
-    {
3146
-        return $this->_views;
3147
-    }
3148
-
3149
-
3150
-
3151
-    /**
3152
-     * get_current_page
3153
-     *
3154
-     * @access public
3155
-     * @return string _current_page property value
3156
-     */
3157
-    public function get_current_page()
3158
-    {
3159
-        return $this->_current_page;
3160
-    }
3161
-
3162
-
3163
-
3164
-    /**
3165
-     * get_current_view
3166
-     *
3167
-     * @access public
3168
-     * @return string _current_view property value
3169
-     */
3170
-    public function get_current_view()
3171
-    {
3172
-        return $this->_current_view;
3173
-    }
3174
-
3175
-
3176
-
3177
-    /**
3178
-     * get_current_screen
3179
-     *
3180
-     * @access public
3181
-     * @return object The current WP_Screen object
3182
-     */
3183
-    public function get_current_screen()
3184
-    {
3185
-        return $this->_current_screen;
3186
-    }
3187
-
3188
-
3189
-
3190
-    /**
3191
-     * get_current_page_view_url
3192
-     *
3193
-     * @access public
3194
-     * @return string This returns the url for the current_page_view.
3195
-     */
3196
-    public function get_current_page_view_url()
3197
-    {
3198
-        return $this->_current_page_view_url;
3199
-    }
3200
-
3201
-
3202
-
3203
-    /**
3204
-     * just returns the _req_data property
3205
-     *
3206
-     * @return array
3207
-     */
3208
-    public function get_request_data()
3209
-    {
3210
-        return $this->_req_data;
3211
-    }
3212
-
3213
-
3214
-
3215
-    /**
3216
-     * returns the _req_data protected property
3217
-     *
3218
-     * @return string
3219
-     */
3220
-    public function get_req_action()
3221
-    {
3222
-        return $this->_req_action;
3223
-    }
3224
-
3225
-
3226
-
3227
-    /**
3228
-     * @return bool  value of $_is_caf property
3229
-     */
3230
-    public function is_caf()
3231
-    {
3232
-        return $this->_is_caf;
3233
-    }
3234
-
3235
-
3236
-
3237
-    /**
3238
-     * @return mixed
3239
-     */
3240
-    public function default_espresso_metaboxes()
3241
-    {
3242
-        return $this->_default_espresso_metaboxes;
3243
-    }
3244
-
3245
-
3246
-
3247
-    /**
3248
-     * @return mixed
3249
-     */
3250
-    public function admin_base_url()
3251
-    {
3252
-        return $this->_admin_base_url;
3253
-    }
3254
-
3255
-
3256
-
3257
-    /**
3258
-     * @return mixed
3259
-     */
3260
-    public function wp_page_slug()
3261
-    {
3262
-        return $this->_wp_page_slug;
3263
-    }
3264
-
3265
-
3266
-
3267
-    /**
3268
-     * updates  espresso configuration settings
3269
-     *
3270
-     * @access    protected
3271
-     * @param string                   $tab
3272
-     * @param EE_Config_Base|EE_Config $config
3273
-     * @param string                   $file file where error occurred
3274
-     * @param string                   $func function  where error occurred
3275
-     * @param string                   $line line no where error occurred
3276
-     * @return boolean
3277
-     */
3278
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3279
-    {
3280
-        //remove any options that are NOT going to be saved with the config settings.
3281
-        if (isset($config->core->ee_ueip_optin)) {
3282
-            $config->core->ee_ueip_has_notified = true;
3283
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3284
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3285
-            update_option('ee_ueip_has_notified', true);
3286
-        }
3287
-        // and save it (note we're also doing the network save here)
3288
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3289
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3290
-        if ($config_saved && $net_saved) {
3291
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3292
-            return true;
3293
-        } else {
3294
-            EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3295
-            return false;
3296
-        }
3297
-    }
3298
-
3299
-
3300
-
3301
-    /**
3302
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3303
-     *
3304
-     * @return array
3305
-     */
3306
-    public function get_yes_no_values()
3307
-    {
3308
-        return $this->_yes_no_values;
3309
-    }
3310
-
3311
-
3312
-
3313
-    protected function _get_dir()
3314
-    {
3315
-        $reflector = new ReflectionClass(get_class($this));
3316
-        return dirname($reflector->getFileName());
3317
-    }
3318
-
3319
-
3320
-
3321
-    /**
3322
-     * A helper for getting a "next link".
3323
-     *
3324
-     * @param string $url   The url to link to
3325
-     * @param string $class The class to use.
3326
-     * @return string
3327
-     */
3328
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3329
-    {
3330
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3331
-    }
3332
-
3333
-
3334
-
3335
-    /**
3336
-     * A helper for getting a "previous link".
3337
-     *
3338
-     * @param string $url   The url to link to
3339
-     * @param string $class The class to use.
3340
-     * @return string
3341
-     */
3342
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3343
-    {
3344
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3345
-    }
3346
-
3347
-
3348
-
3349
-
3350
-
3351
-
3352
-
3353
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3354
-    /**
3355
-     * 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
3356
-     * array.
3357
-     *
3358
-     * @return bool success/fail
3359
-     */
3360
-    protected function _process_resend_registration()
3361
-    {
3362
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3363
-        do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3364
-        return $this->_template_args['success'];
3365
-    }
3366
-
3367
-
3368
-
3369
-    /**
3370
-     * This automatically processes any payment message notifications when manual payment has been applied.
3371
-     *
3372
-     * @access protected
3373
-     * @param \EE_Payment $payment
3374
-     * @return bool success/fail
3375
-     */
3376
-    protected function _process_payment_notification(EE_Payment $payment)
3377
-    {
3378
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3379
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3380
-        $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3381
-        return $this->_template_args['success'];
3382
-    }
2199
+	}
2200
+
2201
+
2202
+
2203
+	/**
2204
+	 * facade for add_meta_box
2205
+	 *
2206
+	 * @param string  $action        where the metabox get's displayed
2207
+	 * @param string  $title         Title of Metabox (output in metabox header)
2208
+	 * @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.
2209
+	 * @param array   $callback_args an array of args supplied for the metabox
2210
+	 * @param string  $column        what metabox column
2211
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2212
+	 * @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.
2213
+	 */
2214
+	public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2215
+	{
2216
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2217
+		//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.
2218
+		if (empty($callback_args) && $create_func) {
2219
+			$callback_args = array(
2220
+					'template_path' => $this->_template_path,
2221
+					'template_args' => $this->_template_args,
2222
+			);
2223
+		}
2224
+		//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)
2225
+		$call_back_func = $create_func ? create_function('$post, $metabox',
2226
+				'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2227
+		add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2228
+	}
2229
+
2230
+
2231
+
2232
+	/**
2233
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2234
+	 *
2235
+	 * @return [type] [description]
2236
+	 */
2237
+	public function display_admin_page_with_metabox_columns()
2238
+	{
2239
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2240
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2241
+		//the final wrapper
2242
+		$this->admin_page_wrapper();
2243
+	}
2244
+
2245
+
2246
+
2247
+	/**
2248
+	 *        generates  HTML wrapper for an admin details page
2249
+	 *
2250
+	 * @access public
2251
+	 * @return void
2252
+	 */
2253
+	public function display_admin_page_with_sidebar()
2254
+	{
2255
+		$this->_display_admin_page(true);
2256
+	}
2257
+
2258
+
2259
+
2260
+	/**
2261
+	 *        generates  HTML wrapper for an admin details page (except no sidebar)
2262
+	 *
2263
+	 * @access public
2264
+	 * @return void
2265
+	 */
2266
+	public function display_admin_page_with_no_sidebar()
2267
+	{
2268
+		$this->_display_admin_page();
2269
+	}
2270
+
2271
+
2272
+
2273
+	/**
2274
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2275
+	 *
2276
+	 * @access public
2277
+	 * @return void
2278
+	 */
2279
+	public function display_about_admin_page()
2280
+	{
2281
+		$this->_display_admin_page(false, true);
2282
+	}
2283
+
2284
+
2285
+
2286
+	/**
2287
+	 * display_admin_page
2288
+	 * contains the code for actually displaying an admin page
2289
+	 *
2290
+	 * @access private
2291
+	 * @param  boolean $sidebar true with sidebar, false without
2292
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2293
+	 * @return void
2294
+	 */
2295
+	private function _display_admin_page($sidebar = false, $about = false)
2296
+	{
2297
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2298
+		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2299
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2300
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2301
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2302
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2303
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2304
+				? 'poststuff'
2305
+				: 'espresso-default-admin';
2306
+		$template_path = $sidebar
2307
+				? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2308
+				: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2309
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2310
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2311
+		}
2312
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2313
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2314
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2315
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2316
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2317
+		// the final template wrapper
2318
+		$this->admin_page_wrapper($about);
2319
+	}
2320
+
2321
+
2322
+
2323
+	/**
2324
+	 * This is used to display caf preview pages.
2325
+	 *
2326
+	 * @since 4.3.2
2327
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2328
+	 * @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.
2329
+	 * @return void
2330
+	 * @throws \EE_Error
2331
+	 */
2332
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2333
+	{
2334
+		//let's generate a default preview action button if there isn't one already present.
2335
+		$this->_labels['buttons']['buy_now'] = __('Upgrade Now', 'event_espresso');
2336
+		$buy_now_url = add_query_arg(
2337
+				array(
2338
+						'ee_ver'       => 'ee4',
2339
+						'utm_source'   => 'ee4_plugin_admin',
2340
+						'utm_medium'   => 'link',
2341
+						'utm_campaign' => $utm_campaign_source,
2342
+						'utm_content'  => 'buy_now_button',
2343
+				),
2344
+				'http://eventespresso.com/pricing/'
2345
+		);
2346
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2347
+				? $this->get_action_link_or_button(
2348
+						'',
2349
+						'buy_now',
2350
+						array(),
2351
+						'button-primary button-large',
2352
+						$buy_now_url,
2353
+						true
2354
+				)
2355
+				: $this->_template_args['preview_action_button'];
2356
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2357
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2358
+				$template_path,
2359
+				$this->_template_args,
2360
+				true
2361
+		);
2362
+		$this->_display_admin_page($display_sidebar);
2363
+	}
2364
+
2365
+
2366
+
2367
+	/**
2368
+	 * display_admin_list_table_page_with_sidebar
2369
+	 * generates HTML wrapper for an admin_page with list_table
2370
+	 *
2371
+	 * @access public
2372
+	 * @return void
2373
+	 */
2374
+	public function display_admin_list_table_page_with_sidebar()
2375
+	{
2376
+		$this->_display_admin_list_table_page(true);
2377
+	}
2378
+
2379
+
2380
+
2381
+	/**
2382
+	 * display_admin_list_table_page_with_no_sidebar
2383
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2384
+	 *
2385
+	 * @access public
2386
+	 * @return void
2387
+	 */
2388
+	public function display_admin_list_table_page_with_no_sidebar()
2389
+	{
2390
+		$this->_display_admin_list_table_page();
2391
+	}
2392
+
2393
+
2394
+
2395
+	/**
2396
+	 * generates html wrapper for an admin_list_table page
2397
+	 *
2398
+	 * @access private
2399
+	 * @param boolean $sidebar whether to display with sidebar or not.
2400
+	 * @return void
2401
+	 */
2402
+	private function _display_admin_list_table_page($sidebar = false)
2403
+	{
2404
+		//setup search attributes
2405
+		$this->_set_search_attributes();
2406
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2407
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2408
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2409
+				? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2410
+				: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2411
+		$this->_template_args['list_table'] = $this->_list_table_object;
2412
+		$this->_template_args['current_route'] = $this->_req_action;
2413
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2414
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2415
+		if ( ! empty($ajax_sorting_callback)) {
2416
+			$sortable_list_table_form_fields = wp_nonce_field(
2417
+					$ajax_sorting_callback . '_nonce',
2418
+					$ajax_sorting_callback . '_nonce',
2419
+					false,
2420
+					false
2421
+			);
2422
+			//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2423
+			//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2424
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2425
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2426
+		} else {
2427
+			$sortable_list_table_form_fields = '';
2428
+		}
2429
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2430
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2431
+		$nonce_ref = $this->_req_action . '_nonce';
2432
+		$hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2433
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2434
+		//display message about search results?
2435
+		$this->_template_args['before_list_table'] .= apply_filters(
2436
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2437
+				! empty($this->_req_data['s'])
2438
+						? '<p class="ee-search-results">'
2439
+							. sprintf(
2440
+								esc_html__(
2441
+										'Displaying search results for the search string: %1$s',
2442
+										'event_espresso'
2443
+								),
2444
+								'<strong><em>' . trim( $this->_req_data['s'], '%' ) . '</em></strong>'
2445
+							)
2446
+							. '</p>'
2447
+						: '',
2448
+				$this->page_slug,
2449
+				$this->_req_data,
2450
+				$this->_req_action
2451
+		);
2452
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2453
+				$template_path,
2454
+				$this->_template_args,
2455
+				true
2456
+		);
2457
+		// the final template wrapper
2458
+		if ($sidebar) {
2459
+			$this->display_admin_page_with_sidebar();
2460
+		} else {
2461
+			$this->display_admin_page_with_no_sidebar();
2462
+		}
2463
+	}
2464
+
2465
+
2466
+
2467
+	/**
2468
+	 * 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.
2469
+	 * $items are expected in an array in the following format:
2470
+	 * $legend_items = array(
2471
+	 *        'item_id' => array(
2472
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2473
+	 *            'desc' => __('localized description of item');
2474
+	 *        )
2475
+	 * );
2476
+	 *
2477
+	 * @param  array $items see above for format of array
2478
+	 * @return string        html string of legend
2479
+	 */
2480
+	protected function _display_legend($items)
2481
+	{
2482
+		$this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2483
+		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2484
+		return EEH_Template::display_template($legend_template, $this->_template_args, true);
2485
+	}
2486
+
2487
+
2488
+
2489
+	/**
2490
+	 * this is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2491
+	 *
2492
+	 * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2493
+	 *                             The returned json object is created from an array in the following format:
2494
+	 *                             array(
2495
+	 *                             'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2496
+	 *                             'success' => FALSE, //(default FALSE) - contains any special success message.
2497
+	 *                             'notices' => '', // - contains any EE_Error formatted notices
2498
+	 *                             'content' => 'string can be html', //this is a string of formatted content (can be html)
2499
+	 *                             '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
2500
+	 *                             specific template args that might be included in here)
2501
+	 *                             )
2502
+	 *                             The json object is populated by whatever is set in the $_template_args property.
2503
+	 * @return void
2504
+	 */
2505
+	protected function _return_json($sticky_notices = false)
2506
+	{
2507
+		//make sure any EE_Error notices have been handled.
2508
+		$this->_process_notices(array(), true, $sticky_notices);
2509
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2510
+		unset($this->_template_args['data']);
2511
+		$json = array(
2512
+				'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2513
+				'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2514
+				'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2515
+				'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2516
+				'notices'   => EE_Error::get_notices(),
2517
+				'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2518
+				'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2519
+				'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2520
+		);
2521
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2522
+		if (null === error_get_last() || ! headers_sent()) {
2523
+			header('Content-Type: application/json; charset=UTF-8');
2524
+		}
2525
+		echo wp_json_encode($json);
2526
+
2527
+		exit();
2528
+	}
2529
+
2530
+
2531
+
2532
+	/**
2533
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2534
+	 *
2535
+	 * @return void
2536
+	 * @throws EE_Error
2537
+	 */
2538
+	public function return_json()
2539
+	{
2540
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2541
+			$this->_return_json();
2542
+		} else {
2543
+			throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2544
+		}
2545
+	}
2546
+
2547
+
2548
+
2549
+	/**
2550
+	 * 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.
2551
+	 *
2552
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2553
+	 * @access   public
2554
+	 */
2555
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
2556
+	{
2557
+		$this->_hook_obj = $hook_obj;
2558
+	}
2559
+
2560
+
2561
+
2562
+	/**
2563
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
2564
+	 *
2565
+	 * @access public
2566
+	 * @param  boolean $about whether to use the special about page wrapper or default.
2567
+	 * @return void
2568
+	 */
2569
+	public function admin_page_wrapper($about = false)
2570
+	{
2571
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2572
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
2573
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2574
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2575
+		$this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2576
+				isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2577
+		$this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2578
+				isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2579
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2580
+		// load settings page wrapper template
2581
+		$template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2582
+		//about page?
2583
+		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2584
+		if (defined('DOING_AJAX')) {
2585
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2586
+			$this->_return_json();
2587
+		} else {
2588
+			EEH_Template::display_template($template_path, $this->_template_args);
2589
+		}
2590
+	}
2591
+
2592
+
2593
+
2594
+	/**
2595
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2596
+	 *
2597
+	 * @return string html
2598
+	 */
2599
+	protected function _get_main_nav_tabs()
2600
+	{
2601
+		//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)
2602
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2603
+	}
2604
+
2605
+
2606
+
2607
+	/**
2608
+	 *        sort nav tabs
2609
+	 *
2610
+	 * @access public
2611
+	 * @param $a
2612
+	 * @param $b
2613
+	 * @return int
2614
+	 */
2615
+	private function _sort_nav_tabs($a, $b)
2616
+	{
2617
+		if ($a['order'] == $b['order']) {
2618
+			return 0;
2619
+		}
2620
+		return ($a['order'] < $b['order']) ? -1 : 1;
2621
+	}
2622
+
2623
+
2624
+
2625
+	/**
2626
+	 *    generates HTML for the forms used on admin pages
2627
+	 *
2628
+	 * @access protected
2629
+	 * @param    array $input_vars - array of input field details
2630
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2631
+	 * @return string
2632
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2633
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2634
+	 */
2635
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2636
+	{
2637
+		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2638
+		return $content;
2639
+	}
2640
+
2641
+
2642
+
2643
+	/**
2644
+	 * generates the "Save" and "Save & Close" buttons for edit forms
2645
+	 *
2646
+	 * @access protected
2647
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2648
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2649
+	 * @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.
2650
+	 * @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).
2651
+	 */
2652
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2653
+	{
2654
+		//make sure $text and $actions are in an array
2655
+		$text = (array)$text;
2656
+		$actions = (array)$actions;
2657
+		$referrer_url = empty($referrer) ? '' : $referrer;
2658
+		$referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2659
+				: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2660
+		$button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2661
+		$default_names = array('save', 'save_and_close');
2662
+		//add in a hidden index for the current page (so save and close redirects properly)
2663
+		$this->_template_args['save_buttons'] = $referrer_url;
2664
+		foreach ($button_text as $key => $button) {
2665
+			$ref = $default_names[$key];
2666
+			$id = $this->_current_view . '_' . $ref;
2667
+			$name = ! empty($actions) ? $actions[$key] : $ref;
2668
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2669
+			if ( ! $both) {
2670
+				break;
2671
+			}
2672
+		}
2673
+	}
2674
+
2675
+
2676
+
2677
+	/**
2678
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2679
+	 *
2680
+	 * @see   $this->_set_add_edit_form_tags() for details on params
2681
+	 * @since 4.6.0
2682
+	 * @param string $route
2683
+	 * @param array  $additional_hidden_fields
2684
+	 */
2685
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2686
+	{
2687
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2688
+	}
2689
+
2690
+
2691
+
2692
+	/**
2693
+	 * set form open and close tags on add/edit pages.
2694
+	 *
2695
+	 * @access protected
2696
+	 * @param string $route                    the route you want the form to direct to
2697
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2698
+	 * @return void
2699
+	 */
2700
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2701
+	{
2702
+		if (empty($route)) {
2703
+			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2704
+			$dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2705
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2706
+		}
2707
+		// open form
2708
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2709
+		// add nonce
2710
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2711
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2712
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2713
+		// add REQUIRED form action
2714
+		$hidden_fields = array(
2715
+				'action' => array('type' => 'hidden', 'value' => $route),
2716
+		);
2717
+		// merge arrays
2718
+		$hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2719
+		// generate form fields
2720
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2721
+		// add fields to form
2722
+		foreach ((array)$form_fields as $field_name => $form_field) {
2723
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2724
+		}
2725
+		// close form
2726
+		$this->_template_args['after_admin_page_content'] = '</form>';
2727
+	}
2728
+
2729
+
2730
+
2731
+	/**
2732
+	 * Public Wrapper for _redirect_after_action() method since its
2733
+	 * discovered it would be useful for external code to have access.
2734
+	 *
2735
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
2736
+	 * @since 4.5.0
2737
+	 */
2738
+	public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2739
+	{
2740
+		$this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2741
+	}
2742
+
2743
+
2744
+
2745
+	/**
2746
+	 *    _redirect_after_action
2747
+	 *
2748
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
2749
+	 * @param string $what               - what the action was performed on
2750
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
2751
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2752
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2753
+	 * @access protected
2754
+	 * @return void
2755
+	 */
2756
+	protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2757
+	{
2758
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2759
+		//class name for actions/filters.
2760
+		$classname = get_class($this);
2761
+		//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
2762
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2763
+		$notices = EE_Error::get_notices(false);
2764
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
2765
+		if ( ! $override_overwrite || ! empty($notices['errors'])) {
2766
+			EE_Error::overwrite_success();
2767
+		}
2768
+		if ( ! empty($what) && ! empty($action_desc)) {
2769
+			// how many records affected ? more than one record ? or just one ?
2770
+			if ($success > 1 && empty($notices['errors'])) {
2771
+				// set plural msg
2772
+				EE_Error::add_success(
2773
+						sprintf(
2774
+								__('The "%s" have been successfully %s.', 'event_espresso'),
2775
+								$what,
2776
+								$action_desc
2777
+						),
2778
+						__FILE__, __FUNCTION__, __LINE__
2779
+				);
2780
+			} else if ($success == 1 && empty($notices['errors'])) {
2781
+				// set singular msg
2782
+				EE_Error::add_success(
2783
+						sprintf(
2784
+								__('The "%s" has been successfully %s.', 'event_espresso'),
2785
+								$what,
2786
+								$action_desc
2787
+						),
2788
+						__FILE__, __FUNCTION__, __LINE__
2789
+				);
2790
+			}
2791
+		}
2792
+		// check that $query_args isn't something crazy
2793
+		if ( ! is_array($query_args)) {
2794
+			$query_args = array();
2795
+		}
2796
+		/**
2797
+		 * Allow injecting actions before the query_args are modified for possible different
2798
+		 * redirections on save and close actions
2799
+		 *
2800
+		 * @since 4.2.0
2801
+		 * @param array $query_args       The original query_args array coming into the
2802
+		 *                                method.
2803
+		 */
2804
+		do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2805
+		//calculate where we're going (if we have a "save and close" button pushed)
2806
+		if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2807
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2808
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2809
+			// regenerate query args array from referrer URL
2810
+			parse_str($parsed_url['query'], $query_args);
2811
+			// correct page and action will be in the query args now
2812
+			$redirect_url = admin_url('admin.php');
2813
+		}
2814
+		//merge any default query_args set in _default_route_query_args property
2815
+		if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2816
+			$args_to_merge = array();
2817
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
2818
+				//is there a wp_referer array in our _default_route_query_args property?
2819
+				if ($query_param == 'wp_referer') {
2820
+					$query_value = (array)$query_value;
2821
+					foreach ($query_value as $reference => $value) {
2822
+						if (strpos($reference, 'nonce') !== false) {
2823
+							continue;
2824
+						}
2825
+						//finally we will override any arguments in the referer with
2826
+						//what might be set on the _default_route_query_args array.
2827
+						if (isset($this->_default_route_query_args[$reference])) {
2828
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2829
+						} else {
2830
+							$args_to_merge[$reference] = urlencode($value);
2831
+						}
2832
+					}
2833
+					continue;
2834
+				}
2835
+				$args_to_merge[$query_param] = $query_value;
2836
+			}
2837
+			//now let's merge these arguments but override with what was specifically sent in to the
2838
+			//redirect.
2839
+			$query_args = array_merge($args_to_merge, $query_args);
2840
+		}
2841
+		$this->_process_notices($query_args);
2842
+		// generate redirect url
2843
+		// if redirecting to anything other than the main page, add a nonce
2844
+		if (isset($query_args['action'])) {
2845
+			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2846
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2847
+		}
2848
+		//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).
2849
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2850
+		$redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2851
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2852
+		if (defined('DOING_AJAX')) {
2853
+			$default_data = array(
2854
+					'close'        => true,
2855
+					'redirect_url' => $redirect_url,
2856
+					'where'        => 'main',
2857
+					'what'         => 'append',
2858
+			);
2859
+			$this->_template_args['success'] = $success;
2860
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2861
+			$this->_return_json();
2862
+		}
2863
+		wp_safe_redirect($redirect_url);
2864
+		exit();
2865
+	}
2866
+
2867
+
2868
+
2869
+	/**
2870
+	 * process any notices before redirecting (or returning ajax request)
2871
+	 * This method sets the $this->_template_args['notices'] attribute;
2872
+	 *
2873
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
2874
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2875
+	 * @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.
2876
+	 * @return void
2877
+	 */
2878
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2879
+	{
2880
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
2881
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2882
+			$notices = EE_Error::get_notices(false);
2883
+			if (empty($this->_template_args['success'])) {
2884
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2885
+			}
2886
+			if (empty($this->_template_args['errors'])) {
2887
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2888
+			}
2889
+			if (empty($this->_template_args['attention'])) {
2890
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2891
+			}
2892
+		}
2893
+		$this->_template_args['notices'] = EE_Error::get_notices();
2894
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2895
+		if ( ! defined('DOING_AJAX') || $sticky_notices) {
2896
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
2897
+			$this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2898
+		}
2899
+	}
2900
+
2901
+
2902
+
2903
+	/**
2904
+	 * get_action_link_or_button
2905
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
2906
+	 *
2907
+	 * @param string $action        use this to indicate which action the url is generated with.
2908
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2909
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2910
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2911
+	 * @param string $base_url      If this is not provided
2912
+	 *                              the _admin_base_url will be used as the default for the button base_url.
2913
+	 *                              Otherwise this value will be used.
2914
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2915
+	 * @return string
2916
+	 * @throws \EE_Error
2917
+	 */
2918
+	public function get_action_link_or_button(
2919
+			$action,
2920
+			$type = 'add',
2921
+			$extra_request = array(),
2922
+			$class = 'button-primary',
2923
+			$base_url = '',
2924
+			$exclude_nonce = false
2925
+	) {
2926
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2927
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2928
+			throw new EE_Error(
2929
+					sprintf(
2930
+							__(
2931
+									'There is no page route for given action for the button.  This action was given: %s',
2932
+									'event_espresso'
2933
+							),
2934
+							$action
2935
+					)
2936
+			);
2937
+		}
2938
+		if ( ! isset($this->_labels['buttons'][$type])) {
2939
+			throw new EE_Error(
2940
+					sprintf(
2941
+							__(
2942
+									'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2943
+									'event_espresso'
2944
+							),
2945
+							$type
2946
+					)
2947
+			);
2948
+		}
2949
+		//finally check user access for this button.
2950
+		$has_access = $this->check_user_access($action, true);
2951
+		if ( ! $has_access) {
2952
+			return '';
2953
+		}
2954
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2955
+		$query_args = array(
2956
+				'action' => $action,
2957
+		);
2958
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2959
+		if ( ! empty($extra_request)) {
2960
+			$query_args = array_merge($extra_request, $query_args);
2961
+		}
2962
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2963
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2964
+	}
2965
+
2966
+
2967
+
2968
+	/**
2969
+	 * _per_page_screen_option
2970
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
2971
+	 *
2972
+	 * @return void
2973
+	 */
2974
+	protected function _per_page_screen_option()
2975
+	{
2976
+		$option = 'per_page';
2977
+		$args = array(
2978
+				'label'   => $this->_admin_page_title,
2979
+				'default' => 10,
2980
+				'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
2981
+		);
2982
+		//ONLY add the screen option if the user has access to it.
2983
+		if ($this->check_user_access($this->_current_view, true)) {
2984
+			add_screen_option($option, $args);
2985
+		}
2986
+	}
2987
+
2988
+
2989
+
2990
+	/**
2991
+	 * set_per_page_screen_option
2992
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
2993
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
2994
+	 *
2995
+	 * @access private
2996
+	 * @return void
2997
+	 */
2998
+	private function _set_per_page_screen_options()
2999
+	{
3000
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3001
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3002
+			if ( ! $user = wp_get_current_user()) {
3003
+				return;
3004
+			}
3005
+			$option = $_POST['wp_screen_options']['option'];
3006
+			$value = $_POST['wp_screen_options']['value'];
3007
+			if ($option != sanitize_key($option)) {
3008
+				return;
3009
+			}
3010
+			$map_option = $option;
3011
+			$option = str_replace('-', '_', $option);
3012
+			switch ($map_option) {
3013
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3014
+					$value = (int)$value;
3015
+					if ($value < 1 || $value > 999) {
3016
+						return;
3017
+					}
3018
+					break;
3019
+				default:
3020
+					$value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3021
+					if (false === $value) {
3022
+						return;
3023
+					}
3024
+					break;
3025
+			}
3026
+			update_user_meta($user->ID, $option, $value);
3027
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3028
+			exit;
3029
+		}
3030
+	}
3031
+
3032
+
3033
+
3034
+	/**
3035
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3036
+	 *
3037
+	 * @param array $data array that will be assigned to template args.
3038
+	 */
3039
+	public function set_template_args($data)
3040
+	{
3041
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3042
+	}
3043
+
3044
+
3045
+
3046
+	/**
3047
+	 * This makes available the WP transient system for temporarily moving data between routes
3048
+	 *
3049
+	 * @access protected
3050
+	 * @param string $route             the route that should receive the transient
3051
+	 * @param array  $data              the data that gets sent
3052
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3053
+	 * @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.
3054
+	 * @return void
3055
+	 */
3056
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3057
+	{
3058
+		$user_id = get_current_user_id();
3059
+		if ( ! $skip_route_verify) {
3060
+			$this->_verify_route($route);
3061
+		}
3062
+		//now let's set the string for what kind of transient we're setting
3063
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3064
+		$data = $notices ? array('notices' => $data) : $data;
3065
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3066
+		$existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3067
+		if ($existing) {
3068
+			$data = array_merge((array)$data, (array)$existing);
3069
+		}
3070
+		if (is_multisite() && is_network_admin()) {
3071
+			set_site_transient($transient, $data, 8);
3072
+		} else {
3073
+			set_transient($transient, $data, 8);
3074
+		}
3075
+	}
3076
+
3077
+
3078
+
3079
+	/**
3080
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3081
+	 *
3082
+	 * @param bool $notices true we get notices transient. False we just return normal route transient
3083
+	 * @return mixed data
3084
+	 */
3085
+	protected function _get_transient($notices = false, $route = false)
3086
+	{
3087
+		$user_id = get_current_user_id();
3088
+		$route = ! $route ? $this->_req_action : $route;
3089
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3090
+		$data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3091
+		//delete transient after retrieval (just in case it hasn't expired);
3092
+		if (is_multisite() && is_network_admin()) {
3093
+			delete_site_transient($transient);
3094
+		} else {
3095
+			delete_transient($transient);
3096
+		}
3097
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3098
+	}
3099
+
3100
+
3101
+
3102
+	/**
3103
+	 * 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.
3104
+	 * 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.)
3105
+	 *
3106
+	 * @return void
3107
+	 */
3108
+	protected function _transient_garbage_collection()
3109
+	{
3110
+		global $wpdb;
3111
+		//retrieve all existing transients
3112
+		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3113
+		if ($results = $wpdb->get_results($query)) {
3114
+			foreach ($results as $result) {
3115
+				$transient = str_replace('_transient_', '', $result->option_name);
3116
+				get_transient($transient);
3117
+				if (is_multisite() && is_network_admin()) {
3118
+					get_site_transient($transient);
3119
+				}
3120
+			}
3121
+		}
3122
+	}
3123
+
3124
+
3125
+
3126
+	/**
3127
+	 * get_view
3128
+	 *
3129
+	 * @access public
3130
+	 * @return string content of _view property
3131
+	 */
3132
+	public function get_view()
3133
+	{
3134
+		return $this->_view;
3135
+	}
3136
+
3137
+
3138
+
3139
+	/**
3140
+	 * getter for the protected $_views property
3141
+	 *
3142
+	 * @return array
3143
+	 */
3144
+	public function get_views()
3145
+	{
3146
+		return $this->_views;
3147
+	}
3148
+
3149
+
3150
+
3151
+	/**
3152
+	 * get_current_page
3153
+	 *
3154
+	 * @access public
3155
+	 * @return string _current_page property value
3156
+	 */
3157
+	public function get_current_page()
3158
+	{
3159
+		return $this->_current_page;
3160
+	}
3161
+
3162
+
3163
+
3164
+	/**
3165
+	 * get_current_view
3166
+	 *
3167
+	 * @access public
3168
+	 * @return string _current_view property value
3169
+	 */
3170
+	public function get_current_view()
3171
+	{
3172
+		return $this->_current_view;
3173
+	}
3174
+
3175
+
3176
+
3177
+	/**
3178
+	 * get_current_screen
3179
+	 *
3180
+	 * @access public
3181
+	 * @return object The current WP_Screen object
3182
+	 */
3183
+	public function get_current_screen()
3184
+	{
3185
+		return $this->_current_screen;
3186
+	}
3187
+
3188
+
3189
+
3190
+	/**
3191
+	 * get_current_page_view_url
3192
+	 *
3193
+	 * @access public
3194
+	 * @return string This returns the url for the current_page_view.
3195
+	 */
3196
+	public function get_current_page_view_url()
3197
+	{
3198
+		return $this->_current_page_view_url;
3199
+	}
3200
+
3201
+
3202
+
3203
+	/**
3204
+	 * just returns the _req_data property
3205
+	 *
3206
+	 * @return array
3207
+	 */
3208
+	public function get_request_data()
3209
+	{
3210
+		return $this->_req_data;
3211
+	}
3212
+
3213
+
3214
+
3215
+	/**
3216
+	 * returns the _req_data protected property
3217
+	 *
3218
+	 * @return string
3219
+	 */
3220
+	public function get_req_action()
3221
+	{
3222
+		return $this->_req_action;
3223
+	}
3224
+
3225
+
3226
+
3227
+	/**
3228
+	 * @return bool  value of $_is_caf property
3229
+	 */
3230
+	public function is_caf()
3231
+	{
3232
+		return $this->_is_caf;
3233
+	}
3234
+
3235
+
3236
+
3237
+	/**
3238
+	 * @return mixed
3239
+	 */
3240
+	public function default_espresso_metaboxes()
3241
+	{
3242
+		return $this->_default_espresso_metaboxes;
3243
+	}
3244
+
3245
+
3246
+
3247
+	/**
3248
+	 * @return mixed
3249
+	 */
3250
+	public function admin_base_url()
3251
+	{
3252
+		return $this->_admin_base_url;
3253
+	}
3254
+
3255
+
3256
+
3257
+	/**
3258
+	 * @return mixed
3259
+	 */
3260
+	public function wp_page_slug()
3261
+	{
3262
+		return $this->_wp_page_slug;
3263
+	}
3264
+
3265
+
3266
+
3267
+	/**
3268
+	 * updates  espresso configuration settings
3269
+	 *
3270
+	 * @access    protected
3271
+	 * @param string                   $tab
3272
+	 * @param EE_Config_Base|EE_Config $config
3273
+	 * @param string                   $file file where error occurred
3274
+	 * @param string                   $func function  where error occurred
3275
+	 * @param string                   $line line no where error occurred
3276
+	 * @return boolean
3277
+	 */
3278
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3279
+	{
3280
+		//remove any options that are NOT going to be saved with the config settings.
3281
+		if (isset($config->core->ee_ueip_optin)) {
3282
+			$config->core->ee_ueip_has_notified = true;
3283
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3284
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3285
+			update_option('ee_ueip_has_notified', true);
3286
+		}
3287
+		// and save it (note we're also doing the network save here)
3288
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3289
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3290
+		if ($config_saved && $net_saved) {
3291
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3292
+			return true;
3293
+		} else {
3294
+			EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3295
+			return false;
3296
+		}
3297
+	}
3298
+
3299
+
3300
+
3301
+	/**
3302
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3303
+	 *
3304
+	 * @return array
3305
+	 */
3306
+	public function get_yes_no_values()
3307
+	{
3308
+		return $this->_yes_no_values;
3309
+	}
3310
+
3311
+
3312
+
3313
+	protected function _get_dir()
3314
+	{
3315
+		$reflector = new ReflectionClass(get_class($this));
3316
+		return dirname($reflector->getFileName());
3317
+	}
3318
+
3319
+
3320
+
3321
+	/**
3322
+	 * A helper for getting a "next link".
3323
+	 *
3324
+	 * @param string $url   The url to link to
3325
+	 * @param string $class The class to use.
3326
+	 * @return string
3327
+	 */
3328
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3329
+	{
3330
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3331
+	}
3332
+
3333
+
3334
+
3335
+	/**
3336
+	 * A helper for getting a "previous link".
3337
+	 *
3338
+	 * @param string $url   The url to link to
3339
+	 * @param string $class The class to use.
3340
+	 * @return string
3341
+	 */
3342
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3343
+	{
3344
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3345
+	}
3346
+
3347
+
3348
+
3349
+
3350
+
3351
+
3352
+
3353
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3354
+	/**
3355
+	 * 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
3356
+	 * array.
3357
+	 *
3358
+	 * @return bool success/fail
3359
+	 */
3360
+	protected function _process_resend_registration()
3361
+	{
3362
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3363
+		do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3364
+		return $this->_template_args['success'];
3365
+	}
3366
+
3367
+
3368
+
3369
+	/**
3370
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3371
+	 *
3372
+	 * @access protected
3373
+	 * @param \EE_Payment $payment
3374
+	 * @return bool success/fail
3375
+	 */
3376
+	protected function _process_payment_notification(EE_Payment $payment)
3377
+	{
3378
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3379
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3380
+		$this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3381
+		return $this->_template_args['success'];
3382
+	}
3383 3383
 
3384 3384
 
3385 3385
 }
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
         $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
474 474
         $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
475 475
         global $ee_menu_slugs;
476
-        $ee_menu_slugs = (array)$ee_menu_slugs;
476
+        $ee_menu_slugs = (array) $ee_menu_slugs;
477 477
         if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
478 478
             return false;
479 479
         }
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
         //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
489 489
         $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
490 490
         $this->_current_view = $this->_req_action;
491
-        $this->_req_nonce = $this->_req_action . '_nonce';
491
+        $this->_req_nonce = $this->_req_action.'_nonce';
492 492
         $this->_define_page_props();
493 493
         $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
494 494
         //default things
@@ -509,11 +509,11 @@  discard block
 block discarded – undo
509 509
             $this->_extend_page_config_for_cpt();
510 510
         }
511 511
         //filter routes and page_config so addons can add their stuff. Filtering done per class
512
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
513
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
512
+        $this->_page_routes = apply_filters('FHEE__'.get_class($this).'__page_setup__page_routes', $this->_page_routes, $this);
513
+        $this->_page_config = apply_filters('FHEE__'.get_class($this).'__page_setup__page_config', $this->_page_config, $this);
514 514
         //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
515
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
516
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
515
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
516
+            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), 10, 2);
517 517
         }
518 518
         //next route only if routing enabled
519 519
         if ($this->_routing && ! defined('DOING_AJAX')) {
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
             if ($this->_is_UI_request) {
524 524
                 //admin_init stuff - global, all views for this page class, specific view
525 525
                 add_action('admin_init', array($this, 'admin_init'), 10);
526
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
527
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
526
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
527
+                    add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15);
528 528
                 }
529 529
             } else {
530 530
                 //hijack regular WP loading and route admin request immediately
@@ -544,17 +544,17 @@  discard block
 block discarded – undo
544 544
      */
545 545
     private function _do_other_page_hooks()
546 546
     {
547
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
547
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array());
548 548
         foreach ($registered_pages as $page) {
549 549
             //now let's setup the file name and class that should be present
550 550
             $classname = str_replace('.class.php', '', $page);
551 551
             //autoloaders should take care of loading file
552 552
             if ( ! class_exists($classname)) {
553
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
553
+                $error_msg[] = sprintf(esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
554 554
                 $error_msg[] = $error_msg[0]
555 555
                                . "\r\n"
556
-                               . 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',
557
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
556
+                               . 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',
557
+                                'event_espresso'), $page, '<br />', '<strong>'.$classname.'</strong>');
558 558
                 throw new EE_Error(implode('||', $error_msg));
559 559
             }
560 560
             $a = new ReflectionClass($classname);
@@ -590,13 +590,13 @@  discard block
 block discarded – undo
590 590
         //load admin_notices - global, page class, and view specific
591 591
         add_action('admin_notices', array($this, 'admin_notices_global'), 5);
592 592
         add_action('admin_notices', array($this, 'admin_notices'), 10);
593
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
594
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
593
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
594
+            add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15);
595 595
         }
596 596
         //load network admin_notices - global, page class, and view specific
597 597
         add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
598
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
599
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
598
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
599
+            add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view));
600 600
         }
601 601
         //this will save any per_page screen options if they are present
602 602
         $this->_set_per_page_screen_options();
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
         //add screen options - global, page child class, and view specific
609 609
         $this->_add_global_screen_options();
610 610
         $this->_add_screen_options();
611
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
612
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
611
+        if (method_exists($this, '_add_screen_options_'.$this->_current_view)) {
612
+            call_user_func(array($this, '_add_screen_options_'.$this->_current_view));
613 613
         }
614 614
         //add help tab(s) and tours- set via page_config and qtips.
615 615
         $this->_add_help_tour();
@@ -618,31 +618,31 @@  discard block
 block discarded – undo
618 618
         //add feature_pointers - global, page child class, and view specific
619 619
         $this->_add_feature_pointers();
620 620
         $this->_add_global_feature_pointers();
621
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
622
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
621
+        if (method_exists($this, '_add_feature_pointer_'.$this->_current_view)) {
622
+            call_user_func(array($this, '_add_feature_pointer_'.$this->_current_view));
623 623
         }
624 624
         //enqueue scripts/styles - global, page class, and view specific
625 625
         add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
626 626
         add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
627
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
628
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
627
+        if (method_exists($this, 'load_scripts_styles_'.$this->_current_view)) {
628
+            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_'.$this->_current_view), 15);
629 629
         }
630 630
         add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
631 631
         //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
632 632
         add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
633 633
         add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
634
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
635
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
634
+        if (method_exists($this, 'admin_footer_scripts_'.$this->_current_view)) {
635
+            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_'.$this->_current_view), 101);
636 636
         }
637 637
         //admin footer scripts
638 638
         add_action('admin_footer', array($this, 'admin_footer_global'), 99);
639 639
         add_action('admin_footer', array($this, 'admin_footer'), 100);
640
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
641
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
640
+        if (method_exists($this, 'admin_footer_'.$this->_current_view)) {
641
+            add_action('admin_footer', array($this, 'admin_footer_'.$this->_current_view), 101);
642 642
         }
643 643
         do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
644 644
         //targeted hook
645
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
645
+        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__'.$this->page_slug.'__'.$this->_req_action);
646 646
     }
647 647
 
648 648
 
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
             // user error msg
719 719
             $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
720 720
             // developer error msg
721
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
721
+            $error_msg .= '||'.$error_msg.__(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
722 722
             throw new EE_Error($error_msg);
723 723
         }
724 724
         // and that the requested page route exists
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
             // user error msg
730 730
             $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
731 731
             // developer error msg
732
-            $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);
732
+            $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);
733 733
             throw new EE_Error($error_msg);
734 734
         }
735 735
         // and that a default route exists
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
             // user error msg
738 738
             $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
739 739
             // developer error msg
740
-            $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');
740
+            $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');
741 741
             throw new EE_Error($error_msg);
742 742
         }
743 743
         //first lets' catch if the UI request has EVER been set.
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
             // user error msg
767 767
             $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
768 768
             // developer error msg
769
-            $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);
769
+            $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);
770 770
             throw new EE_Error($error_msg);
771 771
         }
772 772
     }
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
             // these are not the droids you are looking for !!!
789 789
             $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
790 790
             if (WP_DEBUG) {
791
-                $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__);
791
+                $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__);
792 792
             }
793 793
             if ( ! defined('DOING_AJAX')) {
794 794
                 wp_die($msg);
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
                 if (strpos($key, 'nonce') !== false) {
967 967
                     continue;
968 968
                 }
969
-                $args['wp_referer[' . $key . ']'] = $value;
969
+                $args['wp_referer['.$key.']'] = $value;
970 970
             }
971 971
         }
972 972
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
                     if ($tour instanceof EE_Help_Tour_final_stop) {
1013 1013
                         continue;
1014 1014
                     }
1015
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1015
+                    $tb[] = '<button id="trigger-tour-'.$tour->get_slug().'" class="button-primary trigger-ee-help-tour">'.$tour->get_label().'</button>';
1016 1016
                 }
1017 1017
                 $tour_buttons .= implode('<br />', $tb);
1018 1018
                 $tour_buttons .= '</div></div>';
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
                     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',
1025 1025
                             'event_espresso'), $config['help_sidebar'], get_class($this)));
1026 1026
                 }
1027
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1027
+                $content = apply_filters('FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1028 1028
                 $content .= $tour_buttons; //add help tour buttons.
1029 1029
                 //do we have any help tours setup?  Cause if we do we want to add the buttons
1030 1030
                 $this->_current_screen->set_help_sidebar($content);
@@ -1037,13 +1037,13 @@  discard block
 block discarded – undo
1037 1037
             if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1038 1038
                 $_ht['id'] = $this->page_slug;
1039 1039
                 $_ht['title'] = __('Help Tours', 'event_espresso');
1040
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1040
+                $_ht['content'] = '<p>'.__('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso').'</p>';
1041 1041
                 $this->_current_screen->add_help_tab($_ht);
1042 1042
             }/**/
1043 1043
             if ( ! isset($config['help_tabs'])) {
1044 1044
                 return;
1045 1045
             } //no help tabs for this route
1046
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1046
+            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1047 1047
                 //we're here so there ARE help tabs!
1048 1048
                 //make sure we've got what we need
1049 1049
                 if ( ! isset($cfg['title'])) {
@@ -1058,9 +1058,9 @@  discard block
 block discarded – undo
1058 1058
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1059 1059
                     //second priority goes to filename
1060 1060
                 } else if ( ! empty($cfg['filename'])) {
1061
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1061
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1062 1062
                     //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)
1063
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1063
+                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tabs/'.$cfg['filename'].'.help_tab.php' : $file_path;
1064 1064
                     //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1065 1065
                     if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1066 1066
                         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',
@@ -1079,7 +1079,7 @@  discard block
 block discarded – undo
1079 1079
                     return;
1080 1080
                 }
1081 1081
                 //setup config array for help tab method
1082
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1082
+                $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1083 1083
                 $_ht = array(
1084 1084
                         'id'       => $id,
1085 1085
                         'title'    => $cfg['title'],
@@ -1117,9 +1117,9 @@  discard block
 block discarded – undo
1117 1117
             }
1118 1118
             if (isset($config['help_tour'])) {
1119 1119
                 foreach ($config['help_tour'] as $tour) {
1120
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1120
+                    $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php';
1121 1121
                     //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
1122
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1122
+                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES.basename($this->_get_dir()).'/help_tours/'.$tour.'.class.php' : $file_path;
1123 1123
                     //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1124 1124
                     if ( ! is_readable($file_path)) {
1125 1125
                         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'),
@@ -1129,7 +1129,7 @@  discard block
 block discarded – undo
1129 1129
                     require_once $file_path;
1130 1130
                     if ( ! class_exists($tour)) {
1131 1131
                         $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1132
-                        $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.',
1132
+                        $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.',
1133 1133
                                         'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1134 1134
                         throw new EE_Error(implode('||', $error_msg));
1135 1135
                     }
@@ -1161,11 +1161,11 @@  discard block
 block discarded – undo
1161 1161
     protected function _add_qtips()
1162 1162
     {
1163 1163
         if (isset($this->_route_config['qtips'])) {
1164
-            $qtips = (array)$this->_route_config['qtips'];
1164
+            $qtips = (array) $this->_route_config['qtips'];
1165 1165
             //load qtip loader
1166 1166
             $path = array(
1167
-                    $this->_get_dir() . '/qtips/',
1168
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1167
+                    $this->_get_dir().'/qtips/',
1168
+                    EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1169 1169
             );
1170 1170
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1171 1171
         }
@@ -1195,11 +1195,11 @@  discard block
 block discarded – undo
1195 1195
             if ( ! $this->check_user_access($slug, true)) {
1196 1196
                 continue;
1197 1197
             } //no nav tab becasue current user does not have access.
1198
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1198
+            $css_class = isset($config['css_class']) ? $config['css_class'].' ' : '';
1199 1199
             $this->_nav_tabs[$slug] = array(
1200 1200
                     'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1201 1201
                     'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1202
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1202
+                    'css_class' => $this->_req_action == $slug ? $css_class.'nav-tab-active' : $css_class,
1203 1203
                     'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1204 1204
             );
1205 1205
             $i++;
@@ -1262,11 +1262,11 @@  discard block
 block discarded – undo
1262 1262
             $capability = empty($capability) ? 'manage_options' : $capability;
1263 1263
         }
1264 1264
         $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1265
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1265
+        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug.'_'.$route_to_check, $id)) && ! defined('DOING_AJAX')) {
1266 1266
             if ($verify_only) {
1267 1267
                 return false;
1268 1268
             } else {
1269
-                if ( is_user_logged_in() ) {
1269
+                if (is_user_logged_in()) {
1270 1270
                     wp_die(__('You do not have access to this route.', 'event_espresso'));
1271 1271
                 } else {
1272 1272
                     return false;
@@ -1358,7 +1358,7 @@  discard block
 block discarded – undo
1358 1358
     public function admin_footer_global()
1359 1359
     {
1360 1360
         //dialog container for dialog helper
1361
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1361
+        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n";
1362 1362
         $d_cont .= '<div class="ee-notices"></div>';
1363 1363
         $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1364 1364
         $d_cont .= '</div>';
@@ -1368,7 +1368,7 @@  discard block
 block discarded – undo
1368 1368
             echo implode('<br />', $this->_help_tour[$this->_req_action]);
1369 1369
         }
1370 1370
         //current set timezone for timezone js
1371
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1371
+        echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>';
1372 1372
     }
1373 1373
 
1374 1374
 
@@ -1393,7 +1393,7 @@  discard block
 block discarded – undo
1393 1393
     {
1394 1394
         $content = '';
1395 1395
         $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1396
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1396
+        $template_path = EE_ADMIN_TEMPLATE.'admin_help_popup.template.php';
1397 1397
         //loop through the array and setup content
1398 1398
         foreach ($help_array as $trigger => $help) {
1399 1399
             //make sure the array is setup properly
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
     private function _get_help_content()
1428 1428
     {
1429 1429
         //what is the method we're looking for?
1430
-        $method_name = '_help_popup_content_' . $this->_req_action;
1430
+        $method_name = '_help_popup_content_'.$this->_req_action;
1431 1431
         //if method doesn't exist let's get out.
1432 1432
         if ( ! method_exists($this, $method_name)) {
1433 1433
             return array();
@@ -1471,8 +1471,8 @@  discard block
 block discarded – undo
1471 1471
             $help_content = $this->_set_help_popup_content($help_array, false);
1472 1472
         }
1473 1473
         //let's setup the trigger
1474
-        $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>';
1475
-        $content = $content . $help_content;
1474
+        $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>';
1475
+        $content = $content.$help_content;
1476 1476
         if ($display) {
1477 1477
             echo $content;
1478 1478
         } else {
@@ -1532,32 +1532,32 @@  discard block
 block discarded – undo
1532 1532
             add_action('admin_head', array($this, 'add_xdebug_style'));
1533 1533
         }
1534 1534
         //register all styles
1535
-        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);
1536
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1535
+        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);
1536
+        wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1537 1537
         //helpers styles
1538
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1538
+        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1539 1539
         //enqueue global styles
1540 1540
         wp_enqueue_style('ee-admin-css');
1541 1541
         /** SCRIPTS **/
1542 1542
         //register all scripts
1543
-        wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1544
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1545
-        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);
1546
-        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);
1543
+        wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1544
+        wp_register_script('ee-dialog', EE_ADMIN_URL.'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1545
+        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);
1546
+        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);
1547 1547
         // register jQuery Validate - see /includes/functions/wp_hooks.php
1548 1548
         add_filter('FHEE_load_jquery_validate', '__return_true');
1549 1549
         add_filter('FHEE_load_joyride', '__return_true');
1550 1550
         //script for sorting tables
1551
-        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);
1551
+        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);
1552 1552
         //script for parsing uri's
1553
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1553
+        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1554 1554
         //and parsing associative serialized form elements
1555
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1555
+        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1556 1556
         //helpers scripts
1557
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1558
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1559
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1560
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1557
+        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1558
+        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1559
+        wp_register_script('ee-moment', EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1560
+        wp_register_script('ee-datepicker', EE_ADMIN_URL.'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1561 1561
         //google charts
1562 1562
         wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1563 1563
         //enqueue global scripts
@@ -1578,7 +1578,7 @@  discard block
 block discarded – undo
1578 1578
          */
1579 1579
         if ( ! empty($this->_help_tour)) {
1580 1580
             //register the js for kicking things off
1581
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1581
+            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL.'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1582 1582
             //setup tours for the js tour object
1583 1583
             foreach ($this->_help_tour['tours'] as $tour) {
1584 1584
                 $tours[] = array(
@@ -1677,17 +1677,17 @@  discard block
 block discarded – undo
1677 1677
             return;
1678 1678
         } //not a list_table view so get out.
1679 1679
         //list table functions are per view specific (because some admin pages might have more than one listtable!)
1680
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1680
+        if (call_user_func(array($this, '_set_list_table_views_'.$this->_req_action)) === false) {
1681 1681
             //user error msg
1682 1682
             $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1683 1683
             //developer error msg
1684
-            $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'),
1685
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1684
+            $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'),
1685
+                            $this->_req_action, '_set_list_table_views_'.$this->_req_action);
1686 1686
             throw new EE_Error($error_msg);
1687 1687
         }
1688 1688
         //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1689
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1690
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1689
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, $this->_views);
1690
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
1691 1691
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1692 1692
         $this->_set_list_table_view();
1693 1693
         $this->_set_list_table_object();
@@ -1762,7 +1762,7 @@  discard block
 block discarded – undo
1762 1762
             // check for current view
1763 1763
             $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1764 1764
             $query_args['action'] = $this->_req_action;
1765
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1765
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
1766 1766
             $query_args['status'] = $view['slug'];
1767 1767
             //merge any other arguments sent in.
1768 1768
             if (isset($extra_query_args[$view['slug']])) {
@@ -1800,14 +1800,14 @@  discard block
 block discarded – undo
1800 1800
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1801 1801
         foreach ($values as $value) {
1802 1802
             if ($value < $max_entries) {
1803
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1803
+                $selected = $value == $per_page ? ' selected="'.$per_page.'"' : '';
1804 1804
                 $entries_per_page_dropdown .= '
1805
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1805
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
1806 1806
             }
1807 1807
         }
1808
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1808
+        $selected = $max_entries == $per_page ? ' selected="'.$per_page.'"' : '';
1809 1809
         $entries_per_page_dropdown .= '
1810
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1810
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
1811 1811
         $entries_per_page_dropdown .= '
1812 1812
 					</select>
1813 1813
 					entries
@@ -1829,7 +1829,7 @@  discard block
 block discarded – undo
1829 1829
     public function _set_search_attributes()
1830 1830
     {
1831 1831
         $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1832
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1832
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
1833 1833
     }
1834 1834
 
1835 1835
     /*** END LIST TABLE METHODS **/
@@ -1867,7 +1867,7 @@  discard block
 block discarded – undo
1867 1867
                     // user error msg
1868 1868
                     $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1869 1869
                     // developer error msg
1870
-                    $error_msg .= '||' . sprintf(
1870
+                    $error_msg .= '||'.sprintf(
1871 1871
                                     __(
1872 1872
                                             '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.',
1873 1873
                                             'event_espresso'
@@ -1897,15 +1897,15 @@  discard block
 block discarded – undo
1897 1897
                 && is_array($this->_route_config['columns'])
1898 1898
                 && count($this->_route_config['columns']) === 2
1899 1899
         ) {
1900
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1900
+            add_screen_option('layout_columns', array('max' => (int) $this->_route_config['columns'][0], 'default' => (int) $this->_route_config['columns'][1]));
1901 1901
             $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1902 1902
             $screen_id = $this->_current_screen->id;
1903
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1903
+            $screen_columns = (int) get_user_option("screen_layout_$screen_id");
1904 1904
             $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1905
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1905
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
1906 1906
             $this->_template_args['current_page'] = $this->_wp_page_slug;
1907 1907
             $this->_template_args['screen'] = $this->_current_screen;
1908
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1908
+            $this->_column_template_path = EE_ADMIN_TEMPLATE.'admin_details_metabox_column_wrapper.template.php';
1909 1909
             //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.
1910 1910
             $this->_route_config['has_metaboxes'] = true;
1911 1911
         }
@@ -1952,7 +1952,7 @@  discard block
 block discarded – undo
1952 1952
      */
1953 1953
     public function espresso_ratings_request()
1954 1954
     {
1955
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1955
+        $template_path = EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php';
1956 1956
         EEH_Template::display_template($template_path, array());
1957 1957
     }
1958 1958
 
@@ -1960,18 +1960,18 @@  discard block
 block discarded – undo
1960 1960
 
1961 1961
     public static function cached_rss_display($rss_id, $url)
1962 1962
     {
1963
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1963
+        $loading = '<p class="widget-loading hide-if-no-js">'.__('Loading&#8230;').'</p><p class="hide-if-js">'.__('This widget requires JavaScript.').'</p>';
1964 1964
         $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1965
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1966
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1967
-        $post = '</div>' . "\n";
1968
-        $cache_key = 'ee_rss_' . md5($rss_id);
1965
+        $pre = '<div class="espresso-rss-display">'."\n\t";
1966
+        $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>';
1967
+        $post = '</div>'."\n";
1968
+        $cache_key = 'ee_rss_'.md5($rss_id);
1969 1969
         if (false != ($output = get_transient($cache_key))) {
1970
-            echo $pre . $output . $post;
1970
+            echo $pre.$output.$post;
1971 1971
             return true;
1972 1972
         }
1973 1973
         if ( ! $doing_ajax) {
1974
-            echo $pre . $loading . $post;
1974
+            echo $pre.$loading.$post;
1975 1975
             return false;
1976 1976
         }
1977 1977
         ob_start();
@@ -2030,7 +2030,7 @@  discard block
 block discarded – undo
2030 2030
 
2031 2031
     public function espresso_sponsors_post_box()
2032 2032
     {
2033
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2033
+        $templatepath = EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php';
2034 2034
         EEH_Template::display_template($templatepath);
2035 2035
     }
2036 2036
 
@@ -2038,7 +2038,7 @@  discard block
 block discarded – undo
2038 2038
 
2039 2039
     private function _publish_post_box()
2040 2040
     {
2041
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2041
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2042 2042
         //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)
2043 2043
         if ( ! empty($this->_labels['publishbox'])) {
2044 2044
             $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
@@ -2055,7 +2055,7 @@  discard block
 block discarded – undo
2055 2055
     {
2056 2056
         //if we have extra content set let's add it in if not make sure its empty
2057 2057
         $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2058
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2058
+        $template_path = EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php';
2059 2059
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2060 2060
     }
2061 2061
 
@@ -2224,7 +2224,7 @@  discard block
 block discarded – undo
2224 2224
         //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)
2225 2225
         $call_back_func = $create_func ? create_function('$post, $metabox',
2226 2226
                 'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2227
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2227
+        add_meta_box(str_replace('_', '-', $action).'-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2228 2228
     }
2229 2229
 
2230 2230
 
@@ -2304,10 +2304,10 @@  discard block
 block discarded – undo
2304 2304
                 ? 'poststuff'
2305 2305
                 : 'espresso-default-admin';
2306 2306
         $template_path = $sidebar
2307
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2308
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2307
+                ? EE_ADMIN_TEMPLATE.'admin_details_wrapper.template.php'
2308
+                : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2309 2309
         if (defined('DOING_AJAX') && DOING_AJAX) {
2310
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2310
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2311 2311
         }
2312 2312
         $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2313 2313
         $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
@@ -2353,7 +2353,7 @@  discard block
 block discarded – undo
2353 2353
                         true
2354 2354
                 )
2355 2355
                 : $this->_template_args['preview_action_button'];
2356
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2356
+        $template_path = EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php';
2357 2357
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2358 2358
                 $template_path,
2359 2359
                 $this->_template_args,
@@ -2404,7 +2404,7 @@  discard block
 block discarded – undo
2404 2404
         //setup search attributes
2405 2405
         $this->_set_search_attributes();
2406 2406
         $this->_template_args['current_page'] = $this->_wp_page_slug;
2407
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2407
+        $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2408 2408
         $this->_template_args['table_url'] = defined('DOING_AJAX')
2409 2409
                 ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2410 2410
                 : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
@@ -2414,22 +2414,22 @@  discard block
 block discarded – undo
2414 2414
         $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2415 2415
         if ( ! empty($ajax_sorting_callback)) {
2416 2416
             $sortable_list_table_form_fields = wp_nonce_field(
2417
-                    $ajax_sorting_callback . '_nonce',
2418
-                    $ajax_sorting_callback . '_nonce',
2417
+                    $ajax_sorting_callback.'_nonce',
2418
+                    $ajax_sorting_callback.'_nonce',
2419 2419
                     false,
2420 2420
                     false
2421 2421
             );
2422 2422
             //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2423 2423
             //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2424
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2425
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2424
+            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'.$this->page_slug.'" />';
2425
+            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'.$ajax_sorting_callback.'" />';
2426 2426
         } else {
2427 2427
             $sortable_list_table_form_fields = '';
2428 2428
         }
2429 2429
         $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2430 2430
         $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2431
-        $nonce_ref = $this->_req_action . '_nonce';
2432
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2431
+        $nonce_ref = $this->_req_action.'_nonce';
2432
+        $hidden_form_fields .= '<input type="hidden" name="'.$nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">';
2433 2433
         $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2434 2434
         //display message about search results?
2435 2435
         $this->_template_args['before_list_table'] .= apply_filters(
@@ -2441,7 +2441,7 @@  discard block
 block discarded – undo
2441 2441
                                         'Displaying search results for the search string: %1$s',
2442 2442
                                         'event_espresso'
2443 2443
                                 ),
2444
-                                '<strong><em>' . trim( $this->_req_data['s'], '%' ) . '</em></strong>'
2444
+                                '<strong><em>'.trim($this->_req_data['s'], '%').'</em></strong>'
2445 2445
                             )
2446 2446
                             . '</p>'
2447 2447
                         : '',
@@ -2479,8 +2479,8 @@  discard block
 block discarded – undo
2479 2479
      */
2480 2480
     protected function _display_legend($items)
2481 2481
     {
2482
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2483
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2482
+        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array) $items, $this);
2483
+        $legend_template = EE_ADMIN_TEMPLATE.'admin_details_legend.template.php';
2484 2484
         return EEH_Template::display_template($legend_template, $this->_template_args, true);
2485 2485
     }
2486 2486
 
@@ -2572,15 +2572,15 @@  discard block
 block discarded – undo
2572 2572
         $this->_nav_tabs = $this->_get_main_nav_tabs();
2573 2573
         $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2574 2574
         $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2575
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2575
+        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content'.$this->_current_page.$this->_current_view,
2576 2576
                 isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2577
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2577
+        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content'.$this->_current_page.$this->_current_view,
2578 2578
                 isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2579 2579
         $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2580 2580
         // load settings page wrapper template
2581
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2581
+        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE.'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php';
2582 2582
         //about page?
2583
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2583
+        $template_path = $about ? EE_ADMIN_TEMPLATE.'about_admin_wrapper.template.php' : $template_path;
2584 2584
         if (defined('DOING_AJAX')) {
2585 2585
             $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2586 2586
             $this->_return_json();
@@ -2652,20 +2652,20 @@  discard block
 block discarded – undo
2652 2652
     protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2653 2653
     {
2654 2654
         //make sure $text and $actions are in an array
2655
-        $text = (array)$text;
2656
-        $actions = (array)$actions;
2655
+        $text = (array) $text;
2656
+        $actions = (array) $actions;
2657 2657
         $referrer_url = empty($referrer) ? '' : $referrer;
2658
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2659
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2658
+        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$_SERVER['REQUEST_URI'].'" />'
2659
+                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'.$referrer.'" />';
2660 2660
         $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2661 2661
         $default_names = array('save', 'save_and_close');
2662 2662
         //add in a hidden index for the current page (so save and close redirects properly)
2663 2663
         $this->_template_args['save_buttons'] = $referrer_url;
2664 2664
         foreach ($button_text as $key => $button) {
2665 2665
             $ref = $default_names[$key];
2666
-            $id = $this->_current_view . '_' . $ref;
2666
+            $id = $this->_current_view.'_'.$ref;
2667 2667
             $name = ! empty($actions) ? $actions[$key] : $ref;
2668
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2668
+            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '.$ref.'" value="'.$button.'" name="'.$name.'" id="'.$id.'" />';
2669 2669
             if ( ! $both) {
2670 2670
                 break;
2671 2671
             }
@@ -2701,15 +2701,15 @@  discard block
 block discarded – undo
2701 2701
     {
2702 2702
         if (empty($route)) {
2703 2703
             $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2704
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2705
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2704
+            $dev_msg = $user_msg."\n".sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2705
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
2706 2706
         }
2707 2707
         // open form
2708
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2708
+        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'.$this->_admin_base_url.'" id="'.$route.'_event_form" >';
2709 2709
         // add nonce
2710
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2710
+        $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
2711 2711
         //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2712
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2712
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
2713 2713
         // add REQUIRED form action
2714 2714
         $hidden_fields = array(
2715 2715
                 'action' => array('type' => 'hidden', 'value' => $route),
@@ -2719,8 +2719,8 @@  discard block
 block discarded – undo
2719 2719
         // generate form fields
2720 2720
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2721 2721
         // add fields to form
2722
-        foreach ((array)$form_fields as $field_name => $form_field) {
2723
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2722
+        foreach ((array) $form_fields as $field_name => $form_field) {
2723
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
2724 2724
         }
2725 2725
         // close form
2726 2726
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -2801,7 +2801,7 @@  discard block
 block discarded – undo
2801 2801
          * @param array $query_args       The original query_args array coming into the
2802 2802
          *                                method.
2803 2803
          */
2804
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2804
+        do_action('AHEE__'.$classname.'___redirect_after_action__before_redirect_modification_'.$this->_req_action, $query_args);
2805 2805
         //calculate where we're going (if we have a "save and close" button pushed)
2806 2806
         if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2807 2807
             // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
@@ -2817,7 +2817,7 @@  discard block
 block discarded – undo
2817 2817
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
2818 2818
                 //is there a wp_referer array in our _default_route_query_args property?
2819 2819
                 if ($query_param == 'wp_referer') {
2820
-                    $query_value = (array)$query_value;
2820
+                    $query_value = (array) $query_value;
2821 2821
                     foreach ($query_value as $reference => $value) {
2822 2822
                         if (strpos($reference, 'nonce') !== false) {
2823 2823
                             continue;
@@ -2843,11 +2843,11 @@  discard block
 block discarded – undo
2843 2843
         // if redirecting to anything other than the main page, add a nonce
2844 2844
         if (isset($query_args['action'])) {
2845 2845
             // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2846
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2846
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
2847 2847
         }
2848 2848
         //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).
2849
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2850
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2849
+        do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args);
2850
+        $redirect_url = apply_filters('FHEE_redirect_'.$classname.$this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2851 2851
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2852 2852
         if (defined('DOING_AJAX')) {
2853 2853
             $default_data = array(
@@ -2977,7 +2977,7 @@  discard block
 block discarded – undo
2977 2977
         $args = array(
2978 2978
                 'label'   => $this->_admin_page_title,
2979 2979
                 'default' => 10,
2980
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
2980
+                'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
2981 2981
         );
2982 2982
         //ONLY add the screen option if the user has access to it.
2983 2983
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3010,8 +3010,8 @@  discard block
 block discarded – undo
3010 3010
             $map_option = $option;
3011 3011
             $option = str_replace('-', '_', $option);
3012 3012
             switch ($map_option) {
3013
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3014
-                    $value = (int)$value;
3013
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3014
+                    $value = (int) $value;
3015 3015
                     if ($value < 1 || $value > 999) {
3016 3016
                         return;
3017 3017
                     }
@@ -3038,7 +3038,7 @@  discard block
 block discarded – undo
3038 3038
      */
3039 3039
     public function set_template_args($data)
3040 3040
     {
3041
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3041
+        $this->_template_args = array_merge($this->_template_args, (array) $data);
3042 3042
     }
3043 3043
 
3044 3044
 
@@ -3060,12 +3060,12 @@  discard block
 block discarded – undo
3060 3060
             $this->_verify_route($route);
3061 3061
         }
3062 3062
         //now let's set the string for what kind of transient we're setting
3063
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3063
+        $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id;
3064 3064
         $data = $notices ? array('notices' => $data) : $data;
3065 3065
         //is there already a transient for this route?  If there is then let's ADD to that transient
3066 3066
         $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3067 3067
         if ($existing) {
3068
-            $data = array_merge((array)$data, (array)$existing);
3068
+            $data = array_merge((array) $data, (array) $existing);
3069 3069
         }
3070 3070
         if (is_multisite() && is_network_admin()) {
3071 3071
             set_site_transient($transient, $data, 8);
@@ -3086,7 +3086,7 @@  discard block
 block discarded – undo
3086 3086
     {
3087 3087
         $user_id = get_current_user_id();
3088 3088
         $route = ! $route ? $this->_req_action : $route;
3089
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3089
+        $transient = $notices ? 'ee_rte_n_tx_'.$route.'_'.$user_id : 'rte_tx_'.$route.'_'.$user_id;
3090 3090
         $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3091 3091
         //delete transient after retrieval (just in case it hasn't expired);
3092 3092
         if (is_multisite() && is_network_admin()) {
@@ -3327,7 +3327,7 @@  discard block
 block discarded – undo
3327 3327
      */
3328 3328
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3329 3329
     {
3330
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3330
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3331 3331
     }
3332 3332
 
3333 3333
 
@@ -3341,7 +3341,7 @@  discard block
 block discarded – undo
3341 3341
      */
3342 3342
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3343 3343
     {
3344
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3344
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
3345 3345
     }
3346 3346
 
3347 3347
 
Please login to merge, or discard this patch.
core/db_models/fields/EE_Enum_Integer_Field.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4
-require_once(EE_MODELS . 'fields/EE_Integer_Field.php');
4
+require_once(EE_MODELS.'fields/EE_Integer_Field.php');
5 5
 
6 6
 /**
7 7
  * Class EE_Enum_Integer_Field
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      */
40 40
     protected function _allowed_enum_values()
41 41
     {
42
-        return (array)apply_filters(
42
+        return (array) apply_filters(
43 43
             'FHEE__EE_Enum_Integer_Field___allowed_enum_options',
44 44
             $this->_allowed_enum_values,
45 45
             $this
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             }
78 78
             return $this->get_default_value();
79 79
         }
80
-        return (int)$value_inputted_for_field_on_model_object;
80
+        return (int) $value_inputted_for_field_on_model_object;
81 81
     }
82 82
 
83 83
 
Please login to merge, or discard this patch.
Indentation   +105 added lines, -105 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
 require_once(EE_MODELS . 'fields/EE_Integer_Field.php');
5 5
 
@@ -13,117 +13,117 @@  discard block
 block discarded – undo
13 13
  */
14 14
 class EE_Enum_Integer_Field extends EE_Integer_Field
15 15
 {
16
-    /**
17
-     * @var array $_allowed_enum_values
18
-     */
19
-    public $_allowed_enum_values;
16
+	/**
17
+	 * @var array $_allowed_enum_values
18
+	 */
19
+	public $_allowed_enum_values;
20 20
 
21
-    /**
22
-     * @param string  $table_column
23
-     * @param string  $nicename
24
-     * @param boolean $nullable
25
-     * @param int     $default_value
26
-     * @param array   $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed
27
-     */
28
-    public function __construct($table_column, $nicename, $nullable, $default_value, $allowed_enum_values)
29
-    {
30
-        $this->_allowed_enum_values = $allowed_enum_values;
31
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
32
-    }
21
+	/**
22
+	 * @param string  $table_column
23
+	 * @param string  $nicename
24
+	 * @param boolean $nullable
25
+	 * @param int     $default_value
26
+	 * @param array   $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed
27
+	 */
28
+	public function __construct($table_column, $nicename, $nullable, $default_value, $allowed_enum_values)
29
+	{
30
+		$this->_allowed_enum_values = $allowed_enum_values;
31
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
32
+	}
33 33
 
34
-    /**
35
-     * Returns the list of allowed enum options, but filterable.
36
-     * This is used internally
37
-     *
38
-     * @return array
39
-     */
40
-    protected function _allowed_enum_values()
41
-    {
42
-        return (array)apply_filters(
43
-            'FHEE__EE_Enum_Integer_Field___allowed_enum_options',
44
-            $this->_allowed_enum_values,
45
-            $this
46
-        );
47
-    }
34
+	/**
35
+	 * Returns the list of allowed enum options, but filterable.
36
+	 * This is used internally
37
+	 *
38
+	 * @return array
39
+	 */
40
+	protected function _allowed_enum_values()
41
+	{
42
+		return (array)apply_filters(
43
+			'FHEE__EE_Enum_Integer_Field___allowed_enum_options',
44
+			$this->_allowed_enum_values,
45
+			$this
46
+		);
47
+	}
48 48
 
49
-    /**
50
-     * When setting, just verify that the value being used matches what we've defined as allowable enum values.
51
-     * If not, throw an error (but if WP_DEBUG is false, just set the value to default)
52
-     *
53
-     * @param int $value_inputted_for_field_on_model_object
54
-     * @return int
55
-     * @throws EE_Error
56
-     */
57
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
58
-    {
59
-        $allowed_enum_values = $this->_allowed_enum_values();
60
-        if (
61
-            $value_inputted_for_field_on_model_object !== null
62
-            && ! array_key_exists($value_inputted_for_field_on_model_object, $allowed_enum_values)
63
-        ) {
64
-            if (defined('WP_DEBUG') && WP_DEBUG) {
65
-                $msg = sprintf(
66
-                    __('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'),
67
-                    $value_inputted_for_field_on_model_object,
68
-                    $this->_name
69
-                );
70
-                $msg2 = sprintf(
71
-                    __('Allowed values for "%1$s" are "%2$s". You provided "%3$s"', 'event_espresso'),
72
-                    $this->_name,
73
-                    implode(', ', array_keys($allowed_enum_values)),
74
-                    $value_inputted_for_field_on_model_object
75
-                );
76
-                EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__);
77
-            }
78
-            return $this->get_default_value();
79
-        }
80
-        return (int)$value_inputted_for_field_on_model_object;
81
-    }
49
+	/**
50
+	 * When setting, just verify that the value being used matches what we've defined as allowable enum values.
51
+	 * If not, throw an error (but if WP_DEBUG is false, just set the value to default)
52
+	 *
53
+	 * @param int $value_inputted_for_field_on_model_object
54
+	 * @return int
55
+	 * @throws EE_Error
56
+	 */
57
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
58
+	{
59
+		$allowed_enum_values = $this->_allowed_enum_values();
60
+		if (
61
+			$value_inputted_for_field_on_model_object !== null
62
+			&& ! array_key_exists($value_inputted_for_field_on_model_object, $allowed_enum_values)
63
+		) {
64
+			if (defined('WP_DEBUG') && WP_DEBUG) {
65
+				$msg = sprintf(
66
+					__('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'),
67
+					$value_inputted_for_field_on_model_object,
68
+					$this->_name
69
+				);
70
+				$msg2 = sprintf(
71
+					__('Allowed values for "%1$s" are "%2$s". You provided "%3$s"', 'event_espresso'),
72
+					$this->_name,
73
+					implode(', ', array_keys($allowed_enum_values)),
74
+					$value_inputted_for_field_on_model_object
75
+				);
76
+				EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__);
77
+			}
78
+			return $this->get_default_value();
79
+		}
80
+		return (int)$value_inputted_for_field_on_model_object;
81
+	}
82 82
 
83 83
 
84 84
 
85
-    /**
86
-     * Gets the pretty version of the enum's value.
87
-     *
88
-     * @param int | string $value_on_field_to_be_outputted
89
-     * @param null         $schema
90
-     * @return string
91
-     */
92
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
93
-    {
94
-        $options = $this->_allowed_enum_values();
95
-        if (isset($options[$value_on_field_to_be_outputted])) {
96
-            return $options[$value_on_field_to_be_outputted];
97
-        } else {
98
-            return $value_on_field_to_be_outputted;
99
-        }
100
-    }
85
+	/**
86
+	 * Gets the pretty version of the enum's value.
87
+	 *
88
+	 * @param int | string $value_on_field_to_be_outputted
89
+	 * @param null         $schema
90
+	 * @return string
91
+	 */
92
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
93
+	{
94
+		$options = $this->_allowed_enum_values();
95
+		if (isset($options[$value_on_field_to_be_outputted])) {
96
+			return $options[$value_on_field_to_be_outputted];
97
+		} else {
98
+			return $value_on_field_to_be_outputted;
99
+		}
100
+	}
101 101
 
102 102
 
103 103
 
104
-    public function get_schema()
105
-    {
106
-        $schema = parent::get_schema();
107
-        $schema['type'] = 'object';
108
-        $schema['properties'] = array(
109
-            'raw' => array(
110
-                'description' =>  sprintf(
111
-                    __('%s - the value in the database.', 'event_espresso'),
112
-                    $this->get_nicename()
113
-                ),
114
-                'enum' => array_keys($this->_allowed_enum_values),
115
-                'type' => 'integer'
116
-            ),
117
-            'pretty' => array(
118
-                'description' =>  sprintf(
119
-                    __('%s - the value for display.', 'event_espresso'),
120
-                    $this->get_nicename()
121
-                ),
122
-                'enum' => array_values($this->_allowed_enum_values),
123
-                'type' => 'string',
124
-                'read_only' => true
125
-            )
126
-        );
127
-        return $schema;
128
-    }
104
+	public function get_schema()
105
+	{
106
+		$schema = parent::get_schema();
107
+		$schema['type'] = 'object';
108
+		$schema['properties'] = array(
109
+			'raw' => array(
110
+				'description' =>  sprintf(
111
+					__('%s - the value in the database.', 'event_espresso'),
112
+					$this->get_nicename()
113
+				),
114
+				'enum' => array_keys($this->_allowed_enum_values),
115
+				'type' => 'integer'
116
+			),
117
+			'pretty' => array(
118
+				'description' =>  sprintf(
119
+					__('%s - the value for display.', 'event_espresso'),
120
+					$this->get_nicename()
121
+				),
122
+				'enum' => array_values($this->_allowed_enum_values),
123
+				'type' => 'string',
124
+				'read_only' => true
125
+			)
126
+		);
127
+		return $schema;
128
+	}
129 129
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Enum_Text_Field.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-require_once(EE_MODELS . 'fields/EE_Text_Field_Base.php');
2
+require_once(EE_MODELS.'fields/EE_Text_Field_Base.php');
3 3
 
4 4
 class EE_Plain_Text_Field extends EE_Text_Field_Base
5 5
 {
Please login to merge, or discard this patch.
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -12,135 +12,135 @@
 block discarded – undo
12 12
 class EE_Enum_Text_Field extends EE_Text_Field_Base
13 13
 {
14 14
 
15
-    /**
16
-     * @var array $_allowed_enum_values
17
-     */
18
-    public $_allowed_enum_values;
19
-
20
-
21
-
22
-    /**
23
-     * @param string  $table_column
24
-     * @param string  $nice_name
25
-     * @param boolean $nullable
26
-     * @param mixed   $default_value
27
-     * @param array   $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed
28
-     */
29
-    function __construct($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values)
30
-    {
31
-        $this->_allowed_enum_values = $allowed_enum_values;
32
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
33
-    }
34
-
35
-
36
-
37
-    /**
38
-     * Returns the list of allowed enum options, but filterable.
39
-     * This is used internally
40
-     *
41
-     * @return array
42
-     */
43
-    protected function _allowed_enum_values()
44
-    {
45
-        return apply_filters(
46
-            'FHEE__EE_Enum_Text_Field___allowed_enum_options',
47
-            $this->_allowed_enum_values,
48
-            $this
49
-        );
50
-    }
51
-
52
-
53
-
54
-    /**
55
-     * When setting, just verify that the value being used matches what we've defined as allowable enum values.
56
-     * If not, throw an error (but if WP_DEBUG is false, just set the value to default).
57
-     *
58
-     * @param string $value_inputted_for_field_on_model_object
59
-     * @return string
60
-     * @throws EE_Error
61
-     */
62
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
63
-    {
64
-        if (
65
-            $value_inputted_for_field_on_model_object !== null
66
-            && ! array_key_exists($value_inputted_for_field_on_model_object, $this->_allowed_enum_values())
67
-        ) {
68
-            if (defined('WP_DEBUG') && WP_DEBUG) {
69
-                $msg = sprintf(
70
-                    __('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'),
71
-                    $value_inputted_for_field_on_model_object,
72
-                    $this->_name
73
-                );
74
-                $msg2 = sprintf(
75
-                    __('Allowed values for "%1$s" are "%2$s". You provided: "%3$s"', 'event_espresso'),
76
-                    $this->_name,
77
-                    implode(', ', array_keys($this->_allowed_enum_values())),
78
-                    $value_inputted_for_field_on_model_object
79
-                );
80
-                EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__);
81
-            }
82
-            return $this->get_default_value();
83
-        }
84
-        return $value_inputted_for_field_on_model_object;
85
-    }
86
-
87
-
88
-    /**
89
-     * Gets the pretty version of the enum's value.
90
-     *
91
-     * @param     int |string $value_on_field_to_be_outputted
92
-     * @param    null         $schema
93
-     * @return    string
94
-     */
95
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
96
-    {
97
-        $options = $this->_allowed_enum_values();
98
-        if (isset($options[$value_on_field_to_be_outputted])) {
99
-            return $options[$value_on_field_to_be_outputted];
100
-        } else {
101
-            return $value_on_field_to_be_outputted;
102
-        }
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     * When retrieving something from the DB, don't enforce the enum's options. If it's in the DB, we just have to live
109
-     * with that. Note also: when we're saving to the DB again, we also don't enforce the enum options. It's ONLY
110
-     * when we're receiving USER input from prepare_for_set() that we enforce the enum options.
111
-     *
112
-     * @param mixed $value_in_db
113
-     * @return mixed
114
-     */
115
-    public function prepare_for_set_from_db($value_in_db)
116
-    {
117
-        return $value_in_db;
118
-    }
119
-
120
-
121
-    public function get_schema()
122
-    {
123
-        $schema = parent::get_schema();
124
-        $schema['type'] = 'object';
125
-        $schema['properties'] = array(
126
-            'raw' => array(
127
-                'description' =>  sprintf(
128
-                    __('%s - the value in the database.', 'event_espresso'),
129
-                    $this->get_nicename()
130
-                ),
131
-                'type' => 'string',
132
-                'enum' => array_keys($this->_allowed_enum_values)
133
-            ),
134
-            'pretty' => array(
135
-                'description' =>  sprintf(
136
-                    __('%s - the value for display.', 'event_espresso'),
137
-                    $this->get_nicename()
138
-                ),
139
-                'type' => 'string',
140
-                'enum' => array_values($this->_allowed_enum_values),
141
-                'read_only' => true
142
-            )
143
-        );
144
-        return $schema;
145
-    }
15
+	/**
16
+	 * @var array $_allowed_enum_values
17
+	 */
18
+	public $_allowed_enum_values;
19
+
20
+
21
+
22
+	/**
23
+	 * @param string  $table_column
24
+	 * @param string  $nice_name
25
+	 * @param boolean $nullable
26
+	 * @param mixed   $default_value
27
+	 * @param array   $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed
28
+	 */
29
+	function __construct($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values)
30
+	{
31
+		$this->_allowed_enum_values = $allowed_enum_values;
32
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
33
+	}
34
+
35
+
36
+
37
+	/**
38
+	 * Returns the list of allowed enum options, but filterable.
39
+	 * This is used internally
40
+	 *
41
+	 * @return array
42
+	 */
43
+	protected function _allowed_enum_values()
44
+	{
45
+		return apply_filters(
46
+			'FHEE__EE_Enum_Text_Field___allowed_enum_options',
47
+			$this->_allowed_enum_values,
48
+			$this
49
+		);
50
+	}
51
+
52
+
53
+
54
+	/**
55
+	 * When setting, just verify that the value being used matches what we've defined as allowable enum values.
56
+	 * If not, throw an error (but if WP_DEBUG is false, just set the value to default).
57
+	 *
58
+	 * @param string $value_inputted_for_field_on_model_object
59
+	 * @return string
60
+	 * @throws EE_Error
61
+	 */
62
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
63
+	{
64
+		if (
65
+			$value_inputted_for_field_on_model_object !== null
66
+			&& ! array_key_exists($value_inputted_for_field_on_model_object, $this->_allowed_enum_values())
67
+		) {
68
+			if (defined('WP_DEBUG') && WP_DEBUG) {
69
+				$msg = sprintf(
70
+					__('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'),
71
+					$value_inputted_for_field_on_model_object,
72
+					$this->_name
73
+				);
74
+				$msg2 = sprintf(
75
+					__('Allowed values for "%1$s" are "%2$s". You provided: "%3$s"', 'event_espresso'),
76
+					$this->_name,
77
+					implode(', ', array_keys($this->_allowed_enum_values())),
78
+					$value_inputted_for_field_on_model_object
79
+				);
80
+				EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__);
81
+			}
82
+			return $this->get_default_value();
83
+		}
84
+		return $value_inputted_for_field_on_model_object;
85
+	}
86
+
87
+
88
+	/**
89
+	 * Gets the pretty version of the enum's value.
90
+	 *
91
+	 * @param     int |string $value_on_field_to_be_outputted
92
+	 * @param    null         $schema
93
+	 * @return    string
94
+	 */
95
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
96
+	{
97
+		$options = $this->_allowed_enum_values();
98
+		if (isset($options[$value_on_field_to_be_outputted])) {
99
+			return $options[$value_on_field_to_be_outputted];
100
+		} else {
101
+			return $value_on_field_to_be_outputted;
102
+		}
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 * When retrieving something from the DB, don't enforce the enum's options. If it's in the DB, we just have to live
109
+	 * with that. Note also: when we're saving to the DB again, we also don't enforce the enum options. It's ONLY
110
+	 * when we're receiving USER input from prepare_for_set() that we enforce the enum options.
111
+	 *
112
+	 * @param mixed $value_in_db
113
+	 * @return mixed
114
+	 */
115
+	public function prepare_for_set_from_db($value_in_db)
116
+	{
117
+		return $value_in_db;
118
+	}
119
+
120
+
121
+	public function get_schema()
122
+	{
123
+		$schema = parent::get_schema();
124
+		$schema['type'] = 'object';
125
+		$schema['properties'] = array(
126
+			'raw' => array(
127
+				'description' =>  sprintf(
128
+					__('%s - the value in the database.', 'event_espresso'),
129
+					$this->get_nicename()
130
+				),
131
+				'type' => 'string',
132
+				'enum' => array_keys($this->_allowed_enum_values)
133
+			),
134
+			'pretty' => array(
135
+				'description' =>  sprintf(
136
+					__('%s - the value for display.', 'event_espresso'),
137
+					$this->get_nicename()
138
+				),
139
+				'type' => 'string',
140
+				'enum' => array_values($this->_allowed_enum_values),
141
+				'read_only' => true
142
+			)
143
+		);
144
+		return $schema;
145
+	}
146 146
 }
Please login to merge, or discard this patch.
core/services/database/TableManager.php 2 patches
Indentation   +207 added lines, -209 removed lines patch added patch discarded remove patch
@@ -17,216 +17,214 @@
 block discarded – undo
17 17
 class TableManager extends \EE_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var TableAnalysis $table_analysis
22
-     */
23
-    private $table_analysis;
24
-
25
-
26
-
27
-    /**
28
-     * TableManager constructor.
29
-     *
30
-     * @param TableAnalysis $TableAnalysis
31
-     */
32
-    public function __construct(TableAnalysis $TableAnalysis)
33
-    {
34
-        $this->table_analysis = $TableAnalysis;
35
-    }
36
-
37
-
38
-
39
-    /**
40
-     * Gets the injected table analyzer, or throws an exception
41
-     *
42
-     * @return TableAnalysis
43
-     * @throws \EE_Error
44
-     */
45
-    protected function getTableAnalysis()
46
-    {
47
-        if ($this->table_analysis instanceof TableAnalysis) {
48
-            return $this->table_analysis;
49
-        } else {
50
-            throw new \EE_Error(
51
-                sprintf(
52
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
53
-                    get_class($this)
54
-                )
55
-            );
56
-        }
57
-    }
58
-
59
-
60
-
61
-    /**
62
-     * @param string $table_name which can optionally start with $wpdb->prefix or not
63
-     * @param string $column_name
64
-     * @param string $column_info
65
-     * @return bool|false|int
66
-     */
67
-    public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL')
68
-    {
69
-        if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
70
-            return false;
71
-        }
72
-        global $wpdb;
73
-        $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
74
-        $columns = $this->getTableColumns($table_name);
75
-        if ( ! in_array($column_name, $columns)) {
76
-            $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}";
77
-            return $wpdb->query($alter_query);
78
-        }
79
-        return true;
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * Gets the name of all columns on the  table. $table_name can
86
-     * optionally start with $wpdb->prefix or not
87
-     *
88
-     * @global \wpdb $wpdb
89
-     * @param string $table_name
90
-     * @return array
91
-     */
92
-    public function getTableColumns($table_name)
93
-    {
94
-        global $wpdb;
95
-        $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
96
-        $field_array = array();
97
-        if ( ! empty($table_name)) {
98
-            $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} ");
99
-            if ($columns !== false) {
100
-                foreach ($columns as $column) {
101
-                    $field_array[] = $column->Field;
102
-                }
103
-            }
104
-        }
105
-        return $field_array;
106
-    }
107
-
108
-
109
-
110
-    /**
111
-     * Drops the specified table from the database. $table_name can
112
-     * optionally start with $wpdb->prefix or not
113
-     *
114
-     * @global \wpdb $wpdb
115
-     * @param string $table_name
116
-     * @return int
117
-     */
118
-    public function dropTable($table_name)
119
-    {
120
-        global $wpdb;
121
-        if ($this->getTableAnalysis()->tableExists($table_name)) {
122
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
123
-            return $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
124
-        }
125
-        return 0;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
132
-     * each table name provided has a wpdb prefix attached, and that it exists.
133
-     * Returns the list actually deleted
134
-     *
135
-     * @global WPDB $wpdb
136
-     * @param array $table_names
137
-     * @return array of table names which we deleted
138
-     */
139
-    public function dropTables($table_names)
140
-    {
141
-        $tables_to_delete = array();
142
-        foreach ($table_names as $table_name) {
143
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
144
-            if ($this->getTableAnalysis()->tableExists($table_name)) {
145
-                $tables_to_delete[] = $table_name;
146
-            }
147
-        }
148
-        if( ! empty( $tables_to_delete ) ) {
149
-            global $wpdb;
150
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
151
-        }
152
-        return $tables_to_delete;
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * Drops the specified index from the specified table. $table_name can
159
-     * optionally start with $wpdb->prefix or not
160
-
161
-     *
20
+	/**
21
+	 * @var TableAnalysis $table_analysis
22
+	 */
23
+	private $table_analysis;
24
+
25
+
26
+
27
+	/**
28
+	 * TableManager constructor.
29
+	 *
30
+	 * @param TableAnalysis $TableAnalysis
31
+	 */
32
+	public function __construct(TableAnalysis $TableAnalysis)
33
+	{
34
+		$this->table_analysis = $TableAnalysis;
35
+	}
36
+
37
+
38
+
39
+	/**
40
+	 * Gets the injected table analyzer, or throws an exception
41
+	 *
42
+	 * @return TableAnalysis
43
+	 * @throws \EE_Error
44
+	 */
45
+	protected function getTableAnalysis()
46
+	{
47
+		if ($this->table_analysis instanceof TableAnalysis) {
48
+			return $this->table_analysis;
49
+		} else {
50
+			throw new \EE_Error(
51
+				sprintf(
52
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
53
+					get_class($this)
54
+				)
55
+			);
56
+		}
57
+	}
58
+
59
+
60
+
61
+	/**
62
+	 * @param string $table_name which can optionally start with $wpdb->prefix or not
63
+	 * @param string $column_name
64
+	 * @param string $column_info
65
+	 * @return bool|false|int
66
+	 */
67
+	public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL')
68
+	{
69
+		if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
70
+			return false;
71
+		}
72
+		global $wpdb;
73
+		$full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
74
+		$columns = $this->getTableColumns($table_name);
75
+		if ( ! in_array($column_name, $columns)) {
76
+			$alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}";
77
+			return $wpdb->query($alter_query);
78
+		}
79
+		return true;
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * Gets the name of all columns on the  table. $table_name can
86
+	 * optionally start with $wpdb->prefix or not
87
+	 *
88
+	 * @global \wpdb $wpdb
89
+	 * @param string $table_name
90
+	 * @return array
91
+	 */
92
+	public function getTableColumns($table_name)
93
+	{
94
+		global $wpdb;
95
+		$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
96
+		$field_array = array();
97
+		if ( ! empty($table_name)) {
98
+			$columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} ");
99
+			if ($columns !== false) {
100
+				foreach ($columns as $column) {
101
+					$field_array[] = $column->Field;
102
+				}
103
+			}
104
+		}
105
+		return $field_array;
106
+	}
107
+
108
+
109
+
110
+	/**
111
+	 * Drops the specified table from the database. $table_name can
112
+	 * optionally start with $wpdb->prefix or not
113
+	 *
114
+	 * @global \wpdb $wpdb
115
+	 * @param string $table_name
116
+	 * @return int
117
+	 */
118
+	public function dropTable($table_name)
119
+	{
120
+		global $wpdb;
121
+		if ($this->getTableAnalysis()->tableExists($table_name)) {
122
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
123
+			return $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
124
+		}
125
+		return 0;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
132
+	 * each table name provided has a wpdb prefix attached, and that it exists.
133
+	 * Returns the list actually deleted
134
+	 *
135
+	 * @global WPDB $wpdb
136
+	 * @param array $table_names
137
+	 * @return array of table names which we deleted
138
+	 */
139
+	public function dropTables($table_names)
140
+	{
141
+		$tables_to_delete = array();
142
+		foreach ($table_names as $table_name) {
143
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
144
+			if ($this->getTableAnalysis()->tableExists($table_name)) {
145
+				$tables_to_delete[] = $table_name;
146
+			}
147
+		}
148
+		if( ! empty( $tables_to_delete ) ) {
149
+			global $wpdb;
150
+			$wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
151
+		}
152
+		return $tables_to_delete;
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * Drops the specified index from the specified table. $table_name can
159
+	 * optionally start with $wpdb->prefix or not
160
+	 *
162 161
 *@global \wpdb       $wpdb
163
-     * @param string $table_name
164
-     * @param string $index_name
165
-     * @return int
166
-     */
167
-    public function dropIndex($table_name, $index_name)
168
-    {
169
-        if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
170
-            return false;
171
-        }
172
-        global $wpdb;
173
-        $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
174
-        $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'";
175
-        if (
176
-            $this->getTableAnalysis()->tableExists($table_name)
177
-            && $wpdb->get_var($index_exists_query)
178
-               === $table_name //using get_var with the $index_exists_query returns the table's name
179
-        ) {
180
-            return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
181
-        }
182
-        return 0;
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Just creates the requested table. $table_name can
189
-     * optionally start with $wpdb->prefix or not
190
-
191
-     *
162
+	 * @param string $table_name
163
+	 * @param string $index_name
164
+	 * @return int
165
+	 */
166
+	public function dropIndex($table_name, $index_name)
167
+	{
168
+		if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
169
+			return false;
170
+		}
171
+		global $wpdb;
172
+		$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
173
+		$index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'";
174
+		if (
175
+			$this->getTableAnalysis()->tableExists($table_name)
176
+			&& $wpdb->get_var($index_exists_query)
177
+			   === $table_name //using get_var with the $index_exists_query returns the table's name
178
+		) {
179
+			return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
180
+		}
181
+		return 0;
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Just creates the requested table. $table_name can
188
+	 * optionally start with $wpdb->prefix or not
189
+	 *
192 190
 *@param string       $table_name
193
-     * @param string $create_sql defining the table's columns and indexes
194
-     * @param string $engine     (no need to specify "ENGINE=", that's implied)
195
-     * @return void
196
-     * @throws \EE_Error
197
-     */
198
-    public function createTable($table_name, $create_sql, $engine = 'MyISAM')
199
-    {
200
-        // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
201
-        if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
202
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
203
-            /** @var \wpdb $wpdb */
204
-            global $wpdb;
205
-            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
206
-
207
-            //get $wpdb to echo errors, but buffer them. This way at least WE know an error
208
-            //happened. And then we can choose to tell the end user
209
-            $old_show_errors_policy = $wpdb->show_errors(true);
210
-            $old_error_suppression_policy = $wpdb->suppress_errors(false);
211
-            ob_start();
212
-            dbDelta($SQL);
213
-            $output = ob_get_contents();
214
-            ob_end_clean();
215
-            $wpdb->show_errors($old_show_errors_policy);
216
-            $wpdb->suppress_errors($old_error_suppression_policy);
217
-            if ( ! empty($output)) {
218
-                throw new \EE_Error($output);
219
-            }
220
-        } else {
221
-            throw new \EE_Error(
222
-                sprintf(
223
-                    __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
224
-                        'event_espresso'),
225
-                    '<br />',
226
-                    $create_sql
227
-                )
228
-            );
229
-        }
230
-    }
191
+	 * @param string $create_sql defining the table's columns and indexes
192
+	 * @param string $engine     (no need to specify "ENGINE=", that's implied)
193
+	 * @return void
194
+	 * @throws \EE_Error
195
+	 */
196
+	public function createTable($table_name, $create_sql, $engine = 'MyISAM')
197
+	{
198
+		// does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
199
+		if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
200
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
201
+			/** @var \wpdb $wpdb */
202
+			global $wpdb;
203
+			$SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
204
+
205
+			//get $wpdb to echo errors, but buffer them. This way at least WE know an error
206
+			//happened. And then we can choose to tell the end user
207
+			$old_show_errors_policy = $wpdb->show_errors(true);
208
+			$old_error_suppression_policy = $wpdb->suppress_errors(false);
209
+			ob_start();
210
+			dbDelta($SQL);
211
+			$output = ob_get_contents();
212
+			ob_end_clean();
213
+			$wpdb->show_errors($old_show_errors_policy);
214
+			$wpdb->suppress_errors($old_error_suppression_policy);
215
+			if ( ! empty($output)) {
216
+				throw new \EE_Error($output);
217
+			}
218
+		} else {
219
+			throw new \EE_Error(
220
+				sprintf(
221
+					__('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
222
+						'event_espresso'),
223
+					'<br />',
224
+					$create_sql
225
+				)
226
+			);
227
+		}
228
+	}
231 229
 
232 230
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
                 $tables_to_delete[] = $table_name;
146 146
             }
147 147
         }
148
-        if( ! empty( $tables_to_delete ) ) {
148
+        if ( ! empty($tables_to_delete)) {
149 149
             global $wpdb;
150
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
150
+            $wpdb->query('DROP TABLE '.implode(', ', $tables_to_delete));
151 151
         }
152 152
         return $tables_to_delete;
153 153
     }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
203 203
             /** @var \wpdb $wpdb */
204 204
             global $wpdb;
205
-            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
205
+            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} ".$wpdb->get_charset_collate();
206 206
 
207 207
             //get $wpdb to echo errors, but buffer them. This way at least WE know an error
208 208
             //happened. And then we can choose to tell the end user
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime.model.php 1 patch
Indentation   +541 added lines, -541 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
  *    Datetime Model
@@ -11,546 +11,546 @@  discard block
 block discarded – undo
11 11
 class EEM_Datetime extends EEM_Soft_Delete_Base
12 12
 {
13 13
 
14
-    // private instance of the EEM_Datetime object
15
-    protected static $_instance = null;
16
-
17
-
18
-
19
-    /**
20
-     *        private constructor to prevent direct creation
21
-     *
22
-     * @Constructor
23
-     * @access private
24
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
25
-     *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
26
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
27
-     *                         timezone in the 'timezone_string' wp option)
28
-     */
29
-    protected function __construct($timezone)
30
-    {
31
-        $this->singular_item = __('Datetime', 'event_espresso');
32
-        $this->plural_item = __('Datetimes', 'event_espresso');
33
-        $this->_tables = array(
34
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
35
-        );
36
-        $this->_fields = array(
37
-            'Datetime' => array(
38
-                'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
39
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0,
40
-                    'Event'),
41
-                'DTT_name'        => new EE_Plain_Text_Field('DTT_name', __('Datetime Name', 'event_espresso'), false,
42
-                    ''),
43
-                'DTT_description' => new EE_Post_Content_Field('DTT_description',
44
-                    __('Description for Datetime', 'event_espresso'), false, ''),
45
-                'DTT_EVT_start'   => new EE_Datetime_Field('DTT_EVT_start',
46
-                    __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
47
-                'DTT_EVT_end'     => new EE_Datetime_Field('DTT_EVT_end',
48
-                    __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
49
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field('DTT_reg_limit',
50
-                    __('Registration Limit for this time', 'event_espresso'), true, EE_INF),
51
-                'DTT_sold'        => new EE_Integer_Field('DTT_sold',
52
-                    __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0),
53
-                'DTT_reserved'    => new EE_Integer_Field('DTT_reserved',
54
-                    __('Quantity of tickets that are reserved, but not yet fully purchased', 'event_espresso'), false,
55
-                    0),
56
-                'DTT_is_primary'  => new EE_Boolean_Field('DTT_is_primary',
57
-                    __("Flag indicating datetime is primary one for event", "event_espresso"), false, false),
58
-                'DTT_order'       => new EE_Integer_Field('DTT_order',
59
-                    __('The order in which the Datetime is displayed', 'event_espresso'), false, 0),
60
-                'DTT_parent'      => new EE_Integer_Field('DTT_parent',
61
-                    __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0),
62
-                'DTT_deleted'     => new EE_Trashed_Flag_Field('DTT_deleted',
63
-                    __('Flag indicating datetime is archived', 'event_espresso'), false, false),
64
-            ),
65
-        );
66
-        $this->_model_relations = array(
67
-            'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
68
-            'Event'   => new EE_Belongs_To_Relation(),
69
-            'Checkin' => new EE_Has_Many_Relation(),
70
-        );
71
-        $this->_model_chain_to_wp_user = 'Event';
72
-        //this model is generally available for reading
73
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
74
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
75
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
76
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
77
-            EEM_Base::caps_edit);
78
-        parent::__construct($timezone);
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     *        create new blank datetime
85
-     *
86
-     * @access        public
87
-     * @return        EE_Datetime[]        array on success, FALSE on fail
88
-     */
89
-    public function create_new_blank_datetime()
90
-    {
91
-        //makes sure timezone is always set.
92
-        $timezone_string = $this->get_timezone();
93
-        $blank_datetime = EE_Datetime::new_instance(
94
-            array(
95
-                'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + (60 * 60 * 24 * 30),
96
-                'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + (60 * 60 * 24 * 30),
97
-                'DTT_order'     => 1,
98
-                'DTT_reg_limit' => EE_INF,
99
-            ),
100
-            $timezone_string
101
-        );
102
-        $blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
103
-            $timezone_string));
104
-        $blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string));
105
-        return array($blank_datetime);
106
-    }
107
-
108
-
109
-
110
-    /**
111
-     *        get event start date from db
112
-     *
113
-     * @access        public
114
-     * @param        int $EVT_ID
115
-     * @return        EE_Datetime[]        array on success, FALSE on fail
116
-     */
117
-    public function get_all_event_dates($EVT_ID = 0)
118
-    {
119
-        if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
120
-            return $this->create_new_blank_datetime();
121
-        }
122
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
123
-        if (empty($results)) {
124
-            return $this->create_new_blank_datetime();
125
-        }
126
-        return $results;
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * get all datetimes attached to an event ordered by the DTT_order field
133
-     *
134
-     * @public
135
-     * @param  int    $EVT_ID     event id
136
-     * @param boolean $include_expired
137
-     * @param boolean $include_deleted
138
-     * @param  int    $limit      If included then limit the count of results by
139
-     *                            the given number
140
-     * @return EE_Datetime[]
141
-     */
142
-    public function get_datetimes_for_event_ordered_by_DTT_order(
143
-        $EVT_ID,
144
-        $include_expired = true,
145
-        $include_deleted = true,
146
-        $limit = null
147
-    ) {
148
-        //sanitize EVT_ID
149
-        $EVT_ID = intval($EVT_ID);
150
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
151
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
152
-        $where_params = array('Event.EVT_ID' => $EVT_ID);
153
-        $query_params = ! empty($limit) ? array(
154
-            $where_params,
155
-            'limit'                    => $limit,
156
-            'order_by'                 => array('DTT_order' => 'ASC'),
157
-            'default_where_conditions' => 'none',
158
-        ) : array($where_params, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none');
159
-        if ( ! $include_expired) {
160
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
161
-        }
162
-        if ($include_deleted) {
163
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
164
-        }
165
-        $result = $this->get_all($query_params);
166
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
167
-        return $result;
168
-    }
169
-
170
-
171
-
172
-    /**
173
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
174
-     * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
175
-     * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
176
-     *
177
-     * @param int $EVT_ID
178
-     * @param int $limit
179
-     * @return EE_Datetime[]
180
-     */
181
-    public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
182
-    {
183
-        return $this->get_all(array(
184
-            array('Event.EVT_ID' => $EVT_ID),
185
-            'limit'                    => $limit,
186
-            'order_by'                 => array('DTT_EVT_start' => 'ASC'),
187
-            'default_where_conditions' => 'none',
188
-        ));
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * @param int     $EVT_ID
195
-     * @param boolean $include_expired
196
-     * @param boolean $include_deleted
197
-     * @return EE_Datetime
198
-     */
199
-    public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
200
-    {
201
-        $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
202
-        if ($results) {
203
-            return array_shift($results);
204
-        } else {
205
-            return null;
206
-        }
207
-    }
208
-
209
-
210
-
211
-    /**
212
-     * Gets the 'primary' datetime for an event.
213
-     *
214
-     * @param int  $EVT_ID
215
-     * @param bool $try_to_exclude_expired
216
-     * @param bool $try_to_exclude_deleted
217
-     * @return \EE_Datetime
218
-     */
219
-    public function get_primary_datetime_for_event(
220
-        $EVT_ID,
221
-        $try_to_exclude_expired = true,
222
-        $try_to_exclude_deleted = true
223
-    ) {
224
-        if ($try_to_exclude_expired) {
225
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
226
-            if ($non_expired) {
227
-                return $non_expired;
228
-            }
229
-        }
230
-        if ($try_to_exclude_deleted) {
231
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
232
-            if ($expired_even) {
233
-                return $expired_even;
234
-            }
235
-        }
236
-        $deleted_even = $this->get_oldest_datetime_for_event($EVT_ID, true, true);
237
-        return $deleted_even;
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
244
-     * only by start date
245
-     *
246
-     * @param int     $EVT_ID
247
-     * @param boolean $include_expired
248
-     * @param boolean $include_deleted
249
-     * @param int     $limit
250
-     * @return EE_Datetime[]
251
-     */
252
-    public function get_datetimes_for_event_ordered_by_start_time(
253
-        $EVT_ID,
254
-        $include_expired = true,
255
-        $include_deleted = true,
256
-        $limit = null
257
-    ) {
258
-        //sanitize EVT_ID
259
-        $EVT_ID = intval($EVT_ID);
260
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
261
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
262
-        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
263
-        if ( ! $include_expired) {
264
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
265
-        }
266
-        if ($include_deleted) {
267
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
268
-        }
269
-        if ($limit) {
270
-            $query_params['limit'] = $limit;
271
-        }
272
-        $result = $this->get_all($query_params);
273
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
274
-        return $result;
275
-    }
276
-
277
-
278
-
279
-    /**
280
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
281
-     * only by start date
282
-     *
283
-     * @param int     $TKT_ID
284
-     * @param boolean $include_expired
285
-     * @param boolean $include_deleted
286
-     * @param int     $limit
287
-     * @return EE_Datetime[]
288
-     */
289
-    public function get_datetimes_for_ticket_ordered_by_start_time(
290
-        $TKT_ID,
291
-        $include_expired = true,
292
-        $include_deleted = true,
293
-        $limit = null
294
-    ) {
295
-        //sanitize TKT_ID
296
-        $TKT_ID = intval($TKT_ID);
297
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
298
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
299
-        $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
300
-        if ( ! $include_expired) {
301
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
302
-        }
303
-        if ($include_deleted) {
304
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
305
-        }
306
-        if ($limit) {
307
-            $query_params['limit'] = $limit;
308
-        }
309
-        $result = $this->get_all($query_params);
310
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
311
-        return $result;
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
318
-     * datetimes.
319
-     *
320
-     * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
321
-     * @param  boolean  $include_expired whether to include expired datetimes or not
322
-     * @param  boolean  $include_deleted whether to include trashed datetimes or not.
323
-     * @param  int|null $limit           if null, no limit, if int then limit results by
324
-     *                                   that number
325
-     * @return EE_Datetime[]
326
-     */
327
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
328
-        $TKT_ID,
329
-        $include_expired = true,
330
-        $include_deleted = true,
331
-        $limit = null
332
-    ) {
333
-        //sanitize id.
334
-        $TKT_ID = intval($TKT_ID);
335
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
336
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
337
-        $where_params = array('Ticket.TKT_ID' => $TKT_ID);
338
-        $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
339
-        if ( ! $include_expired) {
340
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
341
-        }
342
-        if ($include_deleted) {
343
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
344
-        }
345
-        if ($limit) {
346
-            $query_params['limit'] = $limit;
347
-        }
348
-        $result = $this->get_all($query_params);
349
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
350
-        return $result;
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
357
-     * reason it doesn't exist, we consider the earliest event the most important)
358
-     *
359
-     * @param int $EVT_ID
360
-     * @return EE_Datetime
361
-     */
362
-    public function get_most_important_datetime_for_event($EVT_ID)
363
-    {
364
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
365
-        if ($results) {
366
-            return array_shift($results);
367
-        } else {
368
-            return null;
369
-        }
370
-    }
371
-
372
-
373
-
374
-    /**
375
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
376
-     * grouped by month and year.
377
-     *
378
-     * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
379
-     * @param  string $evt_active_status A string representing the evt active status to filter the months by.
380
-     *                                   Can be:
381
-     *                                   - '' = no filter
382
-     *                                   - upcoming = Published events with at least one upcoming datetime.
383
-     *                                   - expired = Events with all datetimes expired.
384
-     *                                   - active = Events that are published and have at least one datetime that
385
-     *                                   starts before now and ends after now.
386
-     *                                   - inactive = Events that are either not published.
387
-     * @return wpdb results array
388
-     */
389
-    public function get_dtt_months_and_years($where_params, $evt_active_status = '')
390
-    {
391
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
392
-        $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
393
-        switch ($evt_active_status) {
394
-            case 'upcoming' :
395
-                $where_params['Event.status'] = 'publish';
396
-                //if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
397
-                if (isset($where_params['DTT_EVT_start'])) {
398
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
399
-                }
400
-                $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
401
-                break;
402
-            case 'expired' :
403
-                if (isset($where_params['Event.status'])) {
404
-                    unset($where_params['Event.status']);
405
-                }
406
-                //get events to exclude
407
-                $exclude_query[0] = array_merge($where_params,
408
-                    array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
409
-                //first get all events that have datetimes where its not expired.
410
-                $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
411
-                $event_ids = array_keys($event_ids);
412
-                if (isset($where_params['DTT_EVT_end'])) {
413
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
414
-                }
415
-                $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
416
-                $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
417
-                break;
418
-            case 'active' :
419
-                $where_params['Event.status'] = 'publish';
420
-                if (isset($where_params['DTT_EVT_start'])) {
421
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
422
-                }
423
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
424
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
425
-                }
426
-                $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
427
-                $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
428
-                break;
429
-            case 'inactive' :
430
-                if (isset($where_params['Event.status'])) {
431
-                    unset($where_params['Event.status']);
432
-                }
433
-                if (isset($where_params['OR'])) {
434
-                    $where_params['AND']['OR'] = $where_params['OR'];
435
-                }
436
-                if (isset($where_params['DTT_EVT_end'])) {
437
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
438
-                    unset($where_params['DTT_EVT_end']);
439
-                }
440
-                if (isset($where_params['DTT_EVT_start'])) {
441
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
442
-                    unset($where_params['DTT_EVT_start']);
443
-                }
444
-                $where_params['AND']['Event.status'] = array('!=', 'publish');
445
-                break;
446
-        }
447
-        $query_params[0] = $where_params;
448
-        $query_params['group_by'] = array('dtt_year', 'dtt_month');
449
-        $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
450
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
451
-        $columns_to_select = array(
452
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
453
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
454
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
455
-        );
456
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
457
-    }
458
-
459
-
460
-
461
-    /**
462
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
463
-     * for the tickets for each datetime)
464
-     *
465
-     * @param EE_Datetime[] $datetimes
466
-     */
467
-    public function update_sold($datetimes)
468
-    {
469
-        foreach ($datetimes as $datetime) {
470
-            $datetime->update_sold();
471
-        }
472
-    }
473
-
474
-
475
-
476
-    /**
477
-     *    Gets the total number of tickets available at a particular datetime
478
-     *    (does NOT take into account the datetime's spaces available)
479
-     *
480
-     * @param int   $DTT_ID
481
-     * @param array $query_params
482
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
483
-     *             tickets attached to datetime then FALSE is returned.
484
-     */
485
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array())
486
-    {
487
-        $datetime = $this->get_one_by_ID($DTT_ID);
488
-        if ($datetime instanceof EE_Datetime) {
489
-            return $datetime->tickets_remaining($query_params);
490
-        }
491
-        return 0;
492
-    }
493
-
494
-
495
-
496
-    /**
497
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
498
-     *
499
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
500
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
501
-     *                                 for all valid stati.
502
-     * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
503
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
504
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
505
-     *                stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
506
-     */
507
-    public function get_datetime_counts_by_status($stati_to_include = array(), $query_params = array())
508
-    {
509
-        //only accept where conditions for this query.
510
-        $_where = isset($query_params[0]) ? $query_params[0] : array();
511
-        $status_query_args = array(
512
-            EE_Datetime::active   => array_merge(
513
-                $_where,
514
-                array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
515
-            ),
516
-            EE_Datetime::upcoming => array_merge(
517
-                $_where,
518
-                array('DTT_EVT_start' => array('>', time()))
519
-            ),
520
-            EE_Datetime::expired  => array_merge(
521
-                $_where,
522
-                array('DTT_EVT_end' => array('<', time()))
523
-            ),
524
-        );
525
-        if ( ! empty($stati_to_include)) {
526
-            foreach (array_keys($status_query_args) as $status) {
527
-                if ( ! in_array($status, $stati_to_include)) {
528
-                    unset($status_query_args[$status]);
529
-                }
530
-            }
531
-        }
532
-        //loop through and query counts for each stati.
533
-        $status_query_results = array();
534
-        foreach ($status_query_args as $status => $status_where_conditions) {
535
-            $status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
536
-        }
537
-        return $status_query_results;
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     * Returns the specific count for a given Datetime status matching any given query_params.
544
-     *
545
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
546
-     * @param array  $query_params
547
-     * @return int
548
-     */
549
-    public function get_datetime_count_for_status($status = EE_Datetime::active, $query_params = array())
550
-    {
551
-        $count = $this->get_datetime_counts_by_status(array($status), $query_params);
552
-        return ! empty($count[$status]) ? $count[$status] : 0;
553
-    }
14
+	// private instance of the EEM_Datetime object
15
+	protected static $_instance = null;
16
+
17
+
18
+
19
+	/**
20
+	 *        private constructor to prevent direct creation
21
+	 *
22
+	 * @Constructor
23
+	 * @access private
24
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
25
+	 *                         incoming timezone data that gets saved).  Note this just sends the timezone info to the
26
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
27
+	 *                         timezone in the 'timezone_string' wp option)
28
+	 */
29
+	protected function __construct($timezone)
30
+	{
31
+		$this->singular_item = __('Datetime', 'event_espresso');
32
+		$this->plural_item = __('Datetimes', 'event_espresso');
33
+		$this->_tables = array(
34
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
35
+		);
36
+		$this->_fields = array(
37
+			'Datetime' => array(
38
+				'DTT_ID'          => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')),
39
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0,
40
+					'Event'),
41
+				'DTT_name'        => new EE_Plain_Text_Field('DTT_name', __('Datetime Name', 'event_espresso'), false,
42
+					''),
43
+				'DTT_description' => new EE_Post_Content_Field('DTT_description',
44
+					__('Description for Datetime', 'event_espresso'), false, ''),
45
+				'DTT_EVT_start'   => new EE_Datetime_Field('DTT_EVT_start',
46
+					__('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
47
+				'DTT_EVT_end'     => new EE_Datetime_Field('DTT_EVT_end',
48
+					__('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
49
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field('DTT_reg_limit',
50
+					__('Registration Limit for this time', 'event_espresso'), true, EE_INF),
51
+				'DTT_sold'        => new EE_Integer_Field('DTT_sold',
52
+					__('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0),
53
+				'DTT_reserved'    => new EE_Integer_Field('DTT_reserved',
54
+					__('Quantity of tickets that are reserved, but not yet fully purchased', 'event_espresso'), false,
55
+					0),
56
+				'DTT_is_primary'  => new EE_Boolean_Field('DTT_is_primary',
57
+					__("Flag indicating datetime is primary one for event", "event_espresso"), false, false),
58
+				'DTT_order'       => new EE_Integer_Field('DTT_order',
59
+					__('The order in which the Datetime is displayed', 'event_espresso'), false, 0),
60
+				'DTT_parent'      => new EE_Integer_Field('DTT_parent',
61
+					__('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0),
62
+				'DTT_deleted'     => new EE_Trashed_Flag_Field('DTT_deleted',
63
+					__('Flag indicating datetime is archived', 'event_espresso'), false, false),
64
+			),
65
+		);
66
+		$this->_model_relations = array(
67
+			'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
68
+			'Event'   => new EE_Belongs_To_Relation(),
69
+			'Checkin' => new EE_Has_Many_Relation(),
70
+		);
71
+		$this->_model_chain_to_wp_user = 'Event';
72
+		//this model is generally available for reading
73
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event');
74
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event');
75
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event');
76
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event',
77
+			EEM_Base::caps_edit);
78
+		parent::__construct($timezone);
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 *        create new blank datetime
85
+	 *
86
+	 * @access        public
87
+	 * @return        EE_Datetime[]        array on success, FALSE on fail
88
+	 */
89
+	public function create_new_blank_datetime()
90
+	{
91
+		//makes sure timezone is always set.
92
+		$timezone_string = $this->get_timezone();
93
+		$blank_datetime = EE_Datetime::new_instance(
94
+			array(
95
+				'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + (60 * 60 * 24 * 30),
96
+				'DTT_EVT_end'   => $this->current_time_for_query('DTT_EVT_end', true) + (60 * 60 * 24 * 30),
97
+				'DTT_order'     => 1,
98
+				'DTT_reg_limit' => EE_INF,
99
+			),
100
+			$timezone_string
101
+		);
102
+		$blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga',
103
+			$timezone_string));
104
+		$blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string));
105
+		return array($blank_datetime);
106
+	}
107
+
108
+
109
+
110
+	/**
111
+	 *        get event start date from db
112
+	 *
113
+	 * @access        public
114
+	 * @param        int $EVT_ID
115
+	 * @return        EE_Datetime[]        array on success, FALSE on fail
116
+	 */
117
+	public function get_all_event_dates($EVT_ID = 0)
118
+	{
119
+		if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
120
+			return $this->create_new_blank_datetime();
121
+		}
122
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
123
+		if (empty($results)) {
124
+			return $this->create_new_blank_datetime();
125
+		}
126
+		return $results;
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * get all datetimes attached to an event ordered by the DTT_order field
133
+	 *
134
+	 * @public
135
+	 * @param  int    $EVT_ID     event id
136
+	 * @param boolean $include_expired
137
+	 * @param boolean $include_deleted
138
+	 * @param  int    $limit      If included then limit the count of results by
139
+	 *                            the given number
140
+	 * @return EE_Datetime[]
141
+	 */
142
+	public function get_datetimes_for_event_ordered_by_DTT_order(
143
+		$EVT_ID,
144
+		$include_expired = true,
145
+		$include_deleted = true,
146
+		$limit = null
147
+	) {
148
+		//sanitize EVT_ID
149
+		$EVT_ID = intval($EVT_ID);
150
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
151
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
152
+		$where_params = array('Event.EVT_ID' => $EVT_ID);
153
+		$query_params = ! empty($limit) ? array(
154
+			$where_params,
155
+			'limit'                    => $limit,
156
+			'order_by'                 => array('DTT_order' => 'ASC'),
157
+			'default_where_conditions' => 'none',
158
+		) : array($where_params, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none');
159
+		if ( ! $include_expired) {
160
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
161
+		}
162
+		if ($include_deleted) {
163
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
164
+		}
165
+		$result = $this->get_all($query_params);
166
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
167
+		return $result;
168
+	}
169
+
170
+
171
+
172
+	/**
173
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean
174
+	 * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most
175
+	 * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
176
+	 *
177
+	 * @param int $EVT_ID
178
+	 * @param int $limit
179
+	 * @return EE_Datetime[]
180
+	 */
181
+	public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
182
+	{
183
+		return $this->get_all(array(
184
+			array('Event.EVT_ID' => $EVT_ID),
185
+			'limit'                    => $limit,
186
+			'order_by'                 => array('DTT_EVT_start' => 'ASC'),
187
+			'default_where_conditions' => 'none',
188
+		));
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * @param int     $EVT_ID
195
+	 * @param boolean $include_expired
196
+	 * @param boolean $include_deleted
197
+	 * @return EE_Datetime
198
+	 */
199
+	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
200
+	{
201
+		$results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1);
202
+		if ($results) {
203
+			return array_shift($results);
204
+		} else {
205
+			return null;
206
+		}
207
+	}
208
+
209
+
210
+
211
+	/**
212
+	 * Gets the 'primary' datetime for an event.
213
+	 *
214
+	 * @param int  $EVT_ID
215
+	 * @param bool $try_to_exclude_expired
216
+	 * @param bool $try_to_exclude_deleted
217
+	 * @return \EE_Datetime
218
+	 */
219
+	public function get_primary_datetime_for_event(
220
+		$EVT_ID,
221
+		$try_to_exclude_expired = true,
222
+		$try_to_exclude_deleted = true
223
+	) {
224
+		if ($try_to_exclude_expired) {
225
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
226
+			if ($non_expired) {
227
+				return $non_expired;
228
+			}
229
+		}
230
+		if ($try_to_exclude_deleted) {
231
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
232
+			if ($expired_even) {
233
+				return $expired_even;
234
+			}
235
+		}
236
+		$deleted_even = $this->get_oldest_datetime_for_event($EVT_ID, true, true);
237
+		return $deleted_even;
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
244
+	 * only by start date
245
+	 *
246
+	 * @param int     $EVT_ID
247
+	 * @param boolean $include_expired
248
+	 * @param boolean $include_deleted
249
+	 * @param int     $limit
250
+	 * @return EE_Datetime[]
251
+	 */
252
+	public function get_datetimes_for_event_ordered_by_start_time(
253
+		$EVT_ID,
254
+		$include_expired = true,
255
+		$include_deleted = true,
256
+		$limit = null
257
+	) {
258
+		//sanitize EVT_ID
259
+		$EVT_ID = intval($EVT_ID);
260
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
261
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
262
+		$query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
263
+		if ( ! $include_expired) {
264
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
265
+		}
266
+		if ($include_deleted) {
267
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
268
+		}
269
+		if ($limit) {
270
+			$query_params['limit'] = $limit;
271
+		}
272
+		$result = $this->get_all($query_params);
273
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
274
+		return $result;
275
+	}
276
+
277
+
278
+
279
+	/**
280
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
281
+	 * only by start date
282
+	 *
283
+	 * @param int     $TKT_ID
284
+	 * @param boolean $include_expired
285
+	 * @param boolean $include_deleted
286
+	 * @param int     $limit
287
+	 * @return EE_Datetime[]
288
+	 */
289
+	public function get_datetimes_for_ticket_ordered_by_start_time(
290
+		$TKT_ID,
291
+		$include_expired = true,
292
+		$include_deleted = true,
293
+		$limit = null
294
+	) {
295
+		//sanitize TKT_ID
296
+		$TKT_ID = intval($TKT_ID);
297
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
298
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
299
+		$query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
300
+		if ( ! $include_expired) {
301
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
302
+		}
303
+		if ($include_deleted) {
304
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
305
+		}
306
+		if ($limit) {
307
+			$query_params['limit'] = $limit;
308
+		}
309
+		$result = $this->get_all($query_params);
310
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
311
+		return $result;
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
318
+	 * datetimes.
319
+	 *
320
+	 * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
321
+	 * @param  boolean  $include_expired whether to include expired datetimes or not
322
+	 * @param  boolean  $include_deleted whether to include trashed datetimes or not.
323
+	 * @param  int|null $limit           if null, no limit, if int then limit results by
324
+	 *                                   that number
325
+	 * @return EE_Datetime[]
326
+	 */
327
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
328
+		$TKT_ID,
329
+		$include_expired = true,
330
+		$include_deleted = true,
331
+		$limit = null
332
+	) {
333
+		//sanitize id.
334
+		$TKT_ID = intval($TKT_ID);
335
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
336
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
337
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
338
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
339
+		if ( ! $include_expired) {
340
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
341
+		}
342
+		if ($include_deleted) {
343
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
344
+		}
345
+		if ($limit) {
346
+			$query_params['limit'] = $limit;
347
+		}
348
+		$result = $this->get_all($query_params);
349
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
350
+		return $result;
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
357
+	 * reason it doesn't exist, we consider the earliest event the most important)
358
+	 *
359
+	 * @param int $EVT_ID
360
+	 * @return EE_Datetime
361
+	 */
362
+	public function get_most_important_datetime_for_event($EVT_ID)
363
+	{
364
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
365
+		if ($results) {
366
+			return array_shift($results);
367
+		} else {
368
+			return null;
369
+		}
370
+	}
371
+
372
+
373
+
374
+	/**
375
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
376
+	 * grouped by month and year.
377
+	 *
378
+	 * @param  array  $where_params      Array of query_params as described in the comments for EEM_Base::get_all()
379
+	 * @param  string $evt_active_status A string representing the evt active status to filter the months by.
380
+	 *                                   Can be:
381
+	 *                                   - '' = no filter
382
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
383
+	 *                                   - expired = Events with all datetimes expired.
384
+	 *                                   - active = Events that are published and have at least one datetime that
385
+	 *                                   starts before now and ends after now.
386
+	 *                                   - inactive = Events that are either not published.
387
+	 * @return wpdb results array
388
+	 */
389
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '')
390
+	{
391
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
392
+		$current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end');
393
+		switch ($evt_active_status) {
394
+			case 'upcoming' :
395
+				$where_params['Event.status'] = 'publish';
396
+				//if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
397
+				if (isset($where_params['DTT_EVT_start'])) {
398
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
399
+				}
400
+				$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
401
+				break;
402
+			case 'expired' :
403
+				if (isset($where_params['Event.status'])) {
404
+					unset($where_params['Event.status']);
405
+				}
406
+				//get events to exclude
407
+				$exclude_query[0] = array_merge($where_params,
408
+					array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)));
409
+				//first get all events that have datetimes where its not expired.
410
+				$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID');
411
+				$event_ids = array_keys($event_ids);
412
+				if (isset($where_params['DTT_EVT_end'])) {
413
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
414
+				}
415
+				$where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end);
416
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
417
+				break;
418
+			case 'active' :
419
+				$where_params['Event.status'] = 'publish';
420
+				if (isset($where_params['DTT_EVT_start'])) {
421
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
422
+				}
423
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
424
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
425
+				}
426
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
427
+				$where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end);
428
+				break;
429
+			case 'inactive' :
430
+				if (isset($where_params['Event.status'])) {
431
+					unset($where_params['Event.status']);
432
+				}
433
+				if (isset($where_params['OR'])) {
434
+					$where_params['AND']['OR'] = $where_params['OR'];
435
+				}
436
+				if (isset($where_params['DTT_EVT_end'])) {
437
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
438
+					unset($where_params['DTT_EVT_end']);
439
+				}
440
+				if (isset($where_params['DTT_EVT_start'])) {
441
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
442
+					unset($where_params['DTT_EVT_start']);
443
+				}
444
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
445
+				break;
446
+		}
447
+		$query_params[0] = $where_params;
448
+		$query_params['group_by'] = array('dtt_year', 'dtt_month');
449
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
450
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start');
451
+		$columns_to_select = array(
452
+			'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
453
+			'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
454
+			'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
455
+		);
456
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
457
+	}
458
+
459
+
460
+
461
+	/**
462
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
463
+	 * for the tickets for each datetime)
464
+	 *
465
+	 * @param EE_Datetime[] $datetimes
466
+	 */
467
+	public function update_sold($datetimes)
468
+	{
469
+		foreach ($datetimes as $datetime) {
470
+			$datetime->update_sold();
471
+		}
472
+	}
473
+
474
+
475
+
476
+	/**
477
+	 *    Gets the total number of tickets available at a particular datetime
478
+	 *    (does NOT take into account the datetime's spaces available)
479
+	 *
480
+	 * @param int   $DTT_ID
481
+	 * @param array $query_params
482
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
483
+	 *             tickets attached to datetime then FALSE is returned.
484
+	 */
485
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array())
486
+	{
487
+		$datetime = $this->get_one_by_ID($DTT_ID);
488
+		if ($datetime instanceof EE_Datetime) {
489
+			return $datetime->tickets_remaining($query_params);
490
+		}
491
+		return 0;
492
+	}
493
+
494
+
495
+
496
+	/**
497
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
498
+	 *
499
+	 * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
500
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
501
+	 *                                 for all valid stati.
502
+	 * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
503
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
504
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
505
+	 *                stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired
506
+	 */
507
+	public function get_datetime_counts_by_status($stati_to_include = array(), $query_params = array())
508
+	{
509
+		//only accept where conditions for this query.
510
+		$_where = isset($query_params[0]) ? $query_params[0] : array();
511
+		$status_query_args = array(
512
+			EE_Datetime::active   => array_merge(
513
+				$_where,
514
+				array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
515
+			),
516
+			EE_Datetime::upcoming => array_merge(
517
+				$_where,
518
+				array('DTT_EVT_start' => array('>', time()))
519
+			),
520
+			EE_Datetime::expired  => array_merge(
521
+				$_where,
522
+				array('DTT_EVT_end' => array('<', time()))
523
+			),
524
+		);
525
+		if ( ! empty($stati_to_include)) {
526
+			foreach (array_keys($status_query_args) as $status) {
527
+				if ( ! in_array($status, $stati_to_include)) {
528
+					unset($status_query_args[$status]);
529
+				}
530
+			}
531
+		}
532
+		//loop through and query counts for each stati.
533
+		$status_query_results = array();
534
+		foreach ($status_query_args as $status => $status_where_conditions) {
535
+			$status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true);
536
+		}
537
+		return $status_query_results;
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 * Returns the specific count for a given Datetime status matching any given query_params.
544
+	 *
545
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
546
+	 * @param array  $query_params
547
+	 * @return int
548
+	 */
549
+	public function get_datetime_count_for_status($status = EE_Datetime::active, $query_params = array())
550
+	{
551
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
552
+		return ! empty($count[$status]) ? $count[$status] : 0;
553
+	}
554 554
 
555 555
 
556 556
 
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,239 +40,239 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.028');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.028');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        /**
197
-         *    espresso_plugin_activation
198
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
199
-         */
200
-        function espresso_plugin_activation()
201
-        {
202
-            update_option('ee_espresso_activation', true);
203
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		/**
197
+		 *    espresso_plugin_activation
198
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
199
+		 */
200
+		function espresso_plugin_activation()
201
+		{
202
+			update_option('ee_espresso_activation', true);
203
+		}
204 204
 
205
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
206
-        /**
207
-         *    espresso_load_error_handling
208
-         *    this function loads EE's class for handling exceptions and errors
209
-         */
210
-        function espresso_load_error_handling()
211
-        {
212
-            // load debugging tools
213
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
214
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
215
-                EEH_Debug_Tools::instance();
216
-            }
217
-            // load error handling
218
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
219
-                require_once(EE_CORE . 'EE_Error.core.php');
220
-            } else {
221
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
222
-            }
223
-        }
205
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
206
+		/**
207
+		 *    espresso_load_error_handling
208
+		 *    this function loads EE's class for handling exceptions and errors
209
+		 */
210
+		function espresso_load_error_handling()
211
+		{
212
+			// load debugging tools
213
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
214
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
215
+				EEH_Debug_Tools::instance();
216
+			}
217
+			// load error handling
218
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
219
+				require_once(EE_CORE . 'EE_Error.core.php');
220
+			} else {
221
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
222
+			}
223
+		}
224 224
 
225
-        /**
226
-         *    espresso_load_required
227
-         *    given a class name and path, this function will load that file or throw an exception
228
-         *
229
-         * @param    string $classname
230
-         * @param    string $full_path_to_file
231
-         * @throws    EE_Error
232
-         */
233
-        function espresso_load_required($classname, $full_path_to_file)
234
-        {
235
-            static $error_handling_loaded = false;
236
-            if ( ! $error_handling_loaded) {
237
-                espresso_load_error_handling();
238
-                $error_handling_loaded = true;
239
-            }
240
-            if (is_readable($full_path_to_file)) {
241
-                require_once($full_path_to_file);
242
-            } else {
243
-                throw new EE_Error (
244
-                        sprintf(
245
-                                esc_html__(
246
-                                        'The %s class file could not be located or is not readable due to file permissions.',
247
-                                        'event_espresso'
248
-                                ),
249
-                                $classname
250
-                        )
251
-                );
252
-            }
253
-        }
225
+		/**
226
+		 *    espresso_load_required
227
+		 *    given a class name and path, this function will load that file or throw an exception
228
+		 *
229
+		 * @param    string $classname
230
+		 * @param    string $full_path_to_file
231
+		 * @throws    EE_Error
232
+		 */
233
+		function espresso_load_required($classname, $full_path_to_file)
234
+		{
235
+			static $error_handling_loaded = false;
236
+			if ( ! $error_handling_loaded) {
237
+				espresso_load_error_handling();
238
+				$error_handling_loaded = true;
239
+			}
240
+			if (is_readable($full_path_to_file)) {
241
+				require_once($full_path_to_file);
242
+			} else {
243
+				throw new EE_Error (
244
+						sprintf(
245
+								esc_html__(
246
+										'The %s class file could not be located or is not readable due to file permissions.',
247
+										'event_espresso'
248
+								),
249
+								$classname
250
+						)
251
+				);
252
+			}
253
+		}
254 254
 
255
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
256
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
257
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
258
-        new EE_Bootstrap();
259
-    }
255
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
256
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
257
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
258
+		new EE_Bootstrap();
259
+	}
260 260
 }
261 261
 if ( ! function_exists('espresso_deactivate_plugin')) {
262
-    /**
263
-     *    deactivate_plugin
264
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
265
-     *
266
-     * @access public
267
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
268
-     * @return    void
269
-     */
270
-    function espresso_deactivate_plugin($plugin_basename = '')
271
-    {
272
-        if ( ! function_exists('deactivate_plugins')) {
273
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
274
-        }
275
-        unset($_GET['activate'], $_REQUEST['activate']);
276
-        deactivate_plugins($plugin_basename);
277
-    }
262
+	/**
263
+	 *    deactivate_plugin
264
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
265
+	 *
266
+	 * @access public
267
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
268
+	 * @return    void
269
+	 */
270
+	function espresso_deactivate_plugin($plugin_basename = '')
271
+	{
272
+		if ( ! function_exists('deactivate_plugins')) {
273
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
274
+		}
275
+		unset($_GET['activate'], $_REQUEST['activate']);
276
+		deactivate_plugins($plugin_basename);
277
+	}
278 278
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/controllers/model/Read.php 2 patches
Indentation   +1158 added lines, -1158 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use EventEspresso\core\db_models\helpers\ModelSchema;
9 9
 
10 10
 if (! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -26,1163 +26,1163 @@  discard block
 block discarded – undo
26 26
 
27 27
 
28 28
 
29
-    /**
30
-     * @var Calculated_Model_Fields
31
-     */
32
-    protected $_fields_calculator;
33
-
34
-
35
-
36
-    /**
37
-     * Read constructor.
38
-     */
39
-    public function __construct()
40
-    {
41
-        parent::__construct();
42
-        $this->_fields_calculator = new Calculated_Model_Fields();
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * Handles requests to get all (or a filtered subset) of entities for a particular model
49
-     *
50
-     * @param \WP_REST_Request $request
51
-     * @return \WP_REST_Response|\WP_Error
52
-     */
53
-    public static function handle_request_get_all(\WP_REST_Request $request)
54
-    {
55
-        $controller = new Read();
56
-        try {
57
-            $matches = $controller->parse_route(
58
-                $request->get_route(),
59
-                '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~',
60
-                array('version', 'model')
61
-            );
62
-            $controller->set_requested_version($matches['version']);
63
-            $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
64
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
65
-                return $controller->send_response(
66
-                    new \WP_Error(
67
-                        'endpoint_parsing_error',
68
-                        sprintf(
69
-                            __('There is no model for endpoint %s. Please contact event espresso support',
70
-                                'event_espresso'),
71
-                            $model_name_singular
72
-                        )
73
-                    )
74
-                );
75
-            }
76
-            return $controller->send_response(
77
-                $controller->get_entities_from_model(
78
-                    $controller->get_model_version_info()->load_model($model_name_singular),
79
-                    $request
80
-                )
81
-            );
82
-        } catch (\Exception $e) {
83
-            return $controller->send_response($e);
84
-        }
85
-    }
86
-
87
-
88
-    /**
89
-     * Prepares and returns schema for any OPTIONS request.
90
-     * @return array
91
-     */
92
-    public static function handle_schema_request()
93
-    {
94
-        $controller = new Read();
95
-        //setup request since we dont' have it exposed.
96
-        //@see https://core.trac.wordpress.org/ticket/39376.  If/when that gets patched then we should have the $route
97
-        //exposed for determining what model schema is being requested.
98
-        $request = new \WP_REST_Request($_SERVER['REQUEST_METHOD'], $controller->get_route_from_request());
99
-        try {
100
-            $matches = $controller->parse_route(
101
-                $request->get_route(),
102
-                '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~',
103
-                array('version', 'model')
104
-            );
105
-            $controller->set_requested_version($matches['version']);
106
-            $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
107
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
108
-                return array();
109
-            }
110
-            $model_schema = new ModelSchema();
111
-            $model = $controller->get_model_version_info()->load_model($model_name_singular);
112
-            return array_merge(
113
-                $model_schema->getInitialSchemaStructure($model),
114
-                $model_schema->getModelSchemaForRelations(
115
-                    $controller->get_model_version_info()->relation_settings($model)
116
-                ),
117
-                $model_schema->getModelSchemaForFields(
118
-                    $controller->get_model_version_info()->fields_on_model_in_this_version($model)
119
-                )
120
-            );
121
-        } catch(\Exception $e) {
122
-            return array();
123
-        }
124
-    }
125
-
126
-
127
-
128
-
129
-    /**
130
-     * Used to figure out the route from the request when a `WP_REST_Request` object is not available
131
-     * @return string
132
-     */
133
-    protected function get_route_from_request() {
134
-        if (isset($GLOBALS['wp'])
135
-            && $GLOBALS['wp'] instanceof \WP
136
-            && isset($GLOBALS['wp']->query_vars['rest_route'] )
137
-        ) {
138
-            return $GLOBALS['wp']->query_vars['rest_route'];
139
-        } else {
140
-            return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/';
141
-        }
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * Gets a single entity related to the model indicated in the path and its id
148
-     *
149
-     * @param \WP_REST_Request $request
150
-     * @return \WP_REST_Response|\WP_Error
151
-     */
152
-    public static function handle_request_get_one(\WP_REST_Request $request)
153
-    {
154
-        $controller = new Read();
155
-        try {
156
-            $matches = $controller->parse_route(
157
-                $request->get_route(),
158
-                '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~',
159
-                array('version', 'model', 'id'));
160
-            $controller->set_requested_version($matches['version']);
161
-            $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
162
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
163
-                return $controller->send_response(
164
-                    new \WP_Error(
165
-                        'endpoint_parsing_error',
166
-                        sprintf(
167
-                            __('There is no model for endpoint %s. Please contact event espresso support',
168
-                                'event_espresso'),
169
-                            $model_name_singular
170
-                        )
171
-                    )
172
-                );
173
-            }
174
-            return $controller->send_response(
175
-                $controller->get_entity_from_model(
176
-                    $controller->get_model_version_info()->load_model($model_name_singular),
177
-                    $request
178
-                )
179
-            );
180
-        } catch (\Exception $e) {
181
-            return $controller->send_response($e);
182
-        }
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Gets all the related entities (or if its a belongs-to relation just the one)
189
-     * to the item with the given id
190
-     *
191
-     * @param \WP_REST_Request $request
192
-     * @return \WP_REST_Response|\WP_Error
193
-     */
194
-    public static function handle_request_get_related(\WP_REST_Request $request)
195
-    {
196
-        $controller = new Read();
197
-        try {
198
-            $matches = $controller->parse_route(
199
-                $request->get_route(),
200
-                '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~',
201
-                array('version', 'model', 'id', 'related_model')
202
-            );
203
-            $controller->set_requested_version($matches['version']);
204
-            $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
205
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) {
206
-                return $controller->send_response(
207
-                    new \WP_Error(
208
-                        'endpoint_parsing_error',
209
-                        sprintf(
210
-                            __('There is no model for endpoint %s. Please contact event espresso support',
211
-                                'event_espresso'),
212
-                            $main_model_name_singular
213
-                        )
214
-                    )
215
-                );
216
-            }
217
-            $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular);
218
-            //assume the related model name is plural and try to find the model's name
219
-            $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']);
220
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
221
-                //so the word didn't singularize well. Maybe that's just because it's a singular word?
222
-                $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']);
223
-            }
224
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
225
-                return $controller->send_response(
226
-                    new \WP_Error(
227
-                        'endpoint_parsing_error',
228
-                        sprintf(
229
-                            __('There is no model for endpoint %s. Please contact event espresso support',
230
-                                'event_espresso'),
231
-                            $related_model_name_singular
232
-                        )
233
-                    )
234
-                );
235
-            }
236
-            return $controller->send_response(
237
-                $controller->get_entities_from_relation(
238
-                    $request->get_param('id'),
239
-                    $main_model->related_settings_for($related_model_name_singular),
240
-                    $request
241
-                )
242
-            );
243
-        } catch (\Exception $e) {
244
-            return $controller->send_response($e);
245
-        }
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     * Gets a collection for the given model and filters
252
-     *
253
-     * @param \EEM_Base        $model
254
-     * @param \WP_REST_Request $request
255
-     * @return array|\WP_Error
256
-     */
257
-    public function get_entities_from_model($model, $request)
258
-    {
259
-        $query_params = $this->create_model_query_params($model, $request->get_params());
260
-        if (! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) {
261
-            $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
262
-            return new \WP_Error(
263
-                sprintf('rest_%s_cannot_list', $model_name_plural),
264
-                sprintf(
265
-                    __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'),
266
-                    $model_name_plural,
267
-                    Capabilities::get_missing_permissions_string($model, $query_params['caps'])
268
-                ),
269
-                array('status' => 403)
270
-            );
271
-        }
272
-        if (! $request->get_header('no_rest_headers')) {
273
-            $this->_set_headers_from_query_params($model, $query_params);
274
-        }
275
-        /** @type array $results */
276
-        $results = $model->get_all_wpdb_results($query_params);
277
-        $nice_results = array();
278
-        foreach ($results as $result) {
279
-            $nice_results[] = $this->create_entity_from_wpdb_result(
280
-                $model,
281
-                $result,
282
-                $request
283
-            );
284
-        }
285
-        return $nice_results;
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     * @param array                   $primary_model_query_params query params for finding the item from which
292
-     *                                                            relations will be based
293
-     * @param \EE_Model_Relation_Base $relation
294
-     * @param \WP_REST_Request        $request
295
-     * @return \WP_Error|array
296
-     */
297
-    protected function _get_entities_from_relation($primary_model_query_params, $relation, $request)
298
-    {
299
-        $context = $this->validate_context($request->get_param('caps'));
300
-        $model = $relation->get_this_model();
301
-        $related_model = $relation->get_other_model();
302
-        if (! isset($primary_model_query_params[0])) {
303
-            $primary_model_query_params[0] = array();
304
-        }
305
-        //check if they can access the 1st model object
306
-        $primary_model_query_params = array(
307
-            0       => $primary_model_query_params[0],
308
-            'limit' => 1,
309
-        );
310
-        if ($model instanceof \EEM_Soft_Delete_Base) {
311
-            $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($primary_model_query_params);
312
-        }
313
-        $restricted_query_params = $primary_model_query_params;
314
-        $restricted_query_params['caps'] = $context;
315
-        $this->_set_debug_info('main model query params', $restricted_query_params);
316
-        $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context));
317
-        if (
318
-        ! (
319
-            Capabilities::current_user_has_partial_access_to($related_model, $context)
320
-            && $model->exists($restricted_query_params)
321
-        )
322
-        ) {
323
-            if ($relation instanceof \EE_Belongs_To_Relation) {
324
-                $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name());
325
-            } else {
326
-                $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name());
327
-            }
328
-            return new \WP_Error(
329
-                sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural),
330
-                sprintf(
331
-                    __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s',
332
-                        'event_espresso'),
333
-                    $related_model_name_maybe_plural,
334
-                    $relation->get_this_model()->get_this_model_name(),
335
-                    implode(
336
-                        ',',
337
-                        array_keys(
338
-                            Capabilities::get_missing_permissions($related_model, $context)
339
-                        )
340
-                    )
341
-                ),
342
-                array('status' => 403)
343
-            );
344
-        }
345
-        $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params());
346
-        foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) {
347
-            $query_params[0][$relation->get_this_model()->get_this_model_name()
348
-                             . '.'
349
-                             . $where_condition_key] = $where_condition_value;
350
-        }
351
-        $query_params['default_where_conditions'] = 'none';
352
-        $query_params['caps'] = $context;
353
-        if (! $request->get_header('no_rest_headers')) {
354
-            $this->_set_headers_from_query_params($relation->get_other_model(), $query_params);
355
-        }
356
-        /** @type array $results */
357
-        $results = $relation->get_other_model()->get_all_wpdb_results($query_params);
358
-        $nice_results = array();
359
-        foreach ($results as $result) {
360
-            $nice_result = $this->create_entity_from_wpdb_result(
361
-                $relation->get_other_model(),
362
-                $result,
363
-                $request
364
-            );
365
-            if ($relation instanceof \EE_HABTM_Relation) {
366
-                //put the unusual stuff (properties from the HABTM relation) first, and make sure
367
-                //if there are conflicts we prefer the properties from the main model
368
-                $join_model_result = $this->create_entity_from_wpdb_result(
369
-                    $relation->get_join_model(),
370
-                    $result,
371
-                    $request
372
-                );
373
-                $joined_result = array_merge($nice_result, $join_model_result);
374
-                //but keep the meta stuff from the main model
375
-                if (isset($nice_result['meta'])) {
376
-                    $joined_result['meta'] = $nice_result['meta'];
377
-                }
378
-                $nice_result = $joined_result;
379
-            }
380
-            $nice_results[] = $nice_result;
381
-        }
382
-        if ($relation instanceof \EE_Belongs_To_Relation) {
383
-            return array_shift($nice_results);
384
-        } else {
385
-            return $nice_results;
386
-        }
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * Gets the collection for given relation object
393
-     * The same as Read::get_entities_from_model(), except if the relation
394
-     * is a HABTM relation, in which case it merges any non-foreign-key fields from
395
-     * the join-model-object into the results
396
-     *
397
-     * @param string                  $id the ID of the thing we are fetching related stuff from
398
-     * @param \EE_Model_Relation_Base $relation
399
-     * @param \WP_REST_Request        $request
400
-     * @return array|\WP_Error
401
-     * @throws \EE_Error
402
-     */
403
-    public function get_entities_from_relation($id, $relation, $request)
404
-    {
405
-        if (! $relation->get_this_model()->has_primary_key_field()) {
406
-            throw new \EE_Error(
407
-                sprintf(
408
-                    __('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s',
409
-                        'event_espresso'),
410
-                    $relation->get_this_model()->get_this_model_name()
411
-                )
412
-            );
413
-        }
414
-        return $this->_get_entities_from_relation(
415
-            array(
416
-                array(
417
-                    $relation->get_this_model()->primary_key_name() => $id,
418
-                ),
419
-            ),
420
-            $relation,
421
-            $request
422
-        );
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * Sets the headers that are based on the model and query params,
429
-     * like the total records. This should only be called on the original request
430
-     * from the client, not on subsequent internal
431
-     *
432
-     * @param \EEM_Base $model
433
-     * @param array     $query_params
434
-     * @return void
435
-     */
436
-    protected function _set_headers_from_query_params($model, $query_params)
437
-    {
438
-        $this->_set_debug_info('model query params', $query_params);
439
-        $this->_set_debug_info('missing caps',
440
-            Capabilities::get_missing_permissions_string($model, $query_params['caps']));
441
-        //normally the limit to a 2-part array, where the 2nd item is the limit
442
-        if (! isset($query_params['limit'])) {
443
-            $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit();
444
-        }
445
-        if (is_array($query_params['limit'])) {
446
-            $limit_parts = $query_params['limit'];
447
-        } else {
448
-            $limit_parts = explode(',', $query_params['limit']);
449
-            if (count($limit_parts) == 1) {
450
-                $limit_parts = array(0, $limit_parts[0]);
451
-            }
452
-        }
453
-        //remove the group by and having parts of the query, as those will
454
-        //make the sql query return an array of values, instead of just a single value
455
-        unset($query_params['group_by'], $query_params['having'], $query_params['limit']);
456
-        $count = $model->count($query_params, null, true);
457
-        $pages = $count / $limit_parts[1];
458
-        $this->_set_response_header('Total', $count, false);
459
-        $this->_set_response_header('PageSize', $limit_parts[1], false);
460
-        $this->_set_response_header('TotalPages', ceil($pages), false);
461
-    }
462
-
463
-
464
-
465
-    /**
466
-     * Changes database results into REST API entities
467
-     *
468
-     * @param \EEM_Base        $model
469
-     * @param array            $db_row     like results from $wpdb->get_results()
470
-     * @param \WP_REST_Request $rest_request
471
-     * @param string           $deprecated no longer used
472
-     * @return array ready for being converted into json for sending to client
473
-     */
474
-    public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null)
475
-    {
476
-        if (! $rest_request instanceof \WP_REST_Request) {
477
-            //ok so this was called in the old style, where the 3rd arg was
478
-            //$include, and the 4th arg was $context
479
-            //now setup the request just to avoid fatal errors, although we won't be able
480
-            //to truly make use of it because it's kinda devoid of info
481
-            $rest_request = new \WP_REST_Request();
482
-            $rest_request->set_param('include', $rest_request);
483
-            $rest_request->set_param('caps', $deprecated);
484
-        }
485
-        if ($rest_request->get_param('caps') == null) {
486
-            $rest_request->set_param('caps', \EEM_Base::caps_read);
487
-        }
488
-        $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row);
489
-        $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array);
490
-        $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array);
491
-        $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request);
492
-        $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array, $db_row);
493
-        $entity_array = apply_filters(
494
-            'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
495
-            $entity_array,
496
-            $model,
497
-            $rest_request->get_param('caps'),
498
-            $rest_request,
499
-            $this
500
-        );
501
-        $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields(
502
-            $entity_array,
503
-            $model,
504
-            $rest_request->get_param('caps'),
505
-            $this->get_model_version_info(),
506
-            $model->get_index_primary_key_string(
507
-                $model->deduce_fields_n_values_from_cols_n_values($db_row)
508
-            )
509
-        );
510
-        $this->_set_debug_info(
511
-            'inaccessible fields',
512
-            array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields))
513
-        );
514
-        return apply_filters(
515
-            'FHEE__Read__create_entity_from_wpdb_results__entity_return',
516
-            $result_without_inaccessible_fields,
517
-            $model,
518
-            $rest_request->get_param('caps')
519
-        );
520
-    }
521
-
522
-
523
-
524
-    /**
525
-     * Creates a REST entity array (JSON object we're going to return in the response, but
526
-     * for now still a PHP array, but soon enough we'll call json_encode on it, don't worry),
527
-     * from $wpdb->get_row( $sql, ARRAY_A)
528
-     *
529
-     * @param \EEM_Base $model
530
-     * @param array     $db_row
531
-     * @return array entity mostly ready for converting to JSON and sending in the response
532
-     */
533
-    protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row)
534
-    {
535
-        $result = $model->deduce_fields_n_values_from_cols_n_values($db_row);
536
-        $result = array_intersect_key($result,
537
-            $this->get_model_version_info()->fields_on_model_in_this_version($model));
538
-        foreach ($result as $field_name => $raw_field_value) {
539
-            $field_obj = $model->field_settings_for($field_name);
540
-            $field_value = $field_obj->prepare_for_set_from_db($raw_field_value);
541
-            if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) {
542
-                unset($result[$field_name]);
543
-            } elseif (
544
-            $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format())
545
-            ) {
546
-                $result[$field_name] = array(
547
-                    'raw'      => $field_obj->prepare_for_get($field_value),
548
-                    'rendered' => $field_obj->prepare_for_pretty_echoing($field_value),
549
-                );
550
-            } elseif (
551
-            $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format())
552
-            ) {
553
-                $result[$field_name] = array(
554
-                    'raw'    => $field_obj->prepare_for_get($field_value),
555
-                    'pretty' => $field_obj->prepare_for_pretty_echoing($field_value),
556
-                );
557
-            } elseif ($field_obj instanceof \EE_Datetime_Field) {
558
-                if ($field_value instanceof \DateTime) {
559
-                    $timezone = $field_value->getTimezone();
560
-                    $field_value->setTimezone(new \DateTimeZone('UTC'));
561
-                    $result[$field_name . '_gmt'] = Model_Data_Translator::prepare_field_value_for_json(
562
-                        $field_obj,
563
-                        $field_value,
564
-                        $this->get_model_version_info()->requested_version()
565
-                    );
566
-                    $field_value->setTimezone($timezone);
567
-                    $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json(
568
-                        $field_obj,
569
-                        $field_value,
570
-                        $this->get_model_version_info()->requested_version()
571
-                    );
572
-                }
573
-            } else {
574
-                $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json(
575
-                    $field_obj,
576
-                    $field_obj->prepare_for_get($field_value),
577
-                    $this->get_model_version_info()->requested_version()
578
-                );
579
-            }
580
-        }
581
-        return $result;
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     * Adds a few extra fields to the entity response
588
-     *
589
-     * @param \EEM_Base $model
590
-     * @param array     $db_row
591
-     * @param array     $entity_array
592
-     * @return array modified entity
593
-     */
594
-    protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array)
595
-    {
596
-        if ($model instanceof \EEM_CPT_Base) {
597
-            $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]);
598
-        }
599
-        return $entity_array;
600
-    }
601
-
602
-
603
-
604
-    /**
605
-     * Gets links we want to add to the response
606
-     *
607
-     * @global \WP_REST_Server $wp_rest_server
608
-     * @param \EEM_Base        $model
609
-     * @param array            $db_row
610
-     * @param array            $entity_array
611
-     * @return array the _links item in the entity
612
-     */
613
-    protected function _get_entity_links($model, $db_row, $entity_array)
614
-    {
615
-        //add basic links
616
-        $links = array();
617
-        if ($model->has_primary_key_field()) {
618
-            $links['self'] = array(
619
-                array(
620
-                    'href' => $this->get_versioned_link_to(
621
-                        \EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
622
-                        . '/'
623
-                        . $entity_array[$model->primary_key_name()]
624
-                    ),
625
-                ),
626
-            );
627
-        }
628
-        $links['collection'] = array(
629
-            array(
630
-                'href' => $this->get_versioned_link_to(
631
-                    \EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
632
-                ),
633
-            ),
634
-        );
635
-        //add links to related models
636
-        if ($model->has_primary_key_field()) {
637
-            foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) {
638
-                $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj);
639
-                $links[\EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part] = array(
640
-                    array(
641
-                        'href'   => $this->get_versioned_link_to(
642
-                            \EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
643
-                            . '/'
644
-                            . $entity_array[$model->primary_key_name()]
645
-                            . '/'
646
-                            . $related_model_part
647
-                        ),
648
-                        'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false,
649
-                    ),
650
-                );
651
-            }
652
-        }
653
-        return $links;
654
-    }
655
-
656
-
657
-
658
-    /**
659
-     * Adds the included models indicated in the request to the entity provided
660
-     *
661
-     * @param \EEM_Base        $model
662
-     * @param \WP_REST_Request $rest_request
663
-     * @param array            $entity_array
664
-     * @param array            $db_row
665
-     * @return array the modified entity
666
-     */
667
-    protected function _include_requested_models(
668
-        \EEM_Base $model,
669
-        \WP_REST_Request $rest_request,
670
-        $entity_array,
671
-        $db_row = array()
672
-    ) {
673
-        //if $db_row not included, hope the entity array has what we need
674
-        if (! $db_row) {
675
-            $db_row = $entity_array;
676
-        }
677
-        $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), '');
678
-        $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model);
679
-        //if they passed in * or didn't specify any includes, return everything
680
-        if (! in_array('*', $includes_for_this_model)
681
-            && ! empty($includes_for_this_model)
682
-        ) {
683
-            if ($model->has_primary_key_field()) {
684
-                //always include the primary key. ya just gotta know that at least
685
-                $includes_for_this_model[] = $model->primary_key_name();
686
-            }
687
-            if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) {
688
-                $includes_for_this_model[] = '_calculated_fields';
689
-            }
690
-            $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model));
691
-        }
692
-        $relation_settings = $this->get_model_version_info()->relation_settings($model);
693
-        foreach ($relation_settings as $relation_name => $relation_obj) {
694
-            $related_fields_to_include = $this->explode_and_get_items_prefixed_with(
695
-                $rest_request->get_param('include'),
696
-                $relation_name
697
-            );
698
-            $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with(
699
-                $rest_request->get_param('calculate'),
700
-                $relation_name
701
-            );
702
-            //did they specify they wanted to include a related model, or
703
-            //specific fields from a related model?
704
-            //or did they specify to calculate a field from a related model?
705
-            if ($related_fields_to_include || $related_fields_to_calculate) {
706
-                //if so, we should include at least some part of the related model
707
-                $pretend_related_request = new \WP_REST_Request();
708
-                $pretend_related_request->set_query_params(
709
-                    array(
710
-                        'caps'      => $rest_request->get_param('caps'),
711
-                        'include'   => $related_fields_to_include,
712
-                        'calculate' => $related_fields_to_calculate,
713
-                    )
714
-                );
715
-                $pretend_related_request->add_header('no_rest_headers', true);
716
-                $primary_model_query_params = $model->alter_query_params_to_restrict_by_ID(
717
-                    $model->get_index_primary_key_string(
718
-                        $model->deduce_fields_n_values_from_cols_n_values($db_row)
719
-                    )
720
-                );
721
-                $related_results = $this->_get_entities_from_relation(
722
-                    $primary_model_query_params,
723
-                    $relation_obj,
724
-                    $pretend_related_request
725
-                );
726
-                $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results
727
-                                                                                              instanceof
728
-                                                                                              \WP_Error
729
-                    ? null
730
-                    : $related_results;
731
-            }
732
-        }
733
-        return $entity_array;
734
-    }
735
-
736
-
737
-
738
-    /**
739
-     * Returns a new array with all the names of models removed. Eg
740
-     * array( 'Event', 'Datetime.*', 'foobar' ) would become array( 'Datetime.*', 'foobar' )
741
-     *
742
-     * @param array $arr
743
-     * @return array
744
-     */
745
-    private function _remove_model_names_from_array($arr)
746
-    {
747
-        return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models));
748
-    }
749
-
750
-
751
-
752
-    /**
753
-     * Gets the calculated fields for the response
754
-     *
755
-     * @param \EEM_Base        $model
756
-     * @param array            $wpdb_row
757
-     * @param \WP_REST_Request $rest_request
758
-     * @return \stdClass the _calculations item in the entity
759
-     */
760
-    protected function _get_entity_calculations($model, $wpdb_row, $rest_request)
761
-    {
762
-        $calculated_fields = $this->explode_and_get_items_prefixed_with(
763
-            $rest_request->get_param('calculate'),
764
-            ''
765
-        );
766
-        //note: setting calculate=* doesn't do anything
767
-        $calculated_fields_to_return = new \stdClass();
768
-        foreach ($calculated_fields as $field_to_calculate) {
769
-            try {
770
-                $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json(
771
-                    null,
772
-                    $this->_fields_calculator->retrieve_calculated_field_value(
773
-                        $model,
774
-                        $field_to_calculate,
775
-                        $wpdb_row,
776
-                        $rest_request,
777
-                        $this
778
-                    ),
779
-                    $this->get_model_version_info()->requested_version()
780
-                );
781
-            } catch (Rest_Exception $e) {
782
-                //if we don't have permission to read it, just leave it out. but let devs know about the problem
783
-                $this->_set_response_header(
784
-                    'Notices-Field-Calculation-Errors['
785
-                    . $e->get_string_code()
786
-                    . ']['
787
-                    . $model->get_this_model_name()
788
-                    . ']['
789
-                    . $field_to_calculate
790
-                    . ']',
791
-                    $e->getMessage(),
792
-                    true
793
-                );
794
-            }
795
-        }
796
-        return $calculated_fields_to_return;
797
-    }
798
-
799
-
800
-
801
-    /**
802
-     * Gets the full URL to the resource, taking the requested version into account
803
-     *
804
-     * @param string $link_part_after_version_and_slash eg "events/10/datetimes"
805
-     * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes"
806
-     */
807
-    public function get_versioned_link_to($link_part_after_version_and_slash)
808
-    {
809
-        return rest_url(
810
-            \EED_Core_Rest_Api::ee_api_namespace
811
-            . $this->get_model_version_info()->requested_version()
812
-            . '/'
813
-            . $link_part_after_version_and_slash
814
-        );
815
-    }
816
-
817
-
818
-
819
-    /**
820
-     * Gets the correct lowercase name for the relation in the API according
821
-     * to the relation's type
822
-     *
823
-     * @param string                  $relation_name
824
-     * @param \EE_Model_Relation_Base $relation_obj
825
-     * @return string
826
-     */
827
-    public static function get_related_entity_name($relation_name, $relation_obj)
828
-    {
829
-        if ($relation_obj instanceof \EE_Belongs_To_Relation) {
830
-            return strtolower($relation_name);
831
-        } else {
832
-            return \EEH_Inflector::pluralize_and_lower($relation_name);
833
-        }
834
-    }
835
-
836
-
837
-
838
-    /**
839
-     * Gets the one model object with the specified id for the specified model
840
-     *
841
-     * @param \EEM_Base        $model
842
-     * @param \WP_REST_Request $request
843
-     * @return array|\WP_Error
844
-     */
845
-    public function get_entity_from_model($model, $request)
846
-    {
847
-        $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1);
848
-        if ($model instanceof \EEM_Soft_Delete_Base) {
849
-            $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
850
-        }
851
-        $restricted_query_params = $query_params;
852
-        $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps'));
853
-        $this->_set_debug_info('model query params', $restricted_query_params);
854
-        $model_rows = $model->get_all_wpdb_results($restricted_query_params);
855
-        if (! empty ($model_rows)) {
856
-            return $this->create_entity_from_wpdb_result(
857
-                $model,
858
-                array_shift($model_rows),
859
-                $request);
860
-        } else {
861
-            //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
862
-            $lowercase_model_name = strtolower($model->get_this_model_name());
863
-            $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
864
-            if (! empty($model_rows_found_sans_restrictions)) {
865
-                //you got shafted- it existed but we didn't want to tell you!
866
-                return new \WP_Error(
867
-                    'rest_user_cannot_read',
868
-                    sprintf(
869
-                        __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'),
870
-                        strtolower($model->get_this_model_name()),
871
-                        Capabilities::get_missing_permissions_string(
872
-                            $model,
873
-                            $this->validate_context($request->get_param('caps')))
874
-                    ),
875
-                    array('status' => 403)
876
-                );
877
-            } else {
878
-                //it's not you. It just doesn't exist
879
-                return new \WP_Error(
880
-                    sprintf('rest_%s_invalid_id', $lowercase_model_name),
881
-                    sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
882
-                    array('status' => 404)
883
-                );
884
-            }
885
-        }
886
-    }
887
-
888
-
889
-
890
-    /**
891
-     * If a context is provided which isn't valid, maybe it was added in a future
892
-     * version so just treat it as a default read
893
-     *
894
-     * @param string $context
895
-     * @return string array key of EEM_Base::cap_contexts_to_cap_action_map()
896
-     */
897
-    public function validate_context($context)
898
-    {
899
-        if (! $context) {
900
-            $context = \EEM_Base::caps_read;
901
-        }
902
-        $valid_contexts = \EEM_Base::valid_cap_contexts();
903
-        if (in_array($context, $valid_contexts)) {
904
-            return $context;
905
-        } else {
906
-            return \EEM_Base::caps_read;
907
-        }
908
-    }
909
-
910
-
911
-
912
-    /**
913
-     * Verifies the passed in value is an allowable default where conditions value.
914
-     *
915
-     * @param $default_query_params
916
-     * @return string
917
-     */
918
-    public function validate_default_query_params($default_query_params)
919
-    {
920
-        $valid_default_where_conditions_for_api_calls = array(
921
-            \EEM_Base::default_where_conditions_all,
922
-            \EEM_Base::default_where_conditions_minimum_all,
923
-            \EEM_Base::default_where_conditions_minimum_others,
924
-        );
925
-        if (! $default_query_params) {
926
-            $default_query_params = \EEM_Base::default_where_conditions_all;
927
-        }
928
-        if (
929
-        in_array(
930
-            $default_query_params,
931
-            $valid_default_where_conditions_for_api_calls,
932
-            true
933
-        )
934
-        ) {
935
-            return $default_query_params;
936
-        } else {
937
-            return \EEM_Base::default_where_conditions_all;
938
-        }
939
-    }
940
-
941
-
942
-
943
-    /**
944
-     * Translates API filter get parameter into $query_params array used by EEM_Base::get_all().
945
-     * Note: right now the query parameter keys for fields (and related fields)
946
-     * can be left as-is, but it's quite possible this will change someday.
947
-     * Also, this method's contents might be candidate for moving to Model_Data_Translator
948
-     *
949
-     * @param \EEM_Base $model
950
-     * @param array     $query_parameters from $_GET parameter @see Read:handle_request_get_all
951
-     * @return array like what EEM_Base::get_all() expects or FALSE to indicate
952
-     *                                    that absolutely no results should be returned
953
-     * @throws \EE_Error
954
-     */
955
-    public function create_model_query_params($model, $query_parameters)
956
-    {
957
-        $model_query_params = array();
958
-        if (isset($query_parameters['where'])) {
959
-            $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models(
960
-                $query_parameters['where'],
961
-                $model,
962
-                $this->get_model_version_info()->requested_version()
963
-            );
964
-        }
965
-        if (isset($query_parameters['order_by'])) {
966
-            $order_by = $query_parameters['order_by'];
967
-        } elseif (isset($query_parameters['orderby'])) {
968
-            $order_by = $query_parameters['orderby'];
969
-        } else {
970
-            $order_by = null;
971
-        }
972
-        if ($order_by !== null) {
973
-            if (is_array($order_by)) {
974
-                $order_by = Model_Data_Translator::prepare_field_names_in_array_keys_from_json($order_by);
975
-            } else {
976
-                //it's a single item
977
-                $order_by = Model_Data_Translator::prepare_field_name_from_json($order_by);
978
-            }
979
-            $model_query_params['order_by'] = $order_by;
980
-        }
981
-        if (isset($query_parameters['group_by'])) {
982
-            $group_by = $query_parameters['group_by'];
983
-        } elseif (isset($query_parameters['groupby'])) {
984
-            $group_by = $query_parameters['groupby'];
985
-        } else {
986
-            $group_by = array_keys($model->get_combined_primary_key_fields());
987
-        }
988
-        //make sure they're all real names
989
-        if (is_array($group_by)) {
990
-            $group_by = Model_Data_Translator::prepare_field_names_from_json($group_by);
991
-        }
992
-        if ($group_by !== null) {
993
-            $model_query_params['group_by'] = $group_by;
994
-        }
995
-        if (isset($query_parameters['having'])) {
996
-            $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models(
997
-                $query_parameters['having'],
998
-                $model,
999
-                $this->get_model_version_info()->requested_version()
1000
-            );
1001
-        }
1002
-        if (isset($query_parameters['order'])) {
1003
-            $model_query_params['order'] = $query_parameters['order'];
1004
-        }
1005
-        if (isset($query_parameters['mine'])) {
1006
-            $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params);
1007
-        }
1008
-        if (isset($query_parameters['limit'])) {
1009
-            //limit should be either a string like '23' or '23,43', or an array with two items in it
1010
-            if (! is_array($query_parameters['limit'])) {
1011
-                $limit_array = explode(',', (string)$query_parameters['limit']);
1012
-            } else {
1013
-                $limit_array = $query_parameters['limit'];
1014
-            }
1015
-            $sanitized_limit = array();
1016
-            foreach ($limit_array as $key => $limit_part) {
1017
-                if ($this->_debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1018
-                    throw new \EE_Error(
1019
-                        sprintf(
1020
-                            __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.',
1021
-                                'event_espresso'),
1022
-                            wp_json_encode($query_parameters['limit'])
1023
-                        )
1024
-                    );
1025
-                }
1026
-                $sanitized_limit[] = (int)$limit_part;
1027
-            }
1028
-            $model_query_params['limit'] = implode(',', $sanitized_limit);
1029
-        } else {
1030
-            $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit();
1031
-        }
1032
-        if (isset($query_parameters['caps'])) {
1033
-            $model_query_params['caps'] = $this->validate_context($query_parameters['caps']);
1034
-        } else {
1035
-            $model_query_params['caps'] = \EEM_Base::caps_read;
1036
-        }
1037
-        if (isset($query_parameters['default_where_conditions'])) {
1038
-            $model_query_params['default_where_conditions'] = $this->validate_default_query_params($query_parameters['default_where_conditions']);
1039
-        }
1040
-        return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model);
1041
-    }
1042
-
1043
-
1044
-
1045
-    /**
1046
-     * Changes the REST-style query params for use in the models
1047
-     *
1048
-     * @deprecated
1049
-     * @param \EEM_Base $model
1050
-     * @param array     $query_params sub-array from @see EEM_Base::get_all()
1051
-     * @return array
1052
-     */
1053
-    public function prepare_rest_query_params_key_for_models($model, $query_params)
1054
-    {
1055
-        $model_ready_query_params = array();
1056
-        foreach ($query_params as $key => $value) {
1057
-            if (is_array($value)) {
1058
-                $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value);
1059
-            } else {
1060
-                $model_ready_query_params[$key] = $value;
1061
-            }
1062
-        }
1063
-        return $model_ready_query_params;
1064
-    }
1065
-
1066
-
1067
-
1068
-    /**
1069
-     * @deprecated
1070
-     * @param $model
1071
-     * @param $query_params
1072
-     * @return array
1073
-     */
1074
-    public function prepare_rest_query_params_values_for_models($model, $query_params)
1075
-    {
1076
-        $model_ready_query_params = array();
1077
-        foreach ($query_params as $key => $value) {
1078
-            if (is_array($value)) {
1079
-                $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value);
1080
-            } else {
1081
-                $model_ready_query_params[$key] = $value;
1082
-            }
1083
-        }
1084
-        return $model_ready_query_params;
1085
-    }
1086
-
1087
-
1088
-
1089
-    /**
1090
-     * Explodes the string on commas, and only returns items with $prefix followed by a period.
1091
-     * If no prefix is specified, returns items with no period.
1092
-     *
1093
-     * @param string|array $string_to_explode eg "jibba,jabba, blah, blaabla" or array('jibba', 'jabba' )
1094
-     * @param string       $prefix            "Event" or "foobar"
1095
-     * @return array $string_to_exploded exploded on COMMAS, and if a prefix was specified
1096
-     *                                        we only return strings starting with that and a period; if no prefix was
1097
-     *                                        specified we return all items containing NO periods
1098
-     */
1099
-    public function explode_and_get_items_prefixed_with($string_to_explode, $prefix)
1100
-    {
1101
-        if (is_string($string_to_explode)) {
1102
-            $exploded_contents = explode(',', $string_to_explode);
1103
-        } else if (is_array($string_to_explode)) {
1104
-            $exploded_contents = $string_to_explode;
1105
-        } else {
1106
-            $exploded_contents = array();
1107
-        }
1108
-        //if the string was empty, we want an empty array
1109
-        $exploded_contents = array_filter($exploded_contents);
1110
-        $contents_with_prefix = array();
1111
-        foreach ($exploded_contents as $item) {
1112
-            $item = trim($item);
1113
-            //if no prefix was provided, so we look for items with no "." in them
1114
-            if (! $prefix) {
1115
-                //does this item have a period?
1116
-                if (strpos($item, '.') === false) {
1117
-                    //if not, then its what we're looking for
1118
-                    $contents_with_prefix[] = $item;
1119
-                }
1120
-            } else if (strpos($item, $prefix . '.') === 0) {
1121
-                //this item has the prefix and a period, grab it
1122
-                $contents_with_prefix[] = substr(
1123
-                    $item,
1124
-                    strpos($item, $prefix . '.') + strlen($prefix . '.')
1125
-                );
1126
-            } else if ($item === $prefix) {
1127
-                //this item is JUST the prefix
1128
-                //so let's grab everything after, which is a blank string
1129
-                $contents_with_prefix[] = '';
1130
-            }
1131
-        }
1132
-        return $contents_with_prefix;
1133
-    }
1134
-
1135
-
1136
-
1137
-    /**
1138
-     * @deprecated since 4.8.36.rc.001 You should instead use Read::explode_and_get_items_prefixed_with.
1139
-     * Deprecated because its return values were really quite confusing- sometimes it returned
1140
-     * an empty array (when the include string was blank or '*') or sometimes it returned
1141
-     * array('*') (when you provided a model and a model of that kind was found).
1142
-     * Parses the $include_string so we fetch all the field names relating to THIS model
1143
-     * (ie have NO period in them), or for the provided model (ie start with the model
1144
-     * name and then a period).
1145
-     * @param string $include_string @see Read:handle_request_get_all
1146
-     * @param string $model_name
1147
-     * @return array of fields for this model. If $model_name is provided, then
1148
-     *                               the fields for that model, with the model's name removed from each.
1149
-     *                               If $include_string was blank or '*' returns an empty array
1150
-     */
1151
-    public function extract_includes_for_this_model($include_string, $model_name = null)
1152
-    {
1153
-        if (is_array($include_string)) {
1154
-            $include_string = implode(',', $include_string);
1155
-        }
1156
-        if ($include_string === '*' || $include_string === '') {
1157
-            return array();
1158
-        }
1159
-        $includes = explode(',', $include_string);
1160
-        $extracted_fields_to_include = array();
1161
-        if ($model_name) {
1162
-            foreach ($includes as $field_to_include) {
1163
-                $field_to_include = trim($field_to_include);
1164
-                if (strpos($field_to_include, $model_name . '.') === 0) {
1165
-                    //found the model name at the exact start
1166
-                    $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include);
1167
-                    $extracted_fields_to_include[] = $field_sans_model_name;
1168
-                } elseif ($field_to_include == $model_name) {
1169
-                    $extracted_fields_to_include[] = '*';
1170
-                }
1171
-            }
1172
-        } else {
1173
-            //look for ones with no period
1174
-            foreach ($includes as $field_to_include) {
1175
-                $field_to_include = trim($field_to_include);
1176
-                if (
1177
-                    strpos($field_to_include, '.') === false
1178
-                    && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include)
1179
-                ) {
1180
-                    $extracted_fields_to_include[] = $field_to_include;
1181
-                }
1182
-            }
1183
-        }
1184
-        return $extracted_fields_to_include;
1185
-    }
29
+	/**
30
+	 * @var Calculated_Model_Fields
31
+	 */
32
+	protected $_fields_calculator;
33
+
34
+
35
+
36
+	/**
37
+	 * Read constructor.
38
+	 */
39
+	public function __construct()
40
+	{
41
+		parent::__construct();
42
+		$this->_fields_calculator = new Calculated_Model_Fields();
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * Handles requests to get all (or a filtered subset) of entities for a particular model
49
+	 *
50
+	 * @param \WP_REST_Request $request
51
+	 * @return \WP_REST_Response|\WP_Error
52
+	 */
53
+	public static function handle_request_get_all(\WP_REST_Request $request)
54
+	{
55
+		$controller = new Read();
56
+		try {
57
+			$matches = $controller->parse_route(
58
+				$request->get_route(),
59
+				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~',
60
+				array('version', 'model')
61
+			);
62
+			$controller->set_requested_version($matches['version']);
63
+			$model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
64
+			if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
65
+				return $controller->send_response(
66
+					new \WP_Error(
67
+						'endpoint_parsing_error',
68
+						sprintf(
69
+							__('There is no model for endpoint %s. Please contact event espresso support',
70
+								'event_espresso'),
71
+							$model_name_singular
72
+						)
73
+					)
74
+				);
75
+			}
76
+			return $controller->send_response(
77
+				$controller->get_entities_from_model(
78
+					$controller->get_model_version_info()->load_model($model_name_singular),
79
+					$request
80
+				)
81
+			);
82
+		} catch (\Exception $e) {
83
+			return $controller->send_response($e);
84
+		}
85
+	}
86
+
87
+
88
+	/**
89
+	 * Prepares and returns schema for any OPTIONS request.
90
+	 * @return array
91
+	 */
92
+	public static function handle_schema_request()
93
+	{
94
+		$controller = new Read();
95
+		//setup request since we dont' have it exposed.
96
+		//@see https://core.trac.wordpress.org/ticket/39376.  If/when that gets patched then we should have the $route
97
+		//exposed for determining what model schema is being requested.
98
+		$request = new \WP_REST_Request($_SERVER['REQUEST_METHOD'], $controller->get_route_from_request());
99
+		try {
100
+			$matches = $controller->parse_route(
101
+				$request->get_route(),
102
+				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~',
103
+				array('version', 'model')
104
+			);
105
+			$controller->set_requested_version($matches['version']);
106
+			$model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
107
+			if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
108
+				return array();
109
+			}
110
+			$model_schema = new ModelSchema();
111
+			$model = $controller->get_model_version_info()->load_model($model_name_singular);
112
+			return array_merge(
113
+				$model_schema->getInitialSchemaStructure($model),
114
+				$model_schema->getModelSchemaForRelations(
115
+					$controller->get_model_version_info()->relation_settings($model)
116
+				),
117
+				$model_schema->getModelSchemaForFields(
118
+					$controller->get_model_version_info()->fields_on_model_in_this_version($model)
119
+				)
120
+			);
121
+		} catch(\Exception $e) {
122
+			return array();
123
+		}
124
+	}
125
+
126
+
127
+
128
+
129
+	/**
130
+	 * Used to figure out the route from the request when a `WP_REST_Request` object is not available
131
+	 * @return string
132
+	 */
133
+	protected function get_route_from_request() {
134
+		if (isset($GLOBALS['wp'])
135
+			&& $GLOBALS['wp'] instanceof \WP
136
+			&& isset($GLOBALS['wp']->query_vars['rest_route'] )
137
+		) {
138
+			return $GLOBALS['wp']->query_vars['rest_route'];
139
+		} else {
140
+			return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/';
141
+		}
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * Gets a single entity related to the model indicated in the path and its id
148
+	 *
149
+	 * @param \WP_REST_Request $request
150
+	 * @return \WP_REST_Response|\WP_Error
151
+	 */
152
+	public static function handle_request_get_one(\WP_REST_Request $request)
153
+	{
154
+		$controller = new Read();
155
+		try {
156
+			$matches = $controller->parse_route(
157
+				$request->get_route(),
158
+				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~',
159
+				array('version', 'model', 'id'));
160
+			$controller->set_requested_version($matches['version']);
161
+			$model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
162
+			if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
163
+				return $controller->send_response(
164
+					new \WP_Error(
165
+						'endpoint_parsing_error',
166
+						sprintf(
167
+							__('There is no model for endpoint %s. Please contact event espresso support',
168
+								'event_espresso'),
169
+							$model_name_singular
170
+						)
171
+					)
172
+				);
173
+			}
174
+			return $controller->send_response(
175
+				$controller->get_entity_from_model(
176
+					$controller->get_model_version_info()->load_model($model_name_singular),
177
+					$request
178
+				)
179
+			);
180
+		} catch (\Exception $e) {
181
+			return $controller->send_response($e);
182
+		}
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * Gets all the related entities (or if its a belongs-to relation just the one)
189
+	 * to the item with the given id
190
+	 *
191
+	 * @param \WP_REST_Request $request
192
+	 * @return \WP_REST_Response|\WP_Error
193
+	 */
194
+	public static function handle_request_get_related(\WP_REST_Request $request)
195
+	{
196
+		$controller = new Read();
197
+		try {
198
+			$matches = $controller->parse_route(
199
+				$request->get_route(),
200
+				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~',
201
+				array('version', 'model', 'id', 'related_model')
202
+			);
203
+			$controller->set_requested_version($matches['version']);
204
+			$main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
205
+			if (! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) {
206
+				return $controller->send_response(
207
+					new \WP_Error(
208
+						'endpoint_parsing_error',
209
+						sprintf(
210
+							__('There is no model for endpoint %s. Please contact event espresso support',
211
+								'event_espresso'),
212
+							$main_model_name_singular
213
+						)
214
+					)
215
+				);
216
+			}
217
+			$main_model = $controller->get_model_version_info()->load_model($main_model_name_singular);
218
+			//assume the related model name is plural and try to find the model's name
219
+			$related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']);
220
+			if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
221
+				//so the word didn't singularize well. Maybe that's just because it's a singular word?
222
+				$related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']);
223
+			}
224
+			if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
225
+				return $controller->send_response(
226
+					new \WP_Error(
227
+						'endpoint_parsing_error',
228
+						sprintf(
229
+							__('There is no model for endpoint %s. Please contact event espresso support',
230
+								'event_espresso'),
231
+							$related_model_name_singular
232
+						)
233
+					)
234
+				);
235
+			}
236
+			return $controller->send_response(
237
+				$controller->get_entities_from_relation(
238
+					$request->get_param('id'),
239
+					$main_model->related_settings_for($related_model_name_singular),
240
+					$request
241
+				)
242
+			);
243
+		} catch (\Exception $e) {
244
+			return $controller->send_response($e);
245
+		}
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 * Gets a collection for the given model and filters
252
+	 *
253
+	 * @param \EEM_Base        $model
254
+	 * @param \WP_REST_Request $request
255
+	 * @return array|\WP_Error
256
+	 */
257
+	public function get_entities_from_model($model, $request)
258
+	{
259
+		$query_params = $this->create_model_query_params($model, $request->get_params());
260
+		if (! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) {
261
+			$model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
262
+			return new \WP_Error(
263
+				sprintf('rest_%s_cannot_list', $model_name_plural),
264
+				sprintf(
265
+					__('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'),
266
+					$model_name_plural,
267
+					Capabilities::get_missing_permissions_string($model, $query_params['caps'])
268
+				),
269
+				array('status' => 403)
270
+			);
271
+		}
272
+		if (! $request->get_header('no_rest_headers')) {
273
+			$this->_set_headers_from_query_params($model, $query_params);
274
+		}
275
+		/** @type array $results */
276
+		$results = $model->get_all_wpdb_results($query_params);
277
+		$nice_results = array();
278
+		foreach ($results as $result) {
279
+			$nice_results[] = $this->create_entity_from_wpdb_result(
280
+				$model,
281
+				$result,
282
+				$request
283
+			);
284
+		}
285
+		return $nice_results;
286
+	}
287
+
288
+
289
+
290
+	/**
291
+	 * @param array                   $primary_model_query_params query params for finding the item from which
292
+	 *                                                            relations will be based
293
+	 * @param \EE_Model_Relation_Base $relation
294
+	 * @param \WP_REST_Request        $request
295
+	 * @return \WP_Error|array
296
+	 */
297
+	protected function _get_entities_from_relation($primary_model_query_params, $relation, $request)
298
+	{
299
+		$context = $this->validate_context($request->get_param('caps'));
300
+		$model = $relation->get_this_model();
301
+		$related_model = $relation->get_other_model();
302
+		if (! isset($primary_model_query_params[0])) {
303
+			$primary_model_query_params[0] = array();
304
+		}
305
+		//check if they can access the 1st model object
306
+		$primary_model_query_params = array(
307
+			0       => $primary_model_query_params[0],
308
+			'limit' => 1,
309
+		);
310
+		if ($model instanceof \EEM_Soft_Delete_Base) {
311
+			$primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($primary_model_query_params);
312
+		}
313
+		$restricted_query_params = $primary_model_query_params;
314
+		$restricted_query_params['caps'] = $context;
315
+		$this->_set_debug_info('main model query params', $restricted_query_params);
316
+		$this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context));
317
+		if (
318
+		! (
319
+			Capabilities::current_user_has_partial_access_to($related_model, $context)
320
+			&& $model->exists($restricted_query_params)
321
+		)
322
+		) {
323
+			if ($relation instanceof \EE_Belongs_To_Relation) {
324
+				$related_model_name_maybe_plural = strtolower($related_model->get_this_model_name());
325
+			} else {
326
+				$related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name());
327
+			}
328
+			return new \WP_Error(
329
+				sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural),
330
+				sprintf(
331
+					__('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s',
332
+						'event_espresso'),
333
+					$related_model_name_maybe_plural,
334
+					$relation->get_this_model()->get_this_model_name(),
335
+					implode(
336
+						',',
337
+						array_keys(
338
+							Capabilities::get_missing_permissions($related_model, $context)
339
+						)
340
+					)
341
+				),
342
+				array('status' => 403)
343
+			);
344
+		}
345
+		$query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params());
346
+		foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) {
347
+			$query_params[0][$relation->get_this_model()->get_this_model_name()
348
+							 . '.'
349
+							 . $where_condition_key] = $where_condition_value;
350
+		}
351
+		$query_params['default_where_conditions'] = 'none';
352
+		$query_params['caps'] = $context;
353
+		if (! $request->get_header('no_rest_headers')) {
354
+			$this->_set_headers_from_query_params($relation->get_other_model(), $query_params);
355
+		}
356
+		/** @type array $results */
357
+		$results = $relation->get_other_model()->get_all_wpdb_results($query_params);
358
+		$nice_results = array();
359
+		foreach ($results as $result) {
360
+			$nice_result = $this->create_entity_from_wpdb_result(
361
+				$relation->get_other_model(),
362
+				$result,
363
+				$request
364
+			);
365
+			if ($relation instanceof \EE_HABTM_Relation) {
366
+				//put the unusual stuff (properties from the HABTM relation) first, and make sure
367
+				//if there are conflicts we prefer the properties from the main model
368
+				$join_model_result = $this->create_entity_from_wpdb_result(
369
+					$relation->get_join_model(),
370
+					$result,
371
+					$request
372
+				);
373
+				$joined_result = array_merge($nice_result, $join_model_result);
374
+				//but keep the meta stuff from the main model
375
+				if (isset($nice_result['meta'])) {
376
+					$joined_result['meta'] = $nice_result['meta'];
377
+				}
378
+				$nice_result = $joined_result;
379
+			}
380
+			$nice_results[] = $nice_result;
381
+		}
382
+		if ($relation instanceof \EE_Belongs_To_Relation) {
383
+			return array_shift($nice_results);
384
+		} else {
385
+			return $nice_results;
386
+		}
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * Gets the collection for given relation object
393
+	 * The same as Read::get_entities_from_model(), except if the relation
394
+	 * is a HABTM relation, in which case it merges any non-foreign-key fields from
395
+	 * the join-model-object into the results
396
+	 *
397
+	 * @param string                  $id the ID of the thing we are fetching related stuff from
398
+	 * @param \EE_Model_Relation_Base $relation
399
+	 * @param \WP_REST_Request        $request
400
+	 * @return array|\WP_Error
401
+	 * @throws \EE_Error
402
+	 */
403
+	public function get_entities_from_relation($id, $relation, $request)
404
+	{
405
+		if (! $relation->get_this_model()->has_primary_key_field()) {
406
+			throw new \EE_Error(
407
+				sprintf(
408
+					__('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s',
409
+						'event_espresso'),
410
+					$relation->get_this_model()->get_this_model_name()
411
+				)
412
+			);
413
+		}
414
+		return $this->_get_entities_from_relation(
415
+			array(
416
+				array(
417
+					$relation->get_this_model()->primary_key_name() => $id,
418
+				),
419
+			),
420
+			$relation,
421
+			$request
422
+		);
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * Sets the headers that are based on the model and query params,
429
+	 * like the total records. This should only be called on the original request
430
+	 * from the client, not on subsequent internal
431
+	 *
432
+	 * @param \EEM_Base $model
433
+	 * @param array     $query_params
434
+	 * @return void
435
+	 */
436
+	protected function _set_headers_from_query_params($model, $query_params)
437
+	{
438
+		$this->_set_debug_info('model query params', $query_params);
439
+		$this->_set_debug_info('missing caps',
440
+			Capabilities::get_missing_permissions_string($model, $query_params['caps']));
441
+		//normally the limit to a 2-part array, where the 2nd item is the limit
442
+		if (! isset($query_params['limit'])) {
443
+			$query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit();
444
+		}
445
+		if (is_array($query_params['limit'])) {
446
+			$limit_parts = $query_params['limit'];
447
+		} else {
448
+			$limit_parts = explode(',', $query_params['limit']);
449
+			if (count($limit_parts) == 1) {
450
+				$limit_parts = array(0, $limit_parts[0]);
451
+			}
452
+		}
453
+		//remove the group by and having parts of the query, as those will
454
+		//make the sql query return an array of values, instead of just a single value
455
+		unset($query_params['group_by'], $query_params['having'], $query_params['limit']);
456
+		$count = $model->count($query_params, null, true);
457
+		$pages = $count / $limit_parts[1];
458
+		$this->_set_response_header('Total', $count, false);
459
+		$this->_set_response_header('PageSize', $limit_parts[1], false);
460
+		$this->_set_response_header('TotalPages', ceil($pages), false);
461
+	}
462
+
463
+
464
+
465
+	/**
466
+	 * Changes database results into REST API entities
467
+	 *
468
+	 * @param \EEM_Base        $model
469
+	 * @param array            $db_row     like results from $wpdb->get_results()
470
+	 * @param \WP_REST_Request $rest_request
471
+	 * @param string           $deprecated no longer used
472
+	 * @return array ready for being converted into json for sending to client
473
+	 */
474
+	public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null)
475
+	{
476
+		if (! $rest_request instanceof \WP_REST_Request) {
477
+			//ok so this was called in the old style, where the 3rd arg was
478
+			//$include, and the 4th arg was $context
479
+			//now setup the request just to avoid fatal errors, although we won't be able
480
+			//to truly make use of it because it's kinda devoid of info
481
+			$rest_request = new \WP_REST_Request();
482
+			$rest_request->set_param('include', $rest_request);
483
+			$rest_request->set_param('caps', $deprecated);
484
+		}
485
+		if ($rest_request->get_param('caps') == null) {
486
+			$rest_request->set_param('caps', \EEM_Base::caps_read);
487
+		}
488
+		$entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row);
489
+		$entity_array = $this->_add_extra_fields($model, $db_row, $entity_array);
490
+		$entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array);
491
+		$entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request);
492
+		$entity_array = $this->_include_requested_models($model, $rest_request, $entity_array, $db_row);
493
+		$entity_array = apply_filters(
494
+			'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal',
495
+			$entity_array,
496
+			$model,
497
+			$rest_request->get_param('caps'),
498
+			$rest_request,
499
+			$this
500
+		);
501
+		$result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields(
502
+			$entity_array,
503
+			$model,
504
+			$rest_request->get_param('caps'),
505
+			$this->get_model_version_info(),
506
+			$model->get_index_primary_key_string(
507
+				$model->deduce_fields_n_values_from_cols_n_values($db_row)
508
+			)
509
+		);
510
+		$this->_set_debug_info(
511
+			'inaccessible fields',
512
+			array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields))
513
+		);
514
+		return apply_filters(
515
+			'FHEE__Read__create_entity_from_wpdb_results__entity_return',
516
+			$result_without_inaccessible_fields,
517
+			$model,
518
+			$rest_request->get_param('caps')
519
+		);
520
+	}
521
+
522
+
523
+
524
+	/**
525
+	 * Creates a REST entity array (JSON object we're going to return in the response, but
526
+	 * for now still a PHP array, but soon enough we'll call json_encode on it, don't worry),
527
+	 * from $wpdb->get_row( $sql, ARRAY_A)
528
+	 *
529
+	 * @param \EEM_Base $model
530
+	 * @param array     $db_row
531
+	 * @return array entity mostly ready for converting to JSON and sending in the response
532
+	 */
533
+	protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row)
534
+	{
535
+		$result = $model->deduce_fields_n_values_from_cols_n_values($db_row);
536
+		$result = array_intersect_key($result,
537
+			$this->get_model_version_info()->fields_on_model_in_this_version($model));
538
+		foreach ($result as $field_name => $raw_field_value) {
539
+			$field_obj = $model->field_settings_for($field_name);
540
+			$field_value = $field_obj->prepare_for_set_from_db($raw_field_value);
541
+			if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) {
542
+				unset($result[$field_name]);
543
+			} elseif (
544
+			$this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format())
545
+			) {
546
+				$result[$field_name] = array(
547
+					'raw'      => $field_obj->prepare_for_get($field_value),
548
+					'rendered' => $field_obj->prepare_for_pretty_echoing($field_value),
549
+				);
550
+			} elseif (
551
+			$this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format())
552
+			) {
553
+				$result[$field_name] = array(
554
+					'raw'    => $field_obj->prepare_for_get($field_value),
555
+					'pretty' => $field_obj->prepare_for_pretty_echoing($field_value),
556
+				);
557
+			} elseif ($field_obj instanceof \EE_Datetime_Field) {
558
+				if ($field_value instanceof \DateTime) {
559
+					$timezone = $field_value->getTimezone();
560
+					$field_value->setTimezone(new \DateTimeZone('UTC'));
561
+					$result[$field_name . '_gmt'] = Model_Data_Translator::prepare_field_value_for_json(
562
+						$field_obj,
563
+						$field_value,
564
+						$this->get_model_version_info()->requested_version()
565
+					);
566
+					$field_value->setTimezone($timezone);
567
+					$result[$field_name] = Model_Data_Translator::prepare_field_value_for_json(
568
+						$field_obj,
569
+						$field_value,
570
+						$this->get_model_version_info()->requested_version()
571
+					);
572
+				}
573
+			} else {
574
+				$result[$field_name] = Model_Data_Translator::prepare_field_value_for_json(
575
+					$field_obj,
576
+					$field_obj->prepare_for_get($field_value),
577
+					$this->get_model_version_info()->requested_version()
578
+				);
579
+			}
580
+		}
581
+		return $result;
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 * Adds a few extra fields to the entity response
588
+	 *
589
+	 * @param \EEM_Base $model
590
+	 * @param array     $db_row
591
+	 * @param array     $entity_array
592
+	 * @return array modified entity
593
+	 */
594
+	protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array)
595
+	{
596
+		if ($model instanceof \EEM_CPT_Base) {
597
+			$entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]);
598
+		}
599
+		return $entity_array;
600
+	}
601
+
602
+
603
+
604
+	/**
605
+	 * Gets links we want to add to the response
606
+	 *
607
+	 * @global \WP_REST_Server $wp_rest_server
608
+	 * @param \EEM_Base        $model
609
+	 * @param array            $db_row
610
+	 * @param array            $entity_array
611
+	 * @return array the _links item in the entity
612
+	 */
613
+	protected function _get_entity_links($model, $db_row, $entity_array)
614
+	{
615
+		//add basic links
616
+		$links = array();
617
+		if ($model->has_primary_key_field()) {
618
+			$links['self'] = array(
619
+				array(
620
+					'href' => $this->get_versioned_link_to(
621
+						\EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
622
+						. '/'
623
+						. $entity_array[$model->primary_key_name()]
624
+					),
625
+				),
626
+			);
627
+		}
628
+		$links['collection'] = array(
629
+			array(
630
+				'href' => $this->get_versioned_link_to(
631
+					\EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
632
+				),
633
+			),
634
+		);
635
+		//add links to related models
636
+		if ($model->has_primary_key_field()) {
637
+			foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) {
638
+				$related_model_part = Read::get_related_entity_name($relation_name, $relation_obj);
639
+				$links[\EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part] = array(
640
+					array(
641
+						'href'   => $this->get_versioned_link_to(
642
+							\EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
643
+							. '/'
644
+							. $entity_array[$model->primary_key_name()]
645
+							. '/'
646
+							. $related_model_part
647
+						),
648
+						'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false,
649
+					),
650
+				);
651
+			}
652
+		}
653
+		return $links;
654
+	}
655
+
656
+
657
+
658
+	/**
659
+	 * Adds the included models indicated in the request to the entity provided
660
+	 *
661
+	 * @param \EEM_Base        $model
662
+	 * @param \WP_REST_Request $rest_request
663
+	 * @param array            $entity_array
664
+	 * @param array            $db_row
665
+	 * @return array the modified entity
666
+	 */
667
+	protected function _include_requested_models(
668
+		\EEM_Base $model,
669
+		\WP_REST_Request $rest_request,
670
+		$entity_array,
671
+		$db_row = array()
672
+	) {
673
+		//if $db_row not included, hope the entity array has what we need
674
+		if (! $db_row) {
675
+			$db_row = $entity_array;
676
+		}
677
+		$includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), '');
678
+		$includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model);
679
+		//if they passed in * or didn't specify any includes, return everything
680
+		if (! in_array('*', $includes_for_this_model)
681
+			&& ! empty($includes_for_this_model)
682
+		) {
683
+			if ($model->has_primary_key_field()) {
684
+				//always include the primary key. ya just gotta know that at least
685
+				$includes_for_this_model[] = $model->primary_key_name();
686
+			}
687
+			if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) {
688
+				$includes_for_this_model[] = '_calculated_fields';
689
+			}
690
+			$entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model));
691
+		}
692
+		$relation_settings = $this->get_model_version_info()->relation_settings($model);
693
+		foreach ($relation_settings as $relation_name => $relation_obj) {
694
+			$related_fields_to_include = $this->explode_and_get_items_prefixed_with(
695
+				$rest_request->get_param('include'),
696
+				$relation_name
697
+			);
698
+			$related_fields_to_calculate = $this->explode_and_get_items_prefixed_with(
699
+				$rest_request->get_param('calculate'),
700
+				$relation_name
701
+			);
702
+			//did they specify they wanted to include a related model, or
703
+			//specific fields from a related model?
704
+			//or did they specify to calculate a field from a related model?
705
+			if ($related_fields_to_include || $related_fields_to_calculate) {
706
+				//if so, we should include at least some part of the related model
707
+				$pretend_related_request = new \WP_REST_Request();
708
+				$pretend_related_request->set_query_params(
709
+					array(
710
+						'caps'      => $rest_request->get_param('caps'),
711
+						'include'   => $related_fields_to_include,
712
+						'calculate' => $related_fields_to_calculate,
713
+					)
714
+				);
715
+				$pretend_related_request->add_header('no_rest_headers', true);
716
+				$primary_model_query_params = $model->alter_query_params_to_restrict_by_ID(
717
+					$model->get_index_primary_key_string(
718
+						$model->deduce_fields_n_values_from_cols_n_values($db_row)
719
+					)
720
+				);
721
+				$related_results = $this->_get_entities_from_relation(
722
+					$primary_model_query_params,
723
+					$relation_obj,
724
+					$pretend_related_request
725
+				);
726
+				$entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results
727
+																							  instanceof
728
+																							  \WP_Error
729
+					? null
730
+					: $related_results;
731
+			}
732
+		}
733
+		return $entity_array;
734
+	}
735
+
736
+
737
+
738
+	/**
739
+	 * Returns a new array with all the names of models removed. Eg
740
+	 * array( 'Event', 'Datetime.*', 'foobar' ) would become array( 'Datetime.*', 'foobar' )
741
+	 *
742
+	 * @param array $arr
743
+	 * @return array
744
+	 */
745
+	private function _remove_model_names_from_array($arr)
746
+	{
747
+		return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models));
748
+	}
749
+
750
+
751
+
752
+	/**
753
+	 * Gets the calculated fields for the response
754
+	 *
755
+	 * @param \EEM_Base        $model
756
+	 * @param array            $wpdb_row
757
+	 * @param \WP_REST_Request $rest_request
758
+	 * @return \stdClass the _calculations item in the entity
759
+	 */
760
+	protected function _get_entity_calculations($model, $wpdb_row, $rest_request)
761
+	{
762
+		$calculated_fields = $this->explode_and_get_items_prefixed_with(
763
+			$rest_request->get_param('calculate'),
764
+			''
765
+		);
766
+		//note: setting calculate=* doesn't do anything
767
+		$calculated_fields_to_return = new \stdClass();
768
+		foreach ($calculated_fields as $field_to_calculate) {
769
+			try {
770
+				$calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json(
771
+					null,
772
+					$this->_fields_calculator->retrieve_calculated_field_value(
773
+						$model,
774
+						$field_to_calculate,
775
+						$wpdb_row,
776
+						$rest_request,
777
+						$this
778
+					),
779
+					$this->get_model_version_info()->requested_version()
780
+				);
781
+			} catch (Rest_Exception $e) {
782
+				//if we don't have permission to read it, just leave it out. but let devs know about the problem
783
+				$this->_set_response_header(
784
+					'Notices-Field-Calculation-Errors['
785
+					. $e->get_string_code()
786
+					. ']['
787
+					. $model->get_this_model_name()
788
+					. ']['
789
+					. $field_to_calculate
790
+					. ']',
791
+					$e->getMessage(),
792
+					true
793
+				);
794
+			}
795
+		}
796
+		return $calculated_fields_to_return;
797
+	}
798
+
799
+
800
+
801
+	/**
802
+	 * Gets the full URL to the resource, taking the requested version into account
803
+	 *
804
+	 * @param string $link_part_after_version_and_slash eg "events/10/datetimes"
805
+	 * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes"
806
+	 */
807
+	public function get_versioned_link_to($link_part_after_version_and_slash)
808
+	{
809
+		return rest_url(
810
+			\EED_Core_Rest_Api::ee_api_namespace
811
+			. $this->get_model_version_info()->requested_version()
812
+			. '/'
813
+			. $link_part_after_version_and_slash
814
+		);
815
+	}
816
+
817
+
818
+
819
+	/**
820
+	 * Gets the correct lowercase name for the relation in the API according
821
+	 * to the relation's type
822
+	 *
823
+	 * @param string                  $relation_name
824
+	 * @param \EE_Model_Relation_Base $relation_obj
825
+	 * @return string
826
+	 */
827
+	public static function get_related_entity_name($relation_name, $relation_obj)
828
+	{
829
+		if ($relation_obj instanceof \EE_Belongs_To_Relation) {
830
+			return strtolower($relation_name);
831
+		} else {
832
+			return \EEH_Inflector::pluralize_and_lower($relation_name);
833
+		}
834
+	}
835
+
836
+
837
+
838
+	/**
839
+	 * Gets the one model object with the specified id for the specified model
840
+	 *
841
+	 * @param \EEM_Base        $model
842
+	 * @param \WP_REST_Request $request
843
+	 * @return array|\WP_Error
844
+	 */
845
+	public function get_entity_from_model($model, $request)
846
+	{
847
+		$query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1);
848
+		if ($model instanceof \EEM_Soft_Delete_Base) {
849
+			$query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params);
850
+		}
851
+		$restricted_query_params = $query_params;
852
+		$restricted_query_params['caps'] = $this->validate_context($request->get_param('caps'));
853
+		$this->_set_debug_info('model query params', $restricted_query_params);
854
+		$model_rows = $model->get_all_wpdb_results($restricted_query_params);
855
+		if (! empty ($model_rows)) {
856
+			return $this->create_entity_from_wpdb_result(
857
+				$model,
858
+				array_shift($model_rows),
859
+				$request);
860
+		} else {
861
+			//ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
862
+			$lowercase_model_name = strtolower($model->get_this_model_name());
863
+			$model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
864
+			if (! empty($model_rows_found_sans_restrictions)) {
865
+				//you got shafted- it existed but we didn't want to tell you!
866
+				return new \WP_Error(
867
+					'rest_user_cannot_read',
868
+					sprintf(
869
+						__('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'),
870
+						strtolower($model->get_this_model_name()),
871
+						Capabilities::get_missing_permissions_string(
872
+							$model,
873
+							$this->validate_context($request->get_param('caps')))
874
+					),
875
+					array('status' => 403)
876
+				);
877
+			} else {
878
+				//it's not you. It just doesn't exist
879
+				return new \WP_Error(
880
+					sprintf('rest_%s_invalid_id', $lowercase_model_name),
881
+					sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name),
882
+					array('status' => 404)
883
+				);
884
+			}
885
+		}
886
+	}
887
+
888
+
889
+
890
+	/**
891
+	 * If a context is provided which isn't valid, maybe it was added in a future
892
+	 * version so just treat it as a default read
893
+	 *
894
+	 * @param string $context
895
+	 * @return string array key of EEM_Base::cap_contexts_to_cap_action_map()
896
+	 */
897
+	public function validate_context($context)
898
+	{
899
+		if (! $context) {
900
+			$context = \EEM_Base::caps_read;
901
+		}
902
+		$valid_contexts = \EEM_Base::valid_cap_contexts();
903
+		if (in_array($context, $valid_contexts)) {
904
+			return $context;
905
+		} else {
906
+			return \EEM_Base::caps_read;
907
+		}
908
+	}
909
+
910
+
911
+
912
+	/**
913
+	 * Verifies the passed in value is an allowable default where conditions value.
914
+	 *
915
+	 * @param $default_query_params
916
+	 * @return string
917
+	 */
918
+	public function validate_default_query_params($default_query_params)
919
+	{
920
+		$valid_default_where_conditions_for_api_calls = array(
921
+			\EEM_Base::default_where_conditions_all,
922
+			\EEM_Base::default_where_conditions_minimum_all,
923
+			\EEM_Base::default_where_conditions_minimum_others,
924
+		);
925
+		if (! $default_query_params) {
926
+			$default_query_params = \EEM_Base::default_where_conditions_all;
927
+		}
928
+		if (
929
+		in_array(
930
+			$default_query_params,
931
+			$valid_default_where_conditions_for_api_calls,
932
+			true
933
+		)
934
+		) {
935
+			return $default_query_params;
936
+		} else {
937
+			return \EEM_Base::default_where_conditions_all;
938
+		}
939
+	}
940
+
941
+
942
+
943
+	/**
944
+	 * Translates API filter get parameter into $query_params array used by EEM_Base::get_all().
945
+	 * Note: right now the query parameter keys for fields (and related fields)
946
+	 * can be left as-is, but it's quite possible this will change someday.
947
+	 * Also, this method's contents might be candidate for moving to Model_Data_Translator
948
+	 *
949
+	 * @param \EEM_Base $model
950
+	 * @param array     $query_parameters from $_GET parameter @see Read:handle_request_get_all
951
+	 * @return array like what EEM_Base::get_all() expects or FALSE to indicate
952
+	 *                                    that absolutely no results should be returned
953
+	 * @throws \EE_Error
954
+	 */
955
+	public function create_model_query_params($model, $query_parameters)
956
+	{
957
+		$model_query_params = array();
958
+		if (isset($query_parameters['where'])) {
959
+			$model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models(
960
+				$query_parameters['where'],
961
+				$model,
962
+				$this->get_model_version_info()->requested_version()
963
+			);
964
+		}
965
+		if (isset($query_parameters['order_by'])) {
966
+			$order_by = $query_parameters['order_by'];
967
+		} elseif (isset($query_parameters['orderby'])) {
968
+			$order_by = $query_parameters['orderby'];
969
+		} else {
970
+			$order_by = null;
971
+		}
972
+		if ($order_by !== null) {
973
+			if (is_array($order_by)) {
974
+				$order_by = Model_Data_Translator::prepare_field_names_in_array_keys_from_json($order_by);
975
+			} else {
976
+				//it's a single item
977
+				$order_by = Model_Data_Translator::prepare_field_name_from_json($order_by);
978
+			}
979
+			$model_query_params['order_by'] = $order_by;
980
+		}
981
+		if (isset($query_parameters['group_by'])) {
982
+			$group_by = $query_parameters['group_by'];
983
+		} elseif (isset($query_parameters['groupby'])) {
984
+			$group_by = $query_parameters['groupby'];
985
+		} else {
986
+			$group_by = array_keys($model->get_combined_primary_key_fields());
987
+		}
988
+		//make sure they're all real names
989
+		if (is_array($group_by)) {
990
+			$group_by = Model_Data_Translator::prepare_field_names_from_json($group_by);
991
+		}
992
+		if ($group_by !== null) {
993
+			$model_query_params['group_by'] = $group_by;
994
+		}
995
+		if (isset($query_parameters['having'])) {
996
+			$model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models(
997
+				$query_parameters['having'],
998
+				$model,
999
+				$this->get_model_version_info()->requested_version()
1000
+			);
1001
+		}
1002
+		if (isset($query_parameters['order'])) {
1003
+			$model_query_params['order'] = $query_parameters['order'];
1004
+		}
1005
+		if (isset($query_parameters['mine'])) {
1006
+			$model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params);
1007
+		}
1008
+		if (isset($query_parameters['limit'])) {
1009
+			//limit should be either a string like '23' or '23,43', or an array with two items in it
1010
+			if (! is_array($query_parameters['limit'])) {
1011
+				$limit_array = explode(',', (string)$query_parameters['limit']);
1012
+			} else {
1013
+				$limit_array = $query_parameters['limit'];
1014
+			}
1015
+			$sanitized_limit = array();
1016
+			foreach ($limit_array as $key => $limit_part) {
1017
+				if ($this->_debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1018
+					throw new \EE_Error(
1019
+						sprintf(
1020
+							__('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.',
1021
+								'event_espresso'),
1022
+							wp_json_encode($query_parameters['limit'])
1023
+						)
1024
+					);
1025
+				}
1026
+				$sanitized_limit[] = (int)$limit_part;
1027
+			}
1028
+			$model_query_params['limit'] = implode(',', $sanitized_limit);
1029
+		} else {
1030
+			$model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit();
1031
+		}
1032
+		if (isset($query_parameters['caps'])) {
1033
+			$model_query_params['caps'] = $this->validate_context($query_parameters['caps']);
1034
+		} else {
1035
+			$model_query_params['caps'] = \EEM_Base::caps_read;
1036
+		}
1037
+		if (isset($query_parameters['default_where_conditions'])) {
1038
+			$model_query_params['default_where_conditions'] = $this->validate_default_query_params($query_parameters['default_where_conditions']);
1039
+		}
1040
+		return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model);
1041
+	}
1042
+
1043
+
1044
+
1045
+	/**
1046
+	 * Changes the REST-style query params for use in the models
1047
+	 *
1048
+	 * @deprecated
1049
+	 * @param \EEM_Base $model
1050
+	 * @param array     $query_params sub-array from @see EEM_Base::get_all()
1051
+	 * @return array
1052
+	 */
1053
+	public function prepare_rest_query_params_key_for_models($model, $query_params)
1054
+	{
1055
+		$model_ready_query_params = array();
1056
+		foreach ($query_params as $key => $value) {
1057
+			if (is_array($value)) {
1058
+				$model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value);
1059
+			} else {
1060
+				$model_ready_query_params[$key] = $value;
1061
+			}
1062
+		}
1063
+		return $model_ready_query_params;
1064
+	}
1065
+
1066
+
1067
+
1068
+	/**
1069
+	 * @deprecated
1070
+	 * @param $model
1071
+	 * @param $query_params
1072
+	 * @return array
1073
+	 */
1074
+	public function prepare_rest_query_params_values_for_models($model, $query_params)
1075
+	{
1076
+		$model_ready_query_params = array();
1077
+		foreach ($query_params as $key => $value) {
1078
+			if (is_array($value)) {
1079
+				$model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value);
1080
+			} else {
1081
+				$model_ready_query_params[$key] = $value;
1082
+			}
1083
+		}
1084
+		return $model_ready_query_params;
1085
+	}
1086
+
1087
+
1088
+
1089
+	/**
1090
+	 * Explodes the string on commas, and only returns items with $prefix followed by a period.
1091
+	 * If no prefix is specified, returns items with no period.
1092
+	 *
1093
+	 * @param string|array $string_to_explode eg "jibba,jabba, blah, blaabla" or array('jibba', 'jabba' )
1094
+	 * @param string       $prefix            "Event" or "foobar"
1095
+	 * @return array $string_to_exploded exploded on COMMAS, and if a prefix was specified
1096
+	 *                                        we only return strings starting with that and a period; if no prefix was
1097
+	 *                                        specified we return all items containing NO periods
1098
+	 */
1099
+	public function explode_and_get_items_prefixed_with($string_to_explode, $prefix)
1100
+	{
1101
+		if (is_string($string_to_explode)) {
1102
+			$exploded_contents = explode(',', $string_to_explode);
1103
+		} else if (is_array($string_to_explode)) {
1104
+			$exploded_contents = $string_to_explode;
1105
+		} else {
1106
+			$exploded_contents = array();
1107
+		}
1108
+		//if the string was empty, we want an empty array
1109
+		$exploded_contents = array_filter($exploded_contents);
1110
+		$contents_with_prefix = array();
1111
+		foreach ($exploded_contents as $item) {
1112
+			$item = trim($item);
1113
+			//if no prefix was provided, so we look for items with no "." in them
1114
+			if (! $prefix) {
1115
+				//does this item have a period?
1116
+				if (strpos($item, '.') === false) {
1117
+					//if not, then its what we're looking for
1118
+					$contents_with_prefix[] = $item;
1119
+				}
1120
+			} else if (strpos($item, $prefix . '.') === 0) {
1121
+				//this item has the prefix and a period, grab it
1122
+				$contents_with_prefix[] = substr(
1123
+					$item,
1124
+					strpos($item, $prefix . '.') + strlen($prefix . '.')
1125
+				);
1126
+			} else if ($item === $prefix) {
1127
+				//this item is JUST the prefix
1128
+				//so let's grab everything after, which is a blank string
1129
+				$contents_with_prefix[] = '';
1130
+			}
1131
+		}
1132
+		return $contents_with_prefix;
1133
+	}
1134
+
1135
+
1136
+
1137
+	/**
1138
+	 * @deprecated since 4.8.36.rc.001 You should instead use Read::explode_and_get_items_prefixed_with.
1139
+	 * Deprecated because its return values were really quite confusing- sometimes it returned
1140
+	 * an empty array (when the include string was blank or '*') or sometimes it returned
1141
+	 * array('*') (when you provided a model and a model of that kind was found).
1142
+	 * Parses the $include_string so we fetch all the field names relating to THIS model
1143
+	 * (ie have NO period in them), or for the provided model (ie start with the model
1144
+	 * name and then a period).
1145
+	 * @param string $include_string @see Read:handle_request_get_all
1146
+	 * @param string $model_name
1147
+	 * @return array of fields for this model. If $model_name is provided, then
1148
+	 *                               the fields for that model, with the model's name removed from each.
1149
+	 *                               If $include_string was blank or '*' returns an empty array
1150
+	 */
1151
+	public function extract_includes_for_this_model($include_string, $model_name = null)
1152
+	{
1153
+		if (is_array($include_string)) {
1154
+			$include_string = implode(',', $include_string);
1155
+		}
1156
+		if ($include_string === '*' || $include_string === '') {
1157
+			return array();
1158
+		}
1159
+		$includes = explode(',', $include_string);
1160
+		$extracted_fields_to_include = array();
1161
+		if ($model_name) {
1162
+			foreach ($includes as $field_to_include) {
1163
+				$field_to_include = trim($field_to_include);
1164
+				if (strpos($field_to_include, $model_name . '.') === 0) {
1165
+					//found the model name at the exact start
1166
+					$field_sans_model_name = str_replace($model_name . '.', '', $field_to_include);
1167
+					$extracted_fields_to_include[] = $field_sans_model_name;
1168
+				} elseif ($field_to_include == $model_name) {
1169
+					$extracted_fields_to_include[] = '*';
1170
+				}
1171
+			}
1172
+		} else {
1173
+			//look for ones with no period
1174
+			foreach ($includes as $field_to_include) {
1175
+				$field_to_include = trim($field_to_include);
1176
+				if (
1177
+					strpos($field_to_include, '.') === false
1178
+					&& ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include)
1179
+				) {
1180
+					$extracted_fields_to_include[] = $field_to_include;
1181
+				}
1182
+			}
1183
+		}
1184
+		return $extracted_fields_to_include;
1185
+	}
1186 1186
 }
1187 1187
 
1188 1188
 
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\libraries\rest_api\Model_Data_Translator;
8 8
 use EventEspresso\core\db_models\helpers\ModelSchema;
9 9
 
10
-if (! defined('EVENT_ESPRESSO_VERSION')) {
10
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
11 11
     exit('No direct script access allowed');
12 12
 }
13 13
 
@@ -56,12 +56,12 @@  discard block
 block discarded – undo
56 56
         try {
57 57
             $matches = $controller->parse_route(
58 58
                 $request->get_route(),
59
-                '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~',
59
+                '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~',
60 60
                 array('version', 'model')
61 61
             );
62 62
             $controller->set_requested_version($matches['version']);
63 63
             $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
64
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
64
+            if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
65 65
                 return $controller->send_response(
66 66
                     new \WP_Error(
67 67
                         'endpoint_parsing_error',
@@ -99,12 +99,12 @@  discard block
 block discarded – undo
99 99
         try {
100 100
             $matches = $controller->parse_route(
101 101
                 $request->get_route(),
102
-                '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~',
102
+                '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~',
103 103
                 array('version', 'model')
104 104
             );
105 105
             $controller->set_requested_version($matches['version']);
106 106
             $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
107
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
107
+            if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
108 108
                 return array();
109 109
             }
110 110
             $model_schema = new ModelSchema();
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
                     $controller->get_model_version_info()->fields_on_model_in_this_version($model)
119 119
                 )
120 120
             );
121
-        } catch(\Exception $e) {
121
+        } catch (\Exception $e) {
122 122
             return array();
123 123
         }
124 124
     }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
     protected function get_route_from_request() {
134 134
         if (isset($GLOBALS['wp'])
135 135
             && $GLOBALS['wp'] instanceof \WP
136
-            && isset($GLOBALS['wp']->query_vars['rest_route'] )
136
+            && isset($GLOBALS['wp']->query_vars['rest_route'])
137 137
         ) {
138 138
             return $GLOBALS['wp']->query_vars['rest_route'];
139 139
         } else {
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
         try {
156 156
             $matches = $controller->parse_route(
157 157
                 $request->get_route(),
158
-                '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~',
158
+                '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~',
159 159
                 array('version', 'model', 'id'));
160 160
             $controller->set_requested_version($matches['version']);
161 161
             $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
162
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
162
+            if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) {
163 163
                 return $controller->send_response(
164 164
                     new \WP_Error(
165 165
                         'endpoint_parsing_error',
@@ -197,12 +197,12 @@  discard block
 block discarded – undo
197 197
         try {
198 198
             $matches = $controller->parse_route(
199 199
                 $request->get_route(),
200
-                '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~',
200
+                '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~',
201 201
                 array('version', 'model', 'id', 'related_model')
202 202
             );
203 203
             $controller->set_requested_version($matches['version']);
204 204
             $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']);
205
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) {
205
+            if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) {
206 206
                 return $controller->send_response(
207 207
                     new \WP_Error(
208 208
                         'endpoint_parsing_error',
@@ -217,11 +217,11 @@  discard block
 block discarded – undo
217 217
             $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular);
218 218
             //assume the related model name is plural and try to find the model's name
219 219
             $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']);
220
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
220
+            if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
221 221
                 //so the word didn't singularize well. Maybe that's just because it's a singular word?
222 222
                 $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']);
223 223
             }
224
-            if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
224
+            if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) {
225 225
                 return $controller->send_response(
226 226
                     new \WP_Error(
227 227
                         'endpoint_parsing_error',
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
     public function get_entities_from_model($model, $request)
258 258
     {
259 259
         $query_params = $this->create_model_query_params($model, $request->get_params());
260
-        if (! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) {
260
+        if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) {
261 261
             $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
262 262
             return new \WP_Error(
263 263
                 sprintf('rest_%s_cannot_list', $model_name_plural),
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
                 array('status' => 403)
270 270
             );
271 271
         }
272
-        if (! $request->get_header('no_rest_headers')) {
272
+        if ( ! $request->get_header('no_rest_headers')) {
273 273
             $this->_set_headers_from_query_params($model, $query_params);
274 274
         }
275 275
         /** @type array $results */
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
         $context = $this->validate_context($request->get_param('caps'));
300 300
         $model = $relation->get_this_model();
301 301
         $related_model = $relation->get_other_model();
302
-        if (! isset($primary_model_query_params[0])) {
302
+        if ( ! isset($primary_model_query_params[0])) {
303 303
             $primary_model_query_params[0] = array();
304 304
         }
305 305
         //check if they can access the 1st model object
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
         }
351 351
         $query_params['default_where_conditions'] = 'none';
352 352
         $query_params['caps'] = $context;
353
-        if (! $request->get_header('no_rest_headers')) {
353
+        if ( ! $request->get_header('no_rest_headers')) {
354 354
             $this->_set_headers_from_query_params($relation->get_other_model(), $query_params);
355 355
         }
356 356
         /** @type array $results */
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
      */
403 403
     public function get_entities_from_relation($id, $relation, $request)
404 404
     {
405
-        if (! $relation->get_this_model()->has_primary_key_field()) {
405
+        if ( ! $relation->get_this_model()->has_primary_key_field()) {
406 406
             throw new \EE_Error(
407 407
                 sprintf(
408 408
                     __('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s',
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
         $this->_set_debug_info('missing caps',
440 440
             Capabilities::get_missing_permissions_string($model, $query_params['caps']));
441 441
         //normally the limit to a 2-part array, where the 2nd item is the limit
442
-        if (! isset($query_params['limit'])) {
442
+        if ( ! isset($query_params['limit'])) {
443 443
             $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit();
444 444
         }
445 445
         if (is_array($query_params['limit'])) {
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
      */
474 474
     public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null)
475 475
     {
476
-        if (! $rest_request instanceof \WP_REST_Request) {
476
+        if ( ! $rest_request instanceof \WP_REST_Request) {
477 477
             //ok so this was called in the old style, where the 3rd arg was
478 478
             //$include, and the 4th arg was $context
479 479
             //now setup the request just to avoid fatal errors, although we won't be able
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
                 if ($field_value instanceof \DateTime) {
559 559
                     $timezone = $field_value->getTimezone();
560 560
                     $field_value->setTimezone(new \DateTimeZone('UTC'));
561
-                    $result[$field_name . '_gmt'] = Model_Data_Translator::prepare_field_value_for_json(
561
+                    $result[$field_name.'_gmt'] = Model_Data_Translator::prepare_field_value_for_json(
562 562
                         $field_obj,
563 563
                         $field_value,
564 564
                         $this->get_model_version_info()->requested_version()
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
         if ($model->has_primary_key_field()) {
637 637
             foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) {
638 638
                 $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj);
639
-                $links[\EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part] = array(
639
+                $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array(
640 640
                     array(
641 641
                         'href'   => $this->get_versioned_link_to(
642 642
                             \EEH_Inflector::pluralize_and_lower($model->get_this_model_name())
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
         $db_row = array()
672 672
     ) {
673 673
         //if $db_row not included, hope the entity array has what we need
674
-        if (! $db_row) {
674
+        if ( ! $db_row) {
675 675
             $db_row = $entity_array;
676 676
         }
677 677
         $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), '');
678 678
         $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model);
679 679
         //if they passed in * or didn't specify any includes, return everything
680
-        if (! in_array('*', $includes_for_this_model)
680
+        if ( ! in_array('*', $includes_for_this_model)
681 681
             && ! empty($includes_for_this_model)
682 682
         ) {
683 683
             if ($model->has_primary_key_field()) {
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
         $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps'));
853 853
         $this->_set_debug_info('model query params', $restricted_query_params);
854 854
         $model_rows = $model->get_all_wpdb_results($restricted_query_params);
855
-        if (! empty ($model_rows)) {
855
+        if ( ! empty ($model_rows)) {
856 856
             return $this->create_entity_from_wpdb_result(
857 857
                 $model,
858 858
                 array_shift($model_rows),
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
             //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities
862 862
             $lowercase_model_name = strtolower($model->get_this_model_name());
863 863
             $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params);
864
-            if (! empty($model_rows_found_sans_restrictions)) {
864
+            if ( ! empty($model_rows_found_sans_restrictions)) {
865 865
                 //you got shafted- it existed but we didn't want to tell you!
866 866
                 return new \WP_Error(
867 867
                     'rest_user_cannot_read',
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
      */
897 897
     public function validate_context($context)
898 898
     {
899
-        if (! $context) {
899
+        if ( ! $context) {
900 900
             $context = \EEM_Base::caps_read;
901 901
         }
902 902
         $valid_contexts = \EEM_Base::valid_cap_contexts();
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
             \EEM_Base::default_where_conditions_minimum_all,
923 923
             \EEM_Base::default_where_conditions_minimum_others,
924 924
         );
925
-        if (! $default_query_params) {
925
+        if ( ! $default_query_params) {
926 926
             $default_query_params = \EEM_Base::default_where_conditions_all;
927 927
         }
928 928
         if (
@@ -1007,14 +1007,14 @@  discard block
 block discarded – undo
1007 1007
         }
1008 1008
         if (isset($query_parameters['limit'])) {
1009 1009
             //limit should be either a string like '23' or '23,43', or an array with two items in it
1010
-            if (! is_array($query_parameters['limit'])) {
1011
-                $limit_array = explode(',', (string)$query_parameters['limit']);
1010
+            if ( ! is_array($query_parameters['limit'])) {
1011
+                $limit_array = explode(',', (string) $query_parameters['limit']);
1012 1012
             } else {
1013 1013
                 $limit_array = $query_parameters['limit'];
1014 1014
             }
1015 1015
             $sanitized_limit = array();
1016 1016
             foreach ($limit_array as $key => $limit_part) {
1017
-                if ($this->_debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1017
+                if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) {
1018 1018
                     throw new \EE_Error(
1019 1019
                         sprintf(
1020 1020
                             __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.',
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
                         )
1024 1024
                     );
1025 1025
                 }
1026
-                $sanitized_limit[] = (int)$limit_part;
1026
+                $sanitized_limit[] = (int) $limit_part;
1027 1027
             }
1028 1028
             $model_query_params['limit'] = implode(',', $sanitized_limit);
1029 1029
         } else {
@@ -1111,17 +1111,17 @@  discard block
 block discarded – undo
1111 1111
         foreach ($exploded_contents as $item) {
1112 1112
             $item = trim($item);
1113 1113
             //if no prefix was provided, so we look for items with no "." in them
1114
-            if (! $prefix) {
1114
+            if ( ! $prefix) {
1115 1115
                 //does this item have a period?
1116 1116
                 if (strpos($item, '.') === false) {
1117 1117
                     //if not, then its what we're looking for
1118 1118
                     $contents_with_prefix[] = $item;
1119 1119
                 }
1120
-            } else if (strpos($item, $prefix . '.') === 0) {
1120
+            } else if (strpos($item, $prefix.'.') === 0) {
1121 1121
                 //this item has the prefix and a period, grab it
1122 1122
                 $contents_with_prefix[] = substr(
1123 1123
                     $item,
1124
-                    strpos($item, $prefix . '.') + strlen($prefix . '.')
1124
+                    strpos($item, $prefix.'.') + strlen($prefix.'.')
1125 1125
                 );
1126 1126
             } else if ($item === $prefix) {
1127 1127
                 //this item is JUST the prefix
@@ -1161,9 +1161,9 @@  discard block
 block discarded – undo
1161 1161
         if ($model_name) {
1162 1162
             foreach ($includes as $field_to_include) {
1163 1163
                 $field_to_include = trim($field_to_include);
1164
-                if (strpos($field_to_include, $model_name . '.') === 0) {
1164
+                if (strpos($field_to_include, $model_name.'.') === 0) {
1165 1165
                     //found the model name at the exact start
1166
-                    $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include);
1166
+                    $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include);
1167 1167
                     $extracted_fields_to_include[] = $field_sans_model_name;
1168 1168
                 } elseif ($field_to_include == $model_name) {
1169 1169
                     $extracted_fields_to_include[] = '*';
Please login to merge, or discard this patch.