Completed
Branch FET-10766-extract-activation-d... (a86901)
by
unknown
187:06 queued 176:14
created
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +3299 added lines, -3299 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -28,2114 +28,2114 @@  discard block
 block discarded – undo
28 28
 {
29 29
 
30 30
 
31
-    //set in _init_page_props()
32
-    public $page_slug;
31
+	//set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    //set in define_page_props()
39
-    protected $_admin_base_url;
38
+	//set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    //set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	//set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    //navtabs
52
-    protected $_nav_tabs;
51
+	//navtabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56
-    //helptourstops
57
-    protected $_help_tour = array();
56
+	//helptourstops
57
+	protected $_help_tour = array();
58 58
 
59 59
 
60
-    //template variables (used by templates)
61
-    protected $_template_path;
60
+	//template variables (used by templates)
61
+	protected $_template_path;
62 62
 
63
-    protected $_column_template_path;
63
+	protected $_column_template_path;
64 64
 
65
-    /**
66
-     * @var array $_template_args
67
-     */
68
-    protected $_template_args = array();
65
+	/**
66
+	 * @var array $_template_args
67
+	 */
68
+	protected $_template_args = array();
69 69
 
70
-    /**
71
-     * this will hold the list table object for a given view.
72
-     *
73
-     * @var EE_Admin_List_Table $_list_table_object
74
-     */
75
-    protected $_list_table_object;
70
+	/**
71
+	 * this will hold the list table object for a given view.
72
+	 *
73
+	 * @var EE_Admin_List_Table $_list_table_object
74
+	 */
75
+	protected $_list_table_object;
76 76
 
77
-    //bools
78
-    protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
77
+	//bools
78
+	protected $_is_UI_request = null; //this starts at null so we can have no header routes progress through two states.
79 79
 
80
-    protected $_routing;
80
+	protected $_routing;
81 81
 
82
-    //list table args
83
-    protected $_view;
82
+	//list table args
83
+	protected $_view;
84 84
 
85
-    protected $_views;
85
+	protected $_views;
86 86
 
87 87
 
88
-    //action => method pairs used for routing incoming requests
89
-    protected $_page_routes;
88
+	//action => method pairs used for routing incoming requests
89
+	protected $_page_routes;
90 90
 
91
-    protected $_page_config;
91
+	protected $_page_config;
92 92
 
93
-    //the current page route and route config
94
-    protected $_route;
93
+	//the current page route and route config
94
+	protected $_route;
95 95
 
96
-    protected $_route_config;
96
+	protected $_route_config;
97 97
 
98
-    /**
99
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
100
-     * actions.
101
-     *
102
-     * @since 4.6.x
103
-     * @var array.
104
-     */
105
-    protected $_default_route_query_args;
98
+	/**
99
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
100
+	 * actions.
101
+	 *
102
+	 * @since 4.6.x
103
+	 * @var array.
104
+	 */
105
+	protected $_default_route_query_args;
106 106
 
107
-    //set via request page and action args.
108
-    protected $_current_page;
107
+	//set via request page and action args.
108
+	protected $_current_page;
109 109
 
110
-    protected $_current_view;
110
+	protected $_current_view;
111 111
 
112
-    protected $_current_page_view_url;
112
+	protected $_current_page_view_url;
113 113
 
114
-    //sanitized request action (and nonce)
115
-    /**
116
-     * @var string $_req_action
117
-     */
118
-    protected $_req_action;
114
+	//sanitized request action (and nonce)
115
+	/**
116
+	 * @var string $_req_action
117
+	 */
118
+	protected $_req_action;
119 119
 
120
-    /**
121
-     * @var string $_req_nonce
122
-     */
123
-    protected $_req_nonce;
120
+	/**
121
+	 * @var string $_req_nonce
122
+	 */
123
+	protected $_req_nonce;
124 124
 
125
-    //search related
126
-    protected $_search_btn_label;
125
+	//search related
126
+	protected $_search_btn_label;
127 127
 
128
-    protected $_search_box_callback;
128
+	protected $_search_box_callback;
129 129
 
130
-    /**
131
-     * WP Current Screen object
132
-     *
133
-     * @var WP_Screen
134
-     */
135
-    protected $_current_screen;
130
+	/**
131
+	 * WP Current Screen object
132
+	 *
133
+	 * @var WP_Screen
134
+	 */
135
+	protected $_current_screen;
136 136
 
137
-    //for holding EE_Admin_Hooks object when needed (set via set_hook_object())
138
-    protected $_hook_obj;
137
+	//for holding EE_Admin_Hooks object when needed (set via set_hook_object())
138
+	protected $_hook_obj;
139 139
 
140
-    //for holding incoming request data
141
-    protected $_req_data;
140
+	//for holding incoming request data
141
+	protected $_req_data;
142 142
 
143
-    // yes / no array for admin form fields
144
-    protected $_yes_no_values = array();
145
-
146
-    //some default things shared by all child classes
147
-    protected $_default_espresso_metaboxes;
148
-
149
-    /**
150
-     *    EE_Registry Object
151
-     *
152
-     * @var    EE_Registry
153
-     * @access    protected
154
-     */
155
-    protected $EE = null;
156
-
157
-
158
-
159
-    /**
160
-     * This is just a property that flags whether the given route is a caffeinated route or not.
161
-     *
162
-     * @var boolean
163
-     */
164
-    protected $_is_caf = false;
165
-
166
-
167
-
168
-    /**
169
-     * @Constructor
170
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
171
-     * @access public
172
-     */
173
-    public function __construct($routing = true)
174
-    {
175
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
176
-            $this->_is_caf = true;
177
-        }
178
-        $this->_yes_no_values = array(
179
-                array('id' => true, 'text' => __('Yes', 'event_espresso')),
180
-                array('id' => false, 'text' => __('No', 'event_espresso')),
181
-        );
182
-        //set the _req_data property.
183
-        $this->_req_data = array_merge($_GET, $_POST);
184
-        //routing enabled?
185
-        $this->_routing = $routing;
186
-        //set initial page props (child method)
187
-        $this->_init_page_props();
188
-        //set global defaults
189
-        $this->_set_defaults();
190
-        //set early because incoming requests could be ajax related and we need to register those hooks.
191
-        $this->_global_ajax_hooks();
192
-        $this->_ajax_hooks();
193
-        //other_page_hooks have to be early too.
194
-        $this->_do_other_page_hooks();
195
-        //This just allows us to have extending classes do something specific
196
-        // before the parent constructor runs _page_setup().
197
-        if (method_exists($this, '_before_page_setup')) {
198
-            $this->_before_page_setup();
199
-        }
200
-        //set up page dependencies
201
-        $this->_page_setup();
202
-    }
203
-
204
-
205
-
206
-    /**
207
-     * _init_page_props
208
-     * Child classes use to set at least the following properties:
209
-     * $page_slug.
210
-     * $page_label.
211
-     *
212
-     * @abstract
213
-     * @access protected
214
-     * @return void
215
-     */
216
-    abstract protected function _init_page_props();
217
-
218
-
219
-
220
-    /**
221
-     * _ajax_hooks
222
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
223
-     * Note: within the ajax callback methods.
224
-     *
225
-     * @abstract
226
-     * @access protected
227
-     * @return void
228
-     */
229
-    abstract protected function _ajax_hooks();
230
-
231
-
232
-
233
-    /**
234
-     * _define_page_props
235
-     * child classes define page properties in here.  Must include at least:
236
-     * $_admin_base_url = base_url for all admin pages
237
-     * $_admin_page_title = default admin_page_title for admin pages
238
-     * $_labels = array of default labels for various automatically generated elements:
239
-     *    array(
240
-     *        'buttons' => array(
241
-     *            'add' => __('label for add new button'),
242
-     *            'edit' => __('label for edit button'),
243
-     *            'delete' => __('label for delete button')
244
-     *            )
245
-     *        )
246
-     *
247
-     * @abstract
248
-     * @access protected
249
-     * @return void
250
-     */
251
-    abstract protected function _define_page_props();
252
-
253
-
254
-
255
-    /**
256
-     * _set_page_routes
257
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
258
-     * route. Here's the format
259
-     * $this->_page_routes = array(
260
-     *        'default' => array(
261
-     *            'func' => '_default_method_handling_route',
262
-     *            'args' => array('array','of','args'),
263
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
264
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
265
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
266
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
267
-     *        ),
268
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
269
-     *        )
270
-     * )
271
-     *
272
-     * @abstract
273
-     * @access protected
274
-     * @return void
275
-     */
276
-    abstract protected function _set_page_routes();
277
-
278
-
279
-
280
-    /**
281
-     * _set_page_config
282
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
283
-     * Format:
284
-     * $this->_page_config = array(
285
-     *        'default' => array(
286
-     *            'labels' => array(
287
-     *                'buttons' => array(
288
-     *                    'add' => __('label for adding item'),
289
-     *                    'edit' => __('label for editing item'),
290
-     *                    'delete' => __('label for deleting item')
291
-     *                ),
292
-     *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
293
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
294
-     *            'nav' => array(
295
-     *                'label' => __('Label for Tab', 'event_espresso').
296
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
297
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
298
-     *                'order' => 10, //required to indicate tab position.
299
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
300
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
301
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
302
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
303
-     *            this flag to make sure the necessary js gets enqueued on page load.
304
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
305
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
306
-     *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
307
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
308
-     *                'tab_id' => array(
309
-     *                    'title' => 'tab_title',
310
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
311
-     *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
312
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
313
-     *                    ),
314
-     *                'tab2_id' => array(
315
-     *                    'title' => 'tab2 title',
316
-     *                    'filename' => 'file_name_2'
317
-     *                    'callback' => 'callback_method_for_content',
318
-     *                 ),
319
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
320
-     *            'help_tour' => array(
321
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
322
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
323
-     *            ),
324
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
325
-     *            'require_nonce' to FALSE
326
-     *            )
327
-     * )
328
-     *
329
-     * @abstract
330
-     * @access protected
331
-     * @return void
332
-     */
333
-    abstract protected function _set_page_config();
334
-
335
-
336
-
337
-
338
-
339
-    /** end sample help_tour methods **/
340
-    /**
341
-     * _add_screen_options
342
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
343
-     * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
344
-     *
345
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
346
-     *         see also WP_Screen object documents...
347
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
348
-     * @abstract
349
-     * @access protected
350
-     * @return void
351
-     */
352
-    abstract protected function _add_screen_options();
353
-
354
-
355
-
356
-    /**
357
-     * _add_feature_pointers
358
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
359
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
360
-     * Note: this is just a placeholder for now.  Implementation will come down the road
361
-     * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
362
-     *
363
-     * @link   http://eamann.com/tech/wordpress-portland/
364
-     * @abstract
365
-     * @access protected
366
-     * @return void
367
-     */
368
-    abstract protected function _add_feature_pointers();
369
-
370
-
371
-
372
-    /**
373
-     * load_scripts_styles
374
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
375
-     * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
376
-     *
377
-     * @abstract
378
-     * @access public
379
-     * @return void
380
-     */
381
-    abstract public function load_scripts_styles();
382
-
383
-
384
-
385
-    /**
386
-     * admin_init
387
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
388
-     *
389
-     * @abstract
390
-     * @access public
391
-     * @return void
392
-     */
393
-    abstract public function admin_init();
394
-
395
-
396
-
397
-    /**
398
-     * admin_notices
399
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
400
-     *
401
-     * @abstract
402
-     * @access public
403
-     * @return void
404
-     */
405
-    abstract public function admin_notices();
406
-
407
-
408
-
409
-    /**
410
-     * admin_footer_scripts
411
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
412
-     *
413
-     * @access public
414
-     * @return void
415
-     */
416
-    abstract public function admin_footer_scripts();
417
-
418
-
419
-
420
-    /**
421
-     * admin_footer
422
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
423
-     *
424
-     * @access  public
425
-     * @return void
426
-     */
427
-    public function admin_footer()
428
-    {
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * _global_ajax_hooks
435
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
436
-     * Note: within the ajax callback methods.
437
-     *
438
-     * @abstract
439
-     * @access protected
440
-     * @return void
441
-     */
442
-    protected function _global_ajax_hooks()
443
-    {
444
-        //for lazy loading of metabox content
445
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
446
-    }
447
-
448
-
449
-
450
-    public function ajax_metabox_content()
451
-    {
452
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
453
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
454
-        self::cached_rss_display($contentid, $url);
455
-        wp_die();
456
-    }
457
-
458
-
459
-
460
-    /**
461
-     * _page_setup
462
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
463
-     *
464
-     * @final
465
-     * @access protected
466
-     * @return void
467
-     */
468
-    final protected function _page_setup()
469
-    {
470
-        //requires?
471
-        //admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
472
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
473
-        //next verify if we need to load anything...
474
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475
-        $this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476
-        global $ee_menu_slugs;
477
-        $ee_menu_slugs = (array)$ee_menu_slugs;
478
-        if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479
-            return;
480
-        }
481
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
482
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
483
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
484
-        }
485
-        // then set blank or -1 action values to 'default'
486
-        $this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
487
-        //if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
488
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
489
-        //however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
-        $this->_current_view = $this->_req_action;
492
-        $this->_req_nonce = $this->_req_action . '_nonce';
493
-        $this->_define_page_props();
494
-        $this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495
-        //default things
496
-        $this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
497
-        //set page configs
498
-        $this->_set_page_routes();
499
-        $this->_set_page_config();
500
-        //let's include any referrer data in our default_query_args for this route for "stickiness".
501
-        if (isset($this->_req_data['wp_referer'])) {
502
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
503
-        }
504
-        //for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
505
-        if (method_exists($this, '_extend_page_config')) {
506
-            $this->_extend_page_config();
507
-        }
508
-        //for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
509
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
510
-            $this->_extend_page_config_for_cpt();
511
-        }
512
-        //filter routes and page_config so addons can add their stuff. Filtering done per class
513
-        $this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
-        $this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
515
-        //if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
-            add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
518
-        }
519
-        //next route only if routing enabled
520
-        if ($this->_routing && ! defined('DOING_AJAX')) {
521
-            $this->_verify_routes();
522
-            //next let's just check user_access and kill if no access
523
-            $this->check_user_access();
524
-            if ($this->_is_UI_request) {
525
-                //admin_init stuff - global, all views for this page class, specific view
526
-                add_action('admin_init', array($this, 'admin_init'), 10);
527
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
529
-                }
530
-            } else {
531
-                //hijack regular WP loading and route admin request immediately
532
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
533
-                $this->route_admin_request();
534
-            }
535
-        }
536
-    }
537
-
538
-
539
-
540
-    /**
541
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
542
-     *
543
-     * @access private
544
-     * @return void
545
-     */
546
-    private function _do_other_page_hooks()
547
-    {
548
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
549
-        foreach ($registered_pages as $page) {
550
-            //now let's setup the file name and class that should be present
551
-            $classname = str_replace('.class.php', '', $page);
552
-            //autoloaders should take care of loading file
553
-            if ( ! class_exists($classname)) {
554
-                $error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555
-                $error_msg[] = $error_msg[0]
556
-                               . "\r\n"
557
-                               . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
-                                'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
559
-                throw new EE_Error(implode('||', $error_msg));
560
-            }
561
-            $a = new ReflectionClass($classname);
562
-            //notice we are passing the instance of this class to the hook object.
563
-            $hookobj[] = $a->newInstance($this);
564
-        }
565
-    }
566
-
567
-
568
-
569
-    public function load_page_dependencies()
570
-    {
571
-        try {
572
-            $this->_load_page_dependencies();
573
-        } catch (EE_Error $e) {
574
-            $e->get_error();
575
-        }
576
-    }
577
-
578
-
579
-
580
-    /**
581
-     * load_page_dependencies
582
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
583
-     *
584
-     * @access public
585
-     * @return void
586
-     */
587
-    protected function _load_page_dependencies()
588
-    {
589
-        //let's set the current_screen and screen options to override what WP set
590
-        $this->_current_screen = get_current_screen();
591
-        //load admin_notices - global, page class, and view specific
592
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
594
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
596
-        }
597
-        //load network admin_notices - global, page class, and view specific
598
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
601
-        }
602
-        //this will save any per_page screen options if they are present
603
-        $this->_set_per_page_screen_options();
604
-        //setup list table properties
605
-        $this->_set_list_table();
606
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
607
-        $this->_add_registered_meta_boxes();
608
-        $this->_add_screen_columns();
609
-        //add screen options - global, page child class, and view specific
610
-        $this->_add_global_screen_options();
611
-        $this->_add_screen_options();
612
-        if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
-            call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
614
-        }
615
-        //add help tab(s) and tours- set via page_config and qtips.
616
-        $this->_add_help_tour();
617
-        $this->_add_help_tabs();
618
-        $this->_add_qtips();
619
-        //add feature_pointers - global, page child class, and view specific
620
-        $this->_add_feature_pointers();
621
-        $this->_add_global_feature_pointers();
622
-        if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
-            call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
624
-        }
625
-        //enqueue scripts/styles - global, page class, and view specific
626
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
-        if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
-            add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
630
-        }
631
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632
-        //admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
-        if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
-            add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
637
-        }
638
-        //admin footer scripts
639
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
641
-        if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
-            add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
643
-        }
644
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645
-        //targeted hook
646
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
647
-    }
648
-
649
-
650
-
651
-    /**
652
-     * _set_defaults
653
-     * This sets some global defaults for class properties.
654
-     */
655
-    private function _set_defaults()
656
-    {
657
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
658
-        $this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
659
-        $this->default_nav_tab_name = 'overview';
660
-        //init template args
661
-        $this->_template_args = array(
662
-                'admin_page_header'  => '',
663
-                'admin_page_content' => '',
664
-                'post_body_content'  => '',
665
-                'before_list_table'  => '',
666
-                'after_list_table'   => '',
667
-        );
668
-    }
669
-
670
-
671
-
672
-    /**
673
-     * route_admin_request
674
-     *
675
-     * @see    _route_admin_request()
676
-     * @access public
677
-     * @return void|exception error
678
-     */
679
-    public function route_admin_request()
680
-    {
681
-        try {
682
-            $this->_route_admin_request();
683
-        } catch (EE_Error $e) {
684
-            $e->get_error();
685
-        }
686
-    }
687
-
688
-
689
-
690
-    public function set_wp_page_slug($wp_page_slug)
691
-    {
692
-        $this->_wp_page_slug = $wp_page_slug;
693
-        //if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
694
-        if (is_network_admin()) {
695
-            $this->_wp_page_slug .= '-network';
696
-        }
697
-    }
698
-
699
-
700
-
701
-    /**
702
-     * _verify_routes
703
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
704
-     *
705
-     * @access protected
706
-     * @return void
707
-     */
708
-    protected function _verify_routes()
709
-    {
710
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
711
-        if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
712
-            return false;
713
-        }
714
-        $this->_route = false;
715
-        $func = false;
716
-        $args = array();
717
-        // check that the page_routes array is not empty
718
-        if (empty($this->_page_routes)) {
719
-            // user error msg
720
-            $error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721
-            // developer error msg
722
-            $error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723
-            throw new EE_Error($error_msg);
724
-        }
725
-        // and that the requested page route exists
726
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
727
-            $this->_route = $this->_page_routes[$this->_req_action];
728
-            $this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
729
-        } else {
730
-            // user error msg
731
-            $error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732
-            // developer error msg
733
-            $error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734
-            throw new EE_Error($error_msg);
735
-        }
736
-        // and that a default route exists
737
-        if ( ! array_key_exists('default', $this->_page_routes)) {
738
-            // user error msg
739
-            $error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740
-            // developer error msg
741
-            $error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742
-            throw new EE_Error($error_msg);
743
-        }
744
-        //first lets' catch if the UI request has EVER been set.
745
-        if ($this->_is_UI_request === null) {
746
-            //lets set if this is a UI request or not.
747
-            $this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
748
-            //wait a minute... we might have a noheader in the route array
749
-            $this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
750
-        }
751
-        $this->_set_current_labels();
752
-    }
753
-
754
-
755
-
756
-    /**
757
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
758
-     *
759
-     * @param  string $route the route name we're verifying
760
-     * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
761
-     */
762
-    protected function _verify_route($route)
763
-    {
764
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
765
-            return true;
766
-        } else {
767
-            // user error msg
768
-            $error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769
-            // developer error msg
770
-            $error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771
-            throw new EE_Error($error_msg);
772
-        }
773
-    }
774
-
775
-
776
-
777
-    /**
778
-     * perform nonce verification
779
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
780
-     *
781
-     * @param  string $nonce     The nonce sent
782
-     * @param  string $nonce_ref The nonce reference string (name0)
783
-     * @return mixed (bool|die)
784
-     */
785
-    protected function _verify_nonce($nonce, $nonce_ref)
786
-    {
787
-        // verify nonce against expected value
788
-        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
789
-            // these are not the droids you are looking for !!!
790
-            $msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791
-            if (WP_DEBUG) {
792
-                $msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793
-            }
794
-            if ( ! defined('DOING_AJAX')) {
795
-                wp_die($msg);
796
-            } else {
797
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
798
-                $this->_return_json();
799
-            }
800
-        }
801
-    }
802
-
803
-
804
-
805
-    /**
806
-     * _route_admin_request()
807
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
808
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
809
-     * in the page routes and then will try to load the corresponding method.
810
-     *
811
-     * @access protected
812
-     * @return void
813
-     * @throws \EE_Error
814
-     */
815
-    protected function _route_admin_request()
816
-    {
817
-        if ( ! $this->_is_UI_request) {
818
-            $this->_verify_routes();
819
-        }
820
-        $nonce_check = isset($this->_route_config['require_nonce'])
821
-            ? $this->_route_config['require_nonce']
822
-            : true;
823
-        if ($this->_req_action !== 'default' && $nonce_check) {
824
-            // set nonce from post data
825
-            $nonce = isset($this->_req_data[$this->_req_nonce])
826
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce])
827
-                : '';
828
-            $this->_verify_nonce($nonce, $this->_req_nonce);
829
-        }
830
-        //set the nav_tabs array but ONLY if this is  UI_request
831
-        if ($this->_is_UI_request) {
832
-            $this->_set_nav_tabs();
833
-        }
834
-        // grab callback function
835
-        $func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
836
-        // check if callback has args
837
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
838
-        $error_msg = '';
839
-        // action right before calling route
840
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
841
-        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
842
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
843
-        }
844
-        // right before calling the route, let's remove _wp_http_referer from the
845
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
846
-        $_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
847
-        if ( ! empty($func)) {
848
-            if (is_array($func)) {
849
-                list($class, $method) = $func;
850
-            } else if (strpos($func, '::') !== false) {
851
-                list($class, $method) = explode('::', $func);
852
-            } else {
853
-                $class = $this;
854
-                $method = $func;
855
-            }
856
-            if ( ! (is_object($class) && $class === $this)) {
857
-                // send along this admin page object for access by addons.
858
-                $args['admin_page_object'] = $this;
859
-            }
860
-
861
-            if (
862
-                //is it a method on a class that doesn't work?
863
-                (
864
-                    (
865
-                        method_exists($class, $method)
866
-                        && call_user_func_array(array($class, $method), $args) === false
867
-                    )
868
-                    && (
869
-                        //is it a standalone function that doesn't work?
870
-                        function_exists($method)
871
-                        && call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
872
-                    )
873
-                )
874
-                || (
875
-                    //is it neither a class method NOR a standalone function?
876
-                    ! method_exists($class, $method)
877
-                    && ! function_exists($method)
878
-                )
879
-            ) {
880
-                // user error msg
881
-                $error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
882
-                // developer error msg
883
-                $error_msg .= '||';
884
-                $error_msg .= sprintf(
885
-                    __(
886
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
887
-                        'event_espresso'
888
-                    ),
889
-                    $method
890
-                );
891
-            }
892
-            if ( ! empty($error_msg)) {
893
-                throw new EE_Error($error_msg);
894
-            }
895
-        }
896
-        //if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
897
-        //now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
898
-        if ($this->_is_UI_request === false
899
-            && is_array($this->_route)
900
-            && ! empty($this->_route['headers_sent_route'])
901
-        ) {
902
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
903
-        }
904
-    }
905
-
906
-
907
-
908
-    /**
909
-     * This method just allows the resetting of page properties in the case where a no headers
910
-     * route redirects to a headers route in its route config.
911
-     *
912
-     * @since   4.3.0
913
-     * @param  string $new_route New (non header) route to redirect to.
914
-     * @return   void
915
-     */
916
-    protected function _reset_routing_properties($new_route)
917
-    {
918
-        $this->_is_UI_request = true;
919
-        //now we set the current route to whatever the headers_sent_route is set at
920
-        $this->_req_data['action'] = $new_route;
921
-        //rerun page setup
922
-        $this->_page_setup();
923
-    }
924
-
925
-
926
-
927
-    /**
928
-     * _add_query_arg
929
-     * adds nonce to array of arguments then calls WP add_query_arg function
930
-     *(internally just uses EEH_URL's function with the same name)
931
-     *
932
-     * @access public
933
-     * @param array  $args
934
-     * @param string $url
935
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
936
-     *                                        url in an associative array indexed by the key 'wp_referer';
937
-     *                                        Example usage:
938
-     *                                        If the current page is:
939
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
940
-     *                                        &action=default&event_id=20&month_range=March%202015
941
-     *                                        &_wpnonce=5467821
942
-     *                                        and you call:
943
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
944
-     *                                        array(
945
-     *                                        'action' => 'resend_something',
946
-     *                                        'page=>espresso_registrations'
947
-     *                                        ),
948
-     *                                        $some_url,
949
-     *                                        true
950
-     *                                        );
951
-     *                                        It will produce a url in this structure:
952
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
953
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
954
-     *                                        month_range]=March%202015
955
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
956
-     * @return string
957
-     */
958
-    public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
959
-    {
960
-        //if there is a _wp_http_referer include the values from the request but only if sticky = true
961
-        if ($sticky) {
962
-            $request = $_REQUEST;
963
-            unset($request['_wp_http_referer']);
964
-            unset($request['wp_referer']);
965
-            foreach ($request as $key => $value) {
966
-                //do not add nonces
967
-                if (strpos($key, 'nonce') !== false) {
968
-                    continue;
969
-                }
970
-                $args['wp_referer[' . $key . ']'] = $value;
971
-            }
972
-        }
973
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * This returns a generated link that will load the related help tab.
980
-     *
981
-     * @param  string $help_tab_id the id for the connected help tab
982
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
983
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
984
-     * @uses EEH_Template::get_help_tab_link()
985
-     * @return string              generated link
986
-     */
987
-    protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
988
-    {
989
-        return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
990
-    }
991
-
992
-
993
-
994
-    /**
995
-     * _add_help_tabs
996
-     * Note child classes define their help tabs within the page_config array.
997
-     *
998
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
999
-     * @access protected
1000
-     * @return void
1001
-     */
1002
-    protected function _add_help_tabs()
1003
-    {
1004
-        $tour_buttons = '';
1005
-        if (isset($this->_page_config[$this->_req_action])) {
1006
-            $config = $this->_page_config[$this->_req_action];
1007
-            //is there a help tour for the current route?  if there is let's setup the tour buttons
1008
-            if (isset($this->_help_tour[$this->_req_action])) {
1009
-                $tb = array();
1010
-                $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1011
-                foreach ($this->_help_tour['tours'] as $tour) {
1012
-                    //if this is the end tour then we don't need to setup a button
1013
-                    if ($tour instanceof EE_Help_Tour_final_stop) {
1014
-                        continue;
1015
-                    }
1016
-                    $tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1017
-                }
1018
-                $tour_buttons .= implode('<br />', $tb);
1019
-                $tour_buttons .= '</div></div>';
1020
-            }
1021
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1022
-            if (is_array($config) && isset($config['help_sidebar'])) {
1023
-                //check that the callback given is valid
1024
-                if ( ! method_exists($this, $config['help_sidebar'])) {
1025
-                    throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1026
-                            'event_espresso'), $config['help_sidebar'], get_class($this)));
1027
-                }
1028
-                $content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029
-                $content .= $tour_buttons; //add help tour buttons.
1030
-                //do we have any help tours setup?  Cause if we do we want to add the buttons
1031
-                $this->_current_screen->set_help_sidebar($content);
1032
-            }
1033
-            //if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1034
-            if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1035
-                $this->_current_screen->set_help_sidebar($tour_buttons);
1036
-            }
1037
-            //handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1038
-            if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039
-                $_ht['id'] = $this->page_slug;
1040
-                $_ht['title'] = __('Help Tours', 'event_espresso');
1041
-                $_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1042
-                $this->_current_screen->add_help_tab($_ht);
1043
-            }/**/
1044
-            if ( ! isset($config['help_tabs'])) {
1045
-                return;
1046
-            } //no help tabs for this route
1047
-            foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1048
-                //we're here so there ARE help tabs!
1049
-                //make sure we've got what we need
1050
-                if ( ! isset($cfg['title'])) {
1051
-                    throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1052
-                }
1053
-                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1054
-                    throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1055
-                            'event_espresso'));
1056
-                }
1057
-                //first priority goes to content.
1058
-                if ( ! empty($cfg['content'])) {
1059
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060
-                    //second priority goes to filename
1061
-                } else if ( ! empty($cfg['filename'])) {
1062
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1063
-                    //it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1064
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1065
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066
-                    if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067
-                        EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1068
-                                'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1069
-                        return;
1070
-                    }
1071
-                    $template_args['admin_page_obj'] = $this;
1072
-                    $content = EEH_Template::display_template($file_path, $template_args, true);
1073
-                } else {
1074
-                    $content = '';
1075
-                }
1076
-                //check if callback is valid
1077
-                if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1078
-                    EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1079
-                            'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1080
-                    return;
1081
-                }
1082
-                //setup config array for help tab method
1083
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1084
-                $_ht = array(
1085
-                        'id'       => $id,
1086
-                        'title'    => $cfg['title'],
1087
-                        'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1088
-                        'content'  => $content,
1089
-                );
1090
-                $this->_current_screen->add_help_tab($_ht);
1091
-            }
1092
-        }
1093
-    }
1094
-
1095
-
1096
-
1097
-    /**
1098
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1099
-     *
1100
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1101
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1102
-     * @access protected
1103
-     * @return void
1104
-     */
1105
-    protected function _add_help_tour()
1106
-    {
1107
-        $tours = array();
1108
-        $this->_help_tour = array();
1109
-        //exit early if help tours are turned off globally
1110
-        if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1111
-            return;
1112
-        }
1113
-        //loop through _page_config to find any help_tour defined
1114
-        foreach ($this->_page_config as $route => $config) {
1115
-            //we're only going to set things up for this route
1116
-            if ($route !== $this->_req_action) {
1117
-                continue;
1118
-            }
1119
-            if (isset($config['help_tour'])) {
1120
-                foreach ($config['help_tour'] as $tour) {
1121
-                    $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1122
-                    //let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1124
-                    //if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125
-                    if ( ! is_readable($file_path)) {
1126
-                        EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1127
-                                $file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1128
-                        return;
1129
-                    }
1130
-                    require_once $file_path;
1131
-                    if ( ! class_exists($tour)) {
1132
-                        $error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
-                        $error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1134
-                                        'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135
-                        throw new EE_Error(implode('||', $error_msg));
1136
-                    }
1137
-                    $a = new ReflectionClass($tour);
1138
-                    $tour_obj = $a->newInstance($this->_is_caf);
1139
-                    $tours[] = $tour_obj;
1140
-                    $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1141
-                }
1142
-                //let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1143
-                $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1144
-                $tours[] = $end_stop_tour;
1145
-                $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1146
-            }
1147
-        }
1148
-        if ( ! empty($tours)) {
1149
-            $this->_help_tour['tours'] = $tours;
1150
-        }
1151
-        //thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1152
-    }
1153
-
1154
-
1155
-
1156
-    /**
1157
-     * This simply sets up any qtips that have been defined in the page config
1158
-     *
1159
-     * @access protected
1160
-     * @return void
1161
-     */
1162
-    protected function _add_qtips()
1163
-    {
1164
-        if (isset($this->_route_config['qtips'])) {
1165
-            $qtips = (array)$this->_route_config['qtips'];
1166
-            //load qtip loader
1167
-            $path = array(
1168
-                    $this->_get_dir() . '/qtips/',
1169
-                    EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1170
-            );
1171
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1172
-        }
1173
-    }
1174
-
1175
-
1176
-
1177
-    /**
1178
-     * _set_nav_tabs
1179
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1180
-     *
1181
-     * @access protected
1182
-     * @return void
1183
-     */
1184
-    protected function _set_nav_tabs()
1185
-    {
1186
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1187
-        $i = 0;
1188
-        foreach ($this->_page_config as $slug => $config) {
1189
-            if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1190
-                continue;
1191
-            } //no nav tab for this config
1192
-            //check for persistent flag
1193
-            if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1194
-                continue;
1195
-            } //nav tab is only to appear when route requested.
1196
-            if ( ! $this->check_user_access($slug, true)) {
1197
-                continue;
1198
-            } //no nav tab becasue current user does not have access.
1199
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1200
-            $this->_nav_tabs[$slug] = array(
1201
-                    'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202
-                    'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
-                    'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1204
-                    'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205
-            );
1206
-            $i++;
1207
-        }
1208
-        //if $this->_nav_tabs is empty then lets set the default
1209
-        if (empty($this->_nav_tabs)) {
1210
-            $this->_nav_tabs[$this->default_nav_tab_name] = array(
1211
-                    'url'       => $this->admin_base_url,
1212
-                    'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1213
-                    'css_class' => 'nav-tab-active',
1214
-                    'order'     => 10,
1215
-            );
1216
-        }
1217
-        //now let's sort the tabs according to order
1218
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1219
-    }
1220
-
1221
-
1222
-
1223
-    /**
1224
-     * _set_current_labels
1225
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1226
-     *
1227
-     * @access private
1228
-     * @return void
1229
-     */
1230
-    private function _set_current_labels()
1231
-    {
1232
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1233
-            foreach ($this->_route_config['labels'] as $label => $text) {
1234
-                if (is_array($text)) {
1235
-                    foreach ($text as $sublabel => $subtext) {
1236
-                        $this->_labels[$label][$sublabel] = $subtext;
1237
-                    }
1238
-                } else {
1239
-                    $this->_labels[$label] = $text;
1240
-                }
1241
-            }
1242
-        }
1243
-    }
1244
-
1245
-
1246
-
1247
-    /**
1248
-     *        verifies user access for this admin page
1249
-     *
1250
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1251
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1252
-     * @return        BOOL|wp_die()
1253
-     */
1254
-    public function check_user_access($route_to_check = '', $verify_only = false)
1255
-    {
1256
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1257
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1258
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1259
-                ? $this->_page_routes[$route_to_check]['capability'] : null;
1260
-        if (empty($capability) && empty($route_to_check)) {
1261
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1262
-        } else {
1263
-            $capability = empty($capability) ? 'manage_options' : $capability;
1264
-        }
1265
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
-        if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267
-            if ($verify_only) {
1268
-                return false;
1269
-            } else {
1270
-                if ( is_user_logged_in() ) {
1271
-                    wp_die(__('You do not have access to this route.', 'event_espresso'));
1272
-                } else {
1273
-                    return false;
1274
-                }
1275
-            }
1276
-        }
1277
-        return true;
1278
-    }
1279
-
1280
-
1281
-
1282
-    /**
1283
-     * admin_init_global
1284
-     * This runs all the code that we want executed within the WP admin_init hook.
1285
-     * This method executes for ALL EE Admin pages.
1286
-     *
1287
-     * @access public
1288
-     * @return void
1289
-     */
1290
-    public function admin_init_global()
1291
-    {
1292
-    }
1293
-
1294
-
1295
-
1296
-    /**
1297
-     * wp_loaded_global
1298
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1299
-     *
1300
-     * @access public
1301
-     * @return void
1302
-     */
1303
-    public function wp_loaded()
1304
-    {
1305
-    }
1306
-
1307
-
1308
-
1309
-    /**
1310
-     * admin_notices
1311
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1312
-     *
1313
-     * @access public
1314
-     * @return void
1315
-     */
1316
-    public function admin_notices_global()
1317
-    {
1318
-        $this->_display_no_javascript_warning();
1319
-        $this->_display_espresso_notices();
1320
-    }
1321
-
1322
-
1323
-
1324
-    public function network_admin_notices_global()
1325
-    {
1326
-        $this->_display_no_javascript_warning();
1327
-        $this->_display_espresso_notices();
1328
-    }
1329
-
1330
-
1331
-
1332
-    /**
1333
-     * admin_footer_scripts_global
1334
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1335
-     *
1336
-     * @access public
1337
-     * @return void
1338
-     */
1339
-    public function admin_footer_scripts_global()
1340
-    {
1341
-        $this->_add_admin_page_ajax_loading_img();
1342
-        $this->_add_admin_page_overlay();
1343
-        //if metaboxes are present we need to add the nonce field
1344
-        if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1345
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1346
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1347
-        }
1348
-    }
1349
-
1350
-
1351
-
1352
-    /**
1353
-     * admin_footer_global
1354
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1355
-     *
1356
-     * @access  public
1357
-     * @return  void
1358
-     */
1359
-    public function admin_footer_global()
1360
-    {
1361
-        //dialog container for dialog helper
1362
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1363
-        $d_cont .= '<div class="ee-notices"></div>';
1364
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365
-        $d_cont .= '</div>';
1366
-        echo $d_cont;
1367
-        //help tour stuff?
1368
-        if (isset($this->_help_tour[$this->_req_action])) {
1369
-            echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370
-        }
1371
-        //current set timezone for timezone js
1372
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1373
-    }
1374
-
1375
-
1376
-
1377
-    /**
1378
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1379
-     * For child classes:
1380
-     * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1381
-     * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1382
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1383
-     *    'help_trigger_id' => array(
1384
-     *        'title' => __('localized title for popup', 'event_espresso'),
1385
-     *        'content' => __('localized content for popup', 'event_espresso')
1386
-     *    )
1387
-     * );
1388
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1389
-     *
1390
-     * @access protected
1391
-     * @return string content
1392
-     */
1393
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1394
-    {
1395
-        $content = '';
1396
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1398
-        //loop through the array and setup content
1399
-        foreach ($help_array as $trigger => $help) {
1400
-            //make sure the array is setup properly
1401
-            if ( ! isset($help['title']) || ! isset($help['content'])) {
1402
-                throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1403
-                        'event_espresso'));
1404
-            }
1405
-            //we're good so let'd setup the template vars and then assign parsed template content to our content.
1406
-            $template_args = array(
1407
-                    'help_popup_id'      => $trigger,
1408
-                    'help_popup_title'   => $help['title'],
1409
-                    'help_popup_content' => $help['content'],
1410
-            );
1411
-            $content .= EEH_Template::display_template($template_path, $template_args, true);
1412
-        }
1413
-        if ($display) {
1414
-            echo $content;
1415
-        } else {
1416
-            return $content;
1417
-        }
1418
-    }
1419
-
1420
-
1421
-
1422
-    /**
1423
-     * All this does is retrive the help content array if set by the EE_Admin_Page child
1424
-     *
1425
-     * @access private
1426
-     * @return array properly formatted array for help popup content
1427
-     */
1428
-    private function _get_help_content()
1429
-    {
1430
-        //what is the method we're looking for?
1431
-        $method_name = '_help_popup_content_' . $this->_req_action;
1432
-        //if method doesn't exist let's get out.
1433
-        if ( ! method_exists($this, $method_name)) {
1434
-            return array();
1435
-        }
1436
-        //k we're good to go let's retrieve the help array
1437
-        $help_array = call_user_func(array($this, $method_name));
1438
-        //make sure we've got an array!
1439
-        if ( ! is_array($help_array)) {
1440
-            throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1441
-        }
1442
-        return $help_array;
1443
-    }
1444
-
1445
-
1446
-
1447
-    /**
1448
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1449
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1450
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1451
-     *
1452
-     * @access protected
1453
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1454
-     * @param boolean $display    if false then we return the trigger string
1455
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1456
-     * @return string
1457
-     */
1458
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1459
-    {
1460
-        if (defined('DOING_AJAX')) {
1461
-            return;
1462
-        }
1463
-        //let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1464
-        $help_array = $this->_get_help_content();
1465
-        $help_content = '';
1466
-        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1467
-            $help_array[$trigger_id] = array(
1468
-                    'title'   => __('Missing Content', 'event_espresso'),
1469
-                    'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1470
-                            'event_espresso'),
1471
-            );
1472
-            $help_content = $this->_set_help_popup_content($help_array, false);
1473
-        }
1474
-        //let's setup the trigger
1475
-        $content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
-        $content = $content . $help_content;
1477
-        if ($display) {
1478
-            echo $content;
1479
-        } else {
1480
-            return $content;
1481
-        }
1482
-    }
1483
-
1484
-
1485
-
1486
-    /**
1487
-     * _add_global_screen_options
1488
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1489
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1490
-     *
1491
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1492
-     *         see also WP_Screen object documents...
1493
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1494
-     * @abstract
1495
-     * @access private
1496
-     * @return void
1497
-     */
1498
-    private function _add_global_screen_options()
1499
-    {
1500
-    }
1501
-
1502
-
1503
-
1504
-    /**
1505
-     * _add_global_feature_pointers
1506
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1507
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1508
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1509
-     *
1510
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1511
-     * @link   http://eamann.com/tech/wordpress-portland/
1512
-     * @abstract
1513
-     * @access protected
1514
-     * @return void
1515
-     */
1516
-    private function _add_global_feature_pointers()
1517
-    {
1518
-    }
1519
-
1520
-
1521
-
1522
-    /**
1523
-     * load_global_scripts_styles
1524
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1525
-     *
1526
-     * @return void
1527
-     */
1528
-    public function load_global_scripts_styles()
1529
-    {
1530
-        /** STYLES **/
1531
-        // add debugging styles
1532
-        if (WP_DEBUG) {
1533
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1534
-        }
1535
-        // register all styles
1536
-        wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
-        wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538
-        //helpers styles
1539
-        wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540
-        /** SCRIPTS **/
1541
-        //register all scripts
1542
-        wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1543
-        wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1544
-        wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1545
-        add_filter('FHEE_load_joyride', '__return_true');
1546
-        //script for sorting tables
1547
-        wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1548
-        //script for parsing uri's
1549
-        wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1550
-        //and parsing associative serialized form elements
1551
-        wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1552
-        //helpers scripts
1553
-        wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
-        wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
-        wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1556
-        wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1557
-        //google charts
1558
-        wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1559
-        // ENQUEUE ALL BASICS BY DEFAULT
1560
-        wp_enqueue_style('ee-admin-css');
1561
-        wp_enqueue_script('ee_admin_js');
1562
-        wp_enqueue_script('ee-accounting');
1563
-        wp_enqueue_script('jquery-validate');
1564
-        //taking care of metaboxes
1565
-        if (
1566
-            empty($this->_cpt_route)
1567
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1568
-        ) {
1569
-            wp_enqueue_script('dashboard');
1570
-        }
1571
-        // LOCALIZED DATA
1572
-        //localize script for ajax lazy loading
1573
-        $lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1574
-        wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1575
-        /**
1576
-         * help tour stuff
1577
-         */
1578
-        if ( ! empty($this->_help_tour)) {
1579
-            //register the js for kicking things off
1580
-            wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1581
-            //setup tours for the js tour object
1582
-            foreach ($this->_help_tour['tours'] as $tour) {
1583
-                $tours[] = array(
1584
-                        'id'      => $tour->get_slug(),
1585
-                        'options' => $tour->get_options(),
1586
-                );
1587
-            }
1588
-            wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1589
-            //admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1590
-        }
1591
-    }
1592
-
1593
-
1594
-
1595
-    /**
1596
-     *        admin_footer_scripts_eei18n_js_strings
1597
-     *
1598
-     * @access        public
1599
-     * @return        void
1600
-     */
1601
-    public function admin_footer_scripts_eei18n_js_strings()
1602
-    {
1603
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1604
-        EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1605
-        EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1606
-        EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1607
-        EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1608
-        EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1609
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1610
-        EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1611
-        EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1612
-        EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1613
-        EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1614
-        EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1615
-        EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1616
-        EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1617
-        EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1618
-        EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1619
-        EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1620
-        EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1621
-        EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1622
-        EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1623
-        EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1624
-        EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1625
-        EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1626
-        EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1627
-        EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1628
-        EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1629
-        EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1630
-        EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1631
-        EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1632
-        EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1633
-        EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1634
-        EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1635
-        EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1636
-        EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1637
-        EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1638
-        EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1639
-        EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1640
-        EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1641
-        EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1642
-        EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1643
-    }
1644
-
1645
-
1646
-
1647
-    /**
1648
-     *        load enhanced xdebug styles for ppl with failing eyesight
1649
-     *
1650
-     * @access        public
1651
-     * @return        void
1652
-     */
1653
-    public function add_xdebug_style()
1654
-    {
1655
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1656
-    }
1657
-
1658
-
1659
-    /************************/
1660
-    /** LIST TABLE METHODS **/
1661
-    /************************/
1662
-    /**
1663
-     * this sets up the list table if the current view requires it.
1664
-     *
1665
-     * @access protected
1666
-     * @return void
1667
-     */
1668
-    protected function _set_list_table()
1669
-    {
1670
-        //first is this a list_table view?
1671
-        if ( ! isset($this->_route_config['list_table'])) {
1672
-            return;
1673
-        } //not a list_table view so get out.
1674
-        //list table functions are per view specific (because some admin pages might have more than one listtable!)
1675
-        if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1676
-            //user error msg
1677
-            $error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1678
-            //developer error msg
1679
-            $error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1680
-                            $this->_req_action, '_set_list_table_views_' . $this->_req_action);
1681
-            throw new EE_Error($error_msg);
1682
-        }
1683
-        //let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1684
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1685
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1686
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1687
-        $this->_set_list_table_view();
1688
-        $this->_set_list_table_object();
1689
-    }
1690
-
1691
-
1692
-
1693
-    /**
1694
-     *        set current view for List Table
1695
-     *
1696
-     * @access public
1697
-     * @return array
1698
-     */
1699
-    protected function _set_list_table_view()
1700
-    {
1701
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1702
-        // looking at active items or dumpster diving ?
1703
-        if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1704
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1705
-        } else {
1706
-            $this->_view = sanitize_key($this->_req_data['status']);
1707
-        }
1708
-    }
1709
-
1710
-
1711
-
1712
-    /**
1713
-     * _set_list_table_object
1714
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1715
-     *
1716
-     * @throws \EE_Error
1717
-     */
1718
-    protected function _set_list_table_object()
1719
-    {
1720
-        if (isset($this->_route_config['list_table'])) {
1721
-            if ( ! class_exists($this->_route_config['list_table'])) {
1722
-                throw new EE_Error(
1723
-                        sprintf(
1724
-                                __(
1725
-                                        'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1726
-                                        'event_espresso'
1727
-                                ),
1728
-                                $this->_route_config['list_table'],
1729
-                                get_class($this)
1730
-                        )
1731
-                );
1732
-            }
1733
-            $list_table = $this->_route_config['list_table'];
1734
-            $this->_list_table_object = new $list_table($this);
1735
-        }
1736
-    }
1737
-
1738
-
1739
-
1740
-    /**
1741
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1742
-     *
1743
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1744
-     *                                                    urls.  The array should be indexed by the view it is being
1745
-     *                                                    added to.
1746
-     * @return array
1747
-     */
1748
-    public function get_list_table_view_RLs($extra_query_args = array())
1749
-    {
1750
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1751
-        if (empty($this->_views)) {
1752
-            $this->_views = array();
1753
-        }
1754
-        // cycle thru views
1755
-        foreach ($this->_views as $key => $view) {
1756
-            $query_args = array();
1757
-            // check for current view
1758
-            $this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1759
-            $query_args['action'] = $this->_req_action;
1760
-            $query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1761
-            $query_args['status'] = $view['slug'];
1762
-            //merge any other arguments sent in.
1763
-            if (isset($extra_query_args[$view['slug']])) {
1764
-                $query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1765
-            }
1766
-            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1767
-        }
1768
-        return $this->_views;
1769
-    }
1770
-
1771
-
1772
-
1773
-    /**
1774
-     * _entries_per_page_dropdown
1775
-     * generates a drop down box for selecting the number of visiable rows in an admin page list table
1776
-     *
1777
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1778
-     * @access protected
1779
-     * @param int $max_entries total number of rows in the table
1780
-     * @return string
1781
-     */
1782
-    protected function _entries_per_page_dropdown($max_entries = false)
1783
-    {
1784
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1785
-        $values = array(10, 25, 50, 100);
1786
-        $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1787
-        if ($max_entries) {
1788
-            $values[] = $max_entries;
1789
-            sort($values);
1790
-        }
1791
-        $entries_per_page_dropdown = '
143
+	// yes / no array for admin form fields
144
+	protected $_yes_no_values = array();
145
+
146
+	//some default things shared by all child classes
147
+	protected $_default_espresso_metaboxes;
148
+
149
+	/**
150
+	 *    EE_Registry Object
151
+	 *
152
+	 * @var    EE_Registry
153
+	 * @access    protected
154
+	 */
155
+	protected $EE = null;
156
+
157
+
158
+
159
+	/**
160
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
161
+	 *
162
+	 * @var boolean
163
+	 */
164
+	protected $_is_caf = false;
165
+
166
+
167
+
168
+	/**
169
+	 * @Constructor
170
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
171
+	 * @access public
172
+	 */
173
+	public function __construct($routing = true)
174
+	{
175
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
176
+			$this->_is_caf = true;
177
+		}
178
+		$this->_yes_no_values = array(
179
+				array('id' => true, 'text' => __('Yes', 'event_espresso')),
180
+				array('id' => false, 'text' => __('No', 'event_espresso')),
181
+		);
182
+		//set the _req_data property.
183
+		$this->_req_data = array_merge($_GET, $_POST);
184
+		//routing enabled?
185
+		$this->_routing = $routing;
186
+		//set initial page props (child method)
187
+		$this->_init_page_props();
188
+		//set global defaults
189
+		$this->_set_defaults();
190
+		//set early because incoming requests could be ajax related and we need to register those hooks.
191
+		$this->_global_ajax_hooks();
192
+		$this->_ajax_hooks();
193
+		//other_page_hooks have to be early too.
194
+		$this->_do_other_page_hooks();
195
+		//This just allows us to have extending classes do something specific
196
+		// before the parent constructor runs _page_setup().
197
+		if (method_exists($this, '_before_page_setup')) {
198
+			$this->_before_page_setup();
199
+		}
200
+		//set up page dependencies
201
+		$this->_page_setup();
202
+	}
203
+
204
+
205
+
206
+	/**
207
+	 * _init_page_props
208
+	 * Child classes use to set at least the following properties:
209
+	 * $page_slug.
210
+	 * $page_label.
211
+	 *
212
+	 * @abstract
213
+	 * @access protected
214
+	 * @return void
215
+	 */
216
+	abstract protected function _init_page_props();
217
+
218
+
219
+
220
+	/**
221
+	 * _ajax_hooks
222
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
223
+	 * Note: within the ajax callback methods.
224
+	 *
225
+	 * @abstract
226
+	 * @access protected
227
+	 * @return void
228
+	 */
229
+	abstract protected function _ajax_hooks();
230
+
231
+
232
+
233
+	/**
234
+	 * _define_page_props
235
+	 * child classes define page properties in here.  Must include at least:
236
+	 * $_admin_base_url = base_url for all admin pages
237
+	 * $_admin_page_title = default admin_page_title for admin pages
238
+	 * $_labels = array of default labels for various automatically generated elements:
239
+	 *    array(
240
+	 *        'buttons' => array(
241
+	 *            'add' => __('label for add new button'),
242
+	 *            'edit' => __('label for edit button'),
243
+	 *            'delete' => __('label for delete button')
244
+	 *            )
245
+	 *        )
246
+	 *
247
+	 * @abstract
248
+	 * @access protected
249
+	 * @return void
250
+	 */
251
+	abstract protected function _define_page_props();
252
+
253
+
254
+
255
+	/**
256
+	 * _set_page_routes
257
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also have a 'default'
258
+	 * route. Here's the format
259
+	 * $this->_page_routes = array(
260
+	 *        'default' => array(
261
+	 *            'func' => '_default_method_handling_route',
262
+	 *            'args' => array('array','of','args'),
263
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. ajax request, backend processing)
264
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a headers route after.  The string you enter here should match the defined route reference for a headers sent route.
265
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access this route.
266
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability checks).
267
+	 *        ),
268
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a handling method.
269
+	 *        )
270
+	 * )
271
+	 *
272
+	 * @abstract
273
+	 * @access protected
274
+	 * @return void
275
+	 */
276
+	abstract protected function _set_page_routes();
277
+
278
+
279
+
280
+	/**
281
+	 * _set_page_config
282
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the array corresponds to the page_route for the loaded page.
283
+	 * Format:
284
+	 * $this->_page_config = array(
285
+	 *        'default' => array(
286
+	 *            'labels' => array(
287
+	 *                'buttons' => array(
288
+	 *                    'add' => __('label for adding item'),
289
+	 *                    'edit' => __('label for editing item'),
290
+	 *                    'delete' => __('label for deleting item')
291
+	 *                ),
292
+	 *                'publishbox' => __('Localized Title for Publish metabox', 'event_espresso')
293
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the page. If this isn't present then the defaults will be used as set for the $this->_labels in _define_page_props() method
294
+	 *            'nav' => array(
295
+	 *                'label' => __('Label for Tab', 'event_espresso').
296
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
297
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
298
+	 *                'order' => 10, //required to indicate tab position.
299
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is displayed then add this parameter.
300
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
301
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load metaboxes set for eventespresso admin pages.
302
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added later.  We just use
303
+	 *            this flag to make sure the necessary js gets enqueued on page load.
304
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
305
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The array indicates the max number of columns (4) and the default number of columns on page load (2).  There is an option
306
+	 *            in the "screen_options" dropdown that is setup so users can pick what columns they want to display.
307
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
308
+	 *                'tab_id' => array(
309
+	 *                    'title' => 'tab_title',
310
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting help tab content.  The fallback if it isn't present is to try a the callback.  Filename should match a file in the admin
311
+	 *                    folder's "help_tabs" dir (ie.. events/help_tabs/name_of_file_containing_content.help_tab.php)
312
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will attempt to use the callback which should match the name of a method in the class
313
+	 *                    ),
314
+	 *                'tab2_id' => array(
315
+	 *                    'title' => 'tab2 title',
316
+	 *                    'filename' => 'file_name_2'
317
+	 *                    'callback' => 'callback_method_for_content',
318
+	 *                 ),
319
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the help tab area on an admin page. @link http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
320
+	 *            'help_tour' => array(
321
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located in a folder for this admin page named "help_tours", a file name matching the key given here
322
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
323
+	 *            ),
324
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is true if it isn't present).  To remove the requirement for a nonce check when this route is visited just set
325
+	 *            'require_nonce' to FALSE
326
+	 *            )
327
+	 * )
328
+	 *
329
+	 * @abstract
330
+	 * @access protected
331
+	 * @return void
332
+	 */
333
+	abstract protected function _set_page_config();
334
+
335
+
336
+
337
+
338
+
339
+	/** end sample help_tour methods **/
340
+	/**
341
+	 * _add_screen_options
342
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
343
+	 * Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options to a particular view.
344
+	 *
345
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
346
+	 *         see also WP_Screen object documents...
347
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
348
+	 * @abstract
349
+	 * @access protected
350
+	 * @return void
351
+	 */
352
+	abstract protected function _add_screen_options();
353
+
354
+
355
+
356
+	/**
357
+	 * _add_feature_pointers
358
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
359
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a particular view.
360
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
361
+	 * See: WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
362
+	 *
363
+	 * @link   http://eamann.com/tech/wordpress-portland/
364
+	 * @abstract
365
+	 * @access protected
366
+	 * @return void
367
+	 */
368
+	abstract protected function _add_feature_pointers();
369
+
370
+
371
+
372
+	/**
373
+	 * load_scripts_styles
374
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific scripts/styles
375
+	 * per view by putting them in a dynamic function in this format (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
376
+	 *
377
+	 * @abstract
378
+	 * @access public
379
+	 * @return void
380
+	 */
381
+	abstract public function load_scripts_styles();
382
+
383
+
384
+
385
+	/**
386
+	 * admin_init
387
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to all pages/views loaded by child class.
388
+	 *
389
+	 * @abstract
390
+	 * @access public
391
+	 * @return void
392
+	 */
393
+	abstract public function admin_init();
394
+
395
+
396
+
397
+	/**
398
+	 * admin_notices
399
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to all pages/views loaded by child class.
400
+	 *
401
+	 * @abstract
402
+	 * @access public
403
+	 * @return void
404
+	 */
405
+	abstract public function admin_notices();
406
+
407
+
408
+
409
+	/**
410
+	 * admin_footer_scripts
411
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply to all pages/views loaded by child class.
412
+	 *
413
+	 * @access public
414
+	 * @return void
415
+	 */
416
+	abstract public function admin_footer_scripts();
417
+
418
+
419
+
420
+	/**
421
+	 * admin_footer
422
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will apply to all pages/views loaded by child class.
423
+	 *
424
+	 * @access  public
425
+	 * @return void
426
+	 */
427
+	public function admin_footer()
428
+	{
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * _global_ajax_hooks
435
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
436
+	 * Note: within the ajax callback methods.
437
+	 *
438
+	 * @abstract
439
+	 * @access protected
440
+	 * @return void
441
+	 */
442
+	protected function _global_ajax_hooks()
443
+	{
444
+		//for lazy loading of metabox content
445
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
446
+	}
447
+
448
+
449
+
450
+	public function ajax_metabox_content()
451
+	{
452
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
453
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
454
+		self::cached_rss_display($contentid, $url);
455
+		wp_die();
456
+	}
457
+
458
+
459
+
460
+	/**
461
+	 * _page_setup
462
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested doesn't match the object.
463
+	 *
464
+	 * @final
465
+	 * @access protected
466
+	 * @return void
467
+	 */
468
+	final protected function _page_setup()
469
+	{
470
+		//requires?
471
+		//admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can.  But keep in mind, not everything is available from the EE_Admin Page object at this point.
472
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
473
+		//next verify if we need to load anything...
474
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
475
+		$this->page_folder = strtolower(str_replace('_Admin_Page', '', str_replace('Extend_', '', get_class($this))));
476
+		global $ee_menu_slugs;
477
+		$ee_menu_slugs = (array)$ee_menu_slugs;
478
+		if (( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page])) && ! defined('DOING_AJAX')) {
479
+			return;
480
+		}
481
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
482
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] == -1) {
483
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] != -1 ? $this->_req_data['action2'] : $this->_req_data['action'];
484
+		}
485
+		// then set blank or -1 action values to 'default'
486
+		$this->_req_action = isset($this->_req_data['action']) && ! empty($this->_req_data['action']) && $this->_req_data['action'] != -1 ? sanitize_key($this->_req_data['action']) : 'default';
487
+		//if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.  This covers cases where we're coming in from a list table that isn't on the default route.
488
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
489
+		//however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
490
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) ? $this->_req_data['route'] : $this->_req_action;
491
+		$this->_current_view = $this->_req_action;
492
+		$this->_req_nonce = $this->_req_action . '_nonce';
493
+		$this->_define_page_props();
494
+		$this->_current_page_view_url = add_query_arg(array('page' => $this->_current_page, 'action' => $this->_current_view), $this->_admin_base_url);
495
+		//default things
496
+		$this->_default_espresso_metaboxes = array('_espresso_news_post_box', '_espresso_links_post_box', '_espresso_ratings_request', '_espresso_sponsors_post_box');
497
+		//set page configs
498
+		$this->_set_page_routes();
499
+		$this->_set_page_config();
500
+		//let's include any referrer data in our default_query_args for this route for "stickiness".
501
+		if (isset($this->_req_data['wp_referer'])) {
502
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
503
+		}
504
+		//for caffeinated and other extended functionality.  If there is a _extend_page_config method then let's run that to modify the all the various page configuration arrays
505
+		if (method_exists($this, '_extend_page_config')) {
506
+			$this->_extend_page_config();
507
+		}
508
+		//for CPT and other extended functionality. If there is an _extend_page_config_for_cpt then let's run that to modify all the various page configuration arrays.
509
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
510
+			$this->_extend_page_config_for_cpt();
511
+		}
512
+		//filter routes and page_config so addons can add their stuff. Filtering done per class
513
+		$this->_page_routes = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_routes', $this->_page_routes, $this);
514
+		$this->_page_config = apply_filters('FHEE__' . get_class($this) . '__page_setup__page_config', $this->_page_config, $this);
515
+		//if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
516
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
517
+			add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), 10, 2);
518
+		}
519
+		//next route only if routing enabled
520
+		if ($this->_routing && ! defined('DOING_AJAX')) {
521
+			$this->_verify_routes();
522
+			//next let's just check user_access and kill if no access
523
+			$this->check_user_access();
524
+			if ($this->_is_UI_request) {
525
+				//admin_init stuff - global, all views for this page class, specific view
526
+				add_action('admin_init', array($this, 'admin_init'), 10);
527
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
528
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
529
+				}
530
+			} else {
531
+				//hijack regular WP loading and route admin request immediately
532
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
533
+				$this->route_admin_request();
534
+			}
535
+		}
536
+	}
537
+
538
+
539
+
540
+	/**
541
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
542
+	 *
543
+	 * @access private
544
+	 * @return void
545
+	 */
546
+	private function _do_other_page_hooks()
547
+	{
548
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
549
+		foreach ($registered_pages as $page) {
550
+			//now let's setup the file name and class that should be present
551
+			$classname = str_replace('.class.php', '', $page);
552
+			//autoloaders should take care of loading file
553
+			if ( ! class_exists($classname)) {
554
+				$error_msg[] = sprintf( esc_html__('Something went wrong with loading the %s admin hooks page.', 'event_espresso'), $page);
555
+				$error_msg[] = $error_msg[0]
556
+							   . "\r\n"
557
+							   . sprintf( esc_html__('There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
558
+								'event_espresso'), $page, '<br />', '<strong>' . $classname . '</strong>');
559
+				throw new EE_Error(implode('||', $error_msg));
560
+			}
561
+			$a = new ReflectionClass($classname);
562
+			//notice we are passing the instance of this class to the hook object.
563
+			$hookobj[] = $a->newInstance($this);
564
+		}
565
+	}
566
+
567
+
568
+
569
+	public function load_page_dependencies()
570
+	{
571
+		try {
572
+			$this->_load_page_dependencies();
573
+		} catch (EE_Error $e) {
574
+			$e->get_error();
575
+		}
576
+	}
577
+
578
+
579
+
580
+	/**
581
+	 * load_page_dependencies
582
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
583
+	 *
584
+	 * @access public
585
+	 * @return void
586
+	 */
587
+	protected function _load_page_dependencies()
588
+	{
589
+		//let's set the current_screen and screen options to override what WP set
590
+		$this->_current_screen = get_current_screen();
591
+		//load admin_notices - global, page class, and view specific
592
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
593
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
594
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
595
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
596
+		}
597
+		//load network admin_notices - global, page class, and view specific
598
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
599
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
600
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
601
+		}
602
+		//this will save any per_page screen options if they are present
603
+		$this->_set_per_page_screen_options();
604
+		//setup list table properties
605
+		$this->_set_list_table();
606
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.  However in some cases the metaboxes will need to be added within a route handling callback.
607
+		$this->_add_registered_meta_boxes();
608
+		$this->_add_screen_columns();
609
+		//add screen options - global, page child class, and view specific
610
+		$this->_add_global_screen_options();
611
+		$this->_add_screen_options();
612
+		if (method_exists($this, '_add_screen_options_' . $this->_current_view)) {
613
+			call_user_func(array($this, '_add_screen_options_' . $this->_current_view));
614
+		}
615
+		//add help tab(s) and tours- set via page_config and qtips.
616
+		$this->_add_help_tour();
617
+		$this->_add_help_tabs();
618
+		$this->_add_qtips();
619
+		//add feature_pointers - global, page child class, and view specific
620
+		$this->_add_feature_pointers();
621
+		$this->_add_global_feature_pointers();
622
+		if (method_exists($this, '_add_feature_pointer_' . $this->_current_view)) {
623
+			call_user_func(array($this, '_add_feature_pointer_' . $this->_current_view));
624
+		}
625
+		//enqueue scripts/styles - global, page class, and view specific
626
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
627
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
628
+		if (method_exists($this, 'load_scripts_styles_' . $this->_current_view)) {
629
+			add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles_' . $this->_current_view), 15);
630
+		}
631
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
632
+		//admin_print_footer_scripts - global, page child class, and view specific.  NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.  In most cases that's doing_it_wrong().  But adding hidden container elements etc. is a good use case. Notice the late priority we're giving these
633
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
634
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
635
+		if (method_exists($this, 'admin_footer_scripts_' . $this->_current_view)) {
636
+			add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_' . $this->_current_view), 101);
637
+		}
638
+		//admin footer scripts
639
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
640
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
641
+		if (method_exists($this, 'admin_footer_' . $this->_current_view)) {
642
+			add_action('admin_footer', array($this, 'admin_footer_' . $this->_current_view), 101);
643
+		}
644
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
645
+		//targeted hook
646
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load__' . $this->page_slug . '__' . $this->_req_action);
647
+	}
648
+
649
+
650
+
651
+	/**
652
+	 * _set_defaults
653
+	 * This sets some global defaults for class properties.
654
+	 */
655
+	private function _set_defaults()
656
+	{
657
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = $this->_event = $this->_template_path = $this->_column_template_path = null;
658
+		$this->_nav_tabs = $this_views = $this->_page_routes = $this->_page_config = $this->_default_route_query_args = array();
659
+		$this->default_nav_tab_name = 'overview';
660
+		//init template args
661
+		$this->_template_args = array(
662
+				'admin_page_header'  => '',
663
+				'admin_page_content' => '',
664
+				'post_body_content'  => '',
665
+				'before_list_table'  => '',
666
+				'after_list_table'   => '',
667
+		);
668
+	}
669
+
670
+
671
+
672
+	/**
673
+	 * route_admin_request
674
+	 *
675
+	 * @see    _route_admin_request()
676
+	 * @access public
677
+	 * @return void|exception error
678
+	 */
679
+	public function route_admin_request()
680
+	{
681
+		try {
682
+			$this->_route_admin_request();
683
+		} catch (EE_Error $e) {
684
+			$e->get_error();
685
+		}
686
+	}
687
+
688
+
689
+
690
+	public function set_wp_page_slug($wp_page_slug)
691
+	{
692
+		$this->_wp_page_slug = $wp_page_slug;
693
+		//if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
694
+		if (is_network_admin()) {
695
+			$this->_wp_page_slug .= '-network';
696
+		}
697
+	}
698
+
699
+
700
+
701
+	/**
702
+	 * _verify_routes
703
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so we know if we need to drop out.
704
+	 *
705
+	 * @access protected
706
+	 * @return void
707
+	 */
708
+	protected function _verify_routes()
709
+	{
710
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
711
+		if ( ! $this->_current_page && ! defined('DOING_AJAX')) {
712
+			return false;
713
+		}
714
+		$this->_route = false;
715
+		$func = false;
716
+		$args = array();
717
+		// check that the page_routes array is not empty
718
+		if (empty($this->_page_routes)) {
719
+			// user error msg
720
+			$error_msg = sprintf(__('No page routes have been set for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
721
+			// developer error msg
722
+			$error_msg .= '||' . $error_msg . __(' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', 'event_espresso');
723
+			throw new EE_Error($error_msg);
724
+		}
725
+		// and that the requested page route exists
726
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
727
+			$this->_route = $this->_page_routes[$this->_req_action];
728
+			$this->_route_config = isset($this->_page_config[$this->_req_action]) ? $this->_page_config[$this->_req_action] : array();
729
+		} else {
730
+			// user error msg
731
+			$error_msg = sprintf(__('The requested page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
732
+			// developer error msg
733
+			$error_msg .= '||' . $error_msg . sprintf(__(' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', 'event_espresso'), $this->_req_action);
734
+			throw new EE_Error($error_msg);
735
+		}
736
+		// and that a default route exists
737
+		if ( ! array_key_exists('default', $this->_page_routes)) {
738
+			// user error msg
739
+			$error_msg = sprintf(__('A default page route has not been set for the % admin page.', 'event_espresso'), $this->_admin_page_title);
740
+			// developer error msg
741
+			$error_msg .= '||' . $error_msg . __(' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', 'event_espresso');
742
+			throw new EE_Error($error_msg);
743
+		}
744
+		//first lets' catch if the UI request has EVER been set.
745
+		if ($this->_is_UI_request === null) {
746
+			//lets set if this is a UI request or not.
747
+			$this->_is_UI_request = ( ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true) ? true : false;
748
+			//wait a minute... we might have a noheader in the route array
749
+			$this->_is_UI_request = is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader'] ? false : $this->_is_UI_request;
750
+		}
751
+		$this->_set_current_labels();
752
+	}
753
+
754
+
755
+
756
+	/**
757
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
758
+	 *
759
+	 * @param  string $route the route name we're verifying
760
+	 * @return mixed  (bool|Exception)      we'll throw an exception if this isn't a valid route.
761
+	 */
762
+	protected function _verify_route($route)
763
+	{
764
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
765
+			return true;
766
+		} else {
767
+			// user error msg
768
+			$error_msg = sprintf(__('The given page route does not exist for the %s admin page.', 'event_espresso'), $this->_admin_page_title);
769
+			// developer error msg
770
+			$error_msg .= '||' . $error_msg . sprintf(__(' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', 'event_espresso'), $route);
771
+			throw new EE_Error($error_msg);
772
+		}
773
+	}
774
+
775
+
776
+
777
+	/**
778
+	 * perform nonce verification
779
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces using this method (and save retyping!)
780
+	 *
781
+	 * @param  string $nonce     The nonce sent
782
+	 * @param  string $nonce_ref The nonce reference string (name0)
783
+	 * @return mixed (bool|die)
784
+	 */
785
+	protected function _verify_nonce($nonce, $nonce_ref)
786
+	{
787
+		// verify nonce against expected value
788
+		if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
789
+			// these are not the droids you are looking for !!!
790
+			$msg = sprintf(__('%sNonce Fail.%s', 'event_espresso'), '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', '</a>');
791
+			if (WP_DEBUG) {
792
+				$msg .= "\n  " . sprintf(__('In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', 'event_espresso'), __CLASS__);
793
+			}
794
+			if ( ! defined('DOING_AJAX')) {
795
+				wp_die($msg);
796
+			} else {
797
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
798
+				$this->_return_json();
799
+			}
800
+		}
801
+	}
802
+
803
+
804
+
805
+	/**
806
+	 * _route_admin_request()
807
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if theres are
808
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
809
+	 * in the page routes and then will try to load the corresponding method.
810
+	 *
811
+	 * @access protected
812
+	 * @return void
813
+	 * @throws \EE_Error
814
+	 */
815
+	protected function _route_admin_request()
816
+	{
817
+		if ( ! $this->_is_UI_request) {
818
+			$this->_verify_routes();
819
+		}
820
+		$nonce_check = isset($this->_route_config['require_nonce'])
821
+			? $this->_route_config['require_nonce']
822
+			: true;
823
+		if ($this->_req_action !== 'default' && $nonce_check) {
824
+			// set nonce from post data
825
+			$nonce = isset($this->_req_data[$this->_req_nonce])
826
+				? sanitize_text_field($this->_req_data[$this->_req_nonce])
827
+				: '';
828
+			$this->_verify_nonce($nonce, $this->_req_nonce);
829
+		}
830
+		//set the nav_tabs array but ONLY if this is  UI_request
831
+		if ($this->_is_UI_request) {
832
+			$this->_set_nav_tabs();
833
+		}
834
+		// grab callback function
835
+		$func = is_array($this->_route) ? $this->_route['func'] : $this->_route;
836
+		// check if callback has args
837
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
838
+		$error_msg = '';
839
+		// action right before calling route
840
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
841
+		if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
842
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
843
+		}
844
+		// right before calling the route, let's remove _wp_http_referer from the
845
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
846
+		$_SERVER['REQUEST_URI'] = remove_query_arg('_wp_http_referer', wp_unslash($_SERVER['REQUEST_URI']));
847
+		if ( ! empty($func)) {
848
+			if (is_array($func)) {
849
+				list($class, $method) = $func;
850
+			} else if (strpos($func, '::') !== false) {
851
+				list($class, $method) = explode('::', $func);
852
+			} else {
853
+				$class = $this;
854
+				$method = $func;
855
+			}
856
+			if ( ! (is_object($class) && $class === $this)) {
857
+				// send along this admin page object for access by addons.
858
+				$args['admin_page_object'] = $this;
859
+			}
860
+
861
+			if (
862
+				//is it a method on a class that doesn't work?
863
+				(
864
+					(
865
+						method_exists($class, $method)
866
+						&& call_user_func_array(array($class, $method), $args) === false
867
+					)
868
+					&& (
869
+						//is it a standalone function that doesn't work?
870
+						function_exists($method)
871
+						&& call_user_func_array($func, array_merge(array('admin_page_object' => $this), $args)) === false
872
+					)
873
+				)
874
+				|| (
875
+					//is it neither a class method NOR a standalone function?
876
+					! method_exists($class, $method)
877
+					&& ! function_exists($method)
878
+				)
879
+			) {
880
+				// user error msg
881
+				$error_msg = __('An error occurred. The  requested page route could not be found.', 'event_espresso');
882
+				// developer error msg
883
+				$error_msg .= '||';
884
+				$error_msg .= sprintf(
885
+					__(
886
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
887
+						'event_espresso'
888
+					),
889
+					$method
890
+				);
891
+			}
892
+			if ( ! empty($error_msg)) {
893
+				throw new EE_Error($error_msg);
894
+			}
895
+		}
896
+		//if we've routed and this route has a no headers route AND a sent_headers_route, then we need to reset the routing properties to the new route.
897
+		//now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
898
+		if ($this->_is_UI_request === false
899
+			&& is_array($this->_route)
900
+			&& ! empty($this->_route['headers_sent_route'])
901
+		) {
902
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
903
+		}
904
+	}
905
+
906
+
907
+
908
+	/**
909
+	 * This method just allows the resetting of page properties in the case where a no headers
910
+	 * route redirects to a headers route in its route config.
911
+	 *
912
+	 * @since   4.3.0
913
+	 * @param  string $new_route New (non header) route to redirect to.
914
+	 * @return   void
915
+	 */
916
+	protected function _reset_routing_properties($new_route)
917
+	{
918
+		$this->_is_UI_request = true;
919
+		//now we set the current route to whatever the headers_sent_route is set at
920
+		$this->_req_data['action'] = $new_route;
921
+		//rerun page setup
922
+		$this->_page_setup();
923
+	}
924
+
925
+
926
+
927
+	/**
928
+	 * _add_query_arg
929
+	 * adds nonce to array of arguments then calls WP add_query_arg function
930
+	 *(internally just uses EEH_URL's function with the same name)
931
+	 *
932
+	 * @access public
933
+	 * @param array  $args
934
+	 * @param string $url
935
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the generated
936
+	 *                                        url in an associative array indexed by the key 'wp_referer';
937
+	 *                                        Example usage:
938
+	 *                                        If the current page is:
939
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
940
+	 *                                        &action=default&event_id=20&month_range=March%202015
941
+	 *                                        &_wpnonce=5467821
942
+	 *                                        and you call:
943
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
944
+	 *                                        array(
945
+	 *                                        'action' => 'resend_something',
946
+	 *                                        'page=>espresso_registrations'
947
+	 *                                        ),
948
+	 *                                        $some_url,
949
+	 *                                        true
950
+	 *                                        );
951
+	 *                                        It will produce a url in this structure:
952
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
953
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
954
+	 *                                        month_range]=March%202015
955
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
956
+	 * @return string
957
+	 */
958
+	public static function add_query_args_and_nonce($args = array(), $url = false, $sticky = false, $exclude_nonce = false)
959
+	{
960
+		//if there is a _wp_http_referer include the values from the request but only if sticky = true
961
+		if ($sticky) {
962
+			$request = $_REQUEST;
963
+			unset($request['_wp_http_referer']);
964
+			unset($request['wp_referer']);
965
+			foreach ($request as $key => $value) {
966
+				//do not add nonces
967
+				if (strpos($key, 'nonce') !== false) {
968
+					continue;
969
+				}
970
+				$args['wp_referer[' . $key . ']'] = $value;
971
+			}
972
+		}
973
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * This returns a generated link that will load the related help tab.
980
+	 *
981
+	 * @param  string $help_tab_id the id for the connected help tab
982
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
983
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
984
+	 * @uses EEH_Template::get_help_tab_link()
985
+	 * @return string              generated link
986
+	 */
987
+	protected function _get_help_tab_link($help_tab_id, $icon_style = false, $help_text = false)
988
+	{
989
+		return EEH_Template::get_help_tab_link($help_tab_id, $this->page_slug, $this->_req_action, $icon_style, $help_text);
990
+	}
991
+
992
+
993
+
994
+	/**
995
+	 * _add_help_tabs
996
+	 * Note child classes define their help tabs within the page_config array.
997
+	 *
998
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
999
+	 * @access protected
1000
+	 * @return void
1001
+	 */
1002
+	protected function _add_help_tabs()
1003
+	{
1004
+		$tour_buttons = '';
1005
+		if (isset($this->_page_config[$this->_req_action])) {
1006
+			$config = $this->_page_config[$this->_req_action];
1007
+			//is there a help tour for the current route?  if there is let's setup the tour buttons
1008
+			if (isset($this->_help_tour[$this->_req_action])) {
1009
+				$tb = array();
1010
+				$tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1011
+				foreach ($this->_help_tour['tours'] as $tour) {
1012
+					//if this is the end tour then we don't need to setup a button
1013
+					if ($tour instanceof EE_Help_Tour_final_stop) {
1014
+						continue;
1015
+					}
1016
+					$tb[] = '<button id="trigger-tour-' . $tour->get_slug() . '" class="button-primary trigger-ee-help-tour">' . $tour->get_label() . '</button>';
1017
+				}
1018
+				$tour_buttons .= implode('<br />', $tb);
1019
+				$tour_buttons .= '</div></div>';
1020
+			}
1021
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1022
+			if (is_array($config) && isset($config['help_sidebar'])) {
1023
+				//check that the callback given is valid
1024
+				if ( ! method_exists($this, $config['help_sidebar'])) {
1025
+					throw new EE_Error(sprintf(__('The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1026
+							'event_espresso'), $config['help_sidebar'], get_class($this)));
1027
+				}
1028
+				$content = apply_filters('FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', call_user_func(array($this, $config['help_sidebar'])));
1029
+				$content .= $tour_buttons; //add help tour buttons.
1030
+				//do we have any help tours setup?  Cause if we do we want to add the buttons
1031
+				$this->_current_screen->set_help_sidebar($content);
1032
+			}
1033
+			//if we DON'T have config help sidebar and there ARE toure buttons then we'll just add the tour buttons to the sidebar.
1034
+			if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) {
1035
+				$this->_current_screen->set_help_sidebar($tour_buttons);
1036
+			}
1037
+			//handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1038
+			if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) {
1039
+				$_ht['id'] = $this->page_slug;
1040
+				$_ht['title'] = __('Help Tours', 'event_espresso');
1041
+				$_ht['content'] = '<p>' . __('The buttons to the right allow you to start/restart any help tours available for this page', 'event_espresso') . '</p>';
1042
+				$this->_current_screen->add_help_tab($_ht);
1043
+			}/**/
1044
+			if ( ! isset($config['help_tabs'])) {
1045
+				return;
1046
+			} //no help tabs for this route
1047
+			foreach ((array)$config['help_tabs'] as $tab_id => $cfg) {
1048
+				//we're here so there ARE help tabs!
1049
+				//make sure we've got what we need
1050
+				if ( ! isset($cfg['title'])) {
1051
+					throw new EE_Error(__('The _page_config array is not set up properly for help tabs.  It is missing a title', 'event_espresso'));
1052
+				}
1053
+				if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1054
+					throw new EE_Error(__('The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1055
+							'event_espresso'));
1056
+				}
1057
+				//first priority goes to content.
1058
+				if ( ! empty($cfg['content'])) {
1059
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1060
+					//second priority goes to filename
1061
+				} else if ( ! empty($cfg['filename'])) {
1062
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1063
+					//it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1064
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tabs/' . $cfg['filename'] . '.help_tab.php' : $file_path;
1065
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1066
+					if ( ! is_readable($file_path) && ! isset($cfg['callback'])) {
1067
+						EE_Error::add_error(sprintf(__('The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1068
+								'event_espresso'), $tab_id, key($config), $file_path), __FILE__, __FUNCTION__, __LINE__);
1069
+						return;
1070
+					}
1071
+					$template_args['admin_page_obj'] = $this;
1072
+					$content = EEH_Template::display_template($file_path, $template_args, true);
1073
+				} else {
1074
+					$content = '';
1075
+				}
1076
+				//check if callback is valid
1077
+				if (empty($content) && ( ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']))) {
1078
+					EE_Error::add_error(sprintf(__('The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1079
+							'event_espresso'), $cfg['title']), __FILE__, __FUNCTION__, __LINE__);
1080
+					return;
1081
+				}
1082
+				//setup config array for help tab method
1083
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1084
+				$_ht = array(
1085
+						'id'       => $id,
1086
+						'title'    => $cfg['title'],
1087
+						'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1088
+						'content'  => $content,
1089
+				);
1090
+				$this->_current_screen->add_help_tab($_ht);
1091
+			}
1092
+		}
1093
+	}
1094
+
1095
+
1096
+
1097
+	/**
1098
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is an array with properties for setting up usage of the joyride plugin
1099
+	 *
1100
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1101
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the _set_page_config() comments
1102
+	 * @access protected
1103
+	 * @return void
1104
+	 */
1105
+	protected function _add_help_tour()
1106
+	{
1107
+		$tours = array();
1108
+		$this->_help_tour = array();
1109
+		//exit early if help tours are turned off globally
1110
+		if ( ! EE_Registry::instance()->CFG->admin->help_tour_activation || (defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)) {
1111
+			return;
1112
+		}
1113
+		//loop through _page_config to find any help_tour defined
1114
+		foreach ($this->_page_config as $route => $config) {
1115
+			//we're only going to set things up for this route
1116
+			if ($route !== $this->_req_action) {
1117
+				continue;
1118
+			}
1119
+			if (isset($config['help_tour'])) {
1120
+				foreach ($config['help_tour'] as $tour) {
1121
+					$file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1122
+					//let's see if we can get that file... if not its possible this is a decaf route not set in caffienated so lets try and get the caffeinated equivalent
1123
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES . basename($this->_get_dir()) . '/help_tours/' . $tour . '.class.php' : $file_path;
1124
+					//if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1125
+					if ( ! is_readable($file_path)) {
1126
+						EE_Error::add_error(sprintf(__('The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling', 'event_espresso'),
1127
+								$file_path, $tour), __FILE__, __FUNCTION__, __LINE__);
1128
+						return;
1129
+					}
1130
+					require_once $file_path;
1131
+					if ( ! class_exists($tour)) {
1132
+						$error_msg[] = sprintf(__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), $tour);
1133
+						$error_msg[] = $error_msg[0] . "\r\n" . sprintf(__('There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1134
+										'event_espresso'), $tour, '<br />', $tour, $this->_req_action, get_class($this));
1135
+						throw new EE_Error(implode('||', $error_msg));
1136
+					}
1137
+					$a = new ReflectionClass($tour);
1138
+					$tour_obj = $a->newInstance($this->_is_caf);
1139
+					$tours[] = $tour_obj;
1140
+					$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj);
1141
+				}
1142
+				//let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1143
+				$end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1144
+				$tours[] = $end_stop_tour;
1145
+				$this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1146
+			}
1147
+		}
1148
+		if ( ! empty($tours)) {
1149
+			$this->_help_tour['tours'] = $tours;
1150
+		}
1151
+		//thats it!  Now that the $_help_tours property is set (or not) the scripts and html should be taken care of automatically.
1152
+	}
1153
+
1154
+
1155
+
1156
+	/**
1157
+	 * This simply sets up any qtips that have been defined in the page config
1158
+	 *
1159
+	 * @access protected
1160
+	 * @return void
1161
+	 */
1162
+	protected function _add_qtips()
1163
+	{
1164
+		if (isset($this->_route_config['qtips'])) {
1165
+			$qtips = (array)$this->_route_config['qtips'];
1166
+			//load qtip loader
1167
+			$path = array(
1168
+					$this->_get_dir() . '/qtips/',
1169
+					EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1170
+			);
1171
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1172
+		}
1173
+	}
1174
+
1175
+
1176
+
1177
+	/**
1178
+	 * _set_nav_tabs
1179
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you wish to add additional tabs or modify accordingly.
1180
+	 *
1181
+	 * @access protected
1182
+	 * @return void
1183
+	 */
1184
+	protected function _set_nav_tabs()
1185
+	{
1186
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1187
+		$i = 0;
1188
+		foreach ($this->_page_config as $slug => $config) {
1189
+			if ( ! is_array($config) || (is_array($config) && (isset($config['nav']) && ! $config['nav']) || ! isset($config['nav']))) {
1190
+				continue;
1191
+			} //no nav tab for this config
1192
+			//check for persistent flag
1193
+			if (isset($config['nav']['persistent']) && ! $config['nav']['persistent'] && $slug !== $this->_req_action) {
1194
+				continue;
1195
+			} //nav tab is only to appear when route requested.
1196
+			if ( ! $this->check_user_access($slug, true)) {
1197
+				continue;
1198
+			} //no nav tab becasue current user does not have access.
1199
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1200
+			$this->_nav_tabs[$slug] = array(
1201
+					'url'       => isset($config['nav']['url']) ? $config['nav']['url'] : self::add_query_args_and_nonce(array('action' => $slug), $this->_admin_base_url),
1202
+					'link_text' => isset($config['nav']['label']) ? $config['nav']['label'] : ucwords(str_replace('_', ' ', $slug)),
1203
+					'css_class' => $this->_req_action == $slug ? $css_class . 'nav-tab-active' : $css_class,
1204
+					'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1205
+			);
1206
+			$i++;
1207
+		}
1208
+		//if $this->_nav_tabs is empty then lets set the default
1209
+		if (empty($this->_nav_tabs)) {
1210
+			$this->_nav_tabs[$this->default_nav_tab_name] = array(
1211
+					'url'       => $this->admin_base_url,
1212
+					'link_text' => ucwords(str_replace('_', ' ', $this->default_nav_tab_name)),
1213
+					'css_class' => 'nav-tab-active',
1214
+					'order'     => 10,
1215
+			);
1216
+		}
1217
+		//now let's sort the tabs according to order
1218
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1219
+	}
1220
+
1221
+
1222
+
1223
+	/**
1224
+	 * _set_current_labels
1225
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes property array
1226
+	 *
1227
+	 * @access private
1228
+	 * @return void
1229
+	 */
1230
+	private function _set_current_labels()
1231
+	{
1232
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1233
+			foreach ($this->_route_config['labels'] as $label => $text) {
1234
+				if (is_array($text)) {
1235
+					foreach ($text as $sublabel => $subtext) {
1236
+						$this->_labels[$label][$sublabel] = $subtext;
1237
+					}
1238
+				} else {
1239
+					$this->_labels[$label] = $text;
1240
+				}
1241
+			}
1242
+		}
1243
+	}
1244
+
1245
+
1246
+
1247
+	/**
1248
+	 *        verifies user access for this admin page
1249
+	 *
1250
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1251
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just return false if verify fail.
1252
+	 * @return        BOOL|wp_die()
1253
+	 */
1254
+	public function check_user_access($route_to_check = '', $verify_only = false)
1255
+	{
1256
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1257
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1258
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) && is_array($this->_page_routes[$route_to_check]) && ! empty($this->_page_routes[$route_to_check]['capability'])
1259
+				? $this->_page_routes[$route_to_check]['capability'] : null;
1260
+		if (empty($capability) && empty($route_to_check)) {
1261
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' : $this->_route['capability'];
1262
+		} else {
1263
+			$capability = empty($capability) ? 'manage_options' : $capability;
1264
+		}
1265
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1266
+		if (( ! function_exists('is_admin') || ! EE_Registry::instance()->CAP->current_user_can($capability, $this->page_slug . '_' . $route_to_check, $id)) && ! defined('DOING_AJAX')) {
1267
+			if ($verify_only) {
1268
+				return false;
1269
+			} else {
1270
+				if ( is_user_logged_in() ) {
1271
+					wp_die(__('You do not have access to this route.', 'event_espresso'));
1272
+				} else {
1273
+					return false;
1274
+				}
1275
+			}
1276
+		}
1277
+		return true;
1278
+	}
1279
+
1280
+
1281
+
1282
+	/**
1283
+	 * admin_init_global
1284
+	 * This runs all the code that we want executed within the WP admin_init hook.
1285
+	 * This method executes for ALL EE Admin pages.
1286
+	 *
1287
+	 * @access public
1288
+	 * @return void
1289
+	 */
1290
+	public function admin_init_global()
1291
+	{
1292
+	}
1293
+
1294
+
1295
+
1296
+	/**
1297
+	 * wp_loaded_global
1298
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an EE_Admin page and will execute on every EE Admin Page load
1299
+	 *
1300
+	 * @access public
1301
+	 * @return void
1302
+	 */
1303
+	public function wp_loaded()
1304
+	{
1305
+	}
1306
+
1307
+
1308
+
1309
+	/**
1310
+	 * admin_notices
1311
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on ALL EE_Admin pages.
1312
+	 *
1313
+	 * @access public
1314
+	 * @return void
1315
+	 */
1316
+	public function admin_notices_global()
1317
+	{
1318
+		$this->_display_no_javascript_warning();
1319
+		$this->_display_espresso_notices();
1320
+	}
1321
+
1322
+
1323
+
1324
+	public function network_admin_notices_global()
1325
+	{
1326
+		$this->_display_no_javascript_warning();
1327
+		$this->_display_espresso_notices();
1328
+	}
1329
+
1330
+
1331
+
1332
+	/**
1333
+	 * admin_footer_scripts_global
1334
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method will apply on ALL EE_Admin pages.
1335
+	 *
1336
+	 * @access public
1337
+	 * @return void
1338
+	 */
1339
+	public function admin_footer_scripts_global()
1340
+	{
1341
+		$this->_add_admin_page_ajax_loading_img();
1342
+		$this->_add_admin_page_overlay();
1343
+		//if metaboxes are present we need to add the nonce field
1344
+		if ((isset($this->_route_config['metaboxes']) || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) || isset($this->_route_config['list_table']))) {
1345
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1346
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1347
+		}
1348
+	}
1349
+
1350
+
1351
+
1352
+	/**
1353
+	 * admin_footer_global
1354
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particluar method will apply on ALL EE_Admin Pages.
1355
+	 *
1356
+	 * @access  public
1357
+	 * @return  void
1358
+	 */
1359
+	public function admin_footer_global()
1360
+	{
1361
+		//dialog container for dialog helper
1362
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1363
+		$d_cont .= '<div class="ee-notices"></div>';
1364
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1365
+		$d_cont .= '</div>';
1366
+		echo $d_cont;
1367
+		//help tour stuff?
1368
+		if (isset($this->_help_tour[$this->_req_action])) {
1369
+			echo implode('<br />', $this->_help_tour[$this->_req_action]);
1370
+		}
1371
+		//current set timezone for timezone js
1372
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1373
+	}
1374
+
1375
+
1376
+
1377
+	/**
1378
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then we'll use the retrieved array to output the content using the template.
1379
+	 * For child classes:
1380
+	 * If you want to have help popups then in your templates or your content you set "triggers" for the content using the "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method for
1381
+	 * the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content for the
1382
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1383
+	 *    'help_trigger_id' => array(
1384
+	 *        'title' => __('localized title for popup', 'event_espresso'),
1385
+	 *        'content' => __('localized content for popup', 'event_espresso')
1386
+	 *    )
1387
+	 * );
1388
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1389
+	 *
1390
+	 * @access protected
1391
+	 * @return string content
1392
+	 */
1393
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1394
+	{
1395
+		$content = '';
1396
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1397
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php';
1398
+		//loop through the array and setup content
1399
+		foreach ($help_array as $trigger => $help) {
1400
+			//make sure the array is setup properly
1401
+			if ( ! isset($help['title']) || ! isset($help['content'])) {
1402
+				throw new EE_Error(__('Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1403
+						'event_espresso'));
1404
+			}
1405
+			//we're good so let'd setup the template vars and then assign parsed template content to our content.
1406
+			$template_args = array(
1407
+					'help_popup_id'      => $trigger,
1408
+					'help_popup_title'   => $help['title'],
1409
+					'help_popup_content' => $help['content'],
1410
+			);
1411
+			$content .= EEH_Template::display_template($template_path, $template_args, true);
1412
+		}
1413
+		if ($display) {
1414
+			echo $content;
1415
+		} else {
1416
+			return $content;
1417
+		}
1418
+	}
1419
+
1420
+
1421
+
1422
+	/**
1423
+	 * All this does is retrive the help content array if set by the EE_Admin_Page child
1424
+	 *
1425
+	 * @access private
1426
+	 * @return array properly formatted array for help popup content
1427
+	 */
1428
+	private function _get_help_content()
1429
+	{
1430
+		//what is the method we're looking for?
1431
+		$method_name = '_help_popup_content_' . $this->_req_action;
1432
+		//if method doesn't exist let's get out.
1433
+		if ( ! method_exists($this, $method_name)) {
1434
+			return array();
1435
+		}
1436
+		//k we're good to go let's retrieve the help array
1437
+		$help_array = call_user_func(array($this, $method_name));
1438
+		//make sure we've got an array!
1439
+		if ( ! is_array($help_array)) {
1440
+			throw new EE_Error(__('Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', 'event_espresso'));
1441
+		}
1442
+		return $help_array;
1443
+	}
1444
+
1445
+
1446
+
1447
+	/**
1448
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1449
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1450
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1451
+	 *
1452
+	 * @access protected
1453
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1454
+	 * @param boolean $display    if false then we return the trigger string
1455
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1456
+	 * @return string
1457
+	 */
1458
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1459
+	{
1460
+		if (defined('DOING_AJAX')) {
1461
+			return;
1462
+		}
1463
+		//let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1464
+		$help_array = $this->_get_help_content();
1465
+		$help_content = '';
1466
+		if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1467
+			$help_array[$trigger_id] = array(
1468
+					'title'   => __('Missing Content', 'event_espresso'),
1469
+					'content' => __('A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1470
+							'event_espresso'),
1471
+			);
1472
+			$help_content = $this->_set_help_popup_content($help_array, false);
1473
+		}
1474
+		//let's setup the trigger
1475
+		$content = '<a class="ee-dialog" href="?height=' . $dimensions[0] . '&width=' . $dimensions[1] . '&inlineId=' . $trigger_id . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1476
+		$content = $content . $help_content;
1477
+		if ($display) {
1478
+			echo $content;
1479
+		} else {
1480
+			return $content;
1481
+		}
1482
+	}
1483
+
1484
+
1485
+
1486
+	/**
1487
+	 * _add_global_screen_options
1488
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1489
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1490
+	 *
1491
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1492
+	 *         see also WP_Screen object documents...
1493
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1494
+	 * @abstract
1495
+	 * @access private
1496
+	 * @return void
1497
+	 */
1498
+	private function _add_global_screen_options()
1499
+	{
1500
+	}
1501
+
1502
+
1503
+
1504
+	/**
1505
+	 * _add_global_feature_pointers
1506
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1507
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1508
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1509
+	 *
1510
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be extended) also see:
1511
+	 * @link   http://eamann.com/tech/wordpress-portland/
1512
+	 * @abstract
1513
+	 * @access protected
1514
+	 * @return void
1515
+	 */
1516
+	private function _add_global_feature_pointers()
1517
+	{
1518
+	}
1519
+
1520
+
1521
+
1522
+	/**
1523
+	 * load_global_scripts_styles
1524
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1525
+	 *
1526
+	 * @return void
1527
+	 */
1528
+	public function load_global_scripts_styles()
1529
+	{
1530
+		/** STYLES **/
1531
+		// add debugging styles
1532
+		if (WP_DEBUG) {
1533
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1534
+		}
1535
+		// register all styles
1536
+		wp_register_style('espresso-ui-theme', EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', array(), EVENT_ESPRESSO_VERSION);
1537
+		wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION);
1538
+		//helpers styles
1539
+		wp_register_style('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', array(), EVENT_ESPRESSO_VERSION);
1540
+		/** SCRIPTS **/
1541
+		//register all scripts
1542
+		wp_register_script('ee-dialog', EE_ADMIN_URL . 'assets/ee-dialog-helper.js', array('jquery', 'jquery-ui-draggable'), EVENT_ESPRESSO_VERSION, true);
1543
+		wp_register_script('ee_admin_js', EE_ADMIN_URL . 'assets/ee-admin-page.js', array('espresso_core', 'ee-parse-uri', 'ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1544
+		wp_register_script('jquery-ui-timepicker-addon', EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker', 'jquery-ui-slider'), EVENT_ESPRESSO_VERSION, true);
1545
+		add_filter('FHEE_load_joyride', '__return_true');
1546
+		//script for sorting tables
1547
+		wp_register_script('espresso_ajax_table_sorting', EE_ADMIN_URL . "assets/espresso_ajax_table_sorting.js", array('ee_admin_js', 'jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
1548
+		//script for parsing uri's
1549
+		wp_register_script('ee-parse-uri', EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', array(), EVENT_ESPRESSO_VERSION, true);
1550
+		//and parsing associative serialized form elements
1551
+		wp_register_script('ee-serialize-full-array', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1552
+		//helpers scripts
1553
+		wp_register_script('ee-text-links', EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
1554
+		wp_register_script('ee-moment-core', EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', array(), EVENT_ESPRESSO_VERSION, true);
1555
+		wp_register_script('ee-moment', EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', array('ee-moment-core'), EVENT_ESPRESSO_VERSION, true);
1556
+		wp_register_script('ee-datepicker', EE_ADMIN_URL . 'assets/ee-datepicker.js', array('jquery-ui-timepicker-addon', 'ee-moment'), EVENT_ESPRESSO_VERSION, true);
1557
+		//google charts
1558
+		wp_register_script('google-charts', 'https://www.gstatic.com/charts/loader.js', array(), EVENT_ESPRESSO_VERSION, false);
1559
+		// ENQUEUE ALL BASICS BY DEFAULT
1560
+		wp_enqueue_style('ee-admin-css');
1561
+		wp_enqueue_script('ee_admin_js');
1562
+		wp_enqueue_script('ee-accounting');
1563
+		wp_enqueue_script('jquery-validate');
1564
+		//taking care of metaboxes
1565
+		if (
1566
+			empty($this->_cpt_route)
1567
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1568
+		) {
1569
+			wp_enqueue_script('dashboard');
1570
+		}
1571
+		// LOCALIZED DATA
1572
+		//localize script for ajax lazy loading
1573
+		$lazy_loader_container_ids = apply_filters('FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', array('espresso_news_post_box_content'));
1574
+		wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids);
1575
+		/**
1576
+		 * help tour stuff
1577
+		 */
1578
+		if ( ! empty($this->_help_tour)) {
1579
+			//register the js for kicking things off
1580
+			wp_enqueue_script('ee-help-tour', EE_ADMIN_URL . 'assets/ee-help-tour.js', array('jquery-joyride'), EVENT_ESPRESSO_VERSION, true);
1581
+			//setup tours for the js tour object
1582
+			foreach ($this->_help_tour['tours'] as $tour) {
1583
+				$tours[] = array(
1584
+						'id'      => $tour->get_slug(),
1585
+						'options' => $tour->get_options(),
1586
+				);
1587
+			}
1588
+			wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1589
+			//admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1590
+		}
1591
+	}
1592
+
1593
+
1594
+
1595
+	/**
1596
+	 *        admin_footer_scripts_eei18n_js_strings
1597
+	 *
1598
+	 * @access        public
1599
+	 * @return        void
1600
+	 */
1601
+	public function admin_footer_scripts_eei18n_js_strings()
1602
+	{
1603
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1604
+		EE_Registry::$i18n_js_strings['confirm_delete'] = __('Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', 'event_espresso');
1605
+		EE_Registry::$i18n_js_strings['January'] = __('January', 'event_espresso');
1606
+		EE_Registry::$i18n_js_strings['February'] = __('February', 'event_espresso');
1607
+		EE_Registry::$i18n_js_strings['March'] = __('March', 'event_espresso');
1608
+		EE_Registry::$i18n_js_strings['April'] = __('April', 'event_espresso');
1609
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1610
+		EE_Registry::$i18n_js_strings['June'] = __('June', 'event_espresso');
1611
+		EE_Registry::$i18n_js_strings['July'] = __('July', 'event_espresso');
1612
+		EE_Registry::$i18n_js_strings['August'] = __('August', 'event_espresso');
1613
+		EE_Registry::$i18n_js_strings['September'] = __('September', 'event_espresso');
1614
+		EE_Registry::$i18n_js_strings['October'] = __('October', 'event_espresso');
1615
+		EE_Registry::$i18n_js_strings['November'] = __('November', 'event_espresso');
1616
+		EE_Registry::$i18n_js_strings['December'] = __('December', 'event_espresso');
1617
+		EE_Registry::$i18n_js_strings['Jan'] = __('Jan', 'event_espresso');
1618
+		EE_Registry::$i18n_js_strings['Feb'] = __('Feb', 'event_espresso');
1619
+		EE_Registry::$i18n_js_strings['Mar'] = __('Mar', 'event_espresso');
1620
+		EE_Registry::$i18n_js_strings['Apr'] = __('Apr', 'event_espresso');
1621
+		EE_Registry::$i18n_js_strings['May'] = __('May', 'event_espresso');
1622
+		EE_Registry::$i18n_js_strings['Jun'] = __('Jun', 'event_espresso');
1623
+		EE_Registry::$i18n_js_strings['Jul'] = __('Jul', 'event_espresso');
1624
+		EE_Registry::$i18n_js_strings['Aug'] = __('Aug', 'event_espresso');
1625
+		EE_Registry::$i18n_js_strings['Sep'] = __('Sep', 'event_espresso');
1626
+		EE_Registry::$i18n_js_strings['Oct'] = __('Oct', 'event_espresso');
1627
+		EE_Registry::$i18n_js_strings['Nov'] = __('Nov', 'event_espresso');
1628
+		EE_Registry::$i18n_js_strings['Dec'] = __('Dec', 'event_espresso');
1629
+		EE_Registry::$i18n_js_strings['Sunday'] = __('Sunday', 'event_espresso');
1630
+		EE_Registry::$i18n_js_strings['Monday'] = __('Monday', 'event_espresso');
1631
+		EE_Registry::$i18n_js_strings['Tuesday'] = __('Tuesday', 'event_espresso');
1632
+		EE_Registry::$i18n_js_strings['Wednesday'] = __('Wednesday', 'event_espresso');
1633
+		EE_Registry::$i18n_js_strings['Thursday'] = __('Thursday', 'event_espresso');
1634
+		EE_Registry::$i18n_js_strings['Friday'] = __('Friday', 'event_espresso');
1635
+		EE_Registry::$i18n_js_strings['Saturday'] = __('Saturday', 'event_espresso');
1636
+		EE_Registry::$i18n_js_strings['Sun'] = __('Sun', 'event_espresso');
1637
+		EE_Registry::$i18n_js_strings['Mon'] = __('Mon', 'event_espresso');
1638
+		EE_Registry::$i18n_js_strings['Tue'] = __('Tue', 'event_espresso');
1639
+		EE_Registry::$i18n_js_strings['Wed'] = __('Wed', 'event_espresso');
1640
+		EE_Registry::$i18n_js_strings['Thu'] = __('Thu', 'event_espresso');
1641
+		EE_Registry::$i18n_js_strings['Fri'] = __('Fri', 'event_espresso');
1642
+		EE_Registry::$i18n_js_strings['Sat'] = __('Sat', 'event_espresso');
1643
+	}
1644
+
1645
+
1646
+
1647
+	/**
1648
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1649
+	 *
1650
+	 * @access        public
1651
+	 * @return        void
1652
+	 */
1653
+	public function add_xdebug_style()
1654
+	{
1655
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1656
+	}
1657
+
1658
+
1659
+	/************************/
1660
+	/** LIST TABLE METHODS **/
1661
+	/************************/
1662
+	/**
1663
+	 * this sets up the list table if the current view requires it.
1664
+	 *
1665
+	 * @access protected
1666
+	 * @return void
1667
+	 */
1668
+	protected function _set_list_table()
1669
+	{
1670
+		//first is this a list_table view?
1671
+		if ( ! isset($this->_route_config['list_table'])) {
1672
+			return;
1673
+		} //not a list_table view so get out.
1674
+		//list table functions are per view specific (because some admin pages might have more than one listtable!)
1675
+		if (call_user_func(array($this, '_set_list_table_views_' . $this->_req_action)) === false) {
1676
+			//user error msg
1677
+			$error_msg = __('An error occurred. The requested list table views could not be found.', 'event_espresso');
1678
+			//developer error msg
1679
+			$error_msg .= '||' . sprintf(__('List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', 'event_espresso'),
1680
+							$this->_req_action, '_set_list_table_views_' . $this->_req_action);
1681
+			throw new EE_Error($error_msg);
1682
+		}
1683
+		//let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
1684
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, $this->_views);
1685
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
1686
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
1687
+		$this->_set_list_table_view();
1688
+		$this->_set_list_table_object();
1689
+	}
1690
+
1691
+
1692
+
1693
+	/**
1694
+	 *        set current view for List Table
1695
+	 *
1696
+	 * @access public
1697
+	 * @return array
1698
+	 */
1699
+	protected function _set_list_table_view()
1700
+	{
1701
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1702
+		// looking at active items or dumpster diving ?
1703
+		if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
1704
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
1705
+		} else {
1706
+			$this->_view = sanitize_key($this->_req_data['status']);
1707
+		}
1708
+	}
1709
+
1710
+
1711
+
1712
+	/**
1713
+	 * _set_list_table_object
1714
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
1715
+	 *
1716
+	 * @throws \EE_Error
1717
+	 */
1718
+	protected function _set_list_table_object()
1719
+	{
1720
+		if (isset($this->_route_config['list_table'])) {
1721
+			if ( ! class_exists($this->_route_config['list_table'])) {
1722
+				throw new EE_Error(
1723
+						sprintf(
1724
+								__(
1725
+										'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
1726
+										'event_espresso'
1727
+								),
1728
+								$this->_route_config['list_table'],
1729
+								get_class($this)
1730
+						)
1731
+				);
1732
+			}
1733
+			$list_table = $this->_route_config['list_table'];
1734
+			$this->_list_table_object = new $list_table($this);
1735
+		}
1736
+	}
1737
+
1738
+
1739
+
1740
+	/**
1741
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
1742
+	 *
1743
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
1744
+	 *                                                    urls.  The array should be indexed by the view it is being
1745
+	 *                                                    added to.
1746
+	 * @return array
1747
+	 */
1748
+	public function get_list_table_view_RLs($extra_query_args = array())
1749
+	{
1750
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1751
+		if (empty($this->_views)) {
1752
+			$this->_views = array();
1753
+		}
1754
+		// cycle thru views
1755
+		foreach ($this->_views as $key => $view) {
1756
+			$query_args = array();
1757
+			// check for current view
1758
+			$this->_views[$key]['class'] = $this->_view == $view['slug'] ? 'current' : '';
1759
+			$query_args['action'] = $this->_req_action;
1760
+			$query_args[$this->_req_action . '_nonce'] = wp_create_nonce($query_args['action'] . '_nonce');
1761
+			$query_args['status'] = $view['slug'];
1762
+			//merge any other arguments sent in.
1763
+			if (isset($extra_query_args[$view['slug']])) {
1764
+				$query_args = array_merge($query_args, $extra_query_args[$view['slug']]);
1765
+			}
1766
+			$this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1767
+		}
1768
+		return $this->_views;
1769
+	}
1770
+
1771
+
1772
+
1773
+	/**
1774
+	 * _entries_per_page_dropdown
1775
+	 * generates a drop down box for selecting the number of visiable rows in an admin page list table
1776
+	 *
1777
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how WP does it.
1778
+	 * @access protected
1779
+	 * @param int $max_entries total number of rows in the table
1780
+	 * @return string
1781
+	 */
1782
+	protected function _entries_per_page_dropdown($max_entries = false)
1783
+	{
1784
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1785
+		$values = array(10, 25, 50, 100);
1786
+		$per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
1787
+		if ($max_entries) {
1788
+			$values[] = $max_entries;
1789
+			sort($values);
1790
+		}
1791
+		$entries_per_page_dropdown = '
1792 1792
 			<div id="entries-per-page-dv" class="alignleft actions">
1793 1793
 				<label class="hide-if-no-js">
1794 1794
 					Show
1795 1795
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
1796
-        foreach ($values as $value) {
1797
-            if ($value < $max_entries) {
1798
-                $selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1799
-                $entries_per_page_dropdown .= '
1796
+		foreach ($values as $value) {
1797
+			if ($value < $max_entries) {
1798
+				$selected = $value == $per_page ? ' selected="' . $per_page . '"' : '';
1799
+				$entries_per_page_dropdown .= '
1800 1800
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
1801
-            }
1802
-        }
1803
-        $selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1804
-        $entries_per_page_dropdown .= '
1801
+			}
1802
+		}
1803
+		$selected = $max_entries == $per_page ? ' selected="' . $per_page . '"' : '';
1804
+		$entries_per_page_dropdown .= '
1805 1805
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
1806
-        $entries_per_page_dropdown .= '
1806
+		$entries_per_page_dropdown .= '
1807 1807
 					</select>
1808 1808
 					entries
1809 1809
 				</label>
1810 1810
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
1811 1811
 			</div>
1812 1812
 		';
1813
-        return $entries_per_page_dropdown;
1814
-    }
1815
-
1816
-
1817
-
1818
-    /**
1819
-     *        _set_search_attributes
1820
-     *
1821
-     * @access        protected
1822
-     * @return        void
1823
-     */
1824
-    public function _set_search_attributes()
1825
-    {
1826
-        $this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1827
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1828
-    }
1829
-
1830
-    /*** END LIST TABLE METHODS **/
1831
-    /*****************************/
1832
-    /**
1833
-     *        _add_registered_metaboxes
1834
-     *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1835
-     *
1836
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1837
-     * @access private
1838
-     * @return void
1839
-     */
1840
-    private function _add_registered_meta_boxes()
1841
-    {
1842
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1843
-        //we only add meta boxes if the page_route calls for it
1844
-        if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1845
-            && is_array(
1846
-                    $this->_route_config['metaboxes']
1847
-            )
1848
-        ) {
1849
-            // this simply loops through the callbacks provided
1850
-            // and checks if there is a corresponding callback registered by the child
1851
-            // if there is then we go ahead and process the metabox loader.
1852
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1853
-                // first check for Closures
1854
-                if ($metabox_callback instanceof Closure) {
1855
-                    $result = $metabox_callback();
1856
-                } else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1857
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1858
-                } else {
1859
-                    $result = call_user_func(array($this, &$metabox_callback));
1860
-                }
1861
-                if ($result === false) {
1862
-                    // user error msg
1863
-                    $error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1864
-                    // developer error msg
1865
-                    $error_msg .= '||' . sprintf(
1866
-                                    __(
1867
-                                            'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1868
-                                            'event_espresso'
1869
-                                    ),
1870
-                                    $metabox_callback
1871
-                            );
1872
-                    throw new EE_Error($error_msg);
1873
-                }
1874
-            }
1875
-        }
1876
-    }
1877
-
1878
-
1879
-
1880
-    /**
1881
-     * _add_screen_columns
1882
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1883
-     *
1884
-     * @access private
1885
-     * @return void
1886
-     */
1887
-    private function _add_screen_columns()
1888
-    {
1889
-        if (
1890
-                is_array($this->_route_config)
1891
-                && isset($this->_route_config['columns'])
1892
-                && is_array($this->_route_config['columns'])
1893
-                && count($this->_route_config['columns']) === 2
1894
-        ) {
1895
-            add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1896
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1897
-            $screen_id = $this->_current_screen->id;
1898
-            $screen_columns = (int)get_user_option("screen_layout_$screen_id");
1899
-            $total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1900
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1901
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
1902
-            $this->_template_args['screen'] = $this->_current_screen;
1903
-            $this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1904
-            //finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1905
-            $this->_route_config['has_metaboxes'] = true;
1906
-        }
1907
-    }
1908
-
1909
-
1910
-
1911
-    /**********************************/
1912
-    /** GLOBALLY AVAILABLE METABOXES **/
1913
-    /**
1914
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1915
-     * loaded on.
1916
-     */
1917
-    private function _espresso_news_post_box()
1918
-    {
1919
-        $news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1920
-        add_meta_box('espresso_news_post_box', $news_box_title, array(
1921
-                $this,
1922
-                'espresso_news_post_box',
1923
-        ), $this->_wp_page_slug, 'side');
1924
-    }
1925
-
1926
-
1927
-
1928
-    /**
1929
-     * Code for setting up espresso ratings request metabox.
1930
-     */
1931
-    protected function _espresso_ratings_request()
1932
-    {
1933
-        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1934
-            return '';
1935
-        }
1936
-        $ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1937
-        add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1938
-                $this,
1939
-                'espresso_ratings_request',
1940
-        ), $this->_wp_page_slug, 'side');
1941
-    }
1942
-
1943
-
1944
-
1945
-    /**
1946
-     * Code for setting up espresso ratings request metabox content.
1947
-     */
1948
-    public function espresso_ratings_request()
1949
-    {
1950
-        $template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1951
-        EEH_Template::display_template($template_path, array());
1952
-    }
1953
-
1954
-
1955
-
1956
-    public static function cached_rss_display($rss_id, $url)
1957
-    {
1958
-        $loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1959
-        $doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1960
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
1961
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1962
-        $post = '</div>' . "\n";
1963
-        $cache_key = 'ee_rss_' . md5($rss_id);
1964
-        if (false != ($output = get_transient($cache_key))) {
1965
-            echo $pre . $output . $post;
1966
-            return true;
1967
-        }
1968
-        if ( ! $doing_ajax) {
1969
-            echo $pre . $loading . $post;
1970
-            return false;
1971
-        }
1972
-        ob_start();
1973
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1974
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1975
-        return true;
1976
-    }
1977
-
1978
-
1979
-
1980
-    public function espresso_news_post_box()
1981
-    {
1982
-        ?>
1813
+		return $entries_per_page_dropdown;
1814
+	}
1815
+
1816
+
1817
+
1818
+	/**
1819
+	 *        _set_search_attributes
1820
+	 *
1821
+	 * @access        protected
1822
+	 * @return        void
1823
+	 */
1824
+	public function _set_search_attributes()
1825
+	{
1826
+		$this->_template_args['search']['btn_label'] = sprintf(__('Search %s', 'event_espresso'), empty($this->_search_btn_label) ? $this->page_label : $this->_search_btn_label);
1827
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
1828
+	}
1829
+
1830
+	/*** END LIST TABLE METHODS **/
1831
+	/*****************************/
1832
+	/**
1833
+	 *        _add_registered_metaboxes
1834
+	 *        this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
1835
+	 *
1836
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
1837
+	 * @access private
1838
+	 * @return void
1839
+	 */
1840
+	private function _add_registered_meta_boxes()
1841
+	{
1842
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1843
+		//we only add meta boxes if the page_route calls for it
1844
+		if (is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
1845
+			&& is_array(
1846
+					$this->_route_config['metaboxes']
1847
+			)
1848
+		) {
1849
+			// this simply loops through the callbacks provided
1850
+			// and checks if there is a corresponding callback registered by the child
1851
+			// if there is then we go ahead and process the metabox loader.
1852
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
1853
+				// first check for Closures
1854
+				if ($metabox_callback instanceof Closure) {
1855
+					$result = $metabox_callback();
1856
+				} else if (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
1857
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
1858
+				} else {
1859
+					$result = call_user_func(array($this, &$metabox_callback));
1860
+				}
1861
+				if ($result === false) {
1862
+					// user error msg
1863
+					$error_msg = __('An error occurred. The  requested metabox could not be found.', 'event_espresso');
1864
+					// developer error msg
1865
+					$error_msg .= '||' . sprintf(
1866
+									__(
1867
+											'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
1868
+											'event_espresso'
1869
+									),
1870
+									$metabox_callback
1871
+							);
1872
+					throw new EE_Error($error_msg);
1873
+				}
1874
+			}
1875
+		}
1876
+	}
1877
+
1878
+
1879
+
1880
+	/**
1881
+	 * _add_screen_columns
1882
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as the dynamic column template and we'll setup the column options for the page.
1883
+	 *
1884
+	 * @access private
1885
+	 * @return void
1886
+	 */
1887
+	private function _add_screen_columns()
1888
+	{
1889
+		if (
1890
+				is_array($this->_route_config)
1891
+				&& isset($this->_route_config['columns'])
1892
+				&& is_array($this->_route_config['columns'])
1893
+				&& count($this->_route_config['columns']) === 2
1894
+		) {
1895
+			add_screen_option('layout_columns', array('max' => (int)$this->_route_config['columns'][0], 'default' => (int)$this->_route_config['columns'][1]));
1896
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
1897
+			$screen_id = $this->_current_screen->id;
1898
+			$screen_columns = (int)get_user_option("screen_layout_$screen_id");
1899
+			$total_columns = ! empty($screen_columns) ? $screen_columns : $this->_route_config['columns'][1];
1900
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
1901
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
1902
+			$this->_template_args['screen'] = $this->_current_screen;
1903
+			$this->_column_template_path = EE_ADMIN_TEMPLATE . 'admin_details_metabox_column_wrapper.template.php';
1904
+			//finally if we don't have has_metaboxes set in the route config let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
1905
+			$this->_route_config['has_metaboxes'] = true;
1906
+		}
1907
+	}
1908
+
1909
+
1910
+
1911
+	/**********************************/
1912
+	/** GLOBALLY AVAILABLE METABOXES **/
1913
+	/**
1914
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply referencing the callback in the _page_config array property.  This way you can be very specific about what pages these get
1915
+	 * loaded on.
1916
+	 */
1917
+	private function _espresso_news_post_box()
1918
+	{
1919
+		$news_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('New @ Event Espresso', 'event_espresso'));
1920
+		add_meta_box('espresso_news_post_box', $news_box_title, array(
1921
+				$this,
1922
+				'espresso_news_post_box',
1923
+		), $this->_wp_page_slug, 'side');
1924
+	}
1925
+
1926
+
1927
+
1928
+	/**
1929
+	 * Code for setting up espresso ratings request metabox.
1930
+	 */
1931
+	protected function _espresso_ratings_request()
1932
+	{
1933
+		if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
1934
+			return '';
1935
+		}
1936
+		$ratings_box_title = apply_filters('FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', __('Keep Event Espresso Decaf Free', 'event_espresso'));
1937
+		add_meta_box('espresso_ratings_request', $ratings_box_title, array(
1938
+				$this,
1939
+				'espresso_ratings_request',
1940
+		), $this->_wp_page_slug, 'side');
1941
+	}
1942
+
1943
+
1944
+
1945
+	/**
1946
+	 * Code for setting up espresso ratings request metabox content.
1947
+	 */
1948
+	public function espresso_ratings_request()
1949
+	{
1950
+		$template_path = EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php';
1951
+		EEH_Template::display_template($template_path, array());
1952
+	}
1953
+
1954
+
1955
+
1956
+	public static function cached_rss_display($rss_id, $url)
1957
+	{
1958
+		$loading = '<p class="widget-loading hide-if-no-js">' . __('Loading&#8230;') . '</p><p class="hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
1959
+		$doing_ajax = (defined('DOING_AJAX') && DOING_AJAX);
1960
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
1961
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
1962
+		$post = '</div>' . "\n";
1963
+		$cache_key = 'ee_rss_' . md5($rss_id);
1964
+		if (false != ($output = get_transient($cache_key))) {
1965
+			echo $pre . $output . $post;
1966
+			return true;
1967
+		}
1968
+		if ( ! $doing_ajax) {
1969
+			echo $pre . $loading . $post;
1970
+			return false;
1971
+		}
1972
+		ob_start();
1973
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
1974
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
1975
+		return true;
1976
+	}
1977
+
1978
+
1979
+
1980
+	public function espresso_news_post_box()
1981
+	{
1982
+		?>
1983 1983
         <div class="padding">
1984 1984
             <div id="espresso_news_post_box_content" class="infolinks">
1985 1985
                 <?php
1986
-                // Get RSS Feed(s)
1987
-                $feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1988
-                $url = urlencode($feed_url);
1989
-                self::cached_rss_display('espresso_news_post_box_content', $url);
1990
-                ?>
1986
+				// Get RSS Feed(s)
1987
+				$feed_url = apply_filters('FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', 'http://eventespresso.com/feed/');
1988
+				$url = urlencode($feed_url);
1989
+				self::cached_rss_display('espresso_news_post_box_content', $url);
1990
+				?>
1991 1991
             </div>
1992 1992
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
1993 1993
         </div>
1994 1994
         <?php
1995
-    }
1996
-
1997
-
1998
-
1999
-    private function _espresso_links_post_box()
2000
-    {
2001
-        //Hiding until we actually have content to put in here...
2002
-        //add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2003
-    }
2004
-
2005
-
2006
-
2007
-    public function espresso_links_post_box()
2008
-    {
2009
-        //Hiding until we actually have content to put in here...
2010
-        //$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2011
-        //EEH_Template::display_template( $templatepath );
2012
-    }
2013
-
2014
-
2015
-
2016
-    protected function _espresso_sponsors_post_box()
2017
-    {
2018
-        $show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2019
-        if ($show_sponsors) {
2020
-            add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2021
-        }
2022
-    }
2023
-
2024
-
2025
-
2026
-    public function espresso_sponsors_post_box()
2027
-    {
2028
-        $templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2029
-        EEH_Template::display_template($templatepath);
2030
-    }
2031
-
2032
-
2033
-
2034
-    private function _publish_post_box()
2035
-    {
2036
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2037
-        //if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2038
-        if ( ! empty($this->_labels['publishbox'])) {
2039
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2040
-        } else {
2041
-            $box_label = __('Publish', 'event_espresso');
2042
-        }
2043
-        $box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2044
-        add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2045
-    }
2046
-
2047
-
2048
-
2049
-    public function editor_overview()
2050
-    {
2051
-        //if we have extra content set let's add it in if not make sure its empty
2052
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2053
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2054
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2055
-    }
2056
-
2057
-
2058
-    /** end of globally available metaboxes section **/
2059
-    /*************************************************/
2060
-    /**
2061
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2062
-     * protected method.
2063
-     *
2064
-     * @see   $this->_set_publish_post_box_vars for param details
2065
-     * @since 4.6.0
2066
-     */
2067
-    public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2068
-    {
2069
-        $this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2070
-    }
2071
-
2072
-
2073
-
2074
-    /**
2075
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2076
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2077
-     * save, and save and close buttons to work properly, then you will want to include a
2078
-     * values for the name and id arguments.
2079
-     *
2080
-     * @todo  Add in validation for name/id arguments.
2081
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2082
-     * @param    int     $id                      id attached to the item published
2083
-     * @param    string  $delete                  page route callback for the delete action
2084
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2085
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2086
-     * @throws \EE_Error
2087
-     */
2088
-    protected function _set_publish_post_box_vars(
2089
-            $name = '',
2090
-            $id = 0,
2091
-            $delete = '',
2092
-            $save_close_redirect_URL = '',
2093
-            $both_btns = true
2094
-    ) {
2095
-        // if Save & Close, use a custom redirect URL or default to the main page?
2096
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2097
-        // create the Save & Close and Save buttons
2098
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2099
-        //if we have extra content set let's add it in if not make sure its empty
2100
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2101
-        if ($delete && ! empty($id)) {
2102
-            //make sure we have a default if just true is sent.
2103
-            $delete = ! empty($delete) ? $delete : 'delete';
2104
-            $delete_link_args = array($name => $id);
2105
-            $delete = $this->get_action_link_or_button(
2106
-                    $delete,
2107
-                    $delete,
2108
-                    $delete_link_args,
2109
-                    'submitdelete deletion',
2110
-                    '',
2111
-                    false
2112
-            );
2113
-        }
2114
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2115
-        if ( ! empty($name) && ! empty($id)) {
2116
-            $hidden_field_arr[$name] = array(
2117
-                    'type'  => 'hidden',
2118
-                    'value' => $id,
2119
-            );
2120
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2121
-        } else {
2122
-            $hf = '';
2123
-        }
2124
-        // add hidden field
2125
-        $this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2126
-    }
2127
-
2128
-
2129
-
2130
-    /**
2131
-     *        displays an error message to ppl who have javascript disabled
2132
-     *
2133
-     * @access        private
2134
-     * @return        string
2135
-     */
2136
-    private function _display_no_javascript_warning()
2137
-    {
2138
-        ?>
1995
+	}
1996
+
1997
+
1998
+
1999
+	private function _espresso_links_post_box()
2000
+	{
2001
+		//Hiding until we actually have content to put in here...
2002
+		//add_meta_box('espresso_links_post_box', __('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2003
+	}
2004
+
2005
+
2006
+
2007
+	public function espresso_links_post_box()
2008
+	{
2009
+		//Hiding until we actually have content to put in here...
2010
+		//$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php';
2011
+		//EEH_Template::display_template( $templatepath );
2012
+	}
2013
+
2014
+
2015
+
2016
+	protected function _espresso_sponsors_post_box()
2017
+	{
2018
+		$show_sponsors = apply_filters('FHEE_show_sponsors_meta_box', true);
2019
+		if ($show_sponsors) {
2020
+			add_meta_box('espresso_sponsors_post_box', __('Event Espresso Highlights', 'event_espresso'), array($this, 'espresso_sponsors_post_box'), $this->_wp_page_slug, 'side');
2021
+		}
2022
+	}
2023
+
2024
+
2025
+
2026
+	public function espresso_sponsors_post_box()
2027
+	{
2028
+		$templatepath = EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php';
2029
+		EEH_Template::display_template($templatepath);
2030
+	}
2031
+
2032
+
2033
+
2034
+	private function _publish_post_box()
2035
+	{
2036
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2037
+		//if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array then we'll use that for the metabox label.  Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2038
+		if ( ! empty($this->_labels['publishbox'])) {
2039
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
2040
+		} else {
2041
+			$box_label = __('Publish', 'event_espresso');
2042
+		}
2043
+		$box_label = apply_filters('FHEE__EE_Admin_Page___publish_post_box__box_label', $box_label, $this->_req_action, $this);
2044
+		add_meta_box($meta_box_ref, $box_label, array($this, 'editor_overview'), $this->_current_screen->id, 'side', 'high');
2045
+	}
2046
+
2047
+
2048
+
2049
+	public function editor_overview()
2050
+	{
2051
+		//if we have extra content set let's add it in if not make sure its empty
2052
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2053
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php';
2054
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2055
+	}
2056
+
2057
+
2058
+	/** end of globally available metaboxes section **/
2059
+	/*************************************************/
2060
+	/**
2061
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2062
+	 * protected method.
2063
+	 *
2064
+	 * @see   $this->_set_publish_post_box_vars for param details
2065
+	 * @since 4.6.0
2066
+	 */
2067
+	public function set_publish_post_box_vars($name = null, $id = false, $delete = false, $save_close_redirect_URL = null, $both_btns = true)
2068
+	{
2069
+		$this->_set_publish_post_box_vars($name, $id, $delete, $save_close_redirect_URL, $both_btns);
2070
+	}
2071
+
2072
+
2073
+
2074
+	/**
2075
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2076
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2077
+	 * save, and save and close buttons to work properly, then you will want to include a
2078
+	 * values for the name and id arguments.
2079
+	 *
2080
+	 * @todo  Add in validation for name/id arguments.
2081
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2082
+	 * @param    int     $id                      id attached to the item published
2083
+	 * @param    string  $delete                  page route callback for the delete action
2084
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2085
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just the Save button
2086
+	 * @throws \EE_Error
2087
+	 */
2088
+	protected function _set_publish_post_box_vars(
2089
+			$name = '',
2090
+			$id = 0,
2091
+			$delete = '',
2092
+			$save_close_redirect_URL = '',
2093
+			$both_btns = true
2094
+	) {
2095
+		// if Save & Close, use a custom redirect URL or default to the main page?
2096
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL) ? $save_close_redirect_URL : $this->_admin_base_url;
2097
+		// create the Save & Close and Save buttons
2098
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2099
+		//if we have extra content set let's add it in if not make sure its empty
2100
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) ? $this->_template_args['publish_box_extra_content'] : '';
2101
+		if ($delete && ! empty($id)) {
2102
+			//make sure we have a default if just true is sent.
2103
+			$delete = ! empty($delete) ? $delete : 'delete';
2104
+			$delete_link_args = array($name => $id);
2105
+			$delete = $this->get_action_link_or_button(
2106
+					$delete,
2107
+					$delete,
2108
+					$delete_link_args,
2109
+					'submitdelete deletion',
2110
+					'',
2111
+					false
2112
+			);
2113
+		}
2114
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2115
+		if ( ! empty($name) && ! empty($id)) {
2116
+			$hidden_field_arr[$name] = array(
2117
+					'type'  => 'hidden',
2118
+					'value' => $id,
2119
+			);
2120
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2121
+		} else {
2122
+			$hf = '';
2123
+		}
2124
+		// add hidden field
2125
+		$this->_template_args['publish_hidden_fields'] = ! empty($hf) ? $hf[$name]['field'] : $hf;
2126
+	}
2127
+
2128
+
2129
+
2130
+	/**
2131
+	 *        displays an error message to ppl who have javascript disabled
2132
+	 *
2133
+	 * @access        private
2134
+	 * @return        string
2135
+	 */
2136
+	private function _display_no_javascript_warning()
2137
+	{
2138
+		?>
2139 2139
         <noscript>
2140 2140
             <div id="no-js-message" class="error">
2141 2141
                 <p style="font-size:1.3em;">
@@ -2145,1267 +2145,1267 @@  discard block
 block discarded – undo
2145 2145
             </div>
2146 2146
         </noscript>
2147 2147
         <?php
2148
-    }
2148
+	}
2149 2149
 
2150 2150
 
2151 2151
 
2152
-    /**
2153
-     *        displays espresso success and/or error notices
2154
-     *
2155
-     * @access        private
2156
-     * @return        string
2157
-     */
2158
-    private function _display_espresso_notices()
2159
-    {
2160
-        $notices = $this->_get_transient(true);
2161
-        echo stripslashes($notices);
2162
-    }
2152
+	/**
2153
+	 *        displays espresso success and/or error notices
2154
+	 *
2155
+	 * @access        private
2156
+	 * @return        string
2157
+	 */
2158
+	private function _display_espresso_notices()
2159
+	{
2160
+		$notices = $this->_get_transient(true);
2161
+		echo stripslashes($notices);
2162
+	}
2163 2163
 
2164 2164
 
2165 2165
 
2166
-    /**
2167
-     *        spinny things pacify the masses
2168
-     *
2169
-     * @access private
2170
-     * @return string
2171
-     */
2172
-    protected function _add_admin_page_ajax_loading_img()
2173
-    {
2174
-        ?>
2166
+	/**
2167
+	 *        spinny things pacify the masses
2168
+	 *
2169
+	 * @access private
2170
+	 * @return string
2171
+	 */
2172
+	protected function _add_admin_page_ajax_loading_img()
2173
+	{
2174
+		?>
2175 2175
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2176 2176
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php esc_html_e('loading...', 'event_espresso'); ?></span>
2177 2177
         </div>
2178 2178
         <?php
2179
-    }
2179
+	}
2180 2180
 
2181 2181
 
2182 2182
 
2183
-    /**
2184
-     *        add admin page overlay for modal boxes
2185
-     *
2186
-     * @access private
2187
-     * @return string
2188
-     */
2189
-    protected function _add_admin_page_overlay()
2190
-    {
2191
-        ?>
2183
+	/**
2184
+	 *        add admin page overlay for modal boxes
2185
+	 *
2186
+	 * @access private
2187
+	 * @return string
2188
+	 */
2189
+	protected function _add_admin_page_overlay()
2190
+	{
2191
+		?>
2192 2192
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2193 2193
         <?php
2194
-    }
2195
-
2196
-
2197
-
2198
-    /**
2199
-     * facade for add_meta_box
2200
-     *
2201
-     * @param string  $action        where the metabox get's displayed
2202
-     * @param string  $title         Title of Metabox (output in metabox header)
2203
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2204
-     * @param array   $callback_args an array of args supplied for the metabox
2205
-     * @param string  $column        what metabox column
2206
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2207
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2208
-     */
2209
-    public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2210
-    {
2211
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2212
-        //if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2213
-        if (empty($callback_args) && $create_func) {
2214
-            $callback_args = array(
2215
-                    'template_path' => $this->_template_path,
2216
-                    'template_args' => $this->_template_args,
2217
-            );
2218
-        }
2219
-        //if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2220
-        $call_back_func = $create_func ? create_function('$post, $metabox',
2221
-                'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2222
-        add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2223
-    }
2224
-
2225
-
2226
-
2227
-    /**
2228
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2229
-     *
2230
-     * @return [type] [description]
2231
-     */
2232
-    public function display_admin_page_with_metabox_columns()
2233
-    {
2234
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2235
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2236
-        //the final wrapper
2237
-        $this->admin_page_wrapper();
2238
-    }
2239
-
2240
-
2241
-
2242
-    /**
2243
-     *        generates  HTML wrapper for an admin details page
2244
-     *
2245
-     * @access public
2246
-     * @return void
2247
-     */
2248
-    public function display_admin_page_with_sidebar()
2249
-    {
2250
-        $this->_display_admin_page(true);
2251
-    }
2252
-
2253
-
2254
-
2255
-    /**
2256
-     *        generates  HTML wrapper for an admin details page (except no sidebar)
2257
-     *
2258
-     * @access public
2259
-     * @return void
2260
-     */
2261
-    public function display_admin_page_with_no_sidebar()
2262
-    {
2263
-        $this->_display_admin_page();
2264
-    }
2265
-
2266
-
2267
-
2268
-    /**
2269
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2270
-     *
2271
-     * @access public
2272
-     * @return void
2273
-     */
2274
-    public function display_about_admin_page()
2275
-    {
2276
-        $this->_display_admin_page(false, true);
2277
-    }
2278
-
2279
-
2280
-
2281
-    /**
2282
-     * display_admin_page
2283
-     * contains the code for actually displaying an admin page
2284
-     *
2285
-     * @access private
2286
-     * @param  boolean $sidebar true with sidebar, false without
2287
-     * @param  boolean $about   use the about admin wrapper instead of the default.
2288
-     * @return void
2289
-     */
2290
-    private function _display_admin_page($sidebar = false, $about = false)
2291
-    {
2292
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2293
-        //custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2294
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2295
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2296
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2297
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2298
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2299
-                ? 'poststuff'
2300
-                : 'espresso-default-admin';
2301
-        $template_path = $sidebar
2302
-                ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2303
-                : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2304
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2305
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2306
-        }
2307
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2308
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2309
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2310
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2311
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2312
-        // the final template wrapper
2313
-        $this->admin_page_wrapper($about);
2314
-    }
2315
-
2316
-
2317
-
2318
-    /**
2319
-     * This is used to display caf preview pages.
2320
-     *
2321
-     * @since 4.3.2
2322
-     * @param string $utm_campaign_source what is the key used for google analytics link
2323
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2324
-     * @return void
2325
-     * @throws \EE_Error
2326
-     */
2327
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2328
-    {
2329
-        //let's generate a default preview action button if there isn't one already present.
2330
-        $this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2331
-        $buy_now_url = add_query_arg(
2332
-                array(
2333
-                        'ee_ver'       => 'ee4',
2334
-                        'utm_source'   => 'ee4_plugin_admin',
2335
-                        'utm_medium'   => 'link',
2336
-                        'utm_campaign' => $utm_campaign_source,
2337
-                        'utm_content'  => 'buy_now_button',
2338
-                ),
2339
-                'http://eventespresso.com/pricing/'
2340
-        );
2341
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2342
-                ? $this->get_action_link_or_button(
2343
-                        '',
2344
-                        'buy_now',
2345
-                        array(),
2346
-                        'button-primary button-large',
2347
-                        $buy_now_url,
2348
-                        true
2349
-                )
2350
-                : $this->_template_args['preview_action_button'];
2351
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2352
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2353
-                $template_path,
2354
-                $this->_template_args,
2355
-                true
2356
-        );
2357
-        $this->_display_admin_page($display_sidebar);
2358
-    }
2359
-
2360
-
2361
-
2362
-    /**
2363
-     * display_admin_list_table_page_with_sidebar
2364
-     * generates HTML wrapper for an admin_page with list_table
2365
-     *
2366
-     * @access public
2367
-     * @return void
2368
-     */
2369
-    public function display_admin_list_table_page_with_sidebar()
2370
-    {
2371
-        $this->_display_admin_list_table_page(true);
2372
-    }
2373
-
2374
-
2375
-
2376
-    /**
2377
-     * display_admin_list_table_page_with_no_sidebar
2378
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2379
-     *
2380
-     * @access public
2381
-     * @return void
2382
-     */
2383
-    public function display_admin_list_table_page_with_no_sidebar()
2384
-    {
2385
-        $this->_display_admin_list_table_page();
2386
-    }
2387
-
2388
-
2389
-
2390
-    /**
2391
-     * generates html wrapper for an admin_list_table page
2392
-     *
2393
-     * @access private
2394
-     * @param boolean $sidebar whether to display with sidebar or not.
2395
-     * @return void
2396
-     */
2397
-    private function _display_admin_list_table_page($sidebar = false)
2398
-    {
2399
-        //setup search attributes
2400
-        $this->_set_search_attributes();
2401
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2402
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2403
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2404
-                ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2405
-                : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2406
-        $this->_template_args['list_table'] = $this->_list_table_object;
2407
-        $this->_template_args['current_route'] = $this->_req_action;
2408
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2409
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2410
-        if ( ! empty($ajax_sorting_callback)) {
2411
-            $sortable_list_table_form_fields = wp_nonce_field(
2412
-                    $ajax_sorting_callback . '_nonce',
2413
-                    $ajax_sorting_callback . '_nonce',
2414
-                    false,
2415
-                    false
2416
-            );
2417
-            //			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2418
-            //			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2419
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2420
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2421
-        } else {
2422
-            $sortable_list_table_form_fields = '';
2423
-        }
2424
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2425
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2426
-        $nonce_ref = $this->_req_action . '_nonce';
2427
-        $hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2428
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2429
-        //display message about search results?
2430
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2431
-                ? '<p class="ee-search-results">' . sprintf(
2432
-                        esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2433
-                        trim($this->_req_data['s'], '%')
2434
-                ) . '</p>'
2435
-                : '';
2436
-        // filter before_list_table template arg
2437
-        $this->_template_args['before_list_table'] = apply_filters(
2438
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2439
-            $this->_template_args['before_list_table'],
2440
-            $this->page_slug,
2441
-            $this->_req_data,
2442
-            $this->_req_action
2443
-        );
2444
-        // convert to array and filter again
2445
-        // arrays are easier to inject new items in a specific location,
2446
-        // but would not be backwards compatible, so we have to add a new filter
2447
-        $this->_template_args['before_list_table'] = implode(
2448
-            " \n",
2449
-            (array) apply_filters(
2450
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2451
-                (array) $this->_template_args['before_list_table'],
2452
-                $this->page_slug,
2453
-                $this->_req_data,
2454
-                $this->_req_action
2455
-            )
2456
-        );
2457
-        // filter after_list_table template arg
2458
-        $this->_template_args['after_list_table'] = apply_filters(
2459
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2460
-            $this->_template_args['after_list_table'],
2461
-            $this->page_slug,
2462
-            $this->_req_data,
2463
-            $this->_req_action
2464
-        );
2465
-        // convert to array and filter again
2466
-        // arrays are easier to inject new items in a specific location,
2467
-        // but would not be backwards compatible, so we have to add a new filter
2468
-        $this->_template_args['after_list_table'] = implode(
2469
-            " \n",
2470
-            (array) apply_filters(
2471
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2472
-                (array) $this->_template_args['after_list_table'],
2473
-                $this->page_slug,
2474
-                $this->_req_data,
2475
-                $this->_req_action
2476
-            )
2477
-        );
2478
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2479
-                $template_path,
2480
-                $this->_template_args,
2481
-                true
2482
-        );
2483
-        // the final template wrapper
2484
-        if ($sidebar) {
2485
-            $this->display_admin_page_with_sidebar();
2486
-        } else {
2487
-            $this->display_admin_page_with_no_sidebar();
2488
-        }
2489
-    }
2490
-
2491
-
2492
-
2493
-    /**
2494
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2495
-     * $items are expected in an array in the following format:
2496
-     * $legend_items = array(
2497
-     *        'item_id' => array(
2498
-     *            'icon' => 'http://url_to_icon_being_described.png',
2499
-     *            'desc' => __('localized description of item');
2500
-     *        )
2501
-     * );
2502
-     *
2503
-     * @param  array $items see above for format of array
2504
-     * @return string        html string of legend
2505
-     */
2506
-    protected function _display_legend($items)
2507
-    {
2508
-        $this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2509
-        $legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2510
-        return EEH_Template::display_template($legend_template, $this->_template_args, true);
2511
-    }
2512
-
2513
-
2514
-    /**
2515
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2516
-     * The returned json object is created from an array in the following format:
2517
-     * array(
2518
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2519
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
2520
-     *  'notices' => '', // - contains any EE_Error formatted notices
2521
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2522
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2523
-     *  specific template args that might be included in here)
2524
-     * )
2525
-     * The json object is populated by whatever is set in the $_template_args property.
2526
-     *
2527
-     * @param bool  $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2528
-     * @param array $notices_arguments  Use this to pass any additional args on to the _process_notices.
2529
-     * @return void
2530
-     */
2531
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
2532
-    {
2533
-        //make sure any EE_Error notices have been handled.
2534
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
2535
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2536
-        unset($this->_template_args['data']);
2537
-        $json = array(
2538
-                'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2539
-                'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2540
-                'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2541
-                'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2542
-                'notices'   => EE_Error::get_notices(),
2543
-                'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2544
-                'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2545
-                'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2546
-        );
2547
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
2548
-        if (null === error_get_last() || ! headers_sent()) {
2549
-            header('Content-Type: application/json; charset=UTF-8');
2550
-        }
2551
-        echo wp_json_encode($json);
2552
-
2553
-        exit();
2554
-    }
2555
-
2556
-
2557
-
2558
-    /**
2559
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2560
-     *
2561
-     * @return void
2562
-     * @throws EE_Error
2563
-     */
2564
-    public function return_json()
2565
-    {
2566
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2567
-            $this->_return_json();
2568
-        } else {
2569
-            throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2570
-        }
2571
-    }
2572
-
2573
-
2574
-
2575
-    /**
2576
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2577
-     *
2578
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2579
-     * @access   public
2580
-     */
2581
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
2582
-    {
2583
-        $this->_hook_obj = $hook_obj;
2584
-    }
2585
-
2586
-
2587
-
2588
-    /**
2589
-     *        generates  HTML wrapper with Tabbed nav for an admin page
2590
-     *
2591
-     * @access public
2592
-     * @param  boolean $about whether to use the special about page wrapper or default.
2593
-     * @return void
2594
-     */
2595
-    public function admin_page_wrapper($about = false)
2596
-    {
2597
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2598
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
2599
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
2600
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
2601
-        $this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2602
-                isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2603
-        $this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2604
-                isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2605
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2606
-        // load settings page wrapper template
2607
-        $template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2608
-        //about page?
2609
-        $template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2610
-        if (defined('DOING_AJAX')) {
2611
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2612
-            $this->_return_json();
2613
-        } else {
2614
-            EEH_Template::display_template($template_path, $this->_template_args);
2615
-        }
2616
-    }
2617
-
2618
-
2619
-
2620
-    /**
2621
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2622
-     *
2623
-     * @return string html
2624
-     */
2625
-    protected function _get_main_nav_tabs()
2626
-    {
2627
-        //let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2628
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2629
-    }
2630
-
2631
-
2632
-
2633
-    /**
2634
-     *        sort nav tabs
2635
-     *
2636
-     * @access public
2637
-     * @param $a
2638
-     * @param $b
2639
-     * @return int
2640
-     */
2641
-    private function _sort_nav_tabs($a, $b)
2642
-    {
2643
-        if ($a['order'] == $b['order']) {
2644
-            return 0;
2645
-        }
2646
-        return ($a['order'] < $b['order']) ? -1 : 1;
2647
-    }
2648
-
2649
-
2650
-
2651
-    /**
2652
-     *    generates HTML for the forms used on admin pages
2653
-     *
2654
-     * @access protected
2655
-     * @param    array $input_vars - array of input field details
2656
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2657
-     * @return string
2658
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2659
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2660
-     */
2661
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2662
-    {
2663
-        $content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2664
-        return $content;
2665
-    }
2666
-
2667
-
2668
-
2669
-    /**
2670
-     * generates the "Save" and "Save & Close" buttons for edit forms
2671
-     *
2672
-     * @access protected
2673
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2674
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2675
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2676
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2677
-     */
2678
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2679
-    {
2680
-        //make sure $text and $actions are in an array
2681
-        $text = (array)$text;
2682
-        $actions = (array)$actions;
2683
-        $referrer_url = empty($referrer) ? '' : $referrer;
2684
-        $referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2685
-                : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2686
-        $button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2687
-        $default_names = array('save', 'save_and_close');
2688
-        //add in a hidden index for the current page (so save and close redirects properly)
2689
-        $this->_template_args['save_buttons'] = $referrer_url;
2690
-        foreach ($button_text as $key => $button) {
2691
-            $ref = $default_names[$key];
2692
-            $id = $this->_current_view . '_' . $ref;
2693
-            $name = ! empty($actions) ? $actions[$key] : $ref;
2694
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2695
-            if ( ! $both) {
2696
-                break;
2697
-            }
2698
-        }
2699
-    }
2700
-
2701
-
2702
-
2703
-    /**
2704
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2705
-     *
2706
-     * @see   $this->_set_add_edit_form_tags() for details on params
2707
-     * @since 4.6.0
2708
-     * @param string $route
2709
-     * @param array  $additional_hidden_fields
2710
-     */
2711
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2712
-    {
2713
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2714
-    }
2715
-
2716
-
2717
-
2718
-    /**
2719
-     * set form open and close tags on add/edit pages.
2720
-     *
2721
-     * @access protected
2722
-     * @param string $route                    the route you want the form to direct to
2723
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2724
-     * @return void
2725
-     */
2726
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2727
-    {
2728
-        if (empty($route)) {
2729
-            $user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2730
-            $dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2731
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2732
-        }
2733
-        // open form
2734
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2735
-        // add nonce
2736
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2737
-        //		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2738
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2739
-        // add REQUIRED form action
2740
-        $hidden_fields = array(
2741
-                'action' => array('type' => 'hidden', 'value' => $route),
2742
-        );
2743
-        // merge arrays
2744
-        $hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2745
-        // generate form fields
2746
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2747
-        // add fields to form
2748
-        foreach ((array)$form_fields as $field_name => $form_field) {
2749
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2750
-        }
2751
-        // close form
2752
-        $this->_template_args['after_admin_page_content'] = '</form>';
2753
-    }
2754
-
2755
-
2756
-
2757
-    /**
2758
-     * Public Wrapper for _redirect_after_action() method since its
2759
-     * discovered it would be useful for external code to have access.
2760
-     *
2761
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
2762
-     * @since 4.5.0
2763
-     */
2764
-    public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2765
-    {
2766
-        $this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2767
-    }
2768
-
2769
-
2770
-
2771
-    /**
2772
-     *    _redirect_after_action
2773
-     *
2774
-     * @param int    $success            - whether success was for two or more records, or just one, or none
2775
-     * @param string $what               - what the action was performed on
2776
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
2777
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2778
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2779
-     * @access protected
2780
-     * @return void
2781
-     */
2782
-    protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2783
-    {
2784
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2785
-        //class name for actions/filters.
2786
-        $classname = get_class($this);
2787
-        //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2788
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2789
-        $notices = EE_Error::get_notices(false);
2790
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
2791
-        if ( ! $override_overwrite || ! empty($notices['errors'])) {
2792
-            EE_Error::overwrite_success();
2793
-        }
2794
-        if ( ! empty($what) && ! empty($action_desc)) {
2795
-            // how many records affected ? more than one record ? or just one ?
2796
-            if ($success > 1 && empty($notices['errors'])) {
2797
-                // set plural msg
2798
-                EE_Error::add_success(
2799
-                        sprintf(
2800
-                                __('The "%s" have been successfully %s.', 'event_espresso'),
2801
-                                $what,
2802
-                                $action_desc
2803
-                        ),
2804
-                        __FILE__, __FUNCTION__, __LINE__
2805
-                );
2806
-            } else if ($success == 1 && empty($notices['errors'])) {
2807
-                // set singular msg
2808
-                EE_Error::add_success(
2809
-                        sprintf(
2810
-                                __('The "%s" has been successfully %s.', 'event_espresso'),
2811
-                                $what,
2812
-                                $action_desc
2813
-                        ),
2814
-                        __FILE__, __FUNCTION__, __LINE__
2815
-                );
2816
-            }
2817
-        }
2818
-        // check that $query_args isn't something crazy
2819
-        if ( ! is_array($query_args)) {
2820
-            $query_args = array();
2821
-        }
2822
-        /**
2823
-         * Allow injecting actions before the query_args are modified for possible different
2824
-         * redirections on save and close actions
2825
-         *
2826
-         * @since 4.2.0
2827
-         * @param array $query_args       The original query_args array coming into the
2828
-         *                                method.
2829
-         */
2830
-        do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2831
-        //calculate where we're going (if we have a "save and close" button pushed)
2832
-        if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2833
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2834
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2835
-            // regenerate query args array from referrer URL
2836
-            parse_str($parsed_url['query'], $query_args);
2837
-            // correct page and action will be in the query args now
2838
-            $redirect_url = admin_url('admin.php');
2839
-        }
2840
-        //merge any default query_args set in _default_route_query_args property
2841
-        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2842
-            $args_to_merge = array();
2843
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
2844
-                //is there a wp_referer array in our _default_route_query_args property?
2845
-                if ($query_param == 'wp_referer') {
2846
-                    $query_value = (array)$query_value;
2847
-                    foreach ($query_value as $reference => $value) {
2848
-                        if (strpos($reference, 'nonce') !== false) {
2849
-                            continue;
2850
-                        }
2851
-                        //finally we will override any arguments in the referer with
2852
-                        //what might be set on the _default_route_query_args array.
2853
-                        if (isset($this->_default_route_query_args[$reference])) {
2854
-                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2855
-                        } else {
2856
-                            $args_to_merge[$reference] = urlencode($value);
2857
-                        }
2858
-                    }
2859
-                    continue;
2860
-                }
2861
-                $args_to_merge[$query_param] = $query_value;
2862
-            }
2863
-            //now let's merge these arguments but override with what was specifically sent in to the
2864
-            //redirect.
2865
-            $query_args = array_merge($args_to_merge, $query_args);
2866
-        }
2867
-        $this->_process_notices($query_args);
2868
-        // generate redirect url
2869
-        // if redirecting to anything other than the main page, add a nonce
2870
-        if (isset($query_args['action'])) {
2871
-            // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2872
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2873
-        }
2874
-        //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2875
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2876
-        $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2877
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2878
-        if (defined('DOING_AJAX')) {
2879
-            $default_data = array(
2880
-                    'close'        => true,
2881
-                    'redirect_url' => $redirect_url,
2882
-                    'where'        => 'main',
2883
-                    'what'         => 'append',
2884
-            );
2885
-            $this->_template_args['success'] = $success;
2886
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2887
-            $this->_return_json();
2888
-        }
2889
-        wp_safe_redirect($redirect_url);
2890
-        exit();
2891
-    }
2892
-
2893
-
2894
-
2895
-    /**
2896
-     * process any notices before redirecting (or returning ajax request)
2897
-     * This method sets the $this->_template_args['notices'] attribute;
2898
-     *
2899
-     * @param  array $query_args        any query args that need to be used for notice transient ('action')
2900
-     * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2901
-     * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2902
-     * @return void
2903
-     */
2904
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2905
-    {
2906
-        //first let's set individual error properties if doing_ajax and the properties aren't already set.
2907
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2908
-            $notices = EE_Error::get_notices(false);
2909
-            if (empty($this->_template_args['success'])) {
2910
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2911
-            }
2912
-            if (empty($this->_template_args['errors'])) {
2913
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2914
-            }
2915
-            if (empty($this->_template_args['attention'])) {
2916
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2917
-            }
2918
-        }
2919
-        $this->_template_args['notices'] = EE_Error::get_notices();
2920
-        //IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2921
-        if ( ! defined('DOING_AJAX') || $sticky_notices) {
2922
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
2923
-            $this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2924
-        }
2925
-    }
2926
-
2927
-
2928
-
2929
-    /**
2930
-     * get_action_link_or_button
2931
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
2932
-     *
2933
-     * @param string $action        use this to indicate which action the url is generated with.
2934
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2935
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2936
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2937
-     * @param string $base_url      If this is not provided
2938
-     *                              the _admin_base_url will be used as the default for the button base_url.
2939
-     *                              Otherwise this value will be used.
2940
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2941
-     * @return string
2942
-     * @throws \EE_Error
2943
-     */
2944
-    public function get_action_link_or_button(
2945
-            $action,
2946
-            $type = 'add',
2947
-            $extra_request = array(),
2948
-            $class = 'button-primary',
2949
-            $base_url = '',
2950
-            $exclude_nonce = false
2951
-    ) {
2952
-        //first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2953
-        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2954
-            throw new EE_Error(
2955
-                    sprintf(
2956
-                            __(
2957
-                                    'There is no page route for given action for the button.  This action was given: %s',
2958
-                                    'event_espresso'
2959
-                            ),
2960
-                            $action
2961
-                    )
2962
-            );
2963
-        }
2964
-        if ( ! isset($this->_labels['buttons'][$type])) {
2965
-            throw new EE_Error(
2966
-                    sprintf(
2967
-                            __(
2968
-                                    'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2969
-                                    'event_espresso'
2970
-                            ),
2971
-                            $type
2972
-                    )
2973
-            );
2974
-        }
2975
-        //finally check user access for this button.
2976
-        $has_access = $this->check_user_access($action, true);
2977
-        if ( ! $has_access) {
2978
-            return '';
2979
-        }
2980
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2981
-        $query_args = array(
2982
-                'action' => $action,
2983
-        );
2984
-        //merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2985
-        if ( ! empty($extra_request)) {
2986
-            $query_args = array_merge($extra_request, $query_args);
2987
-        }
2988
-        $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2989
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2990
-    }
2991
-
2992
-
2993
-
2994
-    /**
2995
-     * _per_page_screen_option
2996
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
2997
-     *
2998
-     * @return void
2999
-     */
3000
-    protected function _per_page_screen_option()
3001
-    {
3002
-        $option = 'per_page';
3003
-        $args = array(
3004
-                'label'   => $this->_admin_page_title,
3005
-                'default' => 10,
3006
-                'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3007
-        );
3008
-        //ONLY add the screen option if the user has access to it.
3009
-        if ($this->check_user_access($this->_current_view, true)) {
3010
-            add_screen_option($option, $args);
3011
-        }
3012
-    }
3013
-
3014
-
3015
-
3016
-    /**
3017
-     * set_per_page_screen_option
3018
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3019
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3020
-     *
3021
-     * @access private
3022
-     * @return void
3023
-     */
3024
-    private function _set_per_page_screen_options()
3025
-    {
3026
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3027
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3028
-            if ( ! $user = wp_get_current_user()) {
3029
-                return;
3030
-            }
3031
-            $option = $_POST['wp_screen_options']['option'];
3032
-            $value = $_POST['wp_screen_options']['value'];
3033
-            if ($option != sanitize_key($option)) {
3034
-                return;
3035
-            }
3036
-            $map_option = $option;
3037
-            $option = str_replace('-', '_', $option);
3038
-            switch ($map_option) {
3039
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3040
-                    $value = (int)$value;
3041
-                    if ($value < 1 || $value > 999) {
3042
-                        return;
3043
-                    }
3044
-                    break;
3045
-                default:
3046
-                    $value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3047
-                    if (false === $value) {
3048
-                        return;
3049
-                    }
3050
-                    break;
3051
-            }
3052
-            update_user_meta($user->ID, $option, $value);
3053
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3054
-            exit;
3055
-        }
3056
-    }
3057
-
3058
-
3059
-
3060
-    /**
3061
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3062
-     *
3063
-     * @param array $data array that will be assigned to template args.
3064
-     */
3065
-    public function set_template_args($data)
3066
-    {
3067
-        $this->_template_args = array_merge($this->_template_args, (array)$data);
3068
-    }
3069
-
3070
-
3071
-
3072
-    /**
3073
-     * This makes available the WP transient system for temporarily moving data between routes
3074
-     *
3075
-     * @access protected
3076
-     * @param string $route             the route that should receive the transient
3077
-     * @param array  $data              the data that gets sent
3078
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3079
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3080
-     * @return void
3081
-     */
3082
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3083
-    {
3084
-        $user_id = get_current_user_id();
3085
-        if ( ! $skip_route_verify) {
3086
-            $this->_verify_route($route);
3087
-        }
3088
-        //now let's set the string for what kind of transient we're setting
3089
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3090
-        $data = $notices ? array('notices' => $data) : $data;
3091
-        //is there already a transient for this route?  If there is then let's ADD to that transient
3092
-        $existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3093
-        if ($existing) {
3094
-            $data = array_merge((array)$data, (array)$existing);
3095
-        }
3096
-        if (is_multisite() && is_network_admin()) {
3097
-            set_site_transient($transient, $data, 8);
3098
-        } else {
3099
-            set_transient($transient, $data, 8);
3100
-        }
3101
-    }
3102
-
3103
-
3104
-
3105
-    /**
3106
-     * this retrieves the temporary transient that has been set for moving data between routes.
3107
-     *
3108
-     * @param bool $notices true we get notices transient. False we just return normal route transient
3109
-     * @return mixed data
3110
-     */
3111
-    protected function _get_transient($notices = false, $route = false)
3112
-    {
3113
-        $user_id = get_current_user_id();
3114
-        $route = ! $route ? $this->_req_action : $route;
3115
-        $transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3116
-        $data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3117
-        //delete transient after retrieval (just in case it hasn't expired);
3118
-        if (is_multisite() && is_network_admin()) {
3119
-            delete_site_transient($transient);
3120
-        } else {
3121
-            delete_transient($transient);
3122
-        }
3123
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3124
-    }
3125
-
3126
-
3127
-
3128
-    /**
3129
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3130
-     * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3131
-     *
3132
-     * @return void
3133
-     */
3134
-    protected function _transient_garbage_collection()
3135
-    {
3136
-        global $wpdb;
3137
-        //retrieve all existing transients
3138
-        $query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3139
-        if ($results = $wpdb->get_results($query)) {
3140
-            foreach ($results as $result) {
3141
-                $transient = str_replace('_transient_', '', $result->option_name);
3142
-                get_transient($transient);
3143
-                if (is_multisite() && is_network_admin()) {
3144
-                    get_site_transient($transient);
3145
-                }
3146
-            }
3147
-        }
3148
-    }
3149
-
3150
-
3151
-
3152
-    /**
3153
-     * get_view
3154
-     *
3155
-     * @access public
3156
-     * @return string content of _view property
3157
-     */
3158
-    public function get_view()
3159
-    {
3160
-        return $this->_view;
3161
-    }
3162
-
3163
-
3164
-
3165
-    /**
3166
-     * getter for the protected $_views property
3167
-     *
3168
-     * @return array
3169
-     */
3170
-    public function get_views()
3171
-    {
3172
-        return $this->_views;
3173
-    }
3174
-
3175
-
3176
-
3177
-    /**
3178
-     * get_current_page
3179
-     *
3180
-     * @access public
3181
-     * @return string _current_page property value
3182
-     */
3183
-    public function get_current_page()
3184
-    {
3185
-        return $this->_current_page;
3186
-    }
3187
-
3188
-
3189
-
3190
-    /**
3191
-     * get_current_view
3192
-     *
3193
-     * @access public
3194
-     * @return string _current_view property value
3195
-     */
3196
-    public function get_current_view()
3197
-    {
3198
-        return $this->_current_view;
3199
-    }
3200
-
3201
-
3202
-
3203
-    /**
3204
-     * get_current_screen
3205
-     *
3206
-     * @access public
3207
-     * @return object The current WP_Screen object
3208
-     */
3209
-    public function get_current_screen()
3210
-    {
3211
-        return $this->_current_screen;
3212
-    }
3213
-
3214
-
3215
-
3216
-    /**
3217
-     * get_current_page_view_url
3218
-     *
3219
-     * @access public
3220
-     * @return string This returns the url for the current_page_view.
3221
-     */
3222
-    public function get_current_page_view_url()
3223
-    {
3224
-        return $this->_current_page_view_url;
3225
-    }
3226
-
3227
-
3228
-
3229
-    /**
3230
-     * just returns the _req_data property
3231
-     *
3232
-     * @return array
3233
-     */
3234
-    public function get_request_data()
3235
-    {
3236
-        return $this->_req_data;
3237
-    }
3238
-
3239
-
3240
-
3241
-    /**
3242
-     * returns the _req_data protected property
3243
-     *
3244
-     * @return string
3245
-     */
3246
-    public function get_req_action()
3247
-    {
3248
-        return $this->_req_action;
3249
-    }
3250
-
3251
-
3252
-
3253
-    /**
3254
-     * @return bool  value of $_is_caf property
3255
-     */
3256
-    public function is_caf()
3257
-    {
3258
-        return $this->_is_caf;
3259
-    }
3260
-
3261
-
3262
-
3263
-    /**
3264
-     * @return mixed
3265
-     */
3266
-    public function default_espresso_metaboxes()
3267
-    {
3268
-        return $this->_default_espresso_metaboxes;
3269
-    }
3270
-
3271
-
3272
-
3273
-    /**
3274
-     * @return mixed
3275
-     */
3276
-    public function admin_base_url()
3277
-    {
3278
-        return $this->_admin_base_url;
3279
-    }
3280
-
3281
-
3282
-
3283
-    /**
3284
-     * @return mixed
3285
-     */
3286
-    public function wp_page_slug()
3287
-    {
3288
-        return $this->_wp_page_slug;
3289
-    }
3290
-
3291
-
3292
-
3293
-    /**
3294
-     * updates  espresso configuration settings
3295
-     *
3296
-     * @access    protected
3297
-     * @param string                   $tab
3298
-     * @param EE_Config_Base|EE_Config $config
3299
-     * @param string                   $file file where error occurred
3300
-     * @param string                   $func function  where error occurred
3301
-     * @param string                   $line line no where error occurred
3302
-     * @return boolean
3303
-     */
3304
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3305
-    {
3306
-        //remove any options that are NOT going to be saved with the config settings.
3307
-        if (isset($config->core->ee_ueip_optin)) {
3308
-            $config->core->ee_ueip_has_notified = true;
3309
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3310
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3311
-            update_option('ee_ueip_has_notified', true);
3312
-        }
3313
-        // and save it (note we're also doing the network save here)
3314
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3315
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3316
-        if ($config_saved && $net_saved) {
3317
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3318
-            return true;
3319
-        } else {
3320
-            EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3321
-            return false;
3322
-        }
3323
-    }
3324
-
3325
-
3326
-
3327
-    /**
3328
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3329
-     *
3330
-     * @return array
3331
-     */
3332
-    public function get_yes_no_values()
3333
-    {
3334
-        return $this->_yes_no_values;
3335
-    }
3336
-
3337
-
3338
-
3339
-    protected function _get_dir()
3340
-    {
3341
-        $reflector = new ReflectionClass(get_class($this));
3342
-        return dirname($reflector->getFileName());
3343
-    }
3344
-
3345
-
3346
-
3347
-    /**
3348
-     * A helper for getting a "next link".
3349
-     *
3350
-     * @param string $url   The url to link to
3351
-     * @param string $class The class to use.
3352
-     * @return string
3353
-     */
3354
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3355
-    {
3356
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3357
-    }
3358
-
3359
-
3360
-
3361
-    /**
3362
-     * A helper for getting a "previous link".
3363
-     *
3364
-     * @param string $url   The url to link to
3365
-     * @param string $class The class to use.
3366
-     * @return string
3367
-     */
3368
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3369
-    {
3370
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
3371
-    }
3372
-
3373
-
3374
-
3375
-
3376
-
3377
-
3378
-
3379
-    //below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3380
-    /**
3381
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3382
-     * array.
3383
-     *
3384
-     * @return bool success/fail
3385
-     */
3386
-    protected function _process_resend_registration()
3387
-    {
3388
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3389
-        do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3390
-        return $this->_template_args['success'];
3391
-    }
3392
-
3393
-
3394
-
3395
-    /**
3396
-     * This automatically processes any payment message notifications when manual payment has been applied.
3397
-     *
3398
-     * @access protected
3399
-     * @param \EE_Payment $payment
3400
-     * @return bool success/fail
3401
-     */
3402
-    protected function _process_payment_notification(EE_Payment $payment)
3403
-    {
3404
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3405
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3406
-        $this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3407
-        return $this->_template_args['success'];
3408
-    }
2194
+	}
2195
+
2196
+
2197
+
2198
+	/**
2199
+	 * facade for add_meta_box
2200
+	 *
2201
+	 * @param string  $action        where the metabox get's displayed
2202
+	 * @param string  $title         Title of Metabox (output in metabox header)
2203
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback instead of the one created in here.
2204
+	 * @param array   $callback_args an array of args supplied for the metabox
2205
+	 * @param string  $column        what metabox column
2206
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2207
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function created but just set our own callback for wp's add_meta_box.
2208
+	 */
2209
+	public function _add_admin_page_meta_box($action, $title, $callback, $callback_args, $column = 'normal', $priority = 'high', $create_func = true)
2210
+	{
2211
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2212
+		//if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2213
+		if (empty($callback_args) && $create_func) {
2214
+			$callback_args = array(
2215
+					'template_path' => $this->_template_path,
2216
+					'template_args' => $this->_template_args,
2217
+			);
2218
+		}
2219
+		//if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2220
+		$call_back_func = $create_func ? create_function('$post, $metabox',
2221
+				'do_action( "AHEE_log", __FILE__, __FUNCTION__, ""); echo EEH_Template::display_template( $metabox["args"]["template_path"], $metabox["args"]["template_args"], TRUE );') : $callback;
2222
+		add_meta_box(str_replace('_', '-', $action) . '-mbox', $title, $call_back_func, $this->_wp_page_slug, $column, $priority, $callback_args);
2223
+	}
2224
+
2225
+
2226
+
2227
+	/**
2228
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2229
+	 *
2230
+	 * @return [type] [description]
2231
+	 */
2232
+	public function display_admin_page_with_metabox_columns()
2233
+	{
2234
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2235
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_column_template_path, $this->_template_args, true);
2236
+		//the final wrapper
2237
+		$this->admin_page_wrapper();
2238
+	}
2239
+
2240
+
2241
+
2242
+	/**
2243
+	 *        generates  HTML wrapper for an admin details page
2244
+	 *
2245
+	 * @access public
2246
+	 * @return void
2247
+	 */
2248
+	public function display_admin_page_with_sidebar()
2249
+	{
2250
+		$this->_display_admin_page(true);
2251
+	}
2252
+
2253
+
2254
+
2255
+	/**
2256
+	 *        generates  HTML wrapper for an admin details page (except no sidebar)
2257
+	 *
2258
+	 * @access public
2259
+	 * @return void
2260
+	 */
2261
+	public function display_admin_page_with_no_sidebar()
2262
+	{
2263
+		$this->_display_admin_page();
2264
+	}
2265
+
2266
+
2267
+
2268
+	/**
2269
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2270
+	 *
2271
+	 * @access public
2272
+	 * @return void
2273
+	 */
2274
+	public function display_about_admin_page()
2275
+	{
2276
+		$this->_display_admin_page(false, true);
2277
+	}
2278
+
2279
+
2280
+
2281
+	/**
2282
+	 * display_admin_page
2283
+	 * contains the code for actually displaying an admin page
2284
+	 *
2285
+	 * @access private
2286
+	 * @param  boolean $sidebar true with sidebar, false without
2287
+	 * @param  boolean $about   use the about admin wrapper instead of the default.
2288
+	 * @return void
2289
+	 */
2290
+	private function _display_admin_page($sidebar = false, $about = false)
2291
+	{
2292
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2293
+		//custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2294
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2295
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2296
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2297
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2298
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2299
+				? 'poststuff'
2300
+				: 'espresso-default-admin';
2301
+		$template_path = $sidebar
2302
+				? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2303
+				: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2304
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2305
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2306
+		}
2307
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2308
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '';
2309
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '';
2310
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '';
2311
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2312
+		// the final template wrapper
2313
+		$this->admin_page_wrapper($about);
2314
+	}
2315
+
2316
+
2317
+
2318
+	/**
2319
+	 * This is used to display caf preview pages.
2320
+	 *
2321
+	 * @since 4.3.2
2322
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2323
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2324
+	 * @return void
2325
+	 * @throws \EE_Error
2326
+	 */
2327
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2328
+	{
2329
+		//let's generate a default preview action button if there isn't one already present.
2330
+		$this->_labels['buttons']['buy_now'] = __('Upgrade to Event Espresso 4 Right Now', 'event_espresso');
2331
+		$buy_now_url = add_query_arg(
2332
+				array(
2333
+						'ee_ver'       => 'ee4',
2334
+						'utm_source'   => 'ee4_plugin_admin',
2335
+						'utm_medium'   => 'link',
2336
+						'utm_campaign' => $utm_campaign_source,
2337
+						'utm_content'  => 'buy_now_button',
2338
+				),
2339
+				'http://eventespresso.com/pricing/'
2340
+		);
2341
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2342
+				? $this->get_action_link_or_button(
2343
+						'',
2344
+						'buy_now',
2345
+						array(),
2346
+						'button-primary button-large',
2347
+						$buy_now_url,
2348
+						true
2349
+				)
2350
+				: $this->_template_args['preview_action_button'];
2351
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php';
2352
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2353
+				$template_path,
2354
+				$this->_template_args,
2355
+				true
2356
+		);
2357
+		$this->_display_admin_page($display_sidebar);
2358
+	}
2359
+
2360
+
2361
+
2362
+	/**
2363
+	 * display_admin_list_table_page_with_sidebar
2364
+	 * generates HTML wrapper for an admin_page with list_table
2365
+	 *
2366
+	 * @access public
2367
+	 * @return void
2368
+	 */
2369
+	public function display_admin_list_table_page_with_sidebar()
2370
+	{
2371
+		$this->_display_admin_list_table_page(true);
2372
+	}
2373
+
2374
+
2375
+
2376
+	/**
2377
+	 * display_admin_list_table_page_with_no_sidebar
2378
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2379
+	 *
2380
+	 * @access public
2381
+	 * @return void
2382
+	 */
2383
+	public function display_admin_list_table_page_with_no_sidebar()
2384
+	{
2385
+		$this->_display_admin_list_table_page();
2386
+	}
2387
+
2388
+
2389
+
2390
+	/**
2391
+	 * generates html wrapper for an admin_list_table page
2392
+	 *
2393
+	 * @access private
2394
+	 * @param boolean $sidebar whether to display with sidebar or not.
2395
+	 * @return void
2396
+	 */
2397
+	private function _display_admin_list_table_page($sidebar = false)
2398
+	{
2399
+		//setup search attributes
2400
+		$this->_set_search_attributes();
2401
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2402
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2403
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2404
+				? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2405
+				: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2406
+		$this->_template_args['list_table'] = $this->_list_table_object;
2407
+		$this->_template_args['current_route'] = $this->_req_action;
2408
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2409
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2410
+		if ( ! empty($ajax_sorting_callback)) {
2411
+			$sortable_list_table_form_fields = wp_nonce_field(
2412
+					$ajax_sorting_callback . '_nonce',
2413
+					$ajax_sorting_callback . '_nonce',
2414
+					false,
2415
+					false
2416
+			);
2417
+			//			$reorder_action = 'espresso_' . $ajax_sorting_callback . '_nonce';
2418
+			//			$sortable_list_table_form_fields = wp_nonce_field( $reorder_action, 'ajax_table_sort_nonce', FALSE, FALSE );
2419
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' . $this->page_slug . '" />';
2420
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' . $ajax_sorting_callback . '" />';
2421
+		} else {
2422
+			$sortable_list_table_form_fields = '';
2423
+		}
2424
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2425
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) ? $this->_template_args['list_table_hidden_fields'] : '';
2426
+		$nonce_ref = $this->_req_action . '_nonce';
2427
+		$hidden_form_fields .= '<input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2428
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2429
+		//display message about search results?
2430
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
2431
+				? '<p class="ee-search-results">' . sprintf(
2432
+						esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2433
+						trim($this->_req_data['s'], '%')
2434
+				) . '</p>'
2435
+				: '';
2436
+		// filter before_list_table template arg
2437
+		$this->_template_args['before_list_table'] = apply_filters(
2438
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2439
+			$this->_template_args['before_list_table'],
2440
+			$this->page_slug,
2441
+			$this->_req_data,
2442
+			$this->_req_action
2443
+		);
2444
+		// convert to array and filter again
2445
+		// arrays are easier to inject new items in a specific location,
2446
+		// but would not be backwards compatible, so we have to add a new filter
2447
+		$this->_template_args['before_list_table'] = implode(
2448
+			" \n",
2449
+			(array) apply_filters(
2450
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2451
+				(array) $this->_template_args['before_list_table'],
2452
+				$this->page_slug,
2453
+				$this->_req_data,
2454
+				$this->_req_action
2455
+			)
2456
+		);
2457
+		// filter after_list_table template arg
2458
+		$this->_template_args['after_list_table'] = apply_filters(
2459
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2460
+			$this->_template_args['after_list_table'],
2461
+			$this->page_slug,
2462
+			$this->_req_data,
2463
+			$this->_req_action
2464
+		);
2465
+		// convert to array and filter again
2466
+		// arrays are easier to inject new items in a specific location,
2467
+		// but would not be backwards compatible, so we have to add a new filter
2468
+		$this->_template_args['after_list_table'] = implode(
2469
+			" \n",
2470
+			(array) apply_filters(
2471
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2472
+				(array) $this->_template_args['after_list_table'],
2473
+				$this->page_slug,
2474
+				$this->_req_data,
2475
+				$this->_req_action
2476
+			)
2477
+		);
2478
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2479
+				$template_path,
2480
+				$this->_template_args,
2481
+				true
2482
+		);
2483
+		// the final template wrapper
2484
+		if ($sidebar) {
2485
+			$this->display_admin_page_with_sidebar();
2486
+		} else {
2487
+			$this->display_admin_page_with_no_sidebar();
2488
+		}
2489
+	}
2490
+
2491
+
2492
+
2493
+	/**
2494
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the html string for the legend.
2495
+	 * $items are expected in an array in the following format:
2496
+	 * $legend_items = array(
2497
+	 *        'item_id' => array(
2498
+	 *            'icon' => 'http://url_to_icon_being_described.png',
2499
+	 *            'desc' => __('localized description of item');
2500
+	 *        )
2501
+	 * );
2502
+	 *
2503
+	 * @param  array $items see above for format of array
2504
+	 * @return string        html string of legend
2505
+	 */
2506
+	protected function _display_legend($items)
2507
+	{
2508
+		$this->_template_args['items'] = apply_filters('FHEE__EE_Admin_Page___display_legend__items', (array)$items, $this);
2509
+		$legend_template = EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php';
2510
+		return EEH_Template::display_template($legend_template, $this->_template_args, true);
2511
+	}
2512
+
2513
+
2514
+	/**
2515
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
2516
+	 * The returned json object is created from an array in the following format:
2517
+	 * array(
2518
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
2519
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
2520
+	 *  'notices' => '', // - contains any EE_Error formatted notices
2521
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
2522
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. We're also going to include the template args with every package (so js can pick out any
2523
+	 *  specific template args that might be included in here)
2524
+	 * )
2525
+	 * The json object is populated by whatever is set in the $_template_args property.
2526
+	 *
2527
+	 * @param bool  $sticky_notices Used to indicate whether you want to ensure notices are added to a transient instead of displayed.
2528
+	 * @param array $notices_arguments  Use this to pass any additional args on to the _process_notices.
2529
+	 * @return void
2530
+	 */
2531
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
2532
+	{
2533
+		//make sure any EE_Error notices have been handled.
2534
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
2535
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
2536
+		unset($this->_template_args['data']);
2537
+		$json = array(
2538
+				'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
2539
+				'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
2540
+				'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
2541
+				'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
2542
+				'notices'   => EE_Error::get_notices(),
2543
+				'content'   => isset($this->_template_args['admin_page_content']) ? $this->_template_args['admin_page_content'] : '',
2544
+				'data'      => array_merge($data, array('template_args' => $this->_template_args)),
2545
+				'isEEajax'  => true //special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
2546
+		);
2547
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
2548
+		if (null === error_get_last() || ! headers_sent()) {
2549
+			header('Content-Type: application/json; charset=UTF-8');
2550
+		}
2551
+		echo wp_json_encode($json);
2552
+
2553
+		exit();
2554
+	}
2555
+
2556
+
2557
+
2558
+	/**
2559
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
2560
+	 *
2561
+	 * @return void
2562
+	 * @throws EE_Error
2563
+	 */
2564
+	public function return_json()
2565
+	{
2566
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2567
+			$this->_return_json();
2568
+		} else {
2569
+			throw new EE_Error(sprintf(__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), __FUNCTION__));
2570
+		}
2571
+	}
2572
+
2573
+
2574
+
2575
+	/**
2576
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
2577
+	 *
2578
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
2579
+	 * @access   public
2580
+	 */
2581
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
2582
+	{
2583
+		$this->_hook_obj = $hook_obj;
2584
+	}
2585
+
2586
+
2587
+
2588
+	/**
2589
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
2590
+	 *
2591
+	 * @access public
2592
+	 * @param  boolean $about whether to use the special about page wrapper or default.
2593
+	 * @return void
2594
+	 */
2595
+	public function admin_page_wrapper($about = false)
2596
+	{
2597
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2598
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
2599
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
2600
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
2601
+		$this->_template_args['before_admin_page_content'] = apply_filters('FHEE_before_admin_page_content' . $this->_current_page . $this->_current_view,
2602
+				isset($this->_template_args['before_admin_page_content']) ? $this->_template_args['before_admin_page_content'] : '');
2603
+		$this->_template_args['after_admin_page_content'] = apply_filters('FHEE_after_admin_page_content' . $this->_current_page . $this->_current_view,
2604
+				isset($this->_template_args['after_admin_page_content']) ? $this->_template_args['after_admin_page_content'] : '');
2605
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
2606
+		// load settings page wrapper template
2607
+		$template_path = ! defined('DOING_AJAX') ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' : EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php';
2608
+		//about page?
2609
+		$template_path = $about ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' : $template_path;
2610
+		if (defined('DOING_AJAX')) {
2611
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, $this->_template_args, true);
2612
+			$this->_return_json();
2613
+		} else {
2614
+			EEH_Template::display_template($template_path, $this->_template_args);
2615
+		}
2616
+	}
2617
+
2618
+
2619
+
2620
+	/**
2621
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
2622
+	 *
2623
+	 * @return string html
2624
+	 */
2625
+	protected function _get_main_nav_tabs()
2626
+	{
2627
+		//let's generate the html using the EEH_Tabbed_Content helper.  We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute (rather than setting in the page_routes array)
2628
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
2629
+	}
2630
+
2631
+
2632
+
2633
+	/**
2634
+	 *        sort nav tabs
2635
+	 *
2636
+	 * @access public
2637
+	 * @param $a
2638
+	 * @param $b
2639
+	 * @return int
2640
+	 */
2641
+	private function _sort_nav_tabs($a, $b)
2642
+	{
2643
+		if ($a['order'] == $b['order']) {
2644
+			return 0;
2645
+		}
2646
+		return ($a['order'] < $b['order']) ? -1 : 1;
2647
+	}
2648
+
2649
+
2650
+
2651
+	/**
2652
+	 *    generates HTML for the forms used on admin pages
2653
+	 *
2654
+	 * @access protected
2655
+	 * @param    array $input_vars - array of input field details
2656
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to use)
2657
+	 * @return string
2658
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
2659
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
2660
+	 */
2661
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
2662
+	{
2663
+		$content = $generator == 'string' ? EEH_Form_Fields::get_form_fields($input_vars, $id) : EEH_Form_Fields::get_form_fields_array($input_vars);
2664
+		return $content;
2665
+	}
2666
+
2667
+
2668
+
2669
+	/**
2670
+	 * generates the "Save" and "Save & Close" buttons for edit forms
2671
+	 *
2672
+	 * @access protected
2673
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save & Close" button.
2674
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] => 'Save', [1] => 'save & close')
2675
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e. via the "name" value in the button).  We can also use this to just dump default actions by submitting some other value.
2676
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it will use the $referrer string. IF null, then we don't do ANYTHING on save and close (normal form handling).
2677
+	 */
2678
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
2679
+	{
2680
+		//make sure $text and $actions are in an array
2681
+		$text = (array)$text;
2682
+		$actions = (array)$actions;
2683
+		$referrer_url = empty($referrer) ? '' : $referrer;
2684
+		$referrer_url = ! $referrer ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $_SERVER['REQUEST_URI'] . '" />'
2685
+				: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' . $referrer . '" />';
2686
+		$button_text = ! empty($text) ? $text : array(__('Save', 'event_espresso'), __('Save and Close', 'event_espresso'));
2687
+		$default_names = array('save', 'save_and_close');
2688
+		//add in a hidden index for the current page (so save and close redirects properly)
2689
+		$this->_template_args['save_buttons'] = $referrer_url;
2690
+		foreach ($button_text as $key => $button) {
2691
+			$ref = $default_names[$key];
2692
+			$id = $this->_current_view . '_' . $ref;
2693
+			$name = ! empty($actions) ? $actions[$key] : $ref;
2694
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' . $ref . '" value="' . $button . '" name="' . $name . '" id="' . $id . '" />';
2695
+			if ( ! $both) {
2696
+				break;
2697
+			}
2698
+		}
2699
+	}
2700
+
2701
+
2702
+
2703
+	/**
2704
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
2705
+	 *
2706
+	 * @see   $this->_set_add_edit_form_tags() for details on params
2707
+	 * @since 4.6.0
2708
+	 * @param string $route
2709
+	 * @param array  $additional_hidden_fields
2710
+	 */
2711
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2712
+	{
2713
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
2714
+	}
2715
+
2716
+
2717
+
2718
+	/**
2719
+	 * set form open and close tags on add/edit pages.
2720
+	 *
2721
+	 * @access protected
2722
+	 * @param string $route                    the route you want the form to direct to
2723
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
2724
+	 * @return void
2725
+	 */
2726
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
2727
+	{
2728
+		if (empty($route)) {
2729
+			$user_msg = __('An error occurred. No action was set for this page\'s form.', 'event_espresso');
2730
+			$dev_msg = $user_msg . "\n" . sprintf(__('The $route argument is required for the %s->%s method.', 'event_espresso'), __FUNCTION__, __CLASS__);
2731
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
2732
+		}
2733
+		// open form
2734
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' . $this->_admin_base_url . '" id="' . $route . '_event_form" >';
2735
+		// add nonce
2736
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
2737
+		//		$nonce = wp_nonce_field( $route . '_nonce', '_wpnonce', FALSE, FALSE );
2738
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
2739
+		// add REQUIRED form action
2740
+		$hidden_fields = array(
2741
+				'action' => array('type' => 'hidden', 'value' => $route),
2742
+		);
2743
+		// merge arrays
2744
+		$hidden_fields = is_array($additional_hidden_fields) ? array_merge($hidden_fields, $additional_hidden_fields) : $hidden_fields;
2745
+		// generate form fields
2746
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
2747
+		// add fields to form
2748
+		foreach ((array)$form_fields as $field_name => $form_field) {
2749
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
2750
+		}
2751
+		// close form
2752
+		$this->_template_args['after_admin_page_content'] = '</form>';
2753
+	}
2754
+
2755
+
2756
+
2757
+	/**
2758
+	 * Public Wrapper for _redirect_after_action() method since its
2759
+	 * discovered it would be useful for external code to have access.
2760
+	 *
2761
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
2762
+	 * @since 4.5.0
2763
+	 */
2764
+	public function redirect_after_action($success = false, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2765
+	{
2766
+		$this->_redirect_after_action($success, $what, $action_desc, $query_args, $override_overwrite);
2767
+	}
2768
+
2769
+
2770
+
2771
+	/**
2772
+	 *    _redirect_after_action
2773
+	 *
2774
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
2775
+	 * @param string $what               - what the action was performed on
2776
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
2777
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin action is completed
2778
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
2779
+	 * @access protected
2780
+	 * @return void
2781
+	 */
2782
+	protected function _redirect_after_action($success = 0, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = false)
2783
+	{
2784
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2785
+		//class name for actions/filters.
2786
+		$classname = get_class($this);
2787
+		//set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
2788
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
2789
+		$notices = EE_Error::get_notices(false);
2790
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
2791
+		if ( ! $override_overwrite || ! empty($notices['errors'])) {
2792
+			EE_Error::overwrite_success();
2793
+		}
2794
+		if ( ! empty($what) && ! empty($action_desc)) {
2795
+			// how many records affected ? more than one record ? or just one ?
2796
+			if ($success > 1 && empty($notices['errors'])) {
2797
+				// set plural msg
2798
+				EE_Error::add_success(
2799
+						sprintf(
2800
+								__('The "%s" have been successfully %s.', 'event_espresso'),
2801
+								$what,
2802
+								$action_desc
2803
+						),
2804
+						__FILE__, __FUNCTION__, __LINE__
2805
+				);
2806
+			} else if ($success == 1 && empty($notices['errors'])) {
2807
+				// set singular msg
2808
+				EE_Error::add_success(
2809
+						sprintf(
2810
+								__('The "%s" has been successfully %s.', 'event_espresso'),
2811
+								$what,
2812
+								$action_desc
2813
+						),
2814
+						__FILE__, __FUNCTION__, __LINE__
2815
+				);
2816
+			}
2817
+		}
2818
+		// check that $query_args isn't something crazy
2819
+		if ( ! is_array($query_args)) {
2820
+			$query_args = array();
2821
+		}
2822
+		/**
2823
+		 * Allow injecting actions before the query_args are modified for possible different
2824
+		 * redirections on save and close actions
2825
+		 *
2826
+		 * @since 4.2.0
2827
+		 * @param array $query_args       The original query_args array coming into the
2828
+		 *                                method.
2829
+		 */
2830
+		do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
2831
+		//calculate where we're going (if we have a "save and close" button pushed)
2832
+		if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
2833
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
2834
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
2835
+			// regenerate query args array from referrer URL
2836
+			parse_str($parsed_url['query'], $query_args);
2837
+			// correct page and action will be in the query args now
2838
+			$redirect_url = admin_url('admin.php');
2839
+		}
2840
+		//merge any default query_args set in _default_route_query_args property
2841
+		if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
2842
+			$args_to_merge = array();
2843
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
2844
+				//is there a wp_referer array in our _default_route_query_args property?
2845
+				if ($query_param == 'wp_referer') {
2846
+					$query_value = (array)$query_value;
2847
+					foreach ($query_value as $reference => $value) {
2848
+						if (strpos($reference, 'nonce') !== false) {
2849
+							continue;
2850
+						}
2851
+						//finally we will override any arguments in the referer with
2852
+						//what might be set on the _default_route_query_args array.
2853
+						if (isset($this->_default_route_query_args[$reference])) {
2854
+							$args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
2855
+						} else {
2856
+							$args_to_merge[$reference] = urlencode($value);
2857
+						}
2858
+					}
2859
+					continue;
2860
+				}
2861
+				$args_to_merge[$query_param] = $query_value;
2862
+			}
2863
+			//now let's merge these arguments but override with what was specifically sent in to the
2864
+			//redirect.
2865
+			$query_args = array_merge($args_to_merge, $query_args);
2866
+		}
2867
+		$this->_process_notices($query_args);
2868
+		// generate redirect url
2869
+		// if redirecting to anything other than the main page, add a nonce
2870
+		if (isset($query_args['action'])) {
2871
+			// manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
2872
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
2873
+		}
2874
+		//we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
2875
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
2876
+		$redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
2877
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
2878
+		if (defined('DOING_AJAX')) {
2879
+			$default_data = array(
2880
+					'close'        => true,
2881
+					'redirect_url' => $redirect_url,
2882
+					'where'        => 'main',
2883
+					'what'         => 'append',
2884
+			);
2885
+			$this->_template_args['success'] = $success;
2886
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
2887
+			$this->_return_json();
2888
+		}
2889
+		wp_safe_redirect($redirect_url);
2890
+		exit();
2891
+	}
2892
+
2893
+
2894
+
2895
+	/**
2896
+	 * process any notices before redirecting (or returning ajax request)
2897
+	 * This method sets the $this->_template_args['notices'] attribute;
2898
+	 *
2899
+	 * @param  array $query_args        any query args that need to be used for notice transient ('action')
2900
+	 * @param bool   $skip_route_verify This is typically used when we are processing notices REALLY early and page_routes haven't been defined yet.
2901
+	 * @param bool   $sticky_notices    This is used to flag that regardless of whether this is doing_ajax or not, we still save a transient for the notice.
2902
+	 * @return void
2903
+	 */
2904
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
2905
+	{
2906
+		//first let's set individual error properties if doing_ajax and the properties aren't already set.
2907
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2908
+			$notices = EE_Error::get_notices(false);
2909
+			if (empty($this->_template_args['success'])) {
2910
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
2911
+			}
2912
+			if (empty($this->_template_args['errors'])) {
2913
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
2914
+			}
2915
+			if (empty($this->_template_args['attention'])) {
2916
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
2917
+			}
2918
+		}
2919
+		$this->_template_args['notices'] = EE_Error::get_notices();
2920
+		//IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
2921
+		if ( ! defined('DOING_AJAX') || $sticky_notices) {
2922
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
2923
+			$this->_add_transient($route, $this->_template_args['notices'], true, $skip_route_verify);
2924
+		}
2925
+	}
2926
+
2927
+
2928
+
2929
+	/**
2930
+	 * get_action_link_or_button
2931
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
2932
+	 *
2933
+	 * @param string $action        use this to indicate which action the url is generated with.
2934
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key) property.
2935
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
2936
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
2937
+	 * @param string $base_url      If this is not provided
2938
+	 *                              the _admin_base_url will be used as the default for the button base_url.
2939
+	 *                              Otherwise this value will be used.
2940
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
2941
+	 * @return string
2942
+	 * @throws \EE_Error
2943
+	 */
2944
+	public function get_action_link_or_button(
2945
+			$action,
2946
+			$type = 'add',
2947
+			$extra_request = array(),
2948
+			$class = 'button-primary',
2949
+			$base_url = '',
2950
+			$exclude_nonce = false
2951
+	) {
2952
+		//first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
2953
+		if (empty($base_url) && ! isset($this->_page_routes[$action])) {
2954
+			throw new EE_Error(
2955
+					sprintf(
2956
+							__(
2957
+									'There is no page route for given action for the button.  This action was given: %s',
2958
+									'event_espresso'
2959
+							),
2960
+							$action
2961
+					)
2962
+			);
2963
+		}
2964
+		if ( ! isset($this->_labels['buttons'][$type])) {
2965
+			throw new EE_Error(
2966
+					sprintf(
2967
+							__(
2968
+									'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
2969
+									'event_espresso'
2970
+							),
2971
+							$type
2972
+					)
2973
+			);
2974
+		}
2975
+		//finally check user access for this button.
2976
+		$has_access = $this->check_user_access($action, true);
2977
+		if ( ! $has_access) {
2978
+			return '';
2979
+		}
2980
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
2981
+		$query_args = array(
2982
+				'action' => $action,
2983
+		);
2984
+		//merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
2985
+		if ( ! empty($extra_request)) {
2986
+			$query_args = array_merge($extra_request, $query_args);
2987
+		}
2988
+		$url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
2989
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
2990
+	}
2991
+
2992
+
2993
+
2994
+	/**
2995
+	 * _per_page_screen_option
2996
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
2997
+	 *
2998
+	 * @return void
2999
+	 */
3000
+	protected function _per_page_screen_option()
3001
+	{
3002
+		$option = 'per_page';
3003
+		$args = array(
3004
+				'label'   => $this->_admin_page_title,
3005
+				'default' => 10,
3006
+				'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3007
+		);
3008
+		//ONLY add the screen option if the user has access to it.
3009
+		if ($this->check_user_access($this->_current_view, true)) {
3010
+			add_screen_option($option, $args);
3011
+		}
3012
+	}
3013
+
3014
+
3015
+
3016
+	/**
3017
+	 * set_per_page_screen_option
3018
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3019
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than admin_menu.
3020
+	 *
3021
+	 * @access private
3022
+	 * @return void
3023
+	 */
3024
+	private function _set_per_page_screen_options()
3025
+	{
3026
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3027
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3028
+			if ( ! $user = wp_get_current_user()) {
3029
+				return;
3030
+			}
3031
+			$option = $_POST['wp_screen_options']['option'];
3032
+			$value = $_POST['wp_screen_options']['value'];
3033
+			if ($option != sanitize_key($option)) {
3034
+				return;
3035
+			}
3036
+			$map_option = $option;
3037
+			$option = str_replace('-', '_', $option);
3038
+			switch ($map_option) {
3039
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3040
+					$value = (int)$value;
3041
+					if ($value < 1 || $value > 999) {
3042
+						return;
3043
+					}
3044
+					break;
3045
+				default:
3046
+					$value = apply_filters('FHEE__EE_Admin_Page___set_per_page_screen_options__value', false, $option, $value);
3047
+					if (false === $value) {
3048
+						return;
3049
+					}
3050
+					break;
3051
+			}
3052
+			update_user_meta($user->ID, $option, $value);
3053
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3054
+			exit;
3055
+		}
3056
+	}
3057
+
3058
+
3059
+
3060
+	/**
3061
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3062
+	 *
3063
+	 * @param array $data array that will be assigned to template args.
3064
+	 */
3065
+	public function set_template_args($data)
3066
+	{
3067
+		$this->_template_args = array_merge($this->_template_args, (array)$data);
3068
+	}
3069
+
3070
+
3071
+
3072
+	/**
3073
+	 * This makes available the WP transient system for temporarily moving data between routes
3074
+	 *
3075
+	 * @access protected
3076
+	 * @param string $route             the route that should receive the transient
3077
+	 * @param array  $data              the data that gets sent
3078
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a normal route transient.
3079
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used when we are adding a transient before page_routes have been defined.
3080
+	 * @return void
3081
+	 */
3082
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3083
+	{
3084
+		$user_id = get_current_user_id();
3085
+		if ( ! $skip_route_verify) {
3086
+			$this->_verify_route($route);
3087
+		}
3088
+		//now let's set the string for what kind of transient we're setting
3089
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3090
+		$data = $notices ? array('notices' => $data) : $data;
3091
+		//is there already a transient for this route?  If there is then let's ADD to that transient
3092
+		$existing = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3093
+		if ($existing) {
3094
+			$data = array_merge((array)$data, (array)$existing);
3095
+		}
3096
+		if (is_multisite() && is_network_admin()) {
3097
+			set_site_transient($transient, $data, 8);
3098
+		} else {
3099
+			set_transient($transient, $data, 8);
3100
+		}
3101
+	}
3102
+
3103
+
3104
+
3105
+	/**
3106
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3107
+	 *
3108
+	 * @param bool $notices true we get notices transient. False we just return normal route transient
3109
+	 * @return mixed data
3110
+	 */
3111
+	protected function _get_transient($notices = false, $route = false)
3112
+	{
3113
+		$user_id = get_current_user_id();
3114
+		$route = ! $route ? $this->_req_action : $route;
3115
+		$transient = $notices ? 'ee_rte_n_tx_' . $route . '_' . $user_id : 'rte_tx_' . $route . '_' . $user_id;
3116
+		$data = is_multisite() && is_network_admin() ? get_site_transient($transient) : get_transient($transient);
3117
+		//delete transient after retrieval (just in case it hasn't expired);
3118
+		if (is_multisite() && is_network_admin()) {
3119
+			delete_site_transient($transient);
3120
+		} else {
3121
+			delete_transient($transient);
3122
+		}
3123
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3124
+	}
3125
+
3126
+
3127
+
3128
+	/**
3129
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but would not be called later.
3130
+	 * This will be assigned to run on a specific EE Admin page. (place the method in the default route callback on the EE_Admin page you want it run.)
3131
+	 *
3132
+	 * @return void
3133
+	 */
3134
+	protected function _transient_garbage_collection()
3135
+	{
3136
+		global $wpdb;
3137
+		//retrieve all existing transients
3138
+		$query = "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3139
+		if ($results = $wpdb->get_results($query)) {
3140
+			foreach ($results as $result) {
3141
+				$transient = str_replace('_transient_', '', $result->option_name);
3142
+				get_transient($transient);
3143
+				if (is_multisite() && is_network_admin()) {
3144
+					get_site_transient($transient);
3145
+				}
3146
+			}
3147
+		}
3148
+	}
3149
+
3150
+
3151
+
3152
+	/**
3153
+	 * get_view
3154
+	 *
3155
+	 * @access public
3156
+	 * @return string content of _view property
3157
+	 */
3158
+	public function get_view()
3159
+	{
3160
+		return $this->_view;
3161
+	}
3162
+
3163
+
3164
+
3165
+	/**
3166
+	 * getter for the protected $_views property
3167
+	 *
3168
+	 * @return array
3169
+	 */
3170
+	public function get_views()
3171
+	{
3172
+		return $this->_views;
3173
+	}
3174
+
3175
+
3176
+
3177
+	/**
3178
+	 * get_current_page
3179
+	 *
3180
+	 * @access public
3181
+	 * @return string _current_page property value
3182
+	 */
3183
+	public function get_current_page()
3184
+	{
3185
+		return $this->_current_page;
3186
+	}
3187
+
3188
+
3189
+
3190
+	/**
3191
+	 * get_current_view
3192
+	 *
3193
+	 * @access public
3194
+	 * @return string _current_view property value
3195
+	 */
3196
+	public function get_current_view()
3197
+	{
3198
+		return $this->_current_view;
3199
+	}
3200
+
3201
+
3202
+
3203
+	/**
3204
+	 * get_current_screen
3205
+	 *
3206
+	 * @access public
3207
+	 * @return object The current WP_Screen object
3208
+	 */
3209
+	public function get_current_screen()
3210
+	{
3211
+		return $this->_current_screen;
3212
+	}
3213
+
3214
+
3215
+
3216
+	/**
3217
+	 * get_current_page_view_url
3218
+	 *
3219
+	 * @access public
3220
+	 * @return string This returns the url for the current_page_view.
3221
+	 */
3222
+	public function get_current_page_view_url()
3223
+	{
3224
+		return $this->_current_page_view_url;
3225
+	}
3226
+
3227
+
3228
+
3229
+	/**
3230
+	 * just returns the _req_data property
3231
+	 *
3232
+	 * @return array
3233
+	 */
3234
+	public function get_request_data()
3235
+	{
3236
+		return $this->_req_data;
3237
+	}
3238
+
3239
+
3240
+
3241
+	/**
3242
+	 * returns the _req_data protected property
3243
+	 *
3244
+	 * @return string
3245
+	 */
3246
+	public function get_req_action()
3247
+	{
3248
+		return $this->_req_action;
3249
+	}
3250
+
3251
+
3252
+
3253
+	/**
3254
+	 * @return bool  value of $_is_caf property
3255
+	 */
3256
+	public function is_caf()
3257
+	{
3258
+		return $this->_is_caf;
3259
+	}
3260
+
3261
+
3262
+
3263
+	/**
3264
+	 * @return mixed
3265
+	 */
3266
+	public function default_espresso_metaboxes()
3267
+	{
3268
+		return $this->_default_espresso_metaboxes;
3269
+	}
3270
+
3271
+
3272
+
3273
+	/**
3274
+	 * @return mixed
3275
+	 */
3276
+	public function admin_base_url()
3277
+	{
3278
+		return $this->_admin_base_url;
3279
+	}
3280
+
3281
+
3282
+
3283
+	/**
3284
+	 * @return mixed
3285
+	 */
3286
+	public function wp_page_slug()
3287
+	{
3288
+		return $this->_wp_page_slug;
3289
+	}
3290
+
3291
+
3292
+
3293
+	/**
3294
+	 * updates  espresso configuration settings
3295
+	 *
3296
+	 * @access    protected
3297
+	 * @param string                   $tab
3298
+	 * @param EE_Config_Base|EE_Config $config
3299
+	 * @param string                   $file file where error occurred
3300
+	 * @param string                   $func function  where error occurred
3301
+	 * @param string                   $line line no where error occurred
3302
+	 * @return boolean
3303
+	 */
3304
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3305
+	{
3306
+		//remove any options that are NOT going to be saved with the config settings.
3307
+		if (isset($config->core->ee_ueip_optin)) {
3308
+			$config->core->ee_ueip_has_notified = true;
3309
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3310
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3311
+			update_option('ee_ueip_has_notified', true);
3312
+		}
3313
+		// and save it (note we're also doing the network save here)
3314
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
3315
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3316
+		if ($config_saved && $net_saved) {
3317
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3318
+			return true;
3319
+		} else {
3320
+			EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3321
+			return false;
3322
+		}
3323
+	}
3324
+
3325
+
3326
+
3327
+	/**
3328
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
3329
+	 *
3330
+	 * @return array
3331
+	 */
3332
+	public function get_yes_no_values()
3333
+	{
3334
+		return $this->_yes_no_values;
3335
+	}
3336
+
3337
+
3338
+
3339
+	protected function _get_dir()
3340
+	{
3341
+		$reflector = new ReflectionClass(get_class($this));
3342
+		return dirname($reflector->getFileName());
3343
+	}
3344
+
3345
+
3346
+
3347
+	/**
3348
+	 * A helper for getting a "next link".
3349
+	 *
3350
+	 * @param string $url   The url to link to
3351
+	 * @param string $class The class to use.
3352
+	 * @return string
3353
+	 */
3354
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
3355
+	{
3356
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3357
+	}
3358
+
3359
+
3360
+
3361
+	/**
3362
+	 * A helper for getting a "previous link".
3363
+	 *
3364
+	 * @param string $url   The url to link to
3365
+	 * @param string $class The class to use.
3366
+	 * @return string
3367
+	 */
3368
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
3369
+	{
3370
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
3371
+	}
3372
+
3373
+
3374
+
3375
+
3376
+
3377
+
3378
+
3379
+	//below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
3380
+	/**
3381
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the _req_data
3382
+	 * array.
3383
+	 *
3384
+	 * @return bool success/fail
3385
+	 */
3386
+	protected function _process_resend_registration()
3387
+	{
3388
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
3389
+		do_action('AHEE__EE_Admin_Page___process_resend_registration', $this->_template_args['success'], $this->_req_data);
3390
+		return $this->_template_args['success'];
3391
+	}
3392
+
3393
+
3394
+
3395
+	/**
3396
+	 * This automatically processes any payment message notifications when manual payment has been applied.
3397
+	 *
3398
+	 * @access protected
3399
+	 * @param \EE_Payment $payment
3400
+	 * @return bool success/fail
3401
+	 */
3402
+	protected function _process_payment_notification(EE_Payment $payment)
3403
+	{
3404
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
3405
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
3406
+		$this->_template_args['success'] = apply_filters('FHEE__EE_Admin_Page___process_admin_payment_notification__success', false, $payment);
3407
+		return $this->_template_args['success'];
3408
+	}
3409 3409
 
3410 3410
 
3411 3411
 }
Please login to merge, or discard this patch.
admin_pages/about/templates/credits.template.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 <ul class="wp-people-group" id="ee-people-group-owners">
4 4
 	<li class="wp-person" id="ee-person-sshoultes">
5 5
 		<a href="<?php esp_gravatar_profile('[email protected]'); ?>">
6
-			<?php echo esp_gravatar_image( '[email protected]', 'Seth Shoultes' ); ?>
6
+			<?php echo esp_gravatar_image('[email protected]', 'Seth Shoultes'); ?>
7 7
 		</a>
8 8
 		<a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>">
9 9
 			Seth Shoultes
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	</li>
13 13
 	<li class="wp-person" id="ee-person-gkoyle">
14 14
 		<a href="<?php esp_gravatar_profile('[email protected]'); ?>">
15
-			<?php echo esp_gravatar_image( '[email protected]', 'Garth Koyle' ); ?>
15
+			<?php echo esp_gravatar_image('[email protected]', 'Garth Koyle'); ?>
16 16
 		</a>
17 17
 		<a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>">
18 18
 			Garth Koyle
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 <ul class="wp-people-group" id="ee-people-group-core-developers">
25 25
 	<li class="wp-person" id="ee-person-bchristensen">
26 26
 		<a href="<?php esp_gravatar_profile('[email protected]'); ?>">
27
-			<?php echo esp_gravatar_image( '[email protected]', 'Brent Christensen' ); ?>
27
+			<?php echo esp_gravatar_image('[email protected]', 'Brent Christensen'); ?>
28 28
 		</a>
29 29
 		<a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>">
30 30
 			Brent Christensen
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	</li>
34 34
 	<li class="wp-person" id="ee-person-dethier">
35 35
 		<a href="<?php esp_gravatar_profile('[email protected]'); ?>">
36
-			<?php echo esp_gravatar_image( '[email protected]', 'Darren Ethier' ); ?>
36
+			<?php echo esp_gravatar_image('[email protected]', 'Darren Ethier'); ?>
37 37
 		</a>
38 38
 		<a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>">
39 39
 			Darren Ethier
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	</li>
43 43
 	<li class="wp-person" id="ee-person-mnelson">
44 44
 		<a href="<?php esp_gravatar_profile('[email protected]'); ?>">
45
-			<?php echo esp_gravatar_image( '[email protected]', 'Michael Nelson' ); ?>
45
+			<?php echo esp_gravatar_image('[email protected]', 'Michael Nelson'); ?>
46 46
 		</a>
47 47
 		<a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>">
48 48
 			Michael Nelson
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	</li>
52 52
 	<li class="wp-person" id="ee-person-nkolivoshka">
53 53
 		<a href="<?php esp_gravatar_profile('[email protected]'); ?>">
54
-			<?php echo esp_gravatar_image( '[email protected]', 'Nazar Kolivoshka' ); ?>
54
+			<?php echo esp_gravatar_image('[email protected]', 'Nazar Kolivoshka'); ?>
55 55
 		</a>
56 56
 		<a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>">
57 57
 			Nazar Kolivoshka
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 <ul class="wp-people-group" id="ee-people-group-support-staff">
64 64
 	<li class="wp-person" id="ee-person-jfeck">
65 65
 		<a href="<?php esp_gravatar_profile('[email protected]'); ?>">
66
-			<?php echo esp_gravatar_image( '[email protected]', 'Josh Feck' ); ?>
66
+			<?php echo esp_gravatar_image('[email protected]', 'Josh Feck'); ?>
67 67
 		</a>
68 68
 		<a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>">
69 69
 			Josh Feck
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	</li>
72 72
 	<li class="wp-person" id="ee-person-twarwick">
73 73
 		<a href="<?php esp_gravatar_profile('[email protected]'); ?>">
74
-			<?php echo esp_gravatar_image( '[email protected]', 'Tony Warwick' ); ?>
74
+			<?php echo esp_gravatar_image('[email protected]', 'Tony Warwick'); ?>
75 75
 		</a>
76 76
 		<a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>">
77 77
 			Tony Warwick
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	</li>
80 80
 	<li class="wp-person" id="ee-person-lcaum">
81 81
 		<a href="<?php esp_gravatar_profile('[email protected]'); ?>">
82
-			<?php echo esp_gravatar_image( '[email protected]', 'Lorenzo Caum' ); ?>
82
+			<?php echo esp_gravatar_image('[email protected]', 'Lorenzo Caum'); ?>
83 83
 		</a>
84 84
 		<a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>">
85 85
 			Lorenzo Caum
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	</li>
88 88
 	<li class="wp-person" id="ee-logan-lenz">
89 89
 		<a href="<?php esp_gravatar_profile('[email protected]'); ?>">
90
-			<?php echo esp_gravatar_image( '[email protected]', 'Logan Lenz' ); ?>
90
+			<?php echo esp_gravatar_image('[email protected]', 'Logan Lenz'); ?>
91 91
 		</a>
92 92
 		<a class="web" href="<?php esp_gravatar_profile('[email protected]'); ?>">
93 93
 			Logan Lenz
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 </ul>
98 98
 <h3 class="wp-people-group"><?php _e('Contributor Recognition', 'event_espresso'); ?></h3>
99 99
 <p class="description">
100
-	<?php printf( __('For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', '</a>' ); ?>
100
+	<?php printf(__('For every major release we want to recognize the people who contributed to the release via a GitHub pull request. Want to see your name listed here? %sWhen you submit a pull request that gets included in a major release%s, we\'ll add your name here linked to your GitHub profile.', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core" title="Contribute to Event Espresso by making a pull request via GitHub">', '</a>'); ?>
101 101
 </p>
102 102
 <p class="wp-credits-list">
103 103
 	<ul>
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 </p>
112 112
 <h3 class="wp-people-group"><?php _e('External Libraries', 'event_espresso'); ?></h3>
113 113
 <p class="description">
114
-	<?php printf( __('Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', 'event_espresso'), '<a href="credits.php">', '</a>' ); ?>
114
+	<?php printf(__('Along with the libraries %sincluded with WordPress%s, Event Espresso utilizes the following third party libraries:', 'event_espresso'), '<a href="credits.php">', '</a>'); ?>
115 115
 </p>
116 116
 <p class="wp-credits-list">
117 117
 	<a href="http://josscrowcroft.github.io/accounting.js/"><?php _e('accounting.js', 'event_espresso'); ?></a>,
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
 
128 128
 <?php
129 129
 	function esp_gravatar_profile($email) {
130
-		echo 'http://www.gravatar.com/' . md5($email);
130
+		echo 'http://www.gravatar.com/'.md5($email);
131 131
 	}
132 132
 
133 133
 	function esp_gravatar_image($email, $name) {
134
-		echo '<img src="http://0.gravatar.com/avatar/' . md5($email) . '?s=60" class="gravatar" alt="' . $name . '"/>';
134
+		echo '<img src="http://0.gravatar.com/avatar/'.md5($email).'?s=60" class="gravatar" alt="'.$name.'"/>';
135 135
 	}
136 136
 ?>
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         // when adding a new registration...
70 70
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71 71
             EE_System::do_not_cache();
72
-            if (! isset($this->_req_data['processing_registration'])
72
+            if ( ! isset($this->_req_data['processing_registration'])
73 73
                  || absint($this->_req_data['processing_registration']) !== 1
74 74
             ) {
75 75
                 // and it's NOT the attendee information reg step
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
         //style
578 578
         wp_register_style(
579 579
             'espresso_reg',
580
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
580
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
581 581
             array('ee-admin-css'),
582 582
             EVENT_ESPRESSO_VERSION
583 583
         );
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
         //script
586 586
         wp_register_script(
587 587
             'espresso_reg',
588
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
588
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
589 589
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
590 590
             EVENT_ESPRESSO_VERSION,
591 591
             true
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
         wp_deregister_style('espresso_reg');
624 624
         wp_register_style(
625 625
             'espresso_att',
626
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
626
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
627 627
             array('ee-admin-css'),
628 628
             EVENT_ESPRESSO_VERSION
629 629
         );
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
     {
636 636
         wp_register_script(
637 637
             'ee-spco-for-admin',
638
-            REG_ASSETS_URL . 'spco_for_admin.js',
638
+            REG_ASSETS_URL.'spco_for_admin.js',
639 639
             array('underscore', 'jquery'),
640 640
             EVENT_ESPRESSO_VERSION,
641 641
             true
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
                     'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
769 769
                 ),
770 770
             );
771
-            $this->_views['trash']      = array(
771
+            $this->_views['trash'] = array(
772 772
                 'slug'        => 'trash',
773 773
                 'label'       => esc_html__('Trash', 'event_espresso'),
774 774
                 'count'       => 0,
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
         }
858 858
         $sc_items = array(
859 859
             'approved_status'   => array(
860
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
860
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
861 861
                 'desc'  => EEH_Template::pretty_status(
862 862
                     EEM_Registration::status_id_approved,
863 863
                     false,
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
                 ),
866 866
             ),
867 867
             'pending_status'    => array(
868
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
868
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
869 869
                 'desc'  => EEH_Template::pretty_status(
870 870
                     EEM_Registration::status_id_pending_payment,
871 871
                     false,
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
                 ),
874 874
             ),
875 875
             'wait_list'         => array(
876
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
876
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
877 877
                 'desc'  => EEH_Template::pretty_status(
878 878
                     EEM_Registration::status_id_wait_list,
879 879
                     false,
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
                 ),
882 882
             ),
883 883
             'incomplete_status' => array(
884
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
884
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
885 885
                 'desc'  => EEH_Template::pretty_status(
886 886
                     EEM_Registration::status_id_incomplete,
887 887
                     false,
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
                 ),
890 890
             ),
891 891
             'not_approved'      => array(
892
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
892
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
893 893
                 'desc'  => EEH_Template::pretty_status(
894 894
                     EEM_Registration::status_id_not_approved,
895 895
                     false,
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
                 ),
898 898
             ),
899 899
             'declined_status'   => array(
900
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
900
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
901 901
                 'desc'  => EEH_Template::pretty_status(
902 902
                     EEM_Registration::status_id_declined,
903 903
                     false,
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
                 ),
906 906
             ),
907 907
             'cancelled_status'  => array(
908
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
908
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
909 909
                 'desc'  => EEH_Template::pretty_status(
910 910
                     EEM_Registration::status_id_cancelled,
911 911
                     false,
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
                 'espresso_registrations_new_registration',
935 935
                 $EVT_ID
936 936
             )) {
937
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
937
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
938 938
                     'new_registration',
939 939
                     'add-registrant',
940 940
                     array('event_id' => $EVT_ID),
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
975 975
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
976 976
                 $this->_template_args['admin_page_header'] .= $datetime->name();
977
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
977
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
978 978
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
979 979
             }
980 980
         }
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
             'caps'                     => EEM_Registration::caps_read_admin,
1075 1075
             'default_where_conditions' => 'this_model_only',
1076 1076
         );
1077
-        if (! $count) {
1077
+        if ( ! $count) {
1078 1078
             $query_params = array_merge(
1079 1079
                 $query_params,
1080 1080
                 $this->_get_orderby_for_registrations_query(),
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
     protected function _add_event_id_to_where_conditions(array $request)
1096 1096
     {
1097 1097
         $where = array();
1098
-        if (! empty($request['event_id'])) {
1098
+        if ( ! empty($request['event_id'])) {
1099 1099
             $where['EVT_ID'] = absint($request['event_id']);
1100 1100
         }
1101 1101
         return $where;
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
     protected function _add_category_id_to_where_conditions(array $request)
1112 1112
     {
1113 1113
         $where = array();
1114
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1114
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1115 1115
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1116 1116
         }
1117 1117
         return $where;
@@ -1127,10 +1127,10 @@  discard block
 block discarded – undo
1127 1127
     protected function _add_datetime_id_to_where_conditions(array $request)
1128 1128
     {
1129 1129
         $where = array();
1130
-        if (! empty($request['datetime_id'])) {
1130
+        if ( ! empty($request['datetime_id'])) {
1131 1131
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1132 1132
         }
1133
-        if (! empty($request['DTT_ID'])) {
1133
+        if ( ! empty($request['DTT_ID'])) {
1134 1134
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1135 1135
         }
1136 1136
         return $where;
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1157 1157
          * UNLESS viewing trashed registrations.
1158 1158
          */
1159
-        if (! empty($registration_status)) {
1159
+        if ( ! empty($registration_status)) {
1160 1160
             $where['STS_ID'] = $registration_status;
1161 1161
         } else {
1162 1162
             //make sure we exclude incomplete registrations, but only if not trashed.
@@ -1196,12 +1196,12 @@  discard block
 block discarded – undo
1196 1196
                 array(
1197 1197
                     EEM_Registration::instance()->convert_datetime_for_query(
1198 1198
                         'REG_date',
1199
-                        $now . ' 00:00:00',
1199
+                        $now.' 00:00:00',
1200 1200
                         'Y-m-d H:i:s'
1201 1201
                     ),
1202 1202
                     EEM_Registration::instance()->convert_datetime_for_query(
1203 1203
                         'REG_date',
1204
-                        $now . ' 23:59:59',
1204
+                        $now.' 23:59:59',
1205 1205
                         'Y-m-d H:i:s'
1206 1206
                     ),
1207 1207
                 ),
@@ -1214,12 +1214,12 @@  discard block
 block discarded – undo
1214 1214
                 array(
1215 1215
                     EEM_Registration::instance()->convert_datetime_for_query(
1216 1216
                         'REG_date',
1217
-                        $current_year_and_month . '-01 00:00:00',
1217
+                        $current_year_and_month.'-01 00:00:00',
1218 1218
                         'Y-m-d H:i:s'
1219 1219
                     ),
1220 1220
                     EEM_Registration::instance()->convert_datetime_for_query(
1221 1221
                         'REG_date',
1222
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1222
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1223 1223
                         'Y-m-d H:i:s'
1224 1224
                     ),
1225 1225
                 ),
@@ -1234,18 +1234,18 @@  discard block
 block discarded – undo
1234 1234
                 : '';
1235 1235
             //if there is not a month or year then we can't go further
1236 1236
             if ($month_requested && $year_requested) {
1237
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1237
+                $days_in_month     = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1238 1238
                 $where['REG_date'] = array(
1239 1239
                     'BETWEEN',
1240 1240
                     array(
1241 1241
                         EEM_Registration::instance()->convert_datetime_for_query(
1242 1242
                             'REG_date',
1243
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1243
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1244 1244
                             'Y-m-d H:i:s'
1245 1245
                         ),
1246 1246
                         EEM_Registration::instance()->convert_datetime_for_query(
1247 1247
                             'REG_date',
1248
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1248
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1249 1249
                             'Y-m-d H:i:s'
1250 1250
                         ),
1251 1251
                     ),
@@ -1265,8 +1265,8 @@  discard block
 block discarded – undo
1265 1265
     protected function _add_search_to_where_conditions(array $request)
1266 1266
     {
1267 1267
         $where = array();
1268
-        if (! empty($request['s'])) {
1269
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1268
+        if ( ! empty($request['s'])) {
1269
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1270 1270
             $where['OR*search_conditions'] = array(
1271 1271
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1272 1272
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1379,7 +1379,7 @@  discard block
 block discarded – undo
1379 1379
             : $per_page;
1380 1380
 
1381 1381
         //-1 means return all results so get out if that's set.
1382
-        if ((int)$per_page === -1) {
1382
+        if ((int) $per_page === -1) {
1383 1383
             return array();
1384 1384
         }
1385 1385
         $per_page = absint($per_page);
@@ -1432,7 +1432,7 @@  discard block
 block discarded – undo
1432 1432
                 ),
1433 1433
                 REG_ADMIN_URL
1434 1434
             );
1435
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1435
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1436 1436
                 array(
1437 1437
                     'action' => 'default',
1438 1438
                     'EVT_ID' => $event_id,
@@ -1440,7 +1440,7 @@  discard block
 block discarded – undo
1440 1440
                 ),
1441 1441
                 admin_url('admin.php')
1442 1442
             );
1443
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1443
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1444 1444
                 array(
1445 1445
                     'page'   => 'espresso_events',
1446 1446
                     'action' => 'edit',
@@ -1449,12 +1449,12 @@  discard block
 block discarded – undo
1449 1449
                 admin_url('admin.php')
1450 1450
             );
1451 1451
             //next and previous links
1452
-            $next_reg                                      = $this->_registration->next(
1452
+            $next_reg = $this->_registration->next(
1453 1453
                 null,
1454 1454
                 array(),
1455 1455
                 'REG_ID'
1456 1456
             );
1457
-            $this->_template_args['next_registration']     = $next_reg
1457
+            $this->_template_args['next_registration'] = $next_reg
1458 1458
                 ? $this->_next_link(
1459 1459
                     EE_Admin_Page::add_query_args_and_nonce(
1460 1460
                         array(
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
                     'dashicons dashicons-arrow-right ee-icon-size-22'
1467 1467
                 )
1468 1468
                 : '';
1469
-            $previous_reg                                  = $this->_registration->previous(
1469
+            $previous_reg = $this->_registration->previous(
1470 1470
                 null,
1471 1471
                 array(),
1472 1472
                 'REG_ID'
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
                 )
1485 1485
                 : '';
1486 1486
             // grab header
1487
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1487
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1488 1488
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1489 1489
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1490 1490
                 $template_path,
@@ -1599,7 +1599,7 @@  discard block
 block discarded – undo
1599 1599
                             EEH_HTML::strong(
1600 1600
                                 $this->_registration->pretty_status(),
1601 1601
                                 '',
1602
-                                'status-' . $this->_registration->status_ID(),
1602
+                                'status-'.$this->_registration->status_ID(),
1603 1603
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1604 1604
                             )
1605 1605
                         )
@@ -1669,9 +1669,9 @@  discard block
 block discarded – undo
1669 1669
     {
1670 1670
         if (isset($this->_req_data['reg_status_change_form'])) {
1671 1671
             $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1672
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1672
+                ? (array) $this->_req_data['reg_status_change_form']['REG_ID'] : array();
1673 1673
         } else {
1674
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1674
+            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array) $this->_req_data['_REG_ID'] : array();
1675 1675
         }
1676 1676
         $success = $this->_set_registration_status($REG_IDs, $status);
1677 1677
         //notify?
@@ -1703,7 +1703,7 @@  discard block
 block discarded – undo
1703 1703
     {
1704 1704
         $success = false;
1705 1705
         // typecast $REG_IDs
1706
-        $REG_IDs = (array)$REG_IDs;
1706
+        $REG_IDs = (array) $REG_IDs;
1707 1707
         if ( ! empty($REG_IDs)) {
1708 1708
             $success = true;
1709 1709
             // set default status if none is passed
@@ -1933,7 +1933,7 @@  discard block
 block discarded – undo
1933 1933
             $filtered_line_item_tree,
1934 1934
             array('EE_Registration' => $this->_registration)
1935 1935
         );
1936
-        $attendee                                = $this->_registration->attendee();
1936
+        $attendee = $this->_registration->attendee();
1937 1937
         if (EE_Registry::instance()->CAP->current_user_can(
1938 1938
             'ee_read_transaction',
1939 1939
             'espresso_transactions_view_transaction'
@@ -2012,7 +2012,7 @@  discard block
 block discarded – undo
2012 2012
                 'Payment method response',
2013 2013
                 'event_espresso'
2014 2014
             );
2015
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2015
+            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2016 2016
         }
2017 2017
         $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2018 2018
         $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
@@ -2040,7 +2040,7 @@  discard block
 block discarded – undo
2040 2040
         $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2041 2041
         $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2042 2042
         $template_path                                                        =
2043
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2043
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2044 2044
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2045 2045
     }
2046 2046
 
@@ -2069,7 +2069,7 @@  discard block
 block discarded – undo
2069 2069
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2070 2070
             $this->_template_args['REG_ID']                    = $this->_registration->ID();
2071 2071
             $template_path                                     =
2072
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2072
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2073 2073
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2074 2074
         }
2075 2075
     }
@@ -2086,7 +2086,7 @@  discard block
 block discarded – undo
2086 2086
     public function form_before_question_group($output)
2087 2087
     {
2088 2088
         EE_Error::doing_it_wrong(
2089
-            __CLASS__ . '::' . __FUNCTION__,
2089
+            __CLASS__.'::'.__FUNCTION__,
2090 2090
             esc_html__(
2091 2091
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2092 2092
                 'event_espresso'
@@ -2111,7 +2111,7 @@  discard block
 block discarded – undo
2111 2111
     public function form_after_question_group($output)
2112 2112
     {
2113 2113
         EE_Error::doing_it_wrong(
2114
-            __CLASS__ . '::' . __FUNCTION__,
2114
+            __CLASS__.'::'.__FUNCTION__,
2115 2115
             esc_html__(
2116 2116
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2117 2117
                 'event_espresso'
@@ -2149,7 +2149,7 @@  discard block
 block discarded – undo
2149 2149
     public function form_form_field_label_wrap($label)
2150 2150
     {
2151 2151
         EE_Error::doing_it_wrong(
2152
-            __CLASS__ . '::' . __FUNCTION__,
2152
+            __CLASS__.'::'.__FUNCTION__,
2153 2153
             esc_html__(
2154 2154
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2155 2155
                 'event_espresso'
@@ -2159,7 +2159,7 @@  discard block
 block discarded – undo
2159 2159
         return '
2160 2160
 			<tr>
2161 2161
 				<th>
2162
-					' . $label . '
2162
+					' . $label.'
2163 2163
 				</th>';
2164 2164
     }
2165 2165
 
@@ -2175,7 +2175,7 @@  discard block
 block discarded – undo
2175 2175
     public function form_form_field_input__wrap($input)
2176 2176
     {
2177 2177
         EE_Error::doing_it_wrong(
2178
-            __CLASS__ . '::' . __FUNCTION__,
2178
+            __CLASS__.'::'.__FUNCTION__,
2179 2179
             esc_html__(
2180 2180
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2181 2181
                 'event_espresso'
@@ -2184,7 +2184,7 @@  discard block
 block discarded – undo
2184 2184
         );
2185 2185
         return '
2186 2186
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2187
-					' . $input . '
2187
+					' . $input.'
2188 2188
 				</td>
2189 2189
 			</tr>';
2190 2190
     }
@@ -2226,7 +2226,7 @@  discard block
 block discarded – undo
2226 2226
     protected function _get_reg_custom_questions_form($REG_ID)
2227 2227
     {
2228 2228
         if ( ! $this->_reg_custom_questions_form) {
2229
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2229
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2230 2230
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2231 2231
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2232 2232
             );
@@ -2259,7 +2259,7 @@  discard block
 block discarded – undo
2259 2259
         if ($form->is_valid()) {
2260 2260
             foreach ($form->subforms() as $question_group_id => $question_group_form) {
2261 2261
                 foreach ($question_group_form->inputs() as $question_id => $input) {
2262
-                    $where_conditions    = array(
2262
+                    $where_conditions = array(
2263 2263
                         'QST_ID' => $question_id,
2264 2264
                         'REG_ID' => $REG_ID,
2265 2265
                     );
@@ -2297,7 +2297,7 @@  discard block
 block discarded – undo
2297 2297
         $REG = EEM_Registration::instance();
2298 2298
         //get all other registrations on this transaction, and cache
2299 2299
         //the attendees for them so we don't have to run another query using force_join
2300
-        $registrations                           = $REG->get_all(array(
2300
+        $registrations = $REG->get_all(array(
2301 2301
             array(
2302 2302
                 'TXN_ID' => $this->_registration->transaction_ID(),
2303 2303
                 'REG_ID' => array('!=', $this->_registration->ID()),
@@ -2321,7 +2321,7 @@  discard block
 block discarded – undo
2321 2321
             $att_nmbr = 1;
2322 2322
             foreach ($registrations as $registration) {
2323 2323
                 /* @var $registration EE_Registration */
2324
-                $attendee                                                    = $registration->attendee()
2324
+                $attendee = $registration->attendee()
2325 2325
                     ? $registration->attendee()
2326 2326
                     : EEM_Attendee::instance()
2327 2327
                                   ->create_default_object();
@@ -2334,19 +2334,19 @@  discard block
 block discarded – undo
2334 2334
                     ', ',
2335 2335
                     $attendee->full_address_as_array()
2336 2336
                 );
2337
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2337
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2338 2338
                     array(
2339 2339
                         'action' => 'edit_attendee',
2340 2340
                         'post'   => $attendee->ID(),
2341 2341
                     ),
2342 2342
                     REG_ADMIN_URL
2343 2343
                 );
2344
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2344
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2345 2345
                 $att_nmbr++;
2346 2346
             }
2347 2347
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2348 2348
         }
2349
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2349
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2350 2350
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2351 2351
     }
2352 2352
 
@@ -2386,20 +2386,20 @@  discard block
 block discarded – undo
2386 2386
         $this->_template_args['phone']             = $attendee->phone();
2387 2387
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2388 2388
         //edit link
2389
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2389
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
2390 2390
             'action' => 'edit_attendee',
2391 2391
             'post'   => $attendee->ID(),
2392 2392
         ), REG_ADMIN_URL);
2393 2393
         $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2394 2394
         //create link
2395
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2395
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2396 2396
             ? EE_Admin_Page::add_query_args_and_nonce(array(
2397 2397
                 'action'  => 'duplicate_attendee',
2398 2398
                 '_REG_ID' => $this->_registration->ID(),
2399 2399
             ), REG_ADMIN_URL) : '';
2400 2400
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2401 2401
         $this->_template_args['att_check']    = $att_check;
2402
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2402
+        $template_path                        = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2403 2403
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2404 2404
     }
2405 2405
 
@@ -2441,7 +2441,7 @@  discard block
 block discarded – undo
2441 2441
             /** @var EE_Registration $REG */
2442 2442
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2443 2443
             $payments = $REG->registration_payments();
2444
-            if (! empty($payments)) {
2444
+            if ( ! empty($payments)) {
2445 2445
                 $name = $REG->attendee() instanceof EE_Attendee
2446 2446
                     ? $REG->attendee()->full_name()
2447 2447
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2634,7 +2634,7 @@  discard block
 block discarded – undo
2634 2634
                 'action' => 'edit',
2635 2635
                 'post'   => $this->_reg_event->ID(),
2636 2636
             ), EVENTS_ADMIN_URL);
2637
-            $edit_event_lnk                     = '<a href="'
2637
+            $edit_event_lnk = '<a href="'
2638 2638
                                                   . $edit_event_url
2639 2639
                                                   . '" title="'
2640 2640
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2652,7 +2652,7 @@  discard block
 block discarded – undo
2652 2652
         }
2653 2653
         // grab header
2654 2654
         $template_path                              =
2655
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2655
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2656 2656
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2657 2657
             $this->_template_args, true);
2658 2658
         //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
@@ -2687,7 +2687,7 @@  discard block
 block discarded – undo
2687 2687
                 '</b>'
2688 2688
             );
2689 2689
             return '
2690
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2690
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2691 2691
 	<script >
2692 2692
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2693 2693
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2755,7 +2755,7 @@  discard block
 block discarded – undo
2755 2755
         //we come back to the process_registration_step route.
2756 2756
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2757 2757
         return EEH_Template::display_template(
2758
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2758
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2759 2759
             $template_args,
2760 2760
             true
2761 2761
         );
@@ -2774,7 +2774,7 @@  discard block
 block discarded – undo
2774 2774
         if (is_object($this->_reg_event)) {
2775 2775
             return true;
2776 2776
         }
2777
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2777
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2778 2778
         if ( ! $EVT_ID) {
2779 2779
             return false;
2780 2780
         }
@@ -2840,7 +2840,7 @@  discard block
 block discarded – undo
2840 2840
                 }
2841 2841
                 break;
2842 2842
             case 'questions' :
2843
-                if (! isset(
2843
+                if ( ! isset(
2844 2844
                     $this->_req_data['txn_reg_status_change'],
2845 2845
                     $this->_req_data['txn_reg_status_change']['send_notifications'])
2846 2846
                 ) {
@@ -2954,7 +2954,7 @@  discard block
 block discarded – undo
2954 2954
     public function get_attendees($per_page, $count = false, $trash = false)
2955 2955
     {
2956 2956
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2957
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2957
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
2958 2958
         $ATT_MDL                    = EEM_Attendee::instance();
2959 2959
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2960 2960
         switch ($this->_req_data['orderby']) {
@@ -2991,7 +2991,7 @@  discard block
 block discarded – undo
2991 2991
             : $per_page;
2992 2992
         $_where       = array();
2993 2993
         if ( ! empty($this->_req_data['s'])) {
2994
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2994
+            $sstr         = '%'.$this->_req_data['s'].'%';
2995 2995
             $_where['OR'] = array(
2996 2996
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2997 2997
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3067,9 +3067,9 @@  discard block
 block discarded – undo
3067 3067
      *                                                     the query parameters from the request
3068 3068
      * @return void ends the request with a redirect or download
3069 3069
      */
3070
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3070
+    public function _registrations_report_base($method_name_for_getting_query_params)
3071 3071
     {
3072
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3072
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3073 3073
             wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3074 3074
                 array(
3075 3075
                     'page'        => 'espresso_batch',
@@ -3078,7 +3078,7 @@  discard block
 block discarded – undo
3078 3078
                     'filters'     => urlencode(
3079 3079
                         serialize(
3080 3080
                             call_user_func(
3081
-                                array( $this, $method_name_for_getting_query_params ),
3081
+                                array($this, $method_name_for_getting_query_params),
3082 3082
                                 EEH_Array::is_set(
3083 3083
                                     $this->_req_data,
3084 3084
                                     'filters',
@@ -3098,8 +3098,8 @@  discard block
 block discarded – undo
3098 3098
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3099 3099
             );
3100 3100
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3101
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3102
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3101
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3102
+                require_once(EE_CLASSES.'EE_Export.class.php');
3103 3103
                 $EE_Export = EE_Export::instance($this->_req_data);
3104 3104
                 $EE_Export->export();
3105 3105
             }
@@ -3120,8 +3120,8 @@  discard block
 block discarded – undo
3120 3120
 
3121 3121
     public function _contact_list_export()
3122 3122
     {
3123
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3124
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3123
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3124
+            require_once(EE_CLASSES.'EE_Export.class.php');
3125 3125
             $EE_Export = EE_Export::instance($this->_req_data);
3126 3126
             $EE_Export->export_attendees();
3127 3127
         }
@@ -3138,8 +3138,8 @@  discard block
 block discarded – undo
3138 3138
                 'return_url'  => urlencode($this->_req_data['return_url']),
3139 3139
             )));
3140 3140
         } else {
3141
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3142
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3141
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3142
+                require_once(EE_CLASSES.'EE_Export.class.php');
3143 3143
                 $EE_Export = EE_Export::instance($this->_req_data);
3144 3144
                 $EE_Export->report_attendees();
3145 3145
             }
@@ -3205,7 +3205,7 @@  discard block
 block discarded – undo
3205 3205
             $updated_fields = array(
3206 3206
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3207 3207
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3208
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3208
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3209 3209
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3210 3210
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3211 3211
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3338,7 +3338,7 @@  discard block
 block discarded – undo
3338 3338
     {
3339 3339
         //get attendee object ( should already have it )
3340 3340
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
3341
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3341
+        $template                         = REG_TEMPLATE_PATH.'attendee_contact_info_metabox_content.template.php';
3342 3342
         EEH_Template::display_template($template, $this->_template_args);
3343 3343
     }
3344 3344
 
@@ -3400,8 +3400,8 @@  discard block
 block discarded – undo
3400 3400
                 )
3401 3401
             )
3402 3402
         );
3403
-        $template                             =
3404
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3403
+        $template =
3404
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3405 3405
         EEH_Template::display_template($template, $this->_template_args);
3406 3406
     }
3407 3407
 
@@ -3420,7 +3420,7 @@  discard block
 block discarded – undo
3420 3420
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
3421 3421
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3422 3422
         $template                              =
3423
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3423
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3424 3424
         EEH_Template::display_template($template, $this->_template_args);
3425 3425
     }
3426 3426
 
@@ -3435,7 +3435,7 @@  discard block
 block discarded – undo
3435 3435
     public function after_title_form_fields($post)
3436 3436
     {
3437 3437
         if ($post->post_type == 'espresso_attendees') {
3438
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3438
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3439 3439
             $template_args['attendee'] = $this->_cpt_model_obj;
3440 3440
             EEH_Template::display_template($template, $template_args);
3441 3441
         }
Please login to merge, or discard this patch.
Indentation   +3425 added lines, -3425 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
 
@@ -23,2111 +23,2111 @@  discard block
 block discarded – undo
23 23
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registration
28
-     */
29
-    private $_registration;
30
-
31
-    /**
32
-     * @var EE_Event
33
-     */
34
-    private $_reg_event;
35
-
36
-    /**
37
-     * @var EE_Session
38
-     */
39
-    private $_session;
40
-
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form = null;
50
-
51
-
52
-    /**
53
-     *        constructor
54
-     *
55
-     * @Constructor
56
-     * @access public
57
-     * @param bool $routing
58
-     * @return Registrations_Admin_Page
59
-     */
60
-    public function __construct($routing = true)
61
-    {
62
-        parent::__construct($routing);
63
-        add_action('wp_loaded', array($this, 'wp_loaded'));
64
-    }
65
-
66
-
67
-    public function wp_loaded()
68
-    {
69
-        // when adding a new registration...
70
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
-            EE_System::do_not_cache();
72
-            if (! isset($this->_req_data['processing_registration'])
73
-                 || absint($this->_req_data['processing_registration']) !== 1
74
-            ) {
75
-                // and it's NOT the attendee information reg step
76
-                // force cookie expiration by setting time to last week
77
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
-                // and update the global
79
-                $_COOKIE['ee_registration_added'] = 0;
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-    protected function _init_page_props()
86
-    {
87
-        $this->page_slug        = REG_PG_SLUG;
88
-        $this->_admin_base_url  = REG_ADMIN_URL;
89
-        $this->_admin_base_path = REG_ADMIN;
90
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
91
-        $this->_cpt_routes      = array(
92
-            'add_new_attendee' => 'espresso_attendees',
93
-            'edit_attendee'    => 'espresso_attendees',
94
-            'insert_attendee'  => 'espresso_attendees',
95
-            'update_attendee'  => 'espresso_attendees',
96
-        );
97
-        $this->_cpt_model_names = array(
98
-            'add_new_attendee' => 'EEM_Attendee',
99
-            'edit_attendee'    => 'EEM_Attendee',
100
-        );
101
-        $this->_cpt_edit_routes = array(
102
-            'espresso_attendees' => 'edit_attendee',
103
-        );
104
-        $this->_pagenow_map     = array(
105
-            'add_new_attendee' => 'post-new.php',
106
-            'edit_attendee'    => 'post.php',
107
-            'trash'            => 'post.php',
108
-        );
109
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
-        //add filters so that the comment urls don't take users to a confusing 404 page
111
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
-    }
113
-
114
-
115
-    public function clear_comment_link($link, $comment, $args)
116
-    {
117
-        //gotta make sure this only happens on this route
118
-        $post_type = get_post_type($comment->comment_post_ID);
119
-        if ($post_type === 'espresso_attendees') {
120
-            return '#commentsdiv';
121
-        }
122
-        return $link;
123
-    }
124
-
125
-
126
-    protected function _ajax_hooks()
127
-    {
128
-        //todo: all hooks for registrations ajax goes in here
129
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
-    }
131
-
132
-
133
-    protected function _define_page_props()
134
-    {
135
-        $this->_admin_page_title = $this->page_label;
136
-        $this->_labels           = array(
137
-            'buttons'                      => array(
138
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
-            ),
147
-            'publishbox'                   => array(
148
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
-            ),
151
-            'hide_add_button_on_cpt_route' => array(
152
-                'edit_attendee' => true,
153
-            ),
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     *        grab url requests and route them
160
-     *
161
-     * @access private
162
-     * @return void
163
-     */
164
-    public function _set_page_routes()
165
-    {
166
-        $this->_get_registration_status_array();
167
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
-            ? $this->_req_data['_REG_ID'] : 0;
169
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
-            ? $this->_req_data['ATT_ID'] : 0;
171
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
172
-            ? $this->_req_data['post']
173
-            : $att_id;
174
-        $this->_page_routes = array(
175
-            'default'                            => array(
176
-                'func'       => '_registrations_overview_list_table',
177
-                'capability' => 'ee_read_registrations',
178
-            ),
179
-            'view_registration'                  => array(
180
-                'func'       => '_registration_details',
181
-                'capability' => 'ee_read_registration',
182
-                'obj_id'     => $reg_id,
183
-            ),
184
-            'edit_registration'                  => array(
185
-                'func'               => '_update_attendee_registration_form',
186
-                'noheader'           => true,
187
-                'headers_sent_route' => 'view_registration',
188
-                'capability'         => 'ee_edit_registration',
189
-                'obj_id'             => $reg_id,
190
-                '_REG_ID'            => $reg_id,
191
-            ),
192
-            'trash_registrations'                => array(
193
-                'func'       => '_trash_or_restore_registrations',
194
-                'args'       => array('trash' => true),
195
-                'noheader'   => true,
196
-                'capability' => 'ee_delete_registrations',
197
-            ),
198
-            'restore_registrations'              => array(
199
-                'func'       => '_trash_or_restore_registrations',
200
-                'args'       => array('trash' => false),
201
-                'noheader'   => true,
202
-                'capability' => 'ee_delete_registrations',
203
-            ),
204
-            'delete_registrations'               => array(
205
-                'func'       => '_delete_registrations',
206
-                'noheader'   => true,
207
-                'capability' => 'ee_delete_registrations',
208
-            ),
209
-            'new_registration'                   => array(
210
-                'func'       => 'new_registration',
211
-                'capability' => 'ee_edit_registrations',
212
-            ),
213
-            'process_reg_step'                   => array(
214
-                'func'       => 'process_reg_step',
215
-                'noheader'   => true,
216
-                'capability' => 'ee_edit_registrations',
217
-            ),
218
-            'redirect_to_txn'                    => array(
219
-                'func'       => 'redirect_to_txn',
220
-                'noheader'   => true,
221
-                'capability' => 'ee_edit_registrations',
222
-            ),
223
-            'change_reg_status'                  => array(
224
-                'func'       => '_change_reg_status',
225
-                'noheader'   => true,
226
-                'capability' => 'ee_edit_registration',
227
-                'obj_id'     => $reg_id,
228
-            ),
229
-            'approve_registration'               => array(
230
-                'func'       => 'approve_registration',
231
-                'noheader'   => true,
232
-                'capability' => 'ee_edit_registration',
233
-                'obj_id'     => $reg_id,
234
-            ),
235
-            'approve_and_notify_registration'    => array(
236
-                'func'       => 'approve_registration',
237
-                'noheader'   => true,
238
-                'args'       => array(true),
239
-                'capability' => 'ee_edit_registration',
240
-                'obj_id'     => $reg_id,
241
-            ),
242
-            'decline_registration'               => array(
243
-                'func'       => 'decline_registration',
244
-                'noheader'   => true,
245
-                'capability' => 'ee_edit_registration',
246
-                'obj_id'     => $reg_id,
247
-            ),
248
-            'decline_and_notify_registration'    => array(
249
-                'func'       => 'decline_registration',
250
-                'noheader'   => true,
251
-                'args'       => array(true),
252
-                'capability' => 'ee_edit_registration',
253
-                'obj_id'     => $reg_id,
254
-            ),
255
-            'pending_registration'               => array(
256
-                'func'       => 'pending_registration',
257
-                'noheader'   => true,
258
-                'capability' => 'ee_edit_registration',
259
-                'obj_id'     => $reg_id,
260
-            ),
261
-            'pending_and_notify_registration'    => array(
262
-                'func'       => 'pending_registration',
263
-                'noheader'   => true,
264
-                'args'       => array(true),
265
-                'capability' => 'ee_edit_registration',
266
-                'obj_id'     => $reg_id,
267
-            ),
268
-            'no_approve_registration'            => array(
269
-                'func'       => 'not_approve_registration',
270
-                'noheader'   => true,
271
-                'capability' => 'ee_edit_registration',
272
-                'obj_id'     => $reg_id,
273
-            ),
274
-            'no_approve_and_notify_registration' => array(
275
-                'func'       => 'not_approve_registration',
276
-                'noheader'   => true,
277
-                'args'       => array(true),
278
-                'capability' => 'ee_edit_registration',
279
-                'obj_id'     => $reg_id,
280
-            ),
281
-            'cancel_registration'                => array(
282
-                'func'       => 'cancel_registration',
283
-                'noheader'   => true,
284
-                'capability' => 'ee_edit_registration',
285
-                'obj_id'     => $reg_id,
286
-            ),
287
-            'cancel_and_notify_registration'     => array(
288
-                'func'       => 'cancel_registration',
289
-                'noheader'   => true,
290
-                'args'       => array(true),
291
-                'capability' => 'ee_edit_registration',
292
-                'obj_id'     => $reg_id,
293
-            ),
294
-            'contact_list'                       => array(
295
-                'func'       => '_attendee_contact_list_table',
296
-                'capability' => 'ee_read_contacts',
297
-            ),
298
-            'add_new_attendee'                   => array(
299
-                'func' => '_create_new_cpt_item',
300
-                'args' => array(
301
-                    'new_attendee' => true,
302
-                    'capability'   => 'ee_edit_contacts',
303
-                ),
304
-            ),
305
-            'edit_attendee'                      => array(
306
-                'func'       => '_edit_cpt_item',
307
-                'capability' => 'ee_edit_contacts',
308
-                'obj_id'     => $att_id,
309
-            ),
310
-            'duplicate_attendee'                 => array(
311
-                'func'       => '_duplicate_attendee',
312
-                'noheader'   => true,
313
-                'capability' => 'ee_edit_contacts',
314
-                'obj_id'     => $att_id,
315
-            ),
316
-            'insert_attendee'                    => array(
317
-                'func'       => '_insert_or_update_attendee',
318
-                'args'       => array(
319
-                    'new_attendee' => true,
320
-                ),
321
-                'noheader'   => true,
322
-                'capability' => 'ee_edit_contacts',
323
-            ),
324
-            'update_attendee'                    => array(
325
-                'func'       => '_insert_or_update_attendee',
326
-                'args'       => array(
327
-                    'new_attendee' => false,
328
-                ),
329
-                'noheader'   => true,
330
-                'capability' => 'ee_edit_contacts',
331
-                'obj_id'     => $att_id,
332
-            ),
333
-            'trash_attendee'                    => array(
334
-                'func'       => '_trash_or_restore_attendees',
335
-                'args'       => array(
336
-                    'trash' => true,
337
-                ),
338
-                'noheader'   => true,
339
-                'capability' => 'ee_delete_contacts',
340
-                'obj_id'     => $att_id,
341
-            ),
342
-            'restore_attendees'                  => array(
343
-                'func'       => '_trash_or_restore_attendees',
344
-                'args'       => array(
345
-                    'trash' => false,
346
-                ),
347
-                'noheader'   => true,
348
-                'capability' => 'ee_delete_contacts',
349
-                'obj_id'     => $att_id,
350
-            ),
351
-            'resend_registration'                => array(
352
-                'func'       => '_resend_registration',
353
-                'noheader'   => true,
354
-                'capability' => 'ee_send_message',
355
-            ),
356
-            'registrations_report'               => array(
357
-                'func'       => '_registrations_report',
358
-                'noheader'   => true,
359
-                'capability' => 'ee_read_registrations',
360
-            ),
361
-            'contact_list_export'                => array(
362
-                'func'       => '_contact_list_export',
363
-                'noheader'   => true,
364
-                'capability' => 'export',
365
-            ),
366
-            'contact_list_report'                => array(
367
-                'func'       => '_contact_list_report',
368
-                'noheader'   => true,
369
-                'capability' => 'ee_read_contacts',
370
-            ),
371
-        );
372
-    }
373
-
374
-
375
-    protected function _set_page_config()
376
-    {
377
-        $this->_page_config = array(
378
-            'default'           => array(
379
-                'nav'           => array(
380
-                    'label' => esc_html__('Overview', 'event_espresso'),
381
-                    'order' => 5,
382
-                ),
383
-                'help_tabs'     => array(
384
-                    'registrations_overview_help_tab'                       => array(
385
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
386
-                        'filename' => 'registrations_overview',
387
-                    ),
388
-                    'registrations_overview_table_column_headings_help_tab' => array(
389
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
390
-                        'filename' => 'registrations_overview_table_column_headings',
391
-                    ),
392
-                    'registrations_overview_filters_help_tab'               => array(
393
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
394
-                        'filename' => 'registrations_overview_filters',
395
-                    ),
396
-                    'registrations_overview_views_help_tab'                 => array(
397
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
398
-                        'filename' => 'registrations_overview_views',
399
-                    ),
400
-                    'registrations_regoverview_other_help_tab'              => array(
401
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
402
-                        'filename' => 'registrations_overview_other',
403
-                    ),
404
-                ),
405
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
406
-                'qtips'         => array('Registration_List_Table_Tips'),
407
-                'list_table'    => 'EE_Registrations_List_Table',
408
-                'require_nonce' => false,
409
-            ),
410
-            'view_registration' => array(
411
-                'nav'           => array(
412
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
413
-                    'order'      => 15,
414
-                    'url'        => isset($this->_req_data['_REG_ID'])
415
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
416
-                        : $this->_admin_base_url,
417
-                    'persistent' => false,
418
-                ),
419
-                'help_tabs'     => array(
420
-                    'registrations_details_help_tab'                    => array(
421
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
422
-                        'filename' => 'registrations_details',
423
-                    ),
424
-                    'registrations_details_table_help_tab'              => array(
425
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
426
-                        'filename' => 'registrations_details_table',
427
-                    ),
428
-                    'registrations_details_form_answers_help_tab'       => array(
429
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
430
-                        'filename' => 'registrations_details_form_answers',
431
-                    ),
432
-                    'registrations_details_registrant_details_help_tab' => array(
433
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
434
-                        'filename' => 'registrations_details_registrant_details',
435
-                    ),
436
-                ),
437
-                'help_tour'     => array('Registration_Details_Help_Tour'),
438
-                'metaboxes'     => array_merge(
439
-                    $this->_default_espresso_metaboxes,
440
-                    array('_registration_details_metaboxes')
441
-                ),
442
-                'require_nonce' => false,
443
-            ),
444
-            'new_registration'  => array(
445
-                'nav'           => array(
446
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
447
-                    'url'        => '#',
448
-                    'order'      => 15,
449
-                    'persistent' => false,
450
-                ),
451
-                'metaboxes'     => $this->_default_espresso_metaboxes,
452
-                'labels'        => array(
453
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
454
-                ),
455
-                'require_nonce' => false,
456
-            ),
457
-            'add_new_attendee'  => array(
458
-                'nav'           => array(
459
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
460
-                    'order'      => 15,
461
-                    'persistent' => false,
462
-                ),
463
-                'metaboxes'     => array_merge(
464
-                    $this->_default_espresso_metaboxes,
465
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
466
-                ),
467
-                'require_nonce' => false,
468
-            ),
469
-            'edit_attendee'     => array(
470
-                'nav'           => array(
471
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
472
-                    'order'      => 15,
473
-                    'persistent' => false,
474
-                    'url'        => isset($this->_req_data['ATT_ID'])
475
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
476
-                        : $this->_admin_base_url,
477
-                ),
478
-                'metaboxes'     => array('attendee_editor_metaboxes'),
479
-                'require_nonce' => false,
480
-            ),
481
-            'contact_list'      => array(
482
-                'nav'           => array(
483
-                    'label' => esc_html__('Contact List', 'event_espresso'),
484
-                    'order' => 20,
485
-                ),
486
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
487
-                'help_tabs'     => array(
488
-                    'registrations_contact_list_help_tab'                       => array(
489
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
490
-                        'filename' => 'registrations_contact_list',
491
-                    ),
492
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
493
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
494
-                        'filename' => 'registrations_contact_list_table_column_headings',
495
-                    ),
496
-                    'registrations_contact_list_views_help_tab'                 => array(
497
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
498
-                        'filename' => 'registrations_contact_list_views',
499
-                    ),
500
-                    'registrations_contact_list_other_help_tab'                 => array(
501
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
502
-                        'filename' => 'registrations_contact_list_other',
503
-                    ),
504
-                ),
505
-                'help_tour'     => array('Contact_List_Help_Tour'),
506
-                'metaboxes'     => array(),
507
-                'require_nonce' => false,
508
-            ),
509
-            //override default cpt routes
510
-            'create_new'        => '',
511
-            'edit'              => '',
512
-        );
513
-    }
514
-
515
-
516
-    /**
517
-     * The below methods aren't used by this class currently
518
-     */
519
-    protected function _add_screen_options()
520
-    {
521
-    }
522
-
523
-
524
-    protected function _add_feature_pointers()
525
-    {
526
-    }
527
-
528
-
529
-    public function admin_init()
530
-    {
531
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
532
-            'click "Update Registration Questions" to save your changes',
533
-            'event_espresso'
534
-        );
535
-    }
536
-
537
-
538
-    public function admin_notices()
539
-    {
540
-    }
541
-
542
-
543
-    public function admin_footer_scripts()
544
-    {
545
-    }
546
-
547
-
548
-    /**
549
-     *        get list of registration statuses
550
-     *
551
-     * @access private
552
-     * @return void
553
-     */
554
-    private function _get_registration_status_array()
555
-    {
556
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
557
-    }
558
-
559
-
560
-    protected function _add_screen_options_default()
561
-    {
562
-        $this->_per_page_screen_option();
563
-    }
564
-
565
-
566
-    protected function _add_screen_options_contact_list()
567
-    {
568
-        $page_title              = $this->_admin_page_title;
569
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
570
-        $this->_per_page_screen_option();
571
-        $this->_admin_page_title = $page_title;
572
-    }
573
-
574
-
575
-    public function load_scripts_styles()
576
-    {
577
-        //style
578
-        wp_register_style(
579
-            'espresso_reg',
580
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
581
-            array('ee-admin-css'),
582
-            EVENT_ESPRESSO_VERSION
583
-        );
584
-        wp_enqueue_style('espresso_reg');
585
-        //script
586
-        wp_register_script(
587
-            'espresso_reg',
588
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
589
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
590
-            EVENT_ESPRESSO_VERSION,
591
-            true
592
-        );
593
-        wp_enqueue_script('espresso_reg');
594
-    }
595
-
596
-
597
-    public function load_scripts_styles_edit_attendee()
598
-    {
599
-        //stuff to only show up on our attendee edit details page.
600
-        $attendee_details_translations = array(
601
-            'att_publish_text' => sprintf(
602
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
603
-                $this->_cpt_model_obj->get_datetime('ATT_created')
604
-            ),
605
-        );
606
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
607
-        wp_enqueue_script('jquery-validate');
608
-    }
609
-
610
-
611
-    public function load_scripts_styles_view_registration()
612
-    {
613
-        //styles
614
-        wp_enqueue_style('espresso-ui-theme');
615
-        //scripts
616
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
617
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
618
-    }
619
-
620
-
621
-    public function load_scripts_styles_contact_list()
622
-    {
623
-        wp_deregister_style('espresso_reg');
624
-        wp_register_style(
625
-            'espresso_att',
626
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
627
-            array('ee-admin-css'),
628
-            EVENT_ESPRESSO_VERSION
629
-        );
630
-        wp_enqueue_style('espresso_att');
631
-    }
632
-
633
-
634
-    public function load_scripts_styles_new_registration()
635
-    {
636
-        wp_register_script(
637
-            'ee-spco-for-admin',
638
-            REG_ASSETS_URL . 'spco_for_admin.js',
639
-            array('underscore', 'jquery'),
640
-            EVENT_ESPRESSO_VERSION,
641
-            true
642
-        );
643
-        wp_enqueue_script('ee-spco-for-admin');
644
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
645
-        EE_Form_Section_Proper::wp_enqueue_scripts();
646
-        EED_Ticket_Selector::load_tckt_slctr_assets();
647
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
648
-    }
649
-
650
-
651
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
652
-    {
653
-        add_filter('FHEE_load_EE_messages', '__return_true');
654
-    }
655
-
656
-
657
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
658
-    {
659
-        add_filter('FHEE_load_EE_messages', '__return_true');
660
-    }
661
-
662
-
663
-    protected function _set_list_table_views_default()
664
-    {
665
-        //for notification related bulk actions we need to make sure only active messengers have an option.
666
-        EED_Messages::set_autoloaders();
667
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
668
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
669
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
670
-        //key= bulk_action_slug, value= message type.
671
-        $match_array = array(
672
-            'approve_registration'    => 'registration',
673
-            'decline_registration'    => 'declined_registration',
674
-            'pending_registration'    => 'pending_approval',
675
-            'no_approve_registration' => 'not_approved_registration',
676
-            'cancel_registration'     => 'cancelled_registration',
677
-        );
678
-        /** setup reg status bulk actions **/
679
-        $def_reg_status_actions['approve_registration'] = esc_html__('Approve Registrations', 'event_espresso');
680
-        if (in_array($match_array['approve_registration'], $active_mts)
681
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
682
-        ) {
683
-            $def_reg_status_actions['approve_and_notify_registration'] = esc_html__(
684
-                'Approve and Notify Registrations',
685
-                'event_espresso'
686
-            );
687
-        }
688
-        $def_reg_status_actions['decline_registration'] = esc_html__('Decline Registrations', 'event_espresso');
689
-        if (in_array($match_array['decline_registration'], $active_mts)
690
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
691
-        ) {
692
-            $def_reg_status_actions['decline_and_notify_registration'] = esc_html__(
693
-                'Decline and Notify Registrations',
694
-                'event_espresso'
695
-            );
696
-        }
697
-        $def_reg_status_actions['pending_registration'] = esc_html__(
698
-            'Set Registrations to Pending Payment',
699
-            'event_espresso'
700
-        );
701
-        if (in_array($match_array['pending_registration'], $active_mts)
702
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
703
-        ) {
704
-            $def_reg_status_actions['pending_and_notify_registration'] = esc_html__(
705
-                'Set Registrations to Pending Payment and Notify',
706
-                'event_espresso'
707
-            );
708
-        }
709
-        $def_reg_status_actions['no_approve_registration'] = esc_html__(
710
-            'Set Registrations to Not Approved',
711
-            'event_espresso'
712
-        );
713
-        if (in_array($match_array['no_approve_registration'], $active_mts)
714
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
715
-        ) {
716
-            $def_reg_status_actions['no_approve_and_notify_registration'] = esc_html__(
717
-                'Set Registrations to Not Approved and Notify',
718
-                'event_espresso'
719
-            );
720
-        }
721
-        $def_reg_status_actions['cancel_registration'] = esc_html__('Cancel Registrations', 'event_espresso');
722
-        if (in_array($match_array['cancel_registration'], $active_mts)
723
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
724
-        ) {
725
-            $def_reg_status_actions['cancel_and_notify_registration'] = esc_html__(
726
-                'Cancel Registrations and Notify',
727
-                'event_espresso'
728
-            );
729
-        }
730
-        $this->_views = array(
731
-            'all'   => array(
732
-                'slug'        => 'all',
733
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
734
-                'count'       => 0,
735
-                'bulk_action' => array_merge($def_reg_status_actions, array(
736
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
737
-                )),
738
-            ),
739
-            'month' => array(
740
-                'slug'        => 'month',
741
-                'label'       => esc_html__('This Month', 'event_espresso'),
742
-                'count'       => 0,
743
-                'bulk_action' => array_merge($def_reg_status_actions, array(
744
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
745
-                )),
746
-            ),
747
-            'today' => array(
748
-                'slug'        => 'today',
749
-                'label'       => sprintf(
750
-                    esc_html__('Today - %s', 'event_espresso'),
751
-                    date('M d, Y', current_time('timestamp'))
752
-                ),
753
-                'count'       => 0,
754
-                'bulk_action' => array_merge($def_reg_status_actions, array(
755
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
756
-                )),
757
-            ),
758
-        );
759
-        if (EE_Registry::instance()->CAP->current_user_can(
760
-            'ee_delete_registrations',
761
-            'espresso_registrations_delete_registration'
762
-        )) {
763
-            $this->_views['incomplete'] = array(
764
-                'slug'        => 'incomplete',
765
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
766
-                'count'       => 0,
767
-                'bulk_action' => array(
768
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
769
-                ),
770
-            );
771
-            $this->_views['trash']      = array(
772
-                'slug'        => 'trash',
773
-                'label'       => esc_html__('Trash', 'event_espresso'),
774
-                'count'       => 0,
775
-                'bulk_action' => array(
776
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
777
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
778
-                ),
779
-            );
780
-        }
781
-    }
782
-
783
-
784
-    protected function _set_list_table_views_contact_list()
785
-    {
786
-        $this->_views = array(
787
-            'in_use' => array(
788
-                'slug'        => 'in_use',
789
-                'label'       => esc_html__('In Use', 'event_espresso'),
790
-                'count'       => 0,
791
-                'bulk_action' => array(
792
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
793
-                ),
794
-            ),
795
-        );
796
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
797
-            'espresso_registrations_trash_attendees')
798
-        ) {
799
-            $this->_views['trash'] = array(
800
-                'slug'        => 'trash',
801
-                'label'       => esc_html__('Trash', 'event_espresso'),
802
-                'count'       => 0,
803
-                'bulk_action' => array(
804
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
805
-                ),
806
-            );
807
-        }
808
-    }
809
-
810
-
811
-    protected function _registration_legend_items()
812
-    {
813
-        $fc_items = array(
814
-            'star-icon'        => array(
815
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
816
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
817
-            ),
818
-            'view_details'     => array(
819
-                'class' => 'dashicons dashicons-clipboard',
820
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
821
-            ),
822
-            'edit_attendee'    => array(
823
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
824
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
825
-            ),
826
-            'view_transaction' => array(
827
-                'class' => 'dashicons dashicons-cart',
828
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
829
-            ),
830
-            'view_invoice'     => array(
831
-                'class' => 'dashicons dashicons-media-spreadsheet',
832
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
833
-            ),
834
-        );
835
-        if (EE_Registry::instance()->CAP->current_user_can(
836
-            'ee_send_message',
837
-            'espresso_registrations_resend_registration'
838
-        )) {
839
-            $fc_items['resend_registration'] = array(
840
-                'class' => 'dashicons dashicons-email-alt',
841
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
842
-            );
843
-        } else {
844
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
845
-        }
846
-        if (EE_Registry::instance()->CAP->current_user_can(
847
-            'ee_read_global_messages',
848
-            'view_filtered_messages'
849
-        )) {
850
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
851
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
852
-                $fc_items['view_related_messages'] = array(
853
-                    'class' => $related_for_icon['css_class'],
854
-                    'desc'  => $related_for_icon['label'],
855
-                );
856
-            }
857
-        }
858
-        $sc_items = array(
859
-            'approved_status'   => array(
860
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
861
-                'desc'  => EEH_Template::pretty_status(
862
-                    EEM_Registration::status_id_approved,
863
-                    false,
864
-                    'sentence'
865
-                ),
866
-            ),
867
-            'pending_status'    => array(
868
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
869
-                'desc'  => EEH_Template::pretty_status(
870
-                    EEM_Registration::status_id_pending_payment,
871
-                    false,
872
-                    'sentence'
873
-                ),
874
-            ),
875
-            'wait_list'         => array(
876
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
877
-                'desc'  => EEH_Template::pretty_status(
878
-                    EEM_Registration::status_id_wait_list,
879
-                    false,
880
-                    'sentence'
881
-                ),
882
-            ),
883
-            'incomplete_status' => array(
884
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
885
-                'desc'  => EEH_Template::pretty_status(
886
-                    EEM_Registration::status_id_incomplete,
887
-                    false,
888
-                    'sentence'
889
-                ),
890
-            ),
891
-            'not_approved'      => array(
892
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
893
-                'desc'  => EEH_Template::pretty_status(
894
-                    EEM_Registration::status_id_not_approved,
895
-                    false,
896
-                    'sentence'
897
-                ),
898
-            ),
899
-            'declined_status'   => array(
900
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
901
-                'desc'  => EEH_Template::pretty_status(
902
-                    EEM_Registration::status_id_declined,
903
-                    false,
904
-                    'sentence'
905
-                ),
906
-            ),
907
-            'cancelled_status'  => array(
908
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
909
-                'desc'  => EEH_Template::pretty_status(
910
-                    EEM_Registration::status_id_cancelled,
911
-                    false,
912
-                    'sentence'
913
-                ),
914
-            ),
915
-        );
916
-        return array_merge($fc_items, $sc_items);
917
-    }
918
-
919
-
920
-
921
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
922
-    /**
923
-     * @throws \EE_Error
924
-     */
925
-    protected function _registrations_overview_list_table()
926
-    {
927
-        $this->_template_args['admin_page_header'] = '';
928
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
929
-            ? absint($this->_req_data['event_id'])
930
-            : 0;
931
-        if ($EVT_ID) {
932
-            if (EE_Registry::instance()->CAP->current_user_can(
933
-                'ee_edit_registrations',
934
-                'espresso_registrations_new_registration',
935
-                $EVT_ID
936
-            )) {
937
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
938
-                    'new_registration',
939
-                    'add-registrant',
940
-                    array('event_id' => $EVT_ID),
941
-                    'add-new-h2'
942
-                );
943
-            }
944
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
945
-            if ($event instanceof EE_Event) {
946
-                $this->_template_args['admin_page_header'] = sprintf(
947
-                    esc_html__(
948
-                        '%s Viewing registrations for the event: %s%s',
949
-                        'event_espresso'
950
-                    ),
951
-                    '<h3 style="line-height:1.5em;">',
952
-                    '<br /><a href="'
953
-                        . EE_Admin_Page::add_query_args_and_nonce(
954
-                            array(
955
-                                'action' => 'edit',
956
-                                'post'   => $event->ID(),
957
-                            ),
958
-                            EVENTS_ADMIN_URL
959
-                        )
960
-                        . '">&nbsp;'
961
-                        . $event->get('EVT_name')
962
-                        . '&nbsp;</a>&nbsp;',
963
-                    '</h3>'
964
-                );
965
-            }
966
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
967
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
968
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
969
-                $this->_template_args['admin_page_header'] = substr(
970
-                    $this->_template_args['admin_page_header'],
971
-                    0,
972
-                    -5
973
-                );
974
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
975
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
976
-                $this->_template_args['admin_page_header'] .= $datetime->name();
977
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
978
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
979
-            }
980
-        }
981
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
982
-        $this->display_admin_list_table_page_with_no_sidebar();
983
-    }
984
-
985
-
986
-    /**
987
-     * This sets the _registration property for the registration details screen
988
-     *
989
-     * @access private
990
-     * @return bool
991
-     */
992
-    private function _set_registration_object()
993
-    {
994
-        //get out if we've already set the object
995
-        if (is_object($this->_registration)) {
996
-            return true;
997
-        }
998
-        $REG    = EEM_Registration::instance();
999
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1000
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1001
-            return true;
1002
-        } else {
1003
-            $error_msg = sprintf(
1004
-                esc_html__(
1005
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1006
-                    'event_espresso'
1007
-                ),
1008
-                $REG_ID
1009
-            );
1010
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1011
-            $this->_registration = null;
1012
-            return false;
1013
-        }
1014
-    }
1015
-
1016
-
1017
-    /**
1018
-     * Used to retrieve registrations for the list table.
1019
-     *
1020
-     * @param int  $per_page
1021
-     * @param bool $count
1022
-     * @param bool $this_month
1023
-     * @param bool $today
1024
-     * @return EE_Registration[]|int
1025
-     * @throws EE_Error
1026
-     */
1027
-    public function get_registrations(
1028
-        $per_page = 10,
1029
-        $count = false,
1030
-        $this_month = false,
1031
-        $today = false
1032
-    ) {
1033
-        if ($this_month) {
1034
-            $this->_req_data['status'] = 'month';
1035
-        }
1036
-        if ($today) {
1037
-            $this->_req_data['status'] = 'today';
1038
-        }
1039
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1040
-        /**
1041
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1042
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1043
-         * @see EEM_Base::get_all()
1044
-         */
1045
-        $query_params['group_by'] = '';
1046
-
1047
-        return $count
1048
-            ? EEM_Registration::instance()->count($query_params)
1049
-            /** @type EE_Registration[] */
1050
-            : EEM_Registration::instance()->get_all($query_params);
1051
-    }
1052
-
1053
-
1054
-
1055
-    /**
1056
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1057
-     * Note: this listens to values on the request for some of the query parameters.
1058
-     *
1059
-     * @param array $request
1060
-     * @param int    $per_page
1061
-     * @param bool   $count
1062
-     * @return array
1063
-     */
1064
-    protected function _get_registration_query_parameters(
1065
-        $request = array(),
1066
-        $per_page = 10,
1067
-        $count = false
1068
-    ) {
1069
-
1070
-        $query_params = array(
1071
-            0                          => $this->_get_where_conditions_for_registrations_query(
1072
-                $request
1073
-            ),
1074
-            'caps'                     => EEM_Registration::caps_read_admin,
1075
-            'default_where_conditions' => 'this_model_only',
1076
-        );
1077
-        if (! $count) {
1078
-            $query_params = array_merge(
1079
-                $query_params,
1080
-                $this->_get_orderby_for_registrations_query(),
1081
-                $this->_get_limit($per_page)
1082
-            );
1083
-        }
1084
-
1085
-        return $query_params;
1086
-    }
1087
-
1088
-
1089
-    /**
1090
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1091
-     *
1092
-     * @param array $request usually the same as $this->_req_data but not necessarily
1093
-     * @return array
1094
-     */
1095
-    protected function _add_event_id_to_where_conditions(array $request)
1096
-    {
1097
-        $where = array();
1098
-        if (! empty($request['event_id'])) {
1099
-            $where['EVT_ID'] = absint($request['event_id']);
1100
-        }
1101
-        return $where;
1102
-    }
1103
-
1104
-
1105
-    /**
1106
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1107
-     *
1108
-     * @param array $request usually the same as $this->_req_data but not necessarily
1109
-     * @return array
1110
-     */
1111
-    protected function _add_category_id_to_where_conditions(array $request)
1112
-    {
1113
-        $where = array();
1114
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1115
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1116
-        }
1117
-        return $where;
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1123
-     *
1124
-     * @param array $request usually the same as $this->_req_data but not necessarily
1125
-     * @return array
1126
-     */
1127
-    protected function _add_datetime_id_to_where_conditions(array $request)
1128
-    {
1129
-        $where = array();
1130
-        if (! empty($request['datetime_id'])) {
1131
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1132
-        }
1133
-        if (! empty($request['DTT_ID'])) {
1134
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1135
-        }
1136
-        return $where;
1137
-    }
1138
-
1139
-
1140
-    /**
1141
-     * Adds the correct registration status to the where conditions for the registrations query.
1142
-     *
1143
-     * @param array $request usually the same as $this->_req_data but not necessarily
1144
-     * @return array
1145
-     */
1146
-    protected function _add_registration_status_to_where_conditions(array $request)
1147
-    {
1148
-        $where = array();
1149
-        $view = EEH_Array::is_set($request, 'status', '');
1150
-        $registration_status = ! empty($request['_reg_status'])
1151
-            ? sanitize_text_field($request['_reg_status'])
1152
-            : '';
1153
-
1154
-        /*
26
+	/**
27
+	 * @var EE_Registration
28
+	 */
29
+	private $_registration;
30
+
31
+	/**
32
+	 * @var EE_Event
33
+	 */
34
+	private $_reg_event;
35
+
36
+	/**
37
+	 * @var EE_Session
38
+	 */
39
+	private $_session;
40
+
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form = null;
50
+
51
+
52
+	/**
53
+	 *        constructor
54
+	 *
55
+	 * @Constructor
56
+	 * @access public
57
+	 * @param bool $routing
58
+	 * @return Registrations_Admin_Page
59
+	 */
60
+	public function __construct($routing = true)
61
+	{
62
+		parent::__construct($routing);
63
+		add_action('wp_loaded', array($this, 'wp_loaded'));
64
+	}
65
+
66
+
67
+	public function wp_loaded()
68
+	{
69
+		// when adding a new registration...
70
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
+			EE_System::do_not_cache();
72
+			if (! isset($this->_req_data['processing_registration'])
73
+				 || absint($this->_req_data['processing_registration']) !== 1
74
+			) {
75
+				// and it's NOT the attendee information reg step
76
+				// force cookie expiration by setting time to last week
77
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
+				// and update the global
79
+				$_COOKIE['ee_registration_added'] = 0;
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+	protected function _init_page_props()
86
+	{
87
+		$this->page_slug        = REG_PG_SLUG;
88
+		$this->_admin_base_url  = REG_ADMIN_URL;
89
+		$this->_admin_base_path = REG_ADMIN;
90
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
91
+		$this->_cpt_routes      = array(
92
+			'add_new_attendee' => 'espresso_attendees',
93
+			'edit_attendee'    => 'espresso_attendees',
94
+			'insert_attendee'  => 'espresso_attendees',
95
+			'update_attendee'  => 'espresso_attendees',
96
+		);
97
+		$this->_cpt_model_names = array(
98
+			'add_new_attendee' => 'EEM_Attendee',
99
+			'edit_attendee'    => 'EEM_Attendee',
100
+		);
101
+		$this->_cpt_edit_routes = array(
102
+			'espresso_attendees' => 'edit_attendee',
103
+		);
104
+		$this->_pagenow_map     = array(
105
+			'add_new_attendee' => 'post-new.php',
106
+			'edit_attendee'    => 'post.php',
107
+			'trash'            => 'post.php',
108
+		);
109
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
+		//add filters so that the comment urls don't take users to a confusing 404 page
111
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
+	}
113
+
114
+
115
+	public function clear_comment_link($link, $comment, $args)
116
+	{
117
+		//gotta make sure this only happens on this route
118
+		$post_type = get_post_type($comment->comment_post_ID);
119
+		if ($post_type === 'espresso_attendees') {
120
+			return '#commentsdiv';
121
+		}
122
+		return $link;
123
+	}
124
+
125
+
126
+	protected function _ajax_hooks()
127
+	{
128
+		//todo: all hooks for registrations ajax goes in here
129
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
+	}
131
+
132
+
133
+	protected function _define_page_props()
134
+	{
135
+		$this->_admin_page_title = $this->page_label;
136
+		$this->_labels           = array(
137
+			'buttons'                      => array(
138
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
+			),
147
+			'publishbox'                   => array(
148
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
+			),
151
+			'hide_add_button_on_cpt_route' => array(
152
+				'edit_attendee' => true,
153
+			),
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 *        grab url requests and route them
160
+	 *
161
+	 * @access private
162
+	 * @return void
163
+	 */
164
+	public function _set_page_routes()
165
+	{
166
+		$this->_get_registration_status_array();
167
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
+			? $this->_req_data['_REG_ID'] : 0;
169
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
+			? $this->_req_data['ATT_ID'] : 0;
171
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
172
+			? $this->_req_data['post']
173
+			: $att_id;
174
+		$this->_page_routes = array(
175
+			'default'                            => array(
176
+				'func'       => '_registrations_overview_list_table',
177
+				'capability' => 'ee_read_registrations',
178
+			),
179
+			'view_registration'                  => array(
180
+				'func'       => '_registration_details',
181
+				'capability' => 'ee_read_registration',
182
+				'obj_id'     => $reg_id,
183
+			),
184
+			'edit_registration'                  => array(
185
+				'func'               => '_update_attendee_registration_form',
186
+				'noheader'           => true,
187
+				'headers_sent_route' => 'view_registration',
188
+				'capability'         => 'ee_edit_registration',
189
+				'obj_id'             => $reg_id,
190
+				'_REG_ID'            => $reg_id,
191
+			),
192
+			'trash_registrations'                => array(
193
+				'func'       => '_trash_or_restore_registrations',
194
+				'args'       => array('trash' => true),
195
+				'noheader'   => true,
196
+				'capability' => 'ee_delete_registrations',
197
+			),
198
+			'restore_registrations'              => array(
199
+				'func'       => '_trash_or_restore_registrations',
200
+				'args'       => array('trash' => false),
201
+				'noheader'   => true,
202
+				'capability' => 'ee_delete_registrations',
203
+			),
204
+			'delete_registrations'               => array(
205
+				'func'       => '_delete_registrations',
206
+				'noheader'   => true,
207
+				'capability' => 'ee_delete_registrations',
208
+			),
209
+			'new_registration'                   => array(
210
+				'func'       => 'new_registration',
211
+				'capability' => 'ee_edit_registrations',
212
+			),
213
+			'process_reg_step'                   => array(
214
+				'func'       => 'process_reg_step',
215
+				'noheader'   => true,
216
+				'capability' => 'ee_edit_registrations',
217
+			),
218
+			'redirect_to_txn'                    => array(
219
+				'func'       => 'redirect_to_txn',
220
+				'noheader'   => true,
221
+				'capability' => 'ee_edit_registrations',
222
+			),
223
+			'change_reg_status'                  => array(
224
+				'func'       => '_change_reg_status',
225
+				'noheader'   => true,
226
+				'capability' => 'ee_edit_registration',
227
+				'obj_id'     => $reg_id,
228
+			),
229
+			'approve_registration'               => array(
230
+				'func'       => 'approve_registration',
231
+				'noheader'   => true,
232
+				'capability' => 'ee_edit_registration',
233
+				'obj_id'     => $reg_id,
234
+			),
235
+			'approve_and_notify_registration'    => array(
236
+				'func'       => 'approve_registration',
237
+				'noheader'   => true,
238
+				'args'       => array(true),
239
+				'capability' => 'ee_edit_registration',
240
+				'obj_id'     => $reg_id,
241
+			),
242
+			'decline_registration'               => array(
243
+				'func'       => 'decline_registration',
244
+				'noheader'   => true,
245
+				'capability' => 'ee_edit_registration',
246
+				'obj_id'     => $reg_id,
247
+			),
248
+			'decline_and_notify_registration'    => array(
249
+				'func'       => 'decline_registration',
250
+				'noheader'   => true,
251
+				'args'       => array(true),
252
+				'capability' => 'ee_edit_registration',
253
+				'obj_id'     => $reg_id,
254
+			),
255
+			'pending_registration'               => array(
256
+				'func'       => 'pending_registration',
257
+				'noheader'   => true,
258
+				'capability' => 'ee_edit_registration',
259
+				'obj_id'     => $reg_id,
260
+			),
261
+			'pending_and_notify_registration'    => array(
262
+				'func'       => 'pending_registration',
263
+				'noheader'   => true,
264
+				'args'       => array(true),
265
+				'capability' => 'ee_edit_registration',
266
+				'obj_id'     => $reg_id,
267
+			),
268
+			'no_approve_registration'            => array(
269
+				'func'       => 'not_approve_registration',
270
+				'noheader'   => true,
271
+				'capability' => 'ee_edit_registration',
272
+				'obj_id'     => $reg_id,
273
+			),
274
+			'no_approve_and_notify_registration' => array(
275
+				'func'       => 'not_approve_registration',
276
+				'noheader'   => true,
277
+				'args'       => array(true),
278
+				'capability' => 'ee_edit_registration',
279
+				'obj_id'     => $reg_id,
280
+			),
281
+			'cancel_registration'                => array(
282
+				'func'       => 'cancel_registration',
283
+				'noheader'   => true,
284
+				'capability' => 'ee_edit_registration',
285
+				'obj_id'     => $reg_id,
286
+			),
287
+			'cancel_and_notify_registration'     => array(
288
+				'func'       => 'cancel_registration',
289
+				'noheader'   => true,
290
+				'args'       => array(true),
291
+				'capability' => 'ee_edit_registration',
292
+				'obj_id'     => $reg_id,
293
+			),
294
+			'contact_list'                       => array(
295
+				'func'       => '_attendee_contact_list_table',
296
+				'capability' => 'ee_read_contacts',
297
+			),
298
+			'add_new_attendee'                   => array(
299
+				'func' => '_create_new_cpt_item',
300
+				'args' => array(
301
+					'new_attendee' => true,
302
+					'capability'   => 'ee_edit_contacts',
303
+				),
304
+			),
305
+			'edit_attendee'                      => array(
306
+				'func'       => '_edit_cpt_item',
307
+				'capability' => 'ee_edit_contacts',
308
+				'obj_id'     => $att_id,
309
+			),
310
+			'duplicate_attendee'                 => array(
311
+				'func'       => '_duplicate_attendee',
312
+				'noheader'   => true,
313
+				'capability' => 'ee_edit_contacts',
314
+				'obj_id'     => $att_id,
315
+			),
316
+			'insert_attendee'                    => array(
317
+				'func'       => '_insert_or_update_attendee',
318
+				'args'       => array(
319
+					'new_attendee' => true,
320
+				),
321
+				'noheader'   => true,
322
+				'capability' => 'ee_edit_contacts',
323
+			),
324
+			'update_attendee'                    => array(
325
+				'func'       => '_insert_or_update_attendee',
326
+				'args'       => array(
327
+					'new_attendee' => false,
328
+				),
329
+				'noheader'   => true,
330
+				'capability' => 'ee_edit_contacts',
331
+				'obj_id'     => $att_id,
332
+			),
333
+			'trash_attendee'                    => array(
334
+				'func'       => '_trash_or_restore_attendees',
335
+				'args'       => array(
336
+					'trash' => true,
337
+				),
338
+				'noheader'   => true,
339
+				'capability' => 'ee_delete_contacts',
340
+				'obj_id'     => $att_id,
341
+			),
342
+			'restore_attendees'                  => array(
343
+				'func'       => '_trash_or_restore_attendees',
344
+				'args'       => array(
345
+					'trash' => false,
346
+				),
347
+				'noheader'   => true,
348
+				'capability' => 'ee_delete_contacts',
349
+				'obj_id'     => $att_id,
350
+			),
351
+			'resend_registration'                => array(
352
+				'func'       => '_resend_registration',
353
+				'noheader'   => true,
354
+				'capability' => 'ee_send_message',
355
+			),
356
+			'registrations_report'               => array(
357
+				'func'       => '_registrations_report',
358
+				'noheader'   => true,
359
+				'capability' => 'ee_read_registrations',
360
+			),
361
+			'contact_list_export'                => array(
362
+				'func'       => '_contact_list_export',
363
+				'noheader'   => true,
364
+				'capability' => 'export',
365
+			),
366
+			'contact_list_report'                => array(
367
+				'func'       => '_contact_list_report',
368
+				'noheader'   => true,
369
+				'capability' => 'ee_read_contacts',
370
+			),
371
+		);
372
+	}
373
+
374
+
375
+	protected function _set_page_config()
376
+	{
377
+		$this->_page_config = array(
378
+			'default'           => array(
379
+				'nav'           => array(
380
+					'label' => esc_html__('Overview', 'event_espresso'),
381
+					'order' => 5,
382
+				),
383
+				'help_tabs'     => array(
384
+					'registrations_overview_help_tab'                       => array(
385
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
386
+						'filename' => 'registrations_overview',
387
+					),
388
+					'registrations_overview_table_column_headings_help_tab' => array(
389
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
390
+						'filename' => 'registrations_overview_table_column_headings',
391
+					),
392
+					'registrations_overview_filters_help_tab'               => array(
393
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
394
+						'filename' => 'registrations_overview_filters',
395
+					),
396
+					'registrations_overview_views_help_tab'                 => array(
397
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
398
+						'filename' => 'registrations_overview_views',
399
+					),
400
+					'registrations_regoverview_other_help_tab'              => array(
401
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
402
+						'filename' => 'registrations_overview_other',
403
+					),
404
+				),
405
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
406
+				'qtips'         => array('Registration_List_Table_Tips'),
407
+				'list_table'    => 'EE_Registrations_List_Table',
408
+				'require_nonce' => false,
409
+			),
410
+			'view_registration' => array(
411
+				'nav'           => array(
412
+					'label'      => esc_html__('REG Details', 'event_espresso'),
413
+					'order'      => 15,
414
+					'url'        => isset($this->_req_data['_REG_ID'])
415
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
416
+						: $this->_admin_base_url,
417
+					'persistent' => false,
418
+				),
419
+				'help_tabs'     => array(
420
+					'registrations_details_help_tab'                    => array(
421
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
422
+						'filename' => 'registrations_details',
423
+					),
424
+					'registrations_details_table_help_tab'              => array(
425
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
426
+						'filename' => 'registrations_details_table',
427
+					),
428
+					'registrations_details_form_answers_help_tab'       => array(
429
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
430
+						'filename' => 'registrations_details_form_answers',
431
+					),
432
+					'registrations_details_registrant_details_help_tab' => array(
433
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
434
+						'filename' => 'registrations_details_registrant_details',
435
+					),
436
+				),
437
+				'help_tour'     => array('Registration_Details_Help_Tour'),
438
+				'metaboxes'     => array_merge(
439
+					$this->_default_espresso_metaboxes,
440
+					array('_registration_details_metaboxes')
441
+				),
442
+				'require_nonce' => false,
443
+			),
444
+			'new_registration'  => array(
445
+				'nav'           => array(
446
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
447
+					'url'        => '#',
448
+					'order'      => 15,
449
+					'persistent' => false,
450
+				),
451
+				'metaboxes'     => $this->_default_espresso_metaboxes,
452
+				'labels'        => array(
453
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
454
+				),
455
+				'require_nonce' => false,
456
+			),
457
+			'add_new_attendee'  => array(
458
+				'nav'           => array(
459
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
460
+					'order'      => 15,
461
+					'persistent' => false,
462
+				),
463
+				'metaboxes'     => array_merge(
464
+					$this->_default_espresso_metaboxes,
465
+					array('_publish_post_box', 'attendee_editor_metaboxes')
466
+				),
467
+				'require_nonce' => false,
468
+			),
469
+			'edit_attendee'     => array(
470
+				'nav'           => array(
471
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
472
+					'order'      => 15,
473
+					'persistent' => false,
474
+					'url'        => isset($this->_req_data['ATT_ID'])
475
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
476
+						: $this->_admin_base_url,
477
+				),
478
+				'metaboxes'     => array('attendee_editor_metaboxes'),
479
+				'require_nonce' => false,
480
+			),
481
+			'contact_list'      => array(
482
+				'nav'           => array(
483
+					'label' => esc_html__('Contact List', 'event_espresso'),
484
+					'order' => 20,
485
+				),
486
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
487
+				'help_tabs'     => array(
488
+					'registrations_contact_list_help_tab'                       => array(
489
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
490
+						'filename' => 'registrations_contact_list',
491
+					),
492
+					'registrations_contact-list_table_column_headings_help_tab' => array(
493
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
494
+						'filename' => 'registrations_contact_list_table_column_headings',
495
+					),
496
+					'registrations_contact_list_views_help_tab'                 => array(
497
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
498
+						'filename' => 'registrations_contact_list_views',
499
+					),
500
+					'registrations_contact_list_other_help_tab'                 => array(
501
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
502
+						'filename' => 'registrations_contact_list_other',
503
+					),
504
+				),
505
+				'help_tour'     => array('Contact_List_Help_Tour'),
506
+				'metaboxes'     => array(),
507
+				'require_nonce' => false,
508
+			),
509
+			//override default cpt routes
510
+			'create_new'        => '',
511
+			'edit'              => '',
512
+		);
513
+	}
514
+
515
+
516
+	/**
517
+	 * The below methods aren't used by this class currently
518
+	 */
519
+	protected function _add_screen_options()
520
+	{
521
+	}
522
+
523
+
524
+	protected function _add_feature_pointers()
525
+	{
526
+	}
527
+
528
+
529
+	public function admin_init()
530
+	{
531
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
532
+			'click "Update Registration Questions" to save your changes',
533
+			'event_espresso'
534
+		);
535
+	}
536
+
537
+
538
+	public function admin_notices()
539
+	{
540
+	}
541
+
542
+
543
+	public function admin_footer_scripts()
544
+	{
545
+	}
546
+
547
+
548
+	/**
549
+	 *        get list of registration statuses
550
+	 *
551
+	 * @access private
552
+	 * @return void
553
+	 */
554
+	private function _get_registration_status_array()
555
+	{
556
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
557
+	}
558
+
559
+
560
+	protected function _add_screen_options_default()
561
+	{
562
+		$this->_per_page_screen_option();
563
+	}
564
+
565
+
566
+	protected function _add_screen_options_contact_list()
567
+	{
568
+		$page_title              = $this->_admin_page_title;
569
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
570
+		$this->_per_page_screen_option();
571
+		$this->_admin_page_title = $page_title;
572
+	}
573
+
574
+
575
+	public function load_scripts_styles()
576
+	{
577
+		//style
578
+		wp_register_style(
579
+			'espresso_reg',
580
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
581
+			array('ee-admin-css'),
582
+			EVENT_ESPRESSO_VERSION
583
+		);
584
+		wp_enqueue_style('espresso_reg');
585
+		//script
586
+		wp_register_script(
587
+			'espresso_reg',
588
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
589
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
590
+			EVENT_ESPRESSO_VERSION,
591
+			true
592
+		);
593
+		wp_enqueue_script('espresso_reg');
594
+	}
595
+
596
+
597
+	public function load_scripts_styles_edit_attendee()
598
+	{
599
+		//stuff to only show up on our attendee edit details page.
600
+		$attendee_details_translations = array(
601
+			'att_publish_text' => sprintf(
602
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
603
+				$this->_cpt_model_obj->get_datetime('ATT_created')
604
+			),
605
+		);
606
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
607
+		wp_enqueue_script('jquery-validate');
608
+	}
609
+
610
+
611
+	public function load_scripts_styles_view_registration()
612
+	{
613
+		//styles
614
+		wp_enqueue_style('espresso-ui-theme');
615
+		//scripts
616
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
617
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
618
+	}
619
+
620
+
621
+	public function load_scripts_styles_contact_list()
622
+	{
623
+		wp_deregister_style('espresso_reg');
624
+		wp_register_style(
625
+			'espresso_att',
626
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
627
+			array('ee-admin-css'),
628
+			EVENT_ESPRESSO_VERSION
629
+		);
630
+		wp_enqueue_style('espresso_att');
631
+	}
632
+
633
+
634
+	public function load_scripts_styles_new_registration()
635
+	{
636
+		wp_register_script(
637
+			'ee-spco-for-admin',
638
+			REG_ASSETS_URL . 'spco_for_admin.js',
639
+			array('underscore', 'jquery'),
640
+			EVENT_ESPRESSO_VERSION,
641
+			true
642
+		);
643
+		wp_enqueue_script('ee-spco-for-admin');
644
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
645
+		EE_Form_Section_Proper::wp_enqueue_scripts();
646
+		EED_Ticket_Selector::load_tckt_slctr_assets();
647
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
648
+	}
649
+
650
+
651
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
652
+	{
653
+		add_filter('FHEE_load_EE_messages', '__return_true');
654
+	}
655
+
656
+
657
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
658
+	{
659
+		add_filter('FHEE_load_EE_messages', '__return_true');
660
+	}
661
+
662
+
663
+	protected function _set_list_table_views_default()
664
+	{
665
+		//for notification related bulk actions we need to make sure only active messengers have an option.
666
+		EED_Messages::set_autoloaders();
667
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
668
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
669
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
670
+		//key= bulk_action_slug, value= message type.
671
+		$match_array = array(
672
+			'approve_registration'    => 'registration',
673
+			'decline_registration'    => 'declined_registration',
674
+			'pending_registration'    => 'pending_approval',
675
+			'no_approve_registration' => 'not_approved_registration',
676
+			'cancel_registration'     => 'cancelled_registration',
677
+		);
678
+		/** setup reg status bulk actions **/
679
+		$def_reg_status_actions['approve_registration'] = esc_html__('Approve Registrations', 'event_espresso');
680
+		if (in_array($match_array['approve_registration'], $active_mts)
681
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
682
+		) {
683
+			$def_reg_status_actions['approve_and_notify_registration'] = esc_html__(
684
+				'Approve and Notify Registrations',
685
+				'event_espresso'
686
+			);
687
+		}
688
+		$def_reg_status_actions['decline_registration'] = esc_html__('Decline Registrations', 'event_espresso');
689
+		if (in_array($match_array['decline_registration'], $active_mts)
690
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
691
+		) {
692
+			$def_reg_status_actions['decline_and_notify_registration'] = esc_html__(
693
+				'Decline and Notify Registrations',
694
+				'event_espresso'
695
+			);
696
+		}
697
+		$def_reg_status_actions['pending_registration'] = esc_html__(
698
+			'Set Registrations to Pending Payment',
699
+			'event_espresso'
700
+		);
701
+		if (in_array($match_array['pending_registration'], $active_mts)
702
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
703
+		) {
704
+			$def_reg_status_actions['pending_and_notify_registration'] = esc_html__(
705
+				'Set Registrations to Pending Payment and Notify',
706
+				'event_espresso'
707
+			);
708
+		}
709
+		$def_reg_status_actions['no_approve_registration'] = esc_html__(
710
+			'Set Registrations to Not Approved',
711
+			'event_espresso'
712
+		);
713
+		if (in_array($match_array['no_approve_registration'], $active_mts)
714
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
715
+		) {
716
+			$def_reg_status_actions['no_approve_and_notify_registration'] = esc_html__(
717
+				'Set Registrations to Not Approved and Notify',
718
+				'event_espresso'
719
+			);
720
+		}
721
+		$def_reg_status_actions['cancel_registration'] = esc_html__('Cancel Registrations', 'event_espresso');
722
+		if (in_array($match_array['cancel_registration'], $active_mts)
723
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
724
+		) {
725
+			$def_reg_status_actions['cancel_and_notify_registration'] = esc_html__(
726
+				'Cancel Registrations and Notify',
727
+				'event_espresso'
728
+			);
729
+		}
730
+		$this->_views = array(
731
+			'all'   => array(
732
+				'slug'        => 'all',
733
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
734
+				'count'       => 0,
735
+				'bulk_action' => array_merge($def_reg_status_actions, array(
736
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
737
+				)),
738
+			),
739
+			'month' => array(
740
+				'slug'        => 'month',
741
+				'label'       => esc_html__('This Month', 'event_espresso'),
742
+				'count'       => 0,
743
+				'bulk_action' => array_merge($def_reg_status_actions, array(
744
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
745
+				)),
746
+			),
747
+			'today' => array(
748
+				'slug'        => 'today',
749
+				'label'       => sprintf(
750
+					esc_html__('Today - %s', 'event_espresso'),
751
+					date('M d, Y', current_time('timestamp'))
752
+				),
753
+				'count'       => 0,
754
+				'bulk_action' => array_merge($def_reg_status_actions, array(
755
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
756
+				)),
757
+			),
758
+		);
759
+		if (EE_Registry::instance()->CAP->current_user_can(
760
+			'ee_delete_registrations',
761
+			'espresso_registrations_delete_registration'
762
+		)) {
763
+			$this->_views['incomplete'] = array(
764
+				'slug'        => 'incomplete',
765
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
766
+				'count'       => 0,
767
+				'bulk_action' => array(
768
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
769
+				),
770
+			);
771
+			$this->_views['trash']      = array(
772
+				'slug'        => 'trash',
773
+				'label'       => esc_html__('Trash', 'event_espresso'),
774
+				'count'       => 0,
775
+				'bulk_action' => array(
776
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
777
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
778
+				),
779
+			);
780
+		}
781
+	}
782
+
783
+
784
+	protected function _set_list_table_views_contact_list()
785
+	{
786
+		$this->_views = array(
787
+			'in_use' => array(
788
+				'slug'        => 'in_use',
789
+				'label'       => esc_html__('In Use', 'event_espresso'),
790
+				'count'       => 0,
791
+				'bulk_action' => array(
792
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
793
+				),
794
+			),
795
+		);
796
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
797
+			'espresso_registrations_trash_attendees')
798
+		) {
799
+			$this->_views['trash'] = array(
800
+				'slug'        => 'trash',
801
+				'label'       => esc_html__('Trash', 'event_espresso'),
802
+				'count'       => 0,
803
+				'bulk_action' => array(
804
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
805
+				),
806
+			);
807
+		}
808
+	}
809
+
810
+
811
+	protected function _registration_legend_items()
812
+	{
813
+		$fc_items = array(
814
+			'star-icon'        => array(
815
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
816
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
817
+			),
818
+			'view_details'     => array(
819
+				'class' => 'dashicons dashicons-clipboard',
820
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
821
+			),
822
+			'edit_attendee'    => array(
823
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
824
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
825
+			),
826
+			'view_transaction' => array(
827
+				'class' => 'dashicons dashicons-cart',
828
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
829
+			),
830
+			'view_invoice'     => array(
831
+				'class' => 'dashicons dashicons-media-spreadsheet',
832
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
833
+			),
834
+		);
835
+		if (EE_Registry::instance()->CAP->current_user_can(
836
+			'ee_send_message',
837
+			'espresso_registrations_resend_registration'
838
+		)) {
839
+			$fc_items['resend_registration'] = array(
840
+				'class' => 'dashicons dashicons-email-alt',
841
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
842
+			);
843
+		} else {
844
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
845
+		}
846
+		if (EE_Registry::instance()->CAP->current_user_can(
847
+			'ee_read_global_messages',
848
+			'view_filtered_messages'
849
+		)) {
850
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
851
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
852
+				$fc_items['view_related_messages'] = array(
853
+					'class' => $related_for_icon['css_class'],
854
+					'desc'  => $related_for_icon['label'],
855
+				);
856
+			}
857
+		}
858
+		$sc_items = array(
859
+			'approved_status'   => array(
860
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
861
+				'desc'  => EEH_Template::pretty_status(
862
+					EEM_Registration::status_id_approved,
863
+					false,
864
+					'sentence'
865
+				),
866
+			),
867
+			'pending_status'    => array(
868
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
869
+				'desc'  => EEH_Template::pretty_status(
870
+					EEM_Registration::status_id_pending_payment,
871
+					false,
872
+					'sentence'
873
+				),
874
+			),
875
+			'wait_list'         => array(
876
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
877
+				'desc'  => EEH_Template::pretty_status(
878
+					EEM_Registration::status_id_wait_list,
879
+					false,
880
+					'sentence'
881
+				),
882
+			),
883
+			'incomplete_status' => array(
884
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
885
+				'desc'  => EEH_Template::pretty_status(
886
+					EEM_Registration::status_id_incomplete,
887
+					false,
888
+					'sentence'
889
+				),
890
+			),
891
+			'not_approved'      => array(
892
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
893
+				'desc'  => EEH_Template::pretty_status(
894
+					EEM_Registration::status_id_not_approved,
895
+					false,
896
+					'sentence'
897
+				),
898
+			),
899
+			'declined_status'   => array(
900
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
901
+				'desc'  => EEH_Template::pretty_status(
902
+					EEM_Registration::status_id_declined,
903
+					false,
904
+					'sentence'
905
+				),
906
+			),
907
+			'cancelled_status'  => array(
908
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
909
+				'desc'  => EEH_Template::pretty_status(
910
+					EEM_Registration::status_id_cancelled,
911
+					false,
912
+					'sentence'
913
+				),
914
+			),
915
+		);
916
+		return array_merge($fc_items, $sc_items);
917
+	}
918
+
919
+
920
+
921
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
922
+	/**
923
+	 * @throws \EE_Error
924
+	 */
925
+	protected function _registrations_overview_list_table()
926
+	{
927
+		$this->_template_args['admin_page_header'] = '';
928
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
929
+			? absint($this->_req_data['event_id'])
930
+			: 0;
931
+		if ($EVT_ID) {
932
+			if (EE_Registry::instance()->CAP->current_user_can(
933
+				'ee_edit_registrations',
934
+				'espresso_registrations_new_registration',
935
+				$EVT_ID
936
+			)) {
937
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
938
+					'new_registration',
939
+					'add-registrant',
940
+					array('event_id' => $EVT_ID),
941
+					'add-new-h2'
942
+				);
943
+			}
944
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
945
+			if ($event instanceof EE_Event) {
946
+				$this->_template_args['admin_page_header'] = sprintf(
947
+					esc_html__(
948
+						'%s Viewing registrations for the event: %s%s',
949
+						'event_espresso'
950
+					),
951
+					'<h3 style="line-height:1.5em;">',
952
+					'<br /><a href="'
953
+						. EE_Admin_Page::add_query_args_and_nonce(
954
+							array(
955
+								'action' => 'edit',
956
+								'post'   => $event->ID(),
957
+							),
958
+							EVENTS_ADMIN_URL
959
+						)
960
+						. '">&nbsp;'
961
+						. $event->get('EVT_name')
962
+						. '&nbsp;</a>&nbsp;',
963
+					'</h3>'
964
+				);
965
+			}
966
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
967
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
968
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
969
+				$this->_template_args['admin_page_header'] = substr(
970
+					$this->_template_args['admin_page_header'],
971
+					0,
972
+					-5
973
+				);
974
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
975
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
976
+				$this->_template_args['admin_page_header'] .= $datetime->name();
977
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
978
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
979
+			}
980
+		}
981
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
982
+		$this->display_admin_list_table_page_with_no_sidebar();
983
+	}
984
+
985
+
986
+	/**
987
+	 * This sets the _registration property for the registration details screen
988
+	 *
989
+	 * @access private
990
+	 * @return bool
991
+	 */
992
+	private function _set_registration_object()
993
+	{
994
+		//get out if we've already set the object
995
+		if (is_object($this->_registration)) {
996
+			return true;
997
+		}
998
+		$REG    = EEM_Registration::instance();
999
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1000
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1001
+			return true;
1002
+		} else {
1003
+			$error_msg = sprintf(
1004
+				esc_html__(
1005
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1006
+					'event_espresso'
1007
+				),
1008
+				$REG_ID
1009
+			);
1010
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1011
+			$this->_registration = null;
1012
+			return false;
1013
+		}
1014
+	}
1015
+
1016
+
1017
+	/**
1018
+	 * Used to retrieve registrations for the list table.
1019
+	 *
1020
+	 * @param int  $per_page
1021
+	 * @param bool $count
1022
+	 * @param bool $this_month
1023
+	 * @param bool $today
1024
+	 * @return EE_Registration[]|int
1025
+	 * @throws EE_Error
1026
+	 */
1027
+	public function get_registrations(
1028
+		$per_page = 10,
1029
+		$count = false,
1030
+		$this_month = false,
1031
+		$today = false
1032
+	) {
1033
+		if ($this_month) {
1034
+			$this->_req_data['status'] = 'month';
1035
+		}
1036
+		if ($today) {
1037
+			$this->_req_data['status'] = 'today';
1038
+		}
1039
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1040
+		/**
1041
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1042
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1043
+		 * @see EEM_Base::get_all()
1044
+		 */
1045
+		$query_params['group_by'] = '';
1046
+
1047
+		return $count
1048
+			? EEM_Registration::instance()->count($query_params)
1049
+			/** @type EE_Registration[] */
1050
+			: EEM_Registration::instance()->get_all($query_params);
1051
+	}
1052
+
1053
+
1054
+
1055
+	/**
1056
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1057
+	 * Note: this listens to values on the request for some of the query parameters.
1058
+	 *
1059
+	 * @param array $request
1060
+	 * @param int    $per_page
1061
+	 * @param bool   $count
1062
+	 * @return array
1063
+	 */
1064
+	protected function _get_registration_query_parameters(
1065
+		$request = array(),
1066
+		$per_page = 10,
1067
+		$count = false
1068
+	) {
1069
+
1070
+		$query_params = array(
1071
+			0                          => $this->_get_where_conditions_for_registrations_query(
1072
+				$request
1073
+			),
1074
+			'caps'                     => EEM_Registration::caps_read_admin,
1075
+			'default_where_conditions' => 'this_model_only',
1076
+		);
1077
+		if (! $count) {
1078
+			$query_params = array_merge(
1079
+				$query_params,
1080
+				$this->_get_orderby_for_registrations_query(),
1081
+				$this->_get_limit($per_page)
1082
+			);
1083
+		}
1084
+
1085
+		return $query_params;
1086
+	}
1087
+
1088
+
1089
+	/**
1090
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1091
+	 *
1092
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1093
+	 * @return array
1094
+	 */
1095
+	protected function _add_event_id_to_where_conditions(array $request)
1096
+	{
1097
+		$where = array();
1098
+		if (! empty($request['event_id'])) {
1099
+			$where['EVT_ID'] = absint($request['event_id']);
1100
+		}
1101
+		return $where;
1102
+	}
1103
+
1104
+
1105
+	/**
1106
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1107
+	 *
1108
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1109
+	 * @return array
1110
+	 */
1111
+	protected function _add_category_id_to_where_conditions(array $request)
1112
+	{
1113
+		$where = array();
1114
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1115
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1116
+		}
1117
+		return $where;
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1123
+	 *
1124
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1125
+	 * @return array
1126
+	 */
1127
+	protected function _add_datetime_id_to_where_conditions(array $request)
1128
+	{
1129
+		$where = array();
1130
+		if (! empty($request['datetime_id'])) {
1131
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1132
+		}
1133
+		if (! empty($request['DTT_ID'])) {
1134
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1135
+		}
1136
+		return $where;
1137
+	}
1138
+
1139
+
1140
+	/**
1141
+	 * Adds the correct registration status to the where conditions for the registrations query.
1142
+	 *
1143
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1144
+	 * @return array
1145
+	 */
1146
+	protected function _add_registration_status_to_where_conditions(array $request)
1147
+	{
1148
+		$where = array();
1149
+		$view = EEH_Array::is_set($request, 'status', '');
1150
+		$registration_status = ! empty($request['_reg_status'])
1151
+			? sanitize_text_field($request['_reg_status'])
1152
+			: '';
1153
+
1154
+		/*
1155 1155
          * If filtering by registration status, then we show registrations matching that status.
1156 1156
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1157 1157
          * UNLESS viewing trashed registrations.
1158 1158
          */
1159
-        if (! empty($registration_status)) {
1160
-            $where['STS_ID'] = $registration_status;
1161
-        } else {
1162
-            //make sure we exclude incomplete registrations, but only if not trashed.
1163
-            if ($view === 'trash') {
1164
-                $where['REG_deleted'] = true;
1165
-            } elseif ($view === 'incomplete') {
1166
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1167
-            } else {
1168
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1169
-            }
1170
-        }
1171
-        return $where;
1172
-    }
1173
-
1174
-
1175
-    /**
1176
-     * Adds any provided date restraints to the where conditions for the registrations query.
1177
-     *
1178
-     * @param array $request usually the same as $this->_req_data but not necessarily
1179
-     * @return array
1180
-     * @throws EE_Error
1181
-     */
1182
-    protected function _add_date_to_where_conditions(array $request)
1183
-    {
1184
-        $where = array();
1185
-        $view = EEH_Array::is_set($request, 'status', '');
1186
-        $month_range             = ! empty($request['month_range'])
1187
-            ? sanitize_text_field($request['month_range'])
1188
-            : '';
1189
-        $retrieve_for_today      = $view === 'today';
1190
-        $retrieve_for_this_month = $view === 'month';
1191
-
1192
-        if ($retrieve_for_today) {
1193
-            $now               = date('Y-m-d', current_time('timestamp'));
1194
-            $where['REG_date'] = array(
1195
-                'BETWEEN',
1196
-                array(
1197
-                    EEM_Registration::instance()->convert_datetime_for_query(
1198
-                        'REG_date',
1199
-                        $now . ' 00:00:00',
1200
-                        'Y-m-d H:i:s'
1201
-                    ),
1202
-                    EEM_Registration::instance()->convert_datetime_for_query(
1203
-                        'REG_date',
1204
-                        $now . ' 23:59:59',
1205
-                        'Y-m-d H:i:s'
1206
-                    ),
1207
-                ),
1208
-            );
1209
-        } elseif ($retrieve_for_this_month) {
1210
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1211
-            $days_this_month        = date('t', current_time('timestamp'));
1212
-            $where['REG_date']      = array(
1213
-                'BETWEEN',
1214
-                array(
1215
-                    EEM_Registration::instance()->convert_datetime_for_query(
1216
-                        'REG_date',
1217
-                        $current_year_and_month . '-01 00:00:00',
1218
-                        'Y-m-d H:i:s'
1219
-                    ),
1220
-                    EEM_Registration::instance()->convert_datetime_for_query(
1221
-                        'REG_date',
1222
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1223
-                        'Y-m-d H:i:s'
1224
-                    ),
1225
-                ),
1226
-            );
1227
-        } elseif ($month_range) {
1228
-            $pieces          = explode(' ', $month_range, 3);
1229
-            $month_requested = ! empty($pieces[0])
1230
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1231
-                : '';
1232
-            $year_requested  = ! empty($pieces[1])
1233
-                ? $pieces[1]
1234
-                : '';
1235
-            //if there is not a month or year then we can't go further
1236
-            if ($month_requested && $year_requested) {
1237
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1238
-                $where['REG_date'] = array(
1239
-                    'BETWEEN',
1240
-                    array(
1241
-                        EEM_Registration::instance()->convert_datetime_for_query(
1242
-                            'REG_date',
1243
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1244
-                            'Y-m-d H:i:s'
1245
-                        ),
1246
-                        EEM_Registration::instance()->convert_datetime_for_query(
1247
-                            'REG_date',
1248
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1249
-                            'Y-m-d H:i:s'
1250
-                        ),
1251
-                    ),
1252
-                );
1253
-            }
1254
-        }
1255
-        return $where;
1256
-    }
1257
-
1258
-
1259
-    /**
1260
-     * Adds any provided search restraints to the where conditions for the registrations query
1261
-     *
1262
-     * @param array $request usually the same as $this->_req_data but not necessarily
1263
-     * @return array
1264
-     */
1265
-    protected function _add_search_to_where_conditions(array $request)
1266
-    {
1267
-        $where = array();
1268
-        if (! empty($request['s'])) {
1269
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1270
-            $where['OR*search_conditions'] = array(
1271
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1272
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1273
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1274
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1275
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1276
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1277
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1278
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1279
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1280
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1281
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1282
-                'REG_final_price'                         => array('LIKE', $search_string),
1283
-                'REG_code'                                => array('LIKE', $search_string),
1284
-                'REG_count'                               => array('LIKE', $search_string),
1285
-                'REG_group_size'                          => array('LIKE', $search_string),
1286
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1287
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1288
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1289
-            );
1290
-        }
1291
-        return $where;
1292
-    }
1293
-
1294
-
1295
-    /**
1296
-     * Sets up the where conditions for the registrations query.
1297
-     *
1298
-     * @param array $request
1299
-     * @return array
1300
-     * @throws EE_Error
1301
-     */
1302
-    protected function _get_where_conditions_for_registrations_query($request)
1303
-    {
1304
-        return apply_filters(
1305
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1306
-            array_merge(
1307
-                $this->_add_event_id_to_where_conditions($request),
1308
-                $this->_add_category_id_to_where_conditions($request),
1309
-                $this->_add_datetime_id_to_where_conditions($request),
1310
-                $this->_add_registration_status_to_where_conditions($request),
1311
-                $this->_add_date_to_where_conditions($request),
1312
-                $this->_add_search_to_where_conditions($request)
1313
-            ),
1314
-            $request
1315
-        );
1316
-    }
1317
-
1318
-
1319
-    /**
1320
-     * Sets up the orderby for the registrations query.
1321
-     *
1322
-     * @return array
1323
-     */
1324
-    protected function _get_orderby_for_registrations_query()
1325
-    {
1326
-        $orderby_field = ! empty($this->_req_data['orderby'])
1327
-            ? sanitize_text_field($this->_req_data['orderby'])
1328
-            : '';
1329
-        switch ($orderby_field) {
1330
-            case '_REG_ID':
1331
-                $orderby_field = 'REG_ID';
1332
-                break;
1333
-            case '_Reg_status':
1334
-                $orderby_field = 'STS_ID';
1335
-                break;
1336
-            case 'ATT_fname':
1337
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1338
-                break;
1339
-            case 'ATT_lname':
1340
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1341
-                break;
1342
-            case 'event_name':
1343
-                $orderby_field = 'Event.EVT_name';
1344
-                break;
1345
-            case 'DTT_EVT_start':
1346
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1347
-                break;
1348
-            default: //'REG_date'
1349
-                $orderby_field = 'REG_date';
1350
-        }
1351
-
1352
-        //order
1353
-        $order = ! empty($this->_req_data['order'])
1354
-            ? sanitize_text_field($this->_req_data['order'])
1355
-            : 'DESC';
1356
-
1357
-        //mutate orderby_field
1358
-        $orderby_field = array_combine(
1359
-            (array) $orderby_field,
1360
-            array_fill(0, count($orderby_field), $order)
1361
-        );
1362
-        return array('order_by' => $orderby_field);
1363
-    }
1364
-
1365
-
1366
-    /**
1367
-     * Sets up the limit for the registrations query.
1368
-     *
1369
-     * @param $per_page
1370
-     * @return array
1371
-     */
1372
-    protected function _get_limit($per_page)
1373
-    {
1374
-        $current_page = ! empty($this->_req_data['paged'])
1375
-            ? absint($this->_req_data['paged'])
1376
-            : 1;
1377
-        $per_page     = ! empty($this->_req_data['perpage'])
1378
-            ? $this->_req_data['perpage']
1379
-            : $per_page;
1380
-
1381
-        //-1 means return all results so get out if that's set.
1382
-        if ((int)$per_page === -1) {
1383
-            return array();
1384
-        }
1385
-        $per_page = absint($per_page);
1386
-        $offset   = ($current_page - 1) * $per_page;
1387
-        return array('limit' => array($offset, $per_page));
1388
-    }
1389
-
1390
-
1391
-    public function get_registration_status_array()
1392
-    {
1393
-        return self::$_reg_status;
1394
-    }
1395
-
1396
-
1397
-
1398
-
1399
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1400
-    /**
1401
-     *        generates HTML for the View Registration Details Admin page
1402
-     *
1403
-     * @access protected
1404
-     * @return void
1405
-     * @throws DomainException
1406
-     * @throws EE_Error
1407
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1408
-     */
1409
-    protected function _registration_details()
1410
-    {
1411
-        $this->_template_args = array();
1412
-        $this->_set_registration_object();
1413
-        if (is_object($this->_registration)) {
1414
-            $transaction                                   = $this->_registration->transaction()
1415
-                ? $this->_registration->transaction()
1416
-                : EE_Transaction::new_instance();
1417
-            $this->_session                                = $transaction->session_data();
1418
-            $event_id                                      = $this->_registration->event_ID();
1419
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1420
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1421
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1422
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1423
-            $this->_template_args['grand_total']           = $transaction->total();
1424
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1425
-            // link back to overview
1426
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1427
-            $this->_template_args['registration']                = $this->_registration;
1428
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1429
-                array(
1430
-                    'action'   => 'default',
1431
-                    'event_id' => $event_id,
1432
-                ),
1433
-                REG_ADMIN_URL
1434
-            );
1435
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1436
-                array(
1437
-                    'action' => 'default',
1438
-                    'EVT_ID' => $event_id,
1439
-                    'page'   => 'espresso_transactions',
1440
-                ),
1441
-                admin_url('admin.php')
1442
-            );
1443
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1444
-                array(
1445
-                    'page'   => 'espresso_events',
1446
-                    'action' => 'edit',
1447
-                    'post'   => $event_id,
1448
-                ),
1449
-                admin_url('admin.php')
1450
-            );
1451
-            //next and previous links
1452
-            $next_reg                                      = $this->_registration->next(
1453
-                null,
1454
-                array(),
1455
-                'REG_ID'
1456
-            );
1457
-            $this->_template_args['next_registration']     = $next_reg
1458
-                ? $this->_next_link(
1459
-                    EE_Admin_Page::add_query_args_and_nonce(
1460
-                        array(
1461
-                            'action'  => 'view_registration',
1462
-                            '_REG_ID' => $next_reg['REG_ID'],
1463
-                        ),
1464
-                        REG_ADMIN_URL
1465
-                    ),
1466
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1467
-                )
1468
-                : '';
1469
-            $previous_reg                                  = $this->_registration->previous(
1470
-                null,
1471
-                array(),
1472
-                'REG_ID'
1473
-            );
1474
-            $this->_template_args['previous_registration'] = $previous_reg
1475
-                ? $this->_previous_link(
1476
-                    EE_Admin_Page::add_query_args_and_nonce(
1477
-                        array(
1478
-                            'action'  => 'view_registration',
1479
-                            '_REG_ID' => $previous_reg['REG_ID'],
1480
-                        ),
1481
-                        REG_ADMIN_URL
1482
-                    ),
1483
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1484
-                )
1485
-                : '';
1486
-            // grab header
1487
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1488
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1489
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1490
-                $template_path,
1491
-                $this->_template_args,
1492
-                true
1493
-            );
1494
-        } else {
1495
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1496
-        }
1497
-        // the details template wrapper
1498
-        $this->display_admin_page_with_sidebar();
1499
-    }
1500
-
1501
-
1502
-    protected function _registration_details_metaboxes()
1503
-    {
1504
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1505
-        $this->_set_registration_object();
1506
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1507
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1508
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1509
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1510
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1511
-        if ($attendee instanceof EE_Attendee
1512
-            && EE_Registry::instance()->CAP->current_user_can(
1513
-                'ee_edit_registration',
1514
-                'edit-reg-questions-mbox'
1515
-            )
1516
-        ) {
1517
-            add_meta_box(
1518
-                'edit-reg-questions-mbox',
1519
-                esc_html__('Registration Form Answers', 'event_espresso'),
1520
-                array($this, '_reg_questions_meta_box'),
1521
-                $this->wp_page_slug,
1522
-                'normal',
1523
-                'high'
1524
-            );
1525
-        }
1526
-        add_meta_box(
1527
-            'edit-reg-registrant-mbox',
1528
-            esc_html__('Contact Details', 'event_espresso'),
1529
-            array($this, '_reg_registrant_side_meta_box'),
1530
-            $this->wp_page_slug,
1531
-            'side',
1532
-            'high'
1533
-        );
1534
-        if ($this->_registration->group_size() > 1) {
1535
-            add_meta_box(
1536
-                'edit-reg-attendees-mbox',
1537
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1538
-                array($this, '_reg_attendees_meta_box'),
1539
-                $this->wp_page_slug,
1540
-                'normal',
1541
-                'high'
1542
-            );
1543
-        }
1544
-    }
1545
-
1546
-
1547
-    /**
1548
-     * set_reg_status_buttons_metabox
1549
-     *
1550
-     * @access protected
1551
-     * @return string
1552
-     * @throws \EE_Error
1553
-     */
1554
-    public function set_reg_status_buttons_metabox()
1555
-    {
1556
-        $this->_set_registration_object();
1557
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1558
-        echo $change_reg_status_form->form_open(
1559
-            self::add_query_args_and_nonce(
1560
-                array(
1561
-                    'action' => 'change_reg_status',
1562
-                ),
1563
-                REG_ADMIN_URL
1564
-            )
1565
-        );
1566
-        echo $change_reg_status_form->get_html();
1567
-        echo $change_reg_status_form->form_close();
1568
-    }
1569
-
1570
-
1571
-    /**
1572
-     * @return EE_Form_Section_Proper
1573
-     * @throws EE_Error
1574
-     */
1575
-    protected function _generate_reg_status_change_form()
1576
-    {
1577
-        return new EE_Form_Section_Proper(array(
1578
-            'name'            => 'reg_status_change_form',
1579
-            'html_id'         => 'reg-status-change-form',
1580
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1581
-            'subsections'     => array(
1582
-                'return'             => new EE_Hidden_Input(array(
1583
-                    'name'    => 'return',
1584
-                    'default' => 'view_registration',
1585
-                )),
1586
-                'REG_ID'             => new EE_Hidden_Input(array(
1587
-                    'name'    => 'REG_ID',
1588
-                    'default' => $this->_registration->ID(),
1589
-                )),
1590
-                'current_status'     => new EE_Form_Section_HTML(
1591
-                    EEH_HTML::tr(
1592
-                        EEH_HTML::th(
1593
-                            EEH_HTML::label(
1594
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1595
-                                )
1596
-                            )
1597
-                        )
1598
-                        . EEH_HTML::td(
1599
-                            EEH_HTML::strong(
1600
-                                $this->_registration->pretty_status(),
1601
-                                '',
1602
-                                'status-' . $this->_registration->status_ID(),
1603
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1604
-                            )
1605
-                        )
1606
-                    )
1607
-                ),
1608
-                'reg_status'         => new EE_Select_Input(
1609
-                    $this->_get_reg_statuses(),
1610
-                    array(
1611
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1612
-                        'default'         => $this->_registration->status_ID(),
1613
-                    )
1614
-                ),
1615
-                'send_notifications' => new EE_Yes_No_Input(
1616
-                    array(
1617
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1618
-                        'default'         => false,
1619
-                        'html_help_text'  => esc_html__(
1620
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1621
-                            'event_espresso'
1622
-                        ),
1623
-                    )
1624
-                ),
1625
-                'submit'             => new EE_Submit_Input(
1626
-                    array(
1627
-                        'html_class'      => 'button-primary',
1628
-                        'html_label_text' => '&nbsp;',
1629
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1630
-                    )
1631
-                ),
1632
-            ),
1633
-        ));
1634
-    }
1635
-
1636
-
1637
-    /**
1638
-     * Returns an array of all the buttons for the various statuses and switch status actions
1639
-     *
1640
-     * @return array
1641
-     * @throws EE_Error
1642
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1643
-     */
1644
-    protected function _get_reg_statuses()
1645
-    {
1646
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1647
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1648
-        // get current reg status
1649
-        $current_status = $this->_registration->status_ID();
1650
-        // is registration for free event? This will determine whether to display the pending payment option
1651
-        if ($current_status != EEM_Registration::status_id_pending_payment
1652
-            && $this->_registration->transaction()
1653
-                                   ->is_free()
1654
-        ) {
1655
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1656
-        }
1657
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1658
-    }
1659
-
1660
-
1661
-    /**
1662
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1663
-     *
1664
-     * @param bool $status REG status given for changing registrations to.
1665
-     * @param bool $notify Whether to send messages notifications or not.
1666
-     * @return array  (array with reg_id(s) updated and whether update was successful.
1667
-     */
1668
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1669
-    {
1670
-        if (isset($this->_req_data['reg_status_change_form'])) {
1671
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1672
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1673
-        } else {
1674
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1675
-        }
1676
-        $success = $this->_set_registration_status($REG_IDs, $status);
1677
-        //notify?
1678
-        if ($success
1679
-            && $notify
1680
-            && EE_Registry::instance()->CAP->current_user_can(
1681
-                'ee_send_message',
1682
-                'espresso_registrations_resend_registration'
1683
-            )
1684
-        ) {
1685
-            $this->_process_resend_registration();
1686
-        }
1687
-        return $success;
1688
-    }
1689
-
1690
-
1691
-    /**
1692
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1693
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1694
-     *
1695
-     * @param array $REG_IDs
1696
-     * @param bool  $status
1697
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1698
-     *               the array of updated registrations).
1699
-     * @throws EE_Error
1700
-     * @throws RuntimeException
1701
-     */
1702
-    protected function _set_registration_status($REG_IDs = array(), $status = false)
1703
-    {
1704
-        $success = false;
1705
-        // typecast $REG_IDs
1706
-        $REG_IDs = (array)$REG_IDs;
1707
-        if ( ! empty($REG_IDs)) {
1708
-            $success = true;
1709
-            // set default status if none is passed
1710
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1711
-            // sanitize $REG_IDs
1712
-            $REG_IDs = array_filter($REG_IDs, 'absint');
1713
-            //loop through REG_ID's and change status
1714
-            foreach ($REG_IDs as $REG_ID) {
1715
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1716
-                if ($registration instanceof EE_Registration) {
1717
-                    $registration->set_status($status);
1718
-                    $result = $registration->save();
1719
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1720
-                    $success = $result !== false ? $success : false;
1721
-                }
1722
-            }
1723
-        }
1724
-        //reset _req_data['_REG_ID'] for any potential future messages notifications
1725
-        $this->_req_data['_REG_ID'] = $REG_IDs;
1726
-        //return $success and processed registrations
1727
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1728
-    }
1729
-
1730
-
1731
-    /**
1732
-     * Common logic for setting up success message and redirecting to appropriate route
1733
-     *
1734
-     * @param  string $STS_ID status id for the registration changed to
1735
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1736
-     * @return void
1737
-     */
1738
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1739
-    {
1740
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1741
-            : array('success' => false);
1742
-        $success = isset($result['success']) && $result['success'];
1743
-        //setup success message
1744
-        if ($success) {
1745
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1746
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1747
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1748
-            } else {
1749
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1750
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1751
-            }
1752
-            EE_Error::add_success($msg);
1753
-        } else {
1754
-            EE_Error::add_error(
1755
-                esc_html__(
1756
-                    'Something went wrong, and the status was not changed',
1757
-                    'event_espresso'
1758
-                ), __FILE__, __LINE__, __FUNCTION__
1759
-            );
1760
-        }
1761
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1762
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1763
-        } else {
1764
-            $route = array('action' => 'default');
1765
-        }
1766
-        //unset nonces
1767
-        foreach ($this->_req_data as $ref => $value) {
1768
-            if (strpos($ref, 'nonce') !== false) {
1769
-                unset($this->_req_data[$ref]);
1770
-                continue;
1771
-            }
1772
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1773
-            $this->_req_data[$ref] = $value;
1774
-        }
1775
-        //merge request vars so that the reloaded list table contains any existing filter query params
1776
-        $route = array_merge($this->_req_data, $route);
1777
-        $this->_redirect_after_action($success, '', '', $route, true);
1778
-    }
1779
-
1780
-
1781
-    /**
1782
-     * incoming reg status change from reg details page.
1783
-     *
1784
-     * @return void
1785
-     */
1786
-    protected function _change_reg_status()
1787
-    {
1788
-        $this->_req_data['return'] = 'view_registration';
1789
-        //set notify based on whether the send notifications toggle is set or not
1790
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1791
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1792
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1793
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1794
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1795
-            case EEM_Registration::status_id_approved :
1796
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1797
-                $this->approve_registration($notify);
1798
-                break;
1799
-            case EEM_Registration::status_id_pending_payment :
1800
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1801
-                $this->pending_registration($notify);
1802
-                break;
1803
-            case EEM_Registration::status_id_not_approved :
1804
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1805
-                $this->not_approve_registration($notify);
1806
-                break;
1807
-            case EEM_Registration::status_id_declined :
1808
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1809
-                $this->decline_registration($notify);
1810
-                break;
1811
-            case EEM_Registration::status_id_cancelled :
1812
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1813
-                $this->cancel_registration($notify);
1814
-                break;
1815
-            case EEM_Registration::status_id_wait_list :
1816
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1817
-                $this->waitlist_registration($notify);
1818
-                break;
1819
-            case EEM_Registration::status_id_incomplete :
1820
-            default :
1821
-                $result['success'] = false;
1822
-                unset($this->_req_data['return']);
1823
-                $this->_reg_status_change_return('', false);
1824
-                break;
1825
-        }
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * approve_registration
1831
-     *
1832
-     * @access protected
1833
-     * @param bool $notify whether or not to notify the registrant about their approval.
1834
-     * @return void
1835
-     */
1836
-    protected function approve_registration($notify = false)
1837
-    {
1838
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1839
-    }
1840
-
1841
-
1842
-    /**
1843
-     *        decline_registration
1844
-     *
1845
-     * @access protected
1846
-     * @param bool $notify whether or not to notify the registrant about their status change.
1847
-     * @return void
1848
-     */
1849
-    protected function decline_registration($notify = false)
1850
-    {
1851
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1852
-    }
1853
-
1854
-
1855
-    /**
1856
-     *        cancel_registration
1857
-     *
1858
-     * @access protected
1859
-     * @param bool $notify whether or not to notify the registrant about their status change.
1860
-     * @return void
1861
-     */
1862
-    protected function cancel_registration($notify = false)
1863
-    {
1864
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1865
-    }
1866
-
1867
-
1868
-    /**
1869
-     *        not_approve_registration
1870
-     *
1871
-     * @access protected
1872
-     * @param bool $notify whether or not to notify the registrant about their status change.
1873
-     * @return void
1874
-     */
1875
-    protected function not_approve_registration($notify = false)
1876
-    {
1877
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1878
-    }
1879
-
1880
-
1881
-    /**
1882
-     *        decline_registration
1883
-     *
1884
-     * @access protected
1885
-     * @param bool $notify whether or not to notify the registrant about their status change.
1886
-     * @return void
1887
-     */
1888
-    protected function pending_registration($notify = false)
1889
-    {
1890
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1891
-    }
1892
-
1893
-
1894
-    /**
1895
-     * waitlist_registration
1896
-     *
1897
-     * @access protected
1898
-     * @param bool $notify whether or not to notify the registrant about their status change.
1899
-     * @return void
1900
-     */
1901
-    protected function waitlist_registration($notify = false)
1902
-    {
1903
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1904
-    }
1905
-
1906
-
1907
-    /**
1908
-     *        generates HTML for the Registration main meta box
1909
-     *
1910
-     * @access public
1911
-     * @return void
1912
-     * @throws DomainException
1913
-     * @throws EE_Error
1914
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1915
-     */
1916
-    public function _reg_details_meta_box()
1917
-    {
1918
-        EEH_Autoloader::register_line_item_display_autoloaders();
1919
-        EEH_Autoloader::register_line_item_filter_autoloaders();
1920
-        EE_Registry::instance()->load_helper('Line_Item');
1921
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1922
-            : EE_Transaction::new_instance();
1923
-        $this->_session = $transaction->session_data();
1924
-        $filters        = new EE_Line_Item_Filter_Collection();
1925
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1926
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1927
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1928
-            $transaction->total_line_item());
1929
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
1930
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1931
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1932
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
1933
-            $filtered_line_item_tree,
1934
-            array('EE_Registration' => $this->_registration)
1935
-        );
1936
-        $attendee                                = $this->_registration->attendee();
1937
-        if (EE_Registry::instance()->CAP->current_user_can(
1938
-            'ee_read_transaction',
1939
-            'espresso_transactions_view_transaction'
1940
-        )) {
1941
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
1942
-                EE_Admin_Page::add_query_args_and_nonce(
1943
-                    array(
1944
-                        'action' => 'view_transaction',
1945
-                        'TXN_ID' => $transaction->ID(),
1946
-                    ),
1947
-                    TXN_ADMIN_URL
1948
-                ),
1949
-                esc_html__(' View Transaction', 'event_espresso'),
1950
-                'button secondary-button right',
1951
-                'dashicons dashicons-cart'
1952
-            );
1953
-        } else {
1954
-            $this->_template_args['view_transaction_button'] = '';
1955
-        }
1956
-        if ($attendee instanceof EE_Attendee
1957
-            && EE_Registry::instance()->CAP->current_user_can(
1958
-                'ee_send_message',
1959
-                'espresso_registrations_resend_registration'
1960
-            )
1961
-        ) {
1962
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
1963
-                EE_Admin_Page::add_query_args_and_nonce(
1964
-                    array(
1965
-                        'action'      => 'resend_registration',
1966
-                        '_REG_ID'     => $this->_registration->ID(),
1967
-                        'redirect_to' => 'view_registration',
1968
-                    ),
1969
-                    REG_ADMIN_URL
1970
-                ),
1971
-                esc_html__(' Resend Registration', 'event_espresso'),
1972
-                'button secondary-button right',
1973
-                'dashicons dashicons-email-alt'
1974
-            );
1975
-        } else {
1976
-            $this->_template_args['resend_registration_button'] = '';
1977
-        }
1978
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1979
-        $payment                               = $transaction->get_first_related('Payment');
1980
-        $payment                               = ! $payment instanceof EE_Payment
1981
-            ? EE_Payment::new_instance()
1982
-            : $payment;
1983
-        $payment_method                        = $payment->get_first_related('Payment_Method');
1984
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
1985
-            ? EE_Payment_Method::new_instance()
1986
-            : $payment_method;
1987
-        $reg_details                           = array(
1988
-            'payment_method'       => $payment_method->name(),
1989
-            'response_msg'         => $payment->gateway_response(),
1990
-            'registration_id'      => $this->_registration->get('REG_code'),
1991
-            'registration_session' => $this->_registration->session_ID(),
1992
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1993
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1994
-        );
1995
-        if (isset($reg_details['registration_id'])) {
1996
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1997
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
1998
-                'Registration ID',
1999
-                'event_espresso'
2000
-            );
2001
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2002
-        }
2003
-        if (isset($reg_details['payment_method'])) {
2004
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2005
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2006
-                'Most Recent Payment Method',
2007
-                'event_espresso'
2008
-            );
2009
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2010
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2011
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2012
-                'Payment method response',
2013
-                'event_espresso'
2014
-            );
2015
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2016
-        }
2017
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2018
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2019
-            'Registration Session',
2020
-            'event_espresso'
2021
-        );
2022
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2023
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2024
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2025
-            'Registration placed from IP',
2026
-            'event_espresso'
2027
-        );
2028
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2029
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2030
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2031
-            'event_espresso');
2032
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2033
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2034
-            array(
2035
-                'action'   => 'default',
2036
-                'event_id' => $this->_registration->event_ID(),
2037
-            ),
2038
-            REG_ADMIN_URL
2039
-        );
2040
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2041
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2042
-        $template_path                                                        =
2043
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2044
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2045
-    }
2046
-
2047
-
2048
-    /**
2049
-     * generates HTML for the Registration Questions meta box.
2050
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2051
-     * otherwise uses new forms system
2052
-     *
2053
-     * @access public
2054
-     * @return void
2055
-     * @throws DomainException
2056
-     * @throws EE_Error
2057
-     */
2058
-    public function _reg_questions_meta_box()
2059
-    {
2060
-        //allow someone to override this method entirely
2061
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2062
-            $this->_registration)) {
2063
-            $form                                              = $this->_get_reg_custom_questions_form(
2064
-                $this->_registration->ID()
2065
-            );
2066
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2067
-                ? $form->get_html_and_js()
2068
-                : '';
2069
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2070
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2071
-            $template_path                                     =
2072
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2073
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2074
-        }
2075
-    }
2076
-
2077
-
2078
-    /**
2079
-     * form_before_question_group
2080
-     *
2081
-     * @deprecated    as of 4.8.32.rc.000
2082
-     * @access        public
2083
-     * @param        string $output
2084
-     * @return        string
2085
-     */
2086
-    public function form_before_question_group($output)
2087
-    {
2088
-        EE_Error::doing_it_wrong(
2089
-            __CLASS__ . '::' . __FUNCTION__,
2090
-            esc_html__(
2091
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2092
-                'event_espresso'
2093
-            ),
2094
-            '4.8.32.rc.000'
2095
-        );
2096
-        return '
1159
+		if (! empty($registration_status)) {
1160
+			$where['STS_ID'] = $registration_status;
1161
+		} else {
1162
+			//make sure we exclude incomplete registrations, but only if not trashed.
1163
+			if ($view === 'trash') {
1164
+				$where['REG_deleted'] = true;
1165
+			} elseif ($view === 'incomplete') {
1166
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1167
+			} else {
1168
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1169
+			}
1170
+		}
1171
+		return $where;
1172
+	}
1173
+
1174
+
1175
+	/**
1176
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1177
+	 *
1178
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1179
+	 * @return array
1180
+	 * @throws EE_Error
1181
+	 */
1182
+	protected function _add_date_to_where_conditions(array $request)
1183
+	{
1184
+		$where = array();
1185
+		$view = EEH_Array::is_set($request, 'status', '');
1186
+		$month_range             = ! empty($request['month_range'])
1187
+			? sanitize_text_field($request['month_range'])
1188
+			: '';
1189
+		$retrieve_for_today      = $view === 'today';
1190
+		$retrieve_for_this_month = $view === 'month';
1191
+
1192
+		if ($retrieve_for_today) {
1193
+			$now               = date('Y-m-d', current_time('timestamp'));
1194
+			$where['REG_date'] = array(
1195
+				'BETWEEN',
1196
+				array(
1197
+					EEM_Registration::instance()->convert_datetime_for_query(
1198
+						'REG_date',
1199
+						$now . ' 00:00:00',
1200
+						'Y-m-d H:i:s'
1201
+					),
1202
+					EEM_Registration::instance()->convert_datetime_for_query(
1203
+						'REG_date',
1204
+						$now . ' 23:59:59',
1205
+						'Y-m-d H:i:s'
1206
+					),
1207
+				),
1208
+			);
1209
+		} elseif ($retrieve_for_this_month) {
1210
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1211
+			$days_this_month        = date('t', current_time('timestamp'));
1212
+			$where['REG_date']      = array(
1213
+				'BETWEEN',
1214
+				array(
1215
+					EEM_Registration::instance()->convert_datetime_for_query(
1216
+						'REG_date',
1217
+						$current_year_and_month . '-01 00:00:00',
1218
+						'Y-m-d H:i:s'
1219
+					),
1220
+					EEM_Registration::instance()->convert_datetime_for_query(
1221
+						'REG_date',
1222
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1223
+						'Y-m-d H:i:s'
1224
+					),
1225
+				),
1226
+			);
1227
+		} elseif ($month_range) {
1228
+			$pieces          = explode(' ', $month_range, 3);
1229
+			$month_requested = ! empty($pieces[0])
1230
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1231
+				: '';
1232
+			$year_requested  = ! empty($pieces[1])
1233
+				? $pieces[1]
1234
+				: '';
1235
+			//if there is not a month or year then we can't go further
1236
+			if ($month_requested && $year_requested) {
1237
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1238
+				$where['REG_date'] = array(
1239
+					'BETWEEN',
1240
+					array(
1241
+						EEM_Registration::instance()->convert_datetime_for_query(
1242
+							'REG_date',
1243
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1244
+							'Y-m-d H:i:s'
1245
+						),
1246
+						EEM_Registration::instance()->convert_datetime_for_query(
1247
+							'REG_date',
1248
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1249
+							'Y-m-d H:i:s'
1250
+						),
1251
+					),
1252
+				);
1253
+			}
1254
+		}
1255
+		return $where;
1256
+	}
1257
+
1258
+
1259
+	/**
1260
+	 * Adds any provided search restraints to the where conditions for the registrations query
1261
+	 *
1262
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1263
+	 * @return array
1264
+	 */
1265
+	protected function _add_search_to_where_conditions(array $request)
1266
+	{
1267
+		$where = array();
1268
+		if (! empty($request['s'])) {
1269
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1270
+			$where['OR*search_conditions'] = array(
1271
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1272
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1273
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1274
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1275
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1276
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1277
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1278
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1279
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1280
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1281
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1282
+				'REG_final_price'                         => array('LIKE', $search_string),
1283
+				'REG_code'                                => array('LIKE', $search_string),
1284
+				'REG_count'                               => array('LIKE', $search_string),
1285
+				'REG_group_size'                          => array('LIKE', $search_string),
1286
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1287
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1288
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1289
+			);
1290
+		}
1291
+		return $where;
1292
+	}
1293
+
1294
+
1295
+	/**
1296
+	 * Sets up the where conditions for the registrations query.
1297
+	 *
1298
+	 * @param array $request
1299
+	 * @return array
1300
+	 * @throws EE_Error
1301
+	 */
1302
+	protected function _get_where_conditions_for_registrations_query($request)
1303
+	{
1304
+		return apply_filters(
1305
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1306
+			array_merge(
1307
+				$this->_add_event_id_to_where_conditions($request),
1308
+				$this->_add_category_id_to_where_conditions($request),
1309
+				$this->_add_datetime_id_to_where_conditions($request),
1310
+				$this->_add_registration_status_to_where_conditions($request),
1311
+				$this->_add_date_to_where_conditions($request),
1312
+				$this->_add_search_to_where_conditions($request)
1313
+			),
1314
+			$request
1315
+		);
1316
+	}
1317
+
1318
+
1319
+	/**
1320
+	 * Sets up the orderby for the registrations query.
1321
+	 *
1322
+	 * @return array
1323
+	 */
1324
+	protected function _get_orderby_for_registrations_query()
1325
+	{
1326
+		$orderby_field = ! empty($this->_req_data['orderby'])
1327
+			? sanitize_text_field($this->_req_data['orderby'])
1328
+			: '';
1329
+		switch ($orderby_field) {
1330
+			case '_REG_ID':
1331
+				$orderby_field = 'REG_ID';
1332
+				break;
1333
+			case '_Reg_status':
1334
+				$orderby_field = 'STS_ID';
1335
+				break;
1336
+			case 'ATT_fname':
1337
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1338
+				break;
1339
+			case 'ATT_lname':
1340
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1341
+				break;
1342
+			case 'event_name':
1343
+				$orderby_field = 'Event.EVT_name';
1344
+				break;
1345
+			case 'DTT_EVT_start':
1346
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1347
+				break;
1348
+			default: //'REG_date'
1349
+				$orderby_field = 'REG_date';
1350
+		}
1351
+
1352
+		//order
1353
+		$order = ! empty($this->_req_data['order'])
1354
+			? sanitize_text_field($this->_req_data['order'])
1355
+			: 'DESC';
1356
+
1357
+		//mutate orderby_field
1358
+		$orderby_field = array_combine(
1359
+			(array) $orderby_field,
1360
+			array_fill(0, count($orderby_field), $order)
1361
+		);
1362
+		return array('order_by' => $orderby_field);
1363
+	}
1364
+
1365
+
1366
+	/**
1367
+	 * Sets up the limit for the registrations query.
1368
+	 *
1369
+	 * @param $per_page
1370
+	 * @return array
1371
+	 */
1372
+	protected function _get_limit($per_page)
1373
+	{
1374
+		$current_page = ! empty($this->_req_data['paged'])
1375
+			? absint($this->_req_data['paged'])
1376
+			: 1;
1377
+		$per_page     = ! empty($this->_req_data['perpage'])
1378
+			? $this->_req_data['perpage']
1379
+			: $per_page;
1380
+
1381
+		//-1 means return all results so get out if that's set.
1382
+		if ((int)$per_page === -1) {
1383
+			return array();
1384
+		}
1385
+		$per_page = absint($per_page);
1386
+		$offset   = ($current_page - 1) * $per_page;
1387
+		return array('limit' => array($offset, $per_page));
1388
+	}
1389
+
1390
+
1391
+	public function get_registration_status_array()
1392
+	{
1393
+		return self::$_reg_status;
1394
+	}
1395
+
1396
+
1397
+
1398
+
1399
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1400
+	/**
1401
+	 *        generates HTML for the View Registration Details Admin page
1402
+	 *
1403
+	 * @access protected
1404
+	 * @return void
1405
+	 * @throws DomainException
1406
+	 * @throws EE_Error
1407
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1408
+	 */
1409
+	protected function _registration_details()
1410
+	{
1411
+		$this->_template_args = array();
1412
+		$this->_set_registration_object();
1413
+		if (is_object($this->_registration)) {
1414
+			$transaction                                   = $this->_registration->transaction()
1415
+				? $this->_registration->transaction()
1416
+				: EE_Transaction::new_instance();
1417
+			$this->_session                                = $transaction->session_data();
1418
+			$event_id                                      = $this->_registration->event_ID();
1419
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1420
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1421
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1422
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1423
+			$this->_template_args['grand_total']           = $transaction->total();
1424
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1425
+			// link back to overview
1426
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1427
+			$this->_template_args['registration']                = $this->_registration;
1428
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1429
+				array(
1430
+					'action'   => 'default',
1431
+					'event_id' => $event_id,
1432
+				),
1433
+				REG_ADMIN_URL
1434
+			);
1435
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1436
+				array(
1437
+					'action' => 'default',
1438
+					'EVT_ID' => $event_id,
1439
+					'page'   => 'espresso_transactions',
1440
+				),
1441
+				admin_url('admin.php')
1442
+			);
1443
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1444
+				array(
1445
+					'page'   => 'espresso_events',
1446
+					'action' => 'edit',
1447
+					'post'   => $event_id,
1448
+				),
1449
+				admin_url('admin.php')
1450
+			);
1451
+			//next and previous links
1452
+			$next_reg                                      = $this->_registration->next(
1453
+				null,
1454
+				array(),
1455
+				'REG_ID'
1456
+			);
1457
+			$this->_template_args['next_registration']     = $next_reg
1458
+				? $this->_next_link(
1459
+					EE_Admin_Page::add_query_args_and_nonce(
1460
+						array(
1461
+							'action'  => 'view_registration',
1462
+							'_REG_ID' => $next_reg['REG_ID'],
1463
+						),
1464
+						REG_ADMIN_URL
1465
+					),
1466
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1467
+				)
1468
+				: '';
1469
+			$previous_reg                                  = $this->_registration->previous(
1470
+				null,
1471
+				array(),
1472
+				'REG_ID'
1473
+			);
1474
+			$this->_template_args['previous_registration'] = $previous_reg
1475
+				? $this->_previous_link(
1476
+					EE_Admin_Page::add_query_args_and_nonce(
1477
+						array(
1478
+							'action'  => 'view_registration',
1479
+							'_REG_ID' => $previous_reg['REG_ID'],
1480
+						),
1481
+						REG_ADMIN_URL
1482
+					),
1483
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1484
+				)
1485
+				: '';
1486
+			// grab header
1487
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1488
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1489
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1490
+				$template_path,
1491
+				$this->_template_args,
1492
+				true
1493
+			);
1494
+		} else {
1495
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1496
+		}
1497
+		// the details template wrapper
1498
+		$this->display_admin_page_with_sidebar();
1499
+	}
1500
+
1501
+
1502
+	protected function _registration_details_metaboxes()
1503
+	{
1504
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1505
+		$this->_set_registration_object();
1506
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1507
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1508
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1509
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1510
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1511
+		if ($attendee instanceof EE_Attendee
1512
+			&& EE_Registry::instance()->CAP->current_user_can(
1513
+				'ee_edit_registration',
1514
+				'edit-reg-questions-mbox'
1515
+			)
1516
+		) {
1517
+			add_meta_box(
1518
+				'edit-reg-questions-mbox',
1519
+				esc_html__('Registration Form Answers', 'event_espresso'),
1520
+				array($this, '_reg_questions_meta_box'),
1521
+				$this->wp_page_slug,
1522
+				'normal',
1523
+				'high'
1524
+			);
1525
+		}
1526
+		add_meta_box(
1527
+			'edit-reg-registrant-mbox',
1528
+			esc_html__('Contact Details', 'event_espresso'),
1529
+			array($this, '_reg_registrant_side_meta_box'),
1530
+			$this->wp_page_slug,
1531
+			'side',
1532
+			'high'
1533
+		);
1534
+		if ($this->_registration->group_size() > 1) {
1535
+			add_meta_box(
1536
+				'edit-reg-attendees-mbox',
1537
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1538
+				array($this, '_reg_attendees_meta_box'),
1539
+				$this->wp_page_slug,
1540
+				'normal',
1541
+				'high'
1542
+			);
1543
+		}
1544
+	}
1545
+
1546
+
1547
+	/**
1548
+	 * set_reg_status_buttons_metabox
1549
+	 *
1550
+	 * @access protected
1551
+	 * @return string
1552
+	 * @throws \EE_Error
1553
+	 */
1554
+	public function set_reg_status_buttons_metabox()
1555
+	{
1556
+		$this->_set_registration_object();
1557
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1558
+		echo $change_reg_status_form->form_open(
1559
+			self::add_query_args_and_nonce(
1560
+				array(
1561
+					'action' => 'change_reg_status',
1562
+				),
1563
+				REG_ADMIN_URL
1564
+			)
1565
+		);
1566
+		echo $change_reg_status_form->get_html();
1567
+		echo $change_reg_status_form->form_close();
1568
+	}
1569
+
1570
+
1571
+	/**
1572
+	 * @return EE_Form_Section_Proper
1573
+	 * @throws EE_Error
1574
+	 */
1575
+	protected function _generate_reg_status_change_form()
1576
+	{
1577
+		return new EE_Form_Section_Proper(array(
1578
+			'name'            => 'reg_status_change_form',
1579
+			'html_id'         => 'reg-status-change-form',
1580
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1581
+			'subsections'     => array(
1582
+				'return'             => new EE_Hidden_Input(array(
1583
+					'name'    => 'return',
1584
+					'default' => 'view_registration',
1585
+				)),
1586
+				'REG_ID'             => new EE_Hidden_Input(array(
1587
+					'name'    => 'REG_ID',
1588
+					'default' => $this->_registration->ID(),
1589
+				)),
1590
+				'current_status'     => new EE_Form_Section_HTML(
1591
+					EEH_HTML::tr(
1592
+						EEH_HTML::th(
1593
+							EEH_HTML::label(
1594
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1595
+								)
1596
+							)
1597
+						)
1598
+						. EEH_HTML::td(
1599
+							EEH_HTML::strong(
1600
+								$this->_registration->pretty_status(),
1601
+								'',
1602
+								'status-' . $this->_registration->status_ID(),
1603
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1604
+							)
1605
+						)
1606
+					)
1607
+				),
1608
+				'reg_status'         => new EE_Select_Input(
1609
+					$this->_get_reg_statuses(),
1610
+					array(
1611
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1612
+						'default'         => $this->_registration->status_ID(),
1613
+					)
1614
+				),
1615
+				'send_notifications' => new EE_Yes_No_Input(
1616
+					array(
1617
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1618
+						'default'         => false,
1619
+						'html_help_text'  => esc_html__(
1620
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1621
+							'event_espresso'
1622
+						),
1623
+					)
1624
+				),
1625
+				'submit'             => new EE_Submit_Input(
1626
+					array(
1627
+						'html_class'      => 'button-primary',
1628
+						'html_label_text' => '&nbsp;',
1629
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1630
+					)
1631
+				),
1632
+			),
1633
+		));
1634
+	}
1635
+
1636
+
1637
+	/**
1638
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1639
+	 *
1640
+	 * @return array
1641
+	 * @throws EE_Error
1642
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1643
+	 */
1644
+	protected function _get_reg_statuses()
1645
+	{
1646
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1647
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1648
+		// get current reg status
1649
+		$current_status = $this->_registration->status_ID();
1650
+		// is registration for free event? This will determine whether to display the pending payment option
1651
+		if ($current_status != EEM_Registration::status_id_pending_payment
1652
+			&& $this->_registration->transaction()
1653
+								   ->is_free()
1654
+		) {
1655
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1656
+		}
1657
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1658
+	}
1659
+
1660
+
1661
+	/**
1662
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1663
+	 *
1664
+	 * @param bool $status REG status given for changing registrations to.
1665
+	 * @param bool $notify Whether to send messages notifications or not.
1666
+	 * @return array  (array with reg_id(s) updated and whether update was successful.
1667
+	 */
1668
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1669
+	{
1670
+		if (isset($this->_req_data['reg_status_change_form'])) {
1671
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1672
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1673
+		} else {
1674
+			$REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1675
+		}
1676
+		$success = $this->_set_registration_status($REG_IDs, $status);
1677
+		//notify?
1678
+		if ($success
1679
+			&& $notify
1680
+			&& EE_Registry::instance()->CAP->current_user_can(
1681
+				'ee_send_message',
1682
+				'espresso_registrations_resend_registration'
1683
+			)
1684
+		) {
1685
+			$this->_process_resend_registration();
1686
+		}
1687
+		return $success;
1688
+	}
1689
+
1690
+
1691
+	/**
1692
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1693
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1694
+	 *
1695
+	 * @param array $REG_IDs
1696
+	 * @param bool  $status
1697
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1698
+	 *               the array of updated registrations).
1699
+	 * @throws EE_Error
1700
+	 * @throws RuntimeException
1701
+	 */
1702
+	protected function _set_registration_status($REG_IDs = array(), $status = false)
1703
+	{
1704
+		$success = false;
1705
+		// typecast $REG_IDs
1706
+		$REG_IDs = (array)$REG_IDs;
1707
+		if ( ! empty($REG_IDs)) {
1708
+			$success = true;
1709
+			// set default status if none is passed
1710
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1711
+			// sanitize $REG_IDs
1712
+			$REG_IDs = array_filter($REG_IDs, 'absint');
1713
+			//loop through REG_ID's and change status
1714
+			foreach ($REG_IDs as $REG_ID) {
1715
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1716
+				if ($registration instanceof EE_Registration) {
1717
+					$registration->set_status($status);
1718
+					$result = $registration->save();
1719
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1720
+					$success = $result !== false ? $success : false;
1721
+				}
1722
+			}
1723
+		}
1724
+		//reset _req_data['_REG_ID'] for any potential future messages notifications
1725
+		$this->_req_data['_REG_ID'] = $REG_IDs;
1726
+		//return $success and processed registrations
1727
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1728
+	}
1729
+
1730
+
1731
+	/**
1732
+	 * Common logic for setting up success message and redirecting to appropriate route
1733
+	 *
1734
+	 * @param  string $STS_ID status id for the registration changed to
1735
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1736
+	 * @return void
1737
+	 */
1738
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1739
+	{
1740
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1741
+			: array('success' => false);
1742
+		$success = isset($result['success']) && $result['success'];
1743
+		//setup success message
1744
+		if ($success) {
1745
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1746
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1747
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1748
+			} else {
1749
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1750
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1751
+			}
1752
+			EE_Error::add_success($msg);
1753
+		} else {
1754
+			EE_Error::add_error(
1755
+				esc_html__(
1756
+					'Something went wrong, and the status was not changed',
1757
+					'event_espresso'
1758
+				), __FILE__, __LINE__, __FUNCTION__
1759
+			);
1760
+		}
1761
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1762
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1763
+		} else {
1764
+			$route = array('action' => 'default');
1765
+		}
1766
+		//unset nonces
1767
+		foreach ($this->_req_data as $ref => $value) {
1768
+			if (strpos($ref, 'nonce') !== false) {
1769
+				unset($this->_req_data[$ref]);
1770
+				continue;
1771
+			}
1772
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1773
+			$this->_req_data[$ref] = $value;
1774
+		}
1775
+		//merge request vars so that the reloaded list table contains any existing filter query params
1776
+		$route = array_merge($this->_req_data, $route);
1777
+		$this->_redirect_after_action($success, '', '', $route, true);
1778
+	}
1779
+
1780
+
1781
+	/**
1782
+	 * incoming reg status change from reg details page.
1783
+	 *
1784
+	 * @return void
1785
+	 */
1786
+	protected function _change_reg_status()
1787
+	{
1788
+		$this->_req_data['return'] = 'view_registration';
1789
+		//set notify based on whether the send notifications toggle is set or not
1790
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1791
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1792
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1793
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1794
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1795
+			case EEM_Registration::status_id_approved :
1796
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1797
+				$this->approve_registration($notify);
1798
+				break;
1799
+			case EEM_Registration::status_id_pending_payment :
1800
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1801
+				$this->pending_registration($notify);
1802
+				break;
1803
+			case EEM_Registration::status_id_not_approved :
1804
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1805
+				$this->not_approve_registration($notify);
1806
+				break;
1807
+			case EEM_Registration::status_id_declined :
1808
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1809
+				$this->decline_registration($notify);
1810
+				break;
1811
+			case EEM_Registration::status_id_cancelled :
1812
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1813
+				$this->cancel_registration($notify);
1814
+				break;
1815
+			case EEM_Registration::status_id_wait_list :
1816
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1817
+				$this->waitlist_registration($notify);
1818
+				break;
1819
+			case EEM_Registration::status_id_incomplete :
1820
+			default :
1821
+				$result['success'] = false;
1822
+				unset($this->_req_data['return']);
1823
+				$this->_reg_status_change_return('', false);
1824
+				break;
1825
+		}
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * approve_registration
1831
+	 *
1832
+	 * @access protected
1833
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1834
+	 * @return void
1835
+	 */
1836
+	protected function approve_registration($notify = false)
1837
+	{
1838
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1839
+	}
1840
+
1841
+
1842
+	/**
1843
+	 *        decline_registration
1844
+	 *
1845
+	 * @access protected
1846
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1847
+	 * @return void
1848
+	 */
1849
+	protected function decline_registration($notify = false)
1850
+	{
1851
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1852
+	}
1853
+
1854
+
1855
+	/**
1856
+	 *        cancel_registration
1857
+	 *
1858
+	 * @access protected
1859
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1860
+	 * @return void
1861
+	 */
1862
+	protected function cancel_registration($notify = false)
1863
+	{
1864
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1865
+	}
1866
+
1867
+
1868
+	/**
1869
+	 *        not_approve_registration
1870
+	 *
1871
+	 * @access protected
1872
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1873
+	 * @return void
1874
+	 */
1875
+	protected function not_approve_registration($notify = false)
1876
+	{
1877
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1878
+	}
1879
+
1880
+
1881
+	/**
1882
+	 *        decline_registration
1883
+	 *
1884
+	 * @access protected
1885
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1886
+	 * @return void
1887
+	 */
1888
+	protected function pending_registration($notify = false)
1889
+	{
1890
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1891
+	}
1892
+
1893
+
1894
+	/**
1895
+	 * waitlist_registration
1896
+	 *
1897
+	 * @access protected
1898
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1899
+	 * @return void
1900
+	 */
1901
+	protected function waitlist_registration($notify = false)
1902
+	{
1903
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1904
+	}
1905
+
1906
+
1907
+	/**
1908
+	 *        generates HTML for the Registration main meta box
1909
+	 *
1910
+	 * @access public
1911
+	 * @return void
1912
+	 * @throws DomainException
1913
+	 * @throws EE_Error
1914
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1915
+	 */
1916
+	public function _reg_details_meta_box()
1917
+	{
1918
+		EEH_Autoloader::register_line_item_display_autoloaders();
1919
+		EEH_Autoloader::register_line_item_filter_autoloaders();
1920
+		EE_Registry::instance()->load_helper('Line_Item');
1921
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1922
+			: EE_Transaction::new_instance();
1923
+		$this->_session = $transaction->session_data();
1924
+		$filters        = new EE_Line_Item_Filter_Collection();
1925
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1926
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1927
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1928
+			$transaction->total_line_item());
1929
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
1930
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1931
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1932
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
1933
+			$filtered_line_item_tree,
1934
+			array('EE_Registration' => $this->_registration)
1935
+		);
1936
+		$attendee                                = $this->_registration->attendee();
1937
+		if (EE_Registry::instance()->CAP->current_user_can(
1938
+			'ee_read_transaction',
1939
+			'espresso_transactions_view_transaction'
1940
+		)) {
1941
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
1942
+				EE_Admin_Page::add_query_args_and_nonce(
1943
+					array(
1944
+						'action' => 'view_transaction',
1945
+						'TXN_ID' => $transaction->ID(),
1946
+					),
1947
+					TXN_ADMIN_URL
1948
+				),
1949
+				esc_html__(' View Transaction', 'event_espresso'),
1950
+				'button secondary-button right',
1951
+				'dashicons dashicons-cart'
1952
+			);
1953
+		} else {
1954
+			$this->_template_args['view_transaction_button'] = '';
1955
+		}
1956
+		if ($attendee instanceof EE_Attendee
1957
+			&& EE_Registry::instance()->CAP->current_user_can(
1958
+				'ee_send_message',
1959
+				'espresso_registrations_resend_registration'
1960
+			)
1961
+		) {
1962
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
1963
+				EE_Admin_Page::add_query_args_and_nonce(
1964
+					array(
1965
+						'action'      => 'resend_registration',
1966
+						'_REG_ID'     => $this->_registration->ID(),
1967
+						'redirect_to' => 'view_registration',
1968
+					),
1969
+					REG_ADMIN_URL
1970
+				),
1971
+				esc_html__(' Resend Registration', 'event_espresso'),
1972
+				'button secondary-button right',
1973
+				'dashicons dashicons-email-alt'
1974
+			);
1975
+		} else {
1976
+			$this->_template_args['resend_registration_button'] = '';
1977
+		}
1978
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1979
+		$payment                               = $transaction->get_first_related('Payment');
1980
+		$payment                               = ! $payment instanceof EE_Payment
1981
+			? EE_Payment::new_instance()
1982
+			: $payment;
1983
+		$payment_method                        = $payment->get_first_related('Payment_Method');
1984
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
1985
+			? EE_Payment_Method::new_instance()
1986
+			: $payment_method;
1987
+		$reg_details                           = array(
1988
+			'payment_method'       => $payment_method->name(),
1989
+			'response_msg'         => $payment->gateway_response(),
1990
+			'registration_id'      => $this->_registration->get('REG_code'),
1991
+			'registration_session' => $this->_registration->session_ID(),
1992
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1993
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1994
+		);
1995
+		if (isset($reg_details['registration_id'])) {
1996
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1997
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
1998
+				'Registration ID',
1999
+				'event_espresso'
2000
+			);
2001
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2002
+		}
2003
+		if (isset($reg_details['payment_method'])) {
2004
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2005
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2006
+				'Most Recent Payment Method',
2007
+				'event_espresso'
2008
+			);
2009
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2010
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2011
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2012
+				'Payment method response',
2013
+				'event_espresso'
2014
+			);
2015
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2016
+		}
2017
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2018
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2019
+			'Registration Session',
2020
+			'event_espresso'
2021
+		);
2022
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2023
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2024
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2025
+			'Registration placed from IP',
2026
+			'event_espresso'
2027
+		);
2028
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2029
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2030
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2031
+			'event_espresso');
2032
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2033
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2034
+			array(
2035
+				'action'   => 'default',
2036
+				'event_id' => $this->_registration->event_ID(),
2037
+			),
2038
+			REG_ADMIN_URL
2039
+		);
2040
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2041
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2042
+		$template_path                                                        =
2043
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2044
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2045
+	}
2046
+
2047
+
2048
+	/**
2049
+	 * generates HTML for the Registration Questions meta box.
2050
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2051
+	 * otherwise uses new forms system
2052
+	 *
2053
+	 * @access public
2054
+	 * @return void
2055
+	 * @throws DomainException
2056
+	 * @throws EE_Error
2057
+	 */
2058
+	public function _reg_questions_meta_box()
2059
+	{
2060
+		//allow someone to override this method entirely
2061
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2062
+			$this->_registration)) {
2063
+			$form                                              = $this->_get_reg_custom_questions_form(
2064
+				$this->_registration->ID()
2065
+			);
2066
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2067
+				? $form->get_html_and_js()
2068
+				: '';
2069
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2070
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2071
+			$template_path                                     =
2072
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2073
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2074
+		}
2075
+	}
2076
+
2077
+
2078
+	/**
2079
+	 * form_before_question_group
2080
+	 *
2081
+	 * @deprecated    as of 4.8.32.rc.000
2082
+	 * @access        public
2083
+	 * @param        string $output
2084
+	 * @return        string
2085
+	 */
2086
+	public function form_before_question_group($output)
2087
+	{
2088
+		EE_Error::doing_it_wrong(
2089
+			__CLASS__ . '::' . __FUNCTION__,
2090
+			esc_html__(
2091
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2092
+				'event_espresso'
2093
+			),
2094
+			'4.8.32.rc.000'
2095
+		);
2096
+		return '
2097 2097
 	<table class="form-table ee-width-100">
2098 2098
 		<tbody>
2099 2099
 			';
2100
-    }
2101
-
2102
-
2103
-    /**
2104
-     * form_after_question_group
2105
-     *
2106
-     * @deprecated    as of 4.8.32.rc.000
2107
-     * @access        public
2108
-     * @param        string $output
2109
-     * @return        string
2110
-     */
2111
-    public function form_after_question_group($output)
2112
-    {
2113
-        EE_Error::doing_it_wrong(
2114
-            __CLASS__ . '::' . __FUNCTION__,
2115
-            esc_html__(
2116
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2117
-                'event_espresso'
2118
-            ),
2119
-            '4.8.32.rc.000'
2120
-        );
2121
-        return '
2100
+	}
2101
+
2102
+
2103
+	/**
2104
+	 * form_after_question_group
2105
+	 *
2106
+	 * @deprecated    as of 4.8.32.rc.000
2107
+	 * @access        public
2108
+	 * @param        string $output
2109
+	 * @return        string
2110
+	 */
2111
+	public function form_after_question_group($output)
2112
+	{
2113
+		EE_Error::doing_it_wrong(
2114
+			__CLASS__ . '::' . __FUNCTION__,
2115
+			esc_html__(
2116
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2117
+				'event_espresso'
2118
+			),
2119
+			'4.8.32.rc.000'
2120
+		);
2121
+		return '
2122 2122
 			<tr class="hide-if-no-js">
2123 2123
 				<th> </th>
2124 2124
 				<td class="reg-admin-edit-attendee-question-td">
2125 2125
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2126
-               . esc_attr__('click to edit question', 'event_espresso')
2127
-               . '">
2126
+			   . esc_attr__('click to edit question', 'event_espresso')
2127
+			   . '">
2128 2128
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2129
-               . esc_html__('edit the above question group', 'event_espresso')
2130
-               . '</span>
2129
+			   . esc_html__('edit the above question group', 'event_espresso')
2130
+			   . '</span>
2131 2131
 						<div class="dashicons dashicons-edit"></div>
2132 2132
 					</a>
2133 2133
 				</td>
@@ -2135,558 +2135,558 @@  discard block
 block discarded – undo
2135 2135
 		</tbody>
2136 2136
 	</table>
2137 2137
 ';
2138
-    }
2139
-
2140
-
2141
-    /**
2142
-     * form_form_field_label_wrap
2143
-     *
2144
-     * @deprecated    as of 4.8.32.rc.000
2145
-     * @access        public
2146
-     * @param        string $label
2147
-     * @return        string
2148
-     */
2149
-    public function form_form_field_label_wrap($label)
2150
-    {
2151
-        EE_Error::doing_it_wrong(
2152
-            __CLASS__ . '::' . __FUNCTION__,
2153
-            esc_html__(
2154
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2155
-                'event_espresso'
2156
-            ),
2157
-            '4.8.32.rc.000'
2158
-        );
2159
-        return '
2138
+	}
2139
+
2140
+
2141
+	/**
2142
+	 * form_form_field_label_wrap
2143
+	 *
2144
+	 * @deprecated    as of 4.8.32.rc.000
2145
+	 * @access        public
2146
+	 * @param        string $label
2147
+	 * @return        string
2148
+	 */
2149
+	public function form_form_field_label_wrap($label)
2150
+	{
2151
+		EE_Error::doing_it_wrong(
2152
+			__CLASS__ . '::' . __FUNCTION__,
2153
+			esc_html__(
2154
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2155
+				'event_espresso'
2156
+			),
2157
+			'4.8.32.rc.000'
2158
+		);
2159
+		return '
2160 2160
 			<tr>
2161 2161
 				<th>
2162 2162
 					' . $label . '
2163 2163
 				</th>';
2164
-    }
2165
-
2166
-
2167
-    /**
2168
-     * form_form_field_input__wrap
2169
-     *
2170
-     * @deprecated    as of 4.8.32.rc.000
2171
-     * @access        public
2172
-     * @param        string $input
2173
-     * @return        string
2174
-     */
2175
-    public function form_form_field_input__wrap($input)
2176
-    {
2177
-        EE_Error::doing_it_wrong(
2178
-            __CLASS__ . '::' . __FUNCTION__,
2179
-            esc_html__(
2180
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2181
-                'event_espresso'
2182
-            ),
2183
-            '4.8.32.rc.000'
2184
-        );
2185
-        return '
2164
+	}
2165
+
2166
+
2167
+	/**
2168
+	 * form_form_field_input__wrap
2169
+	 *
2170
+	 * @deprecated    as of 4.8.32.rc.000
2171
+	 * @access        public
2172
+	 * @param        string $input
2173
+	 * @return        string
2174
+	 */
2175
+	public function form_form_field_input__wrap($input)
2176
+	{
2177
+		EE_Error::doing_it_wrong(
2178
+			__CLASS__ . '::' . __FUNCTION__,
2179
+			esc_html__(
2180
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2181
+				'event_espresso'
2182
+			),
2183
+			'4.8.32.rc.000'
2184
+		);
2185
+		return '
2186 2186
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2187 2187
 					' . $input . '
2188 2188
 				</td>
2189 2189
 			</tr>';
2190
-    }
2191
-
2192
-
2193
-    /**
2194
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2195
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2196
-     * to display the page
2197
-     *
2198
-     * @access protected
2199
-     * @return void
2200
-     * @throws EE_Error
2201
-     */
2202
-    protected function _update_attendee_registration_form()
2203
-    {
2204
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2205
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2206
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2207
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2208
-            if ($success) {
2209
-                $what  = esc_html__('Registration Form', 'event_espresso');
2210
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2211
-                    : array('action' => 'default');
2212
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2213
-            }
2214
-        }
2215
-    }
2216
-
2217
-
2218
-    /**
2219
-     * Gets the form for saving registrations custom questions (if done
2220
-     * previously retrieves the cached form object, which may have validation errors in it)
2221
-     *
2222
-     * @param int $REG_ID
2223
-     * @return EE_Registration_Custom_Questions_Form
2224
-     * @throws EE_Error
2225
-     */
2226
-    protected function _get_reg_custom_questions_form($REG_ID)
2227
-    {
2228
-        if ( ! $this->_reg_custom_questions_form) {
2229
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2230
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2231
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2232
-            );
2233
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2234
-        }
2235
-        return $this->_reg_custom_questions_form;
2236
-    }
2237
-
2238
-
2239
-    /**
2240
-     * Saves
2241
-     *
2242
-     * @access private
2243
-     * @param bool $REG_ID
2244
-     * @return bool
2245
-     * @throws EE_Error
2246
-     */
2247
-    private function _save_reg_custom_questions_form($REG_ID = false)
2248
-    {
2249
-        if ( ! $REG_ID) {
2250
-            EE_Error::add_error(
2251
-                esc_html__(
2252
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2253
-                __FILE__, __FUNCTION__, __LINE__
2254
-            );
2255
-        }
2256
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2257
-        $form->receive_form_submission($this->_req_data);
2258
-        $success = false;
2259
-        if ($form->is_valid()) {
2260
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2261
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2262
-                    $where_conditions    = array(
2263
-                        'QST_ID' => $question_id,
2264
-                        'REG_ID' => $REG_ID,
2265
-                    );
2266
-                    $possibly_new_values = array(
2267
-                        'ANS_value' => $input->normalized_value(),
2268
-                    );
2269
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2270
-                    if ($answer instanceof EE_Answer) {
2271
-                        $success = $answer->save($possibly_new_values);
2272
-                    } else {
2273
-                        //insert it then
2274
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2275
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2276
-                        $success     = $answer->save();
2277
-                    }
2278
-                }
2279
-            }
2280
-        } else {
2281
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2282
-        }
2283
-        return $success;
2284
-    }
2285
-
2286
-
2287
-    /**
2288
-     *        generates HTML for the Registration main meta box
2289
-     *
2290
-     * @access public
2291
-     * @return void
2292
-     * @throws DomainException
2293
-     * @throws EE_Error
2294
-     */
2295
-    public function _reg_attendees_meta_box()
2296
-    {
2297
-        $REG = EEM_Registration::instance();
2298
-        //get all other registrations on this transaction, and cache
2299
-        //the attendees for them so we don't have to run another query using force_join
2300
-        $registrations                           = $REG->get_all(array(
2301
-            array(
2302
-                'TXN_ID' => $this->_registration->transaction_ID(),
2303
-                'REG_ID' => array('!=', $this->_registration->ID()),
2304
-            ),
2305
-            'force_join' => array('Attendee'),
2306
-        ));
2307
-        $this->_template_args['attendees']       = array();
2308
-        $this->_template_args['attendee_notice'] = '';
2309
-        if (empty($registrations)
2310
-            || (is_array($registrations)
2311
-                && ! EEH_Array::get_one_item_from_array($registrations))
2312
-        ) {
2313
-            EE_Error::add_error(
2314
-                esc_html__(
2315
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2316
-                    'event_espresso'
2317
-                ), __FILE__, __FUNCTION__, __LINE__
2318
-            );
2319
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2320
-        } else {
2321
-            $att_nmbr = 1;
2322
-            foreach ($registrations as $registration) {
2323
-                /* @var $registration EE_Registration */
2324
-                $attendee                                                    = $registration->attendee()
2325
-                    ? $registration->attendee()
2326
-                    : EEM_Attendee::instance()
2327
-                                  ->create_default_object();
2328
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2329
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2330
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2331
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2332
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2333
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2334
-                    ', ',
2335
-                    $attendee->full_address_as_array()
2336
-                );
2337
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2338
-                    array(
2339
-                        'action' => 'edit_attendee',
2340
-                        'post'   => $attendee->ID(),
2341
-                    ),
2342
-                    REG_ADMIN_URL
2343
-                );
2344
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2345
-                $att_nmbr++;
2346
-            }
2347
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2348
-        }
2349
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2350
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2351
-    }
2352
-
2353
-
2354
-    /**
2355
-     *        generates HTML for the Edit Registration side meta box
2356
-     *
2357
-     * @access public
2358
-     * @return void
2359
-     * @throws DomainException
2360
-     * @throws EE_Error
2361
-     */
2362
-    public function _reg_registrant_side_meta_box()
2363
-    {
2364
-        /*@var $attendee EE_Attendee */
2365
-        $att_check = $this->_registration->attendee();
2366
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2367
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2368
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2369
-        //primary registration object (that way we know if we need to show create button or not)
2370
-        if ( ! $this->_registration->is_primary_registrant()) {
2371
-            $primary_registration = $this->_registration->get_primary_registration();
2372
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2373
-                : null;
2374
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2375
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2376
-                //custom attendee object so let's not worry about the primary reg.
2377
-                $primary_registration = null;
2378
-            }
2379
-        } else {
2380
-            $primary_registration = null;
2381
-        }
2382
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2383
-        $this->_template_args['fname']             = $attendee->fname();
2384
-        $this->_template_args['lname']             = $attendee->lname();
2385
-        $this->_template_args['email']             = $attendee->email();
2386
-        $this->_template_args['phone']             = $attendee->phone();
2387
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2388
-        //edit link
2389
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2390
-            'action' => 'edit_attendee',
2391
-            'post'   => $attendee->ID(),
2392
-        ), REG_ADMIN_URL);
2393
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2394
-        //create link
2395
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2396
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2397
-                'action'  => 'duplicate_attendee',
2398
-                '_REG_ID' => $this->_registration->ID(),
2399
-            ), REG_ADMIN_URL) : '';
2400
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2401
-        $this->_template_args['att_check']    = $att_check;
2402
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2403
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2404
-    }
2405
-
2406
-
2407
-    /**
2408
-     * trash or restore registrations
2409
-     *
2410
-     * @param  boolean $trash whether to archive or restore
2411
-     * @return void
2412
-     * @throws EE_Error
2413
-     * @throws RuntimeException
2414
-     * @access protected
2415
-     */
2416
-    protected function _trash_or_restore_registrations($trash = true)
2417
-    {
2418
-        //if empty _REG_ID then get out because there's nothing to do
2419
-        if (empty($this->_req_data['_REG_ID'])) {
2420
-            EE_Error::add_error(
2421
-                sprintf(
2422
-                    esc_html__(
2423
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2424
-                        'event_espresso'
2425
-                    ),
2426
-                    $trash ? 'trash' : 'restore'
2427
-                ),
2428
-                __FILE__, __LINE__, __FUNCTION__
2429
-            );
2430
-            $this->_redirect_after_action(false, '', '', array(), true);
2431
-        }
2432
-        $success = 0;
2433
-        $overwrite_msgs = false;
2434
-        //Checkboxes
2435
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2436
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2437
-        }
2438
-        $reg_count = count($this->_req_data['_REG_ID']);
2439
-        // cycle thru checkboxes
2440
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2441
-            /** @var EE_Registration $REG */
2442
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2443
-            $payments = $REG->registration_payments();
2444
-            if (! empty($payments)) {
2445
-                $name = $REG->attendee() instanceof EE_Attendee
2446
-                    ? $REG->attendee()->full_name()
2447
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2448
-                $overwrite_msgs = true;
2449
-                EE_Error::add_error(
2450
-                    sprintf(
2451
-                        esc_html__(
2452
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2453
-                            'event_espresso'
2454
-                        ),
2455
-                        $name
2456
-                    ),
2457
-                    __FILE__, __FUNCTION__, __LINE__
2458
-                );
2459
-                //can't trash this registration because it has payments.
2460
-                continue;
2461
-            }
2462
-            $updated = $trash ? $REG->delete() : $REG->restore();
2463
-            if ($updated) {
2464
-                $success++;
2465
-            }
2466
-        }
2467
-        $this->_redirect_after_action(
2468
-            $success === $reg_count, // were ALL registrations affected?
2469
-            $success > 1
2470
-                ? esc_html__('Registrations', 'event_espresso')
2471
-                : esc_html__('Registration', 'event_espresso'),
2472
-            $trash
2473
-                ? esc_html__('moved to the trash', 'event_espresso')
2474
-                : esc_html__('restored', 'event_espresso'),
2475
-            array('action' => 'default'),
2476
-            $overwrite_msgs
2477
-        );
2478
-    }
2479
-
2480
-
2481
-    /**
2482
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2483
-     * registration but also.
2484
-     * 1. Removing relations to EE_Attendee
2485
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2486
-     * ALSO trashed.
2487
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2488
-     * 4. Removing relationships between all tickets and the related registrations
2489
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2490
-     * 6. Deleting permanently any related Checkins.
2491
-     *
2492
-     * @return void
2493
-     * @throws EE_Error
2494
-     */
2495
-    protected function _delete_registrations()
2496
-    {
2497
-        $REG_MDL = EEM_Registration::instance();
2498
-        $success = 1;
2499
-        //Checkboxes
2500
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2501
-            // if array has more than one element than success message should be plural
2502
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2503
-            // cycle thru checkboxes
2504
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2505
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2506
-                if ( ! $REG instanceof EE_Registration) {
2507
-                    continue;
2508
-                }
2509
-                $deleted = $this->_delete_registration($REG);
2510
-                if ( ! $deleted) {
2511
-                    $success = 0;
2512
-                }
2513
-            }
2514
-        } else {
2515
-            // grab single id and delete
2516
-            $REG_ID  = $this->_req_data['_REG_ID'];
2517
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2518
-            $deleted = $this->_delete_registration($REG);
2519
-            if ( ! $deleted) {
2520
-                $success = 0;
2521
-            }
2522
-        }
2523
-        $what        = $success > 1
2524
-            ? esc_html__('Registrations', 'event_espresso')
2525
-            : esc_html__('Registration', 'event_espresso');
2526
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2527
-        $this->_redirect_after_action(
2528
-            $success,
2529
-            $what,
2530
-            $action_desc,
2531
-            array('action' => 'default'),
2532
-            true
2533
-        );
2534
-    }
2535
-
2536
-
2537
-    /**
2538
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2539
-     * models get affected.
2540
-     *
2541
-     * @param  EE_Registration $REG registration to be deleted permenantly
2542
-     * @return bool true = successful deletion, false = fail.
2543
-     * @throws EE_Error
2544
-     */
2545
-    protected function _delete_registration(EE_Registration $REG)
2546
-    {
2547
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2548
-        //registrations on the transaction that are NOT trashed.
2549
-        $TXN         = $REG->get_first_related('Transaction');
2550
-        $REGS        = $TXN->get_many_related('Registration');
2551
-        $all_trashed = true;
2552
-        foreach ($REGS as $registration) {
2553
-            if ( ! $registration->get('REG_deleted')) {
2554
-                $all_trashed = false;
2555
-            }
2556
-        }
2557
-        if ( ! $all_trashed) {
2558
-            EE_Error::add_error(
2559
-                esc_html__(
2560
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2561
-                    'event_espresso'
2562
-                ),
2563
-                __FILE__, __FUNCTION__, __LINE__
2564
-            );
2565
-            return false;
2566
-        }
2567
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2568
-        //separately from THIS one).
2569
-        foreach ($REGS as $registration) {
2570
-            //delete related answers
2571
-            $registration->delete_related_permanently('Answer');
2572
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2573
-            $attendee = $registration->get_first_related('Attendee');
2574
-            if ($attendee instanceof EE_Attendee) {
2575
-                $registration->_remove_relation_to($attendee, 'Attendee');
2576
-            }
2577
-            //now remove relationships to tickets on this registration.
2578
-            $registration->_remove_relations('Ticket');
2579
-            //now delete permanently the checkins related to this registration.
2580
-            $registration->delete_related_permanently('Checkin');
2581
-            if ($registration->ID() === $REG->ID()) {
2582
-                continue;
2583
-            } //we don't want to delete permanently the existing registration just yet.
2584
-            //remove relation to transaction for these registrations if NOT the existing registrations
2585
-            $registration->_remove_relations('Transaction');
2586
-            //delete permanently any related messages.
2587
-            $registration->delete_related_permanently('Message');
2588
-            //now delete this registration permanently
2589
-            $registration->delete_permanently();
2590
-        }
2591
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2592
-        // (the transaction and line items should be all that's left).
2593
-        // delete the line items related to the transaction for this registration.
2594
-        $TXN->delete_related_permanently('Line_Item');
2595
-        //we need to remove all the relationships on the transaction
2596
-        $TXN->delete_related_permanently('Payment');
2597
-        $TXN->delete_related_permanently('Extra_Meta');
2598
-        $TXN->delete_related_permanently('Message');
2599
-        //now we can delete this REG permanently (and the transaction of course)
2600
-        $REG->delete_related_permanently('Transaction');
2601
-        return $REG->delete_permanently();
2602
-    }
2603
-
2604
-
2605
-    /**
2606
-     *    generates HTML for the Register New Attendee Admin page
2607
-     *
2608
-     * @access private
2609
-     * @throws DomainException
2610
-     * @throws EE_Error
2611
-     */
2612
-    public function new_registration()
2613
-    {
2614
-        if ( ! $this->_set_reg_event()) {
2615
-            throw new EE_Error(
2616
-                esc_html__(
2617
-                    'Unable to continue with registering because there is no Event ID in the request',
2618
-                    'event_espresso'
2619
-                )
2620
-            );
2621
-        }
2622
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2623
-        // gotta start with a clean slate if we're not coming here via ajax
2624
-        if ( ! defined('DOING_AJAX')
2625
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2626
-        ) {
2627
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2628
-        }
2629
-        $this->_template_args['event_name'] = '';
2630
-        // event name
2631
-        if ($this->_reg_event) {
2632
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2633
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2634
-                'action' => 'edit',
2635
-                'post'   => $this->_reg_event->ID(),
2636
-            ), EVENTS_ADMIN_URL);
2637
-            $edit_event_lnk                     = '<a href="'
2638
-                                                  . $edit_event_url
2639
-                                                  . '" title="'
2640
-                                                  . esc_attr__('Edit ', 'event_espresso')
2641
-                                                  . $this->_reg_event->name()
2642
-                                                  . '">'
2643
-                                                  . esc_html__('Edit Event', 'event_espresso')
2644
-                                                  . '</a>';
2645
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2646
-                                                   . $edit_event_lnk
2647
-                                                   . '</span>';
2648
-        }
2649
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2650
-        if (defined('DOING_AJAX')) {
2651
-            $this->_return_json();
2652
-        }
2653
-        // grab header
2654
-        $template_path                              =
2655
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2656
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2657
-            $this->_template_args, true);
2658
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2659
-        // the details template wrapper
2660
-        $this->display_admin_page_with_sidebar();
2661
-    }
2662
-
2663
-
2664
-    /**
2665
-     * This returns the content for a registration step
2666
-     *
2667
-     * @access protected
2668
-     * @return string html
2669
-     * @throws DomainException
2670
-     * @throws EE_Error
2671
-     */
2672
-    protected function _get_registration_step_content()
2673
-    {
2674
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2675
-            $warning_msg = sprintf(
2676
-                esc_html__(
2677
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2678
-                    'event_espresso'
2679
-                ),
2680
-                '<br />',
2681
-                '<h3 class="important-notice">',
2682
-                '</h3>',
2683
-                '<div class="float-right">',
2684
-                '<span id="redirect_timer" class="important-notice">30</span>',
2685
-                '</div>',
2686
-                '<b>',
2687
-                '</b>'
2688
-            );
2689
-            return '
2190
+	}
2191
+
2192
+
2193
+	/**
2194
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2195
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2196
+	 * to display the page
2197
+	 *
2198
+	 * @access protected
2199
+	 * @return void
2200
+	 * @throws EE_Error
2201
+	 */
2202
+	protected function _update_attendee_registration_form()
2203
+	{
2204
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2205
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2206
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2207
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2208
+			if ($success) {
2209
+				$what  = esc_html__('Registration Form', 'event_espresso');
2210
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2211
+					: array('action' => 'default');
2212
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2213
+			}
2214
+		}
2215
+	}
2216
+
2217
+
2218
+	/**
2219
+	 * Gets the form for saving registrations custom questions (if done
2220
+	 * previously retrieves the cached form object, which may have validation errors in it)
2221
+	 *
2222
+	 * @param int $REG_ID
2223
+	 * @return EE_Registration_Custom_Questions_Form
2224
+	 * @throws EE_Error
2225
+	 */
2226
+	protected function _get_reg_custom_questions_form($REG_ID)
2227
+	{
2228
+		if ( ! $this->_reg_custom_questions_form) {
2229
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2230
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2231
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2232
+			);
2233
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2234
+		}
2235
+		return $this->_reg_custom_questions_form;
2236
+	}
2237
+
2238
+
2239
+	/**
2240
+	 * Saves
2241
+	 *
2242
+	 * @access private
2243
+	 * @param bool $REG_ID
2244
+	 * @return bool
2245
+	 * @throws EE_Error
2246
+	 */
2247
+	private function _save_reg_custom_questions_form($REG_ID = false)
2248
+	{
2249
+		if ( ! $REG_ID) {
2250
+			EE_Error::add_error(
2251
+				esc_html__(
2252
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2253
+				__FILE__, __FUNCTION__, __LINE__
2254
+			);
2255
+		}
2256
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2257
+		$form->receive_form_submission($this->_req_data);
2258
+		$success = false;
2259
+		if ($form->is_valid()) {
2260
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2261
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2262
+					$where_conditions    = array(
2263
+						'QST_ID' => $question_id,
2264
+						'REG_ID' => $REG_ID,
2265
+					);
2266
+					$possibly_new_values = array(
2267
+						'ANS_value' => $input->normalized_value(),
2268
+					);
2269
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2270
+					if ($answer instanceof EE_Answer) {
2271
+						$success = $answer->save($possibly_new_values);
2272
+					} else {
2273
+						//insert it then
2274
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2275
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2276
+						$success     = $answer->save();
2277
+					}
2278
+				}
2279
+			}
2280
+		} else {
2281
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2282
+		}
2283
+		return $success;
2284
+	}
2285
+
2286
+
2287
+	/**
2288
+	 *        generates HTML for the Registration main meta box
2289
+	 *
2290
+	 * @access public
2291
+	 * @return void
2292
+	 * @throws DomainException
2293
+	 * @throws EE_Error
2294
+	 */
2295
+	public function _reg_attendees_meta_box()
2296
+	{
2297
+		$REG = EEM_Registration::instance();
2298
+		//get all other registrations on this transaction, and cache
2299
+		//the attendees for them so we don't have to run another query using force_join
2300
+		$registrations                           = $REG->get_all(array(
2301
+			array(
2302
+				'TXN_ID' => $this->_registration->transaction_ID(),
2303
+				'REG_ID' => array('!=', $this->_registration->ID()),
2304
+			),
2305
+			'force_join' => array('Attendee'),
2306
+		));
2307
+		$this->_template_args['attendees']       = array();
2308
+		$this->_template_args['attendee_notice'] = '';
2309
+		if (empty($registrations)
2310
+			|| (is_array($registrations)
2311
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2312
+		) {
2313
+			EE_Error::add_error(
2314
+				esc_html__(
2315
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2316
+					'event_espresso'
2317
+				), __FILE__, __FUNCTION__, __LINE__
2318
+			);
2319
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2320
+		} else {
2321
+			$att_nmbr = 1;
2322
+			foreach ($registrations as $registration) {
2323
+				/* @var $registration EE_Registration */
2324
+				$attendee                                                    = $registration->attendee()
2325
+					? $registration->attendee()
2326
+					: EEM_Attendee::instance()
2327
+								  ->create_default_object();
2328
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2329
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2330
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2331
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2332
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2333
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2334
+					', ',
2335
+					$attendee->full_address_as_array()
2336
+				);
2337
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2338
+					array(
2339
+						'action' => 'edit_attendee',
2340
+						'post'   => $attendee->ID(),
2341
+					),
2342
+					REG_ADMIN_URL
2343
+				);
2344
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2345
+				$att_nmbr++;
2346
+			}
2347
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2348
+		}
2349
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2350
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2351
+	}
2352
+
2353
+
2354
+	/**
2355
+	 *        generates HTML for the Edit Registration side meta box
2356
+	 *
2357
+	 * @access public
2358
+	 * @return void
2359
+	 * @throws DomainException
2360
+	 * @throws EE_Error
2361
+	 */
2362
+	public function _reg_registrant_side_meta_box()
2363
+	{
2364
+		/*@var $attendee EE_Attendee */
2365
+		$att_check = $this->_registration->attendee();
2366
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2367
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2368
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2369
+		//primary registration object (that way we know if we need to show create button or not)
2370
+		if ( ! $this->_registration->is_primary_registrant()) {
2371
+			$primary_registration = $this->_registration->get_primary_registration();
2372
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2373
+				: null;
2374
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2375
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2376
+				//custom attendee object so let's not worry about the primary reg.
2377
+				$primary_registration = null;
2378
+			}
2379
+		} else {
2380
+			$primary_registration = null;
2381
+		}
2382
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2383
+		$this->_template_args['fname']             = $attendee->fname();
2384
+		$this->_template_args['lname']             = $attendee->lname();
2385
+		$this->_template_args['email']             = $attendee->email();
2386
+		$this->_template_args['phone']             = $attendee->phone();
2387
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2388
+		//edit link
2389
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2390
+			'action' => 'edit_attendee',
2391
+			'post'   => $attendee->ID(),
2392
+		), REG_ADMIN_URL);
2393
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2394
+		//create link
2395
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2396
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2397
+				'action'  => 'duplicate_attendee',
2398
+				'_REG_ID' => $this->_registration->ID(),
2399
+			), REG_ADMIN_URL) : '';
2400
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2401
+		$this->_template_args['att_check']    = $att_check;
2402
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2403
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2404
+	}
2405
+
2406
+
2407
+	/**
2408
+	 * trash or restore registrations
2409
+	 *
2410
+	 * @param  boolean $trash whether to archive or restore
2411
+	 * @return void
2412
+	 * @throws EE_Error
2413
+	 * @throws RuntimeException
2414
+	 * @access protected
2415
+	 */
2416
+	protected function _trash_or_restore_registrations($trash = true)
2417
+	{
2418
+		//if empty _REG_ID then get out because there's nothing to do
2419
+		if (empty($this->_req_data['_REG_ID'])) {
2420
+			EE_Error::add_error(
2421
+				sprintf(
2422
+					esc_html__(
2423
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2424
+						'event_espresso'
2425
+					),
2426
+					$trash ? 'trash' : 'restore'
2427
+				),
2428
+				__FILE__, __LINE__, __FUNCTION__
2429
+			);
2430
+			$this->_redirect_after_action(false, '', '', array(), true);
2431
+		}
2432
+		$success = 0;
2433
+		$overwrite_msgs = false;
2434
+		//Checkboxes
2435
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2436
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2437
+		}
2438
+		$reg_count = count($this->_req_data['_REG_ID']);
2439
+		// cycle thru checkboxes
2440
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2441
+			/** @var EE_Registration $REG */
2442
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2443
+			$payments = $REG->registration_payments();
2444
+			if (! empty($payments)) {
2445
+				$name = $REG->attendee() instanceof EE_Attendee
2446
+					? $REG->attendee()->full_name()
2447
+					: esc_html__('Unknown Attendee', 'event_espresso');
2448
+				$overwrite_msgs = true;
2449
+				EE_Error::add_error(
2450
+					sprintf(
2451
+						esc_html__(
2452
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2453
+							'event_espresso'
2454
+						),
2455
+						$name
2456
+					),
2457
+					__FILE__, __FUNCTION__, __LINE__
2458
+				);
2459
+				//can't trash this registration because it has payments.
2460
+				continue;
2461
+			}
2462
+			$updated = $trash ? $REG->delete() : $REG->restore();
2463
+			if ($updated) {
2464
+				$success++;
2465
+			}
2466
+		}
2467
+		$this->_redirect_after_action(
2468
+			$success === $reg_count, // were ALL registrations affected?
2469
+			$success > 1
2470
+				? esc_html__('Registrations', 'event_espresso')
2471
+				: esc_html__('Registration', 'event_espresso'),
2472
+			$trash
2473
+				? esc_html__('moved to the trash', 'event_espresso')
2474
+				: esc_html__('restored', 'event_espresso'),
2475
+			array('action' => 'default'),
2476
+			$overwrite_msgs
2477
+		);
2478
+	}
2479
+
2480
+
2481
+	/**
2482
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2483
+	 * registration but also.
2484
+	 * 1. Removing relations to EE_Attendee
2485
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2486
+	 * ALSO trashed.
2487
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2488
+	 * 4. Removing relationships between all tickets and the related registrations
2489
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2490
+	 * 6. Deleting permanently any related Checkins.
2491
+	 *
2492
+	 * @return void
2493
+	 * @throws EE_Error
2494
+	 */
2495
+	protected function _delete_registrations()
2496
+	{
2497
+		$REG_MDL = EEM_Registration::instance();
2498
+		$success = 1;
2499
+		//Checkboxes
2500
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2501
+			// if array has more than one element than success message should be plural
2502
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2503
+			// cycle thru checkboxes
2504
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2505
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2506
+				if ( ! $REG instanceof EE_Registration) {
2507
+					continue;
2508
+				}
2509
+				$deleted = $this->_delete_registration($REG);
2510
+				if ( ! $deleted) {
2511
+					$success = 0;
2512
+				}
2513
+			}
2514
+		} else {
2515
+			// grab single id and delete
2516
+			$REG_ID  = $this->_req_data['_REG_ID'];
2517
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2518
+			$deleted = $this->_delete_registration($REG);
2519
+			if ( ! $deleted) {
2520
+				$success = 0;
2521
+			}
2522
+		}
2523
+		$what        = $success > 1
2524
+			? esc_html__('Registrations', 'event_espresso')
2525
+			: esc_html__('Registration', 'event_espresso');
2526
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2527
+		$this->_redirect_after_action(
2528
+			$success,
2529
+			$what,
2530
+			$action_desc,
2531
+			array('action' => 'default'),
2532
+			true
2533
+		);
2534
+	}
2535
+
2536
+
2537
+	/**
2538
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2539
+	 * models get affected.
2540
+	 *
2541
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2542
+	 * @return bool true = successful deletion, false = fail.
2543
+	 * @throws EE_Error
2544
+	 */
2545
+	protected function _delete_registration(EE_Registration $REG)
2546
+	{
2547
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2548
+		//registrations on the transaction that are NOT trashed.
2549
+		$TXN         = $REG->get_first_related('Transaction');
2550
+		$REGS        = $TXN->get_many_related('Registration');
2551
+		$all_trashed = true;
2552
+		foreach ($REGS as $registration) {
2553
+			if ( ! $registration->get('REG_deleted')) {
2554
+				$all_trashed = false;
2555
+			}
2556
+		}
2557
+		if ( ! $all_trashed) {
2558
+			EE_Error::add_error(
2559
+				esc_html__(
2560
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2561
+					'event_espresso'
2562
+				),
2563
+				__FILE__, __FUNCTION__, __LINE__
2564
+			);
2565
+			return false;
2566
+		}
2567
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2568
+		//separately from THIS one).
2569
+		foreach ($REGS as $registration) {
2570
+			//delete related answers
2571
+			$registration->delete_related_permanently('Answer');
2572
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2573
+			$attendee = $registration->get_first_related('Attendee');
2574
+			if ($attendee instanceof EE_Attendee) {
2575
+				$registration->_remove_relation_to($attendee, 'Attendee');
2576
+			}
2577
+			//now remove relationships to tickets on this registration.
2578
+			$registration->_remove_relations('Ticket');
2579
+			//now delete permanently the checkins related to this registration.
2580
+			$registration->delete_related_permanently('Checkin');
2581
+			if ($registration->ID() === $REG->ID()) {
2582
+				continue;
2583
+			} //we don't want to delete permanently the existing registration just yet.
2584
+			//remove relation to transaction for these registrations if NOT the existing registrations
2585
+			$registration->_remove_relations('Transaction');
2586
+			//delete permanently any related messages.
2587
+			$registration->delete_related_permanently('Message');
2588
+			//now delete this registration permanently
2589
+			$registration->delete_permanently();
2590
+		}
2591
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2592
+		// (the transaction and line items should be all that's left).
2593
+		// delete the line items related to the transaction for this registration.
2594
+		$TXN->delete_related_permanently('Line_Item');
2595
+		//we need to remove all the relationships on the transaction
2596
+		$TXN->delete_related_permanently('Payment');
2597
+		$TXN->delete_related_permanently('Extra_Meta');
2598
+		$TXN->delete_related_permanently('Message');
2599
+		//now we can delete this REG permanently (and the transaction of course)
2600
+		$REG->delete_related_permanently('Transaction');
2601
+		return $REG->delete_permanently();
2602
+	}
2603
+
2604
+
2605
+	/**
2606
+	 *    generates HTML for the Register New Attendee Admin page
2607
+	 *
2608
+	 * @access private
2609
+	 * @throws DomainException
2610
+	 * @throws EE_Error
2611
+	 */
2612
+	public function new_registration()
2613
+	{
2614
+		if ( ! $this->_set_reg_event()) {
2615
+			throw new EE_Error(
2616
+				esc_html__(
2617
+					'Unable to continue with registering because there is no Event ID in the request',
2618
+					'event_espresso'
2619
+				)
2620
+			);
2621
+		}
2622
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2623
+		// gotta start with a clean slate if we're not coming here via ajax
2624
+		if ( ! defined('DOING_AJAX')
2625
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2626
+		) {
2627
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2628
+		}
2629
+		$this->_template_args['event_name'] = '';
2630
+		// event name
2631
+		if ($this->_reg_event) {
2632
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2633
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2634
+				'action' => 'edit',
2635
+				'post'   => $this->_reg_event->ID(),
2636
+			), EVENTS_ADMIN_URL);
2637
+			$edit_event_lnk                     = '<a href="'
2638
+												  . $edit_event_url
2639
+												  . '" title="'
2640
+												  . esc_attr__('Edit ', 'event_espresso')
2641
+												  . $this->_reg_event->name()
2642
+												  . '">'
2643
+												  . esc_html__('Edit Event', 'event_espresso')
2644
+												  . '</a>';
2645
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2646
+												   . $edit_event_lnk
2647
+												   . '</span>';
2648
+		}
2649
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2650
+		if (defined('DOING_AJAX')) {
2651
+			$this->_return_json();
2652
+		}
2653
+		// grab header
2654
+		$template_path                              =
2655
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2656
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2657
+			$this->_template_args, true);
2658
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2659
+		// the details template wrapper
2660
+		$this->display_admin_page_with_sidebar();
2661
+	}
2662
+
2663
+
2664
+	/**
2665
+	 * This returns the content for a registration step
2666
+	 *
2667
+	 * @access protected
2668
+	 * @return string html
2669
+	 * @throws DomainException
2670
+	 * @throws EE_Error
2671
+	 */
2672
+	protected function _get_registration_step_content()
2673
+	{
2674
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2675
+			$warning_msg = sprintf(
2676
+				esc_html__(
2677
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2678
+					'event_espresso'
2679
+				),
2680
+				'<br />',
2681
+				'<h3 class="important-notice">',
2682
+				'</h3>',
2683
+				'<div class="float-right">',
2684
+				'<span id="redirect_timer" class="important-notice">30</span>',
2685
+				'</div>',
2686
+				'<b>',
2687
+				'</b>'
2688
+			);
2689
+			return '
2690 2690
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2691 2691
 	<script >
2692 2692
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2699,792 +2699,792 @@  discard block
 block discarded – undo
2699 2699
 	        }
2700 2700
 	    }, 800 );
2701 2701
 	</script >';
2702
-        }
2703
-        $template_args = array(
2704
-            'title'                    => '',
2705
-            'content'                  => '',
2706
-            'step_button_text'         => '',
2707
-            'show_notification_toggle' => false,
2708
-        );
2709
-        //to indicate we're processing a new registration
2710
-        $hidden_fields = array(
2711
-            'processing_registration' => array(
2712
-                'type'  => 'hidden',
2713
-                'value' => 0,
2714
-            ),
2715
-            'event_id'                => array(
2716
-                'type'  => 'hidden',
2717
-                'value' => $this->_reg_event->ID(),
2718
-            ),
2719
-        );
2720
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2721
-        $cart = EE_Registry::instance()->SSN->cart();
2722
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2723
-        switch ($step) {
2724
-            case 'ticket' :
2725
-                $hidden_fields['processing_registration']['value'] = 1;
2726
-                $template_args['title']                            = esc_html__(
2727
-                    'Step One: Select the Ticket for this registration',
2728
-                    'event_espresso'
2729
-                );
2730
-                $template_args['content']                          =
2731
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2732
-                $template_args['step_button_text']                 = esc_html__(
2733
-                    'Add Tickets and Continue to Registrant Details',
2734
-                    'event_espresso'
2735
-                );
2736
-                $template_args['show_notification_toggle']         = false;
2737
-                break;
2738
-            case 'questions' :
2739
-                $hidden_fields['processing_registration']['value'] = 2;
2740
-                $template_args['title']                            = esc_html__(
2741
-                    'Step Two: Add Registrant Details for this Registration',
2742
-                    'event_espresso'
2743
-                );
2744
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2745
-                // properly by the first process_reg_step run.
2746
-                $template_args['content']                  =
2747
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2748
-                $template_args['step_button_text']         = esc_html__(
2749
-                    'Save Registration and Continue to Details',
2750
-                    'event_espresso'
2751
-                );
2752
-                $template_args['show_notification_toggle'] = true;
2753
-                break;
2754
-        }
2755
-        //we come back to the process_registration_step route.
2756
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2757
-        return EEH_Template::display_template(
2758
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2759
-            $template_args,
2760
-            true
2761
-        );
2762
-    }
2763
-
2764
-
2765
-    /**
2766
-     *        set_reg_event
2767
-     *
2768
-     * @access private
2769
-     * @return bool
2770
-     * @throws EE_Error
2771
-     */
2772
-    private function _set_reg_event()
2773
-    {
2774
-        if (is_object($this->_reg_event)) {
2775
-            return true;
2776
-        }
2777
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2778
-        if ( ! $EVT_ID) {
2779
-            return false;
2780
-        }
2781
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2782
-        return true;
2783
-    }
2784
-
2785
-
2786
-    /**
2787
-     * process_reg_step
2788
-     *
2789
-     * @access        public
2790
-     * @return string
2791
-     * @throws DomainException
2792
-     * @throws EE_Error
2793
-     * @throws RuntimeException
2794
-     */
2795
-    public function process_reg_step()
2796
-    {
2797
-        EE_System::do_not_cache();
2798
-        $this->_set_reg_event();
2799
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2800
-        EE_Registry::instance()->REQ->set('uts', time());
2801
-        //what step are we on?
2802
-        $cart = EE_Registry::instance()->SSN->cart();
2803
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2804
-        //if doing ajax then we need to verify the nonce
2805
-        if (defined('DOING_AJAX')) {
2806
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2807
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2808
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2809
-        }
2810
-        switch ($step) {
2811
-            case 'ticket' :
2812
-                //process ticket selection
2813
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2814
-                if ($success) {
2815
-                    EE_Error::add_success(
2816
-                        esc_html__(
2817
-                            'Tickets Selected. Now complete the registration.',
2818
-                            'event_espresso'
2819
-                        )
2820
-                    );
2821
-                } else {
2822
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2823
-                }
2824
-                if (defined('DOING_AJAX')) {
2825
-                    $this->new_registration(); //display next step
2826
-                } else {
2827
-                    $query_args = array(
2828
-                        'action'                  => 'new_registration',
2829
-                        'processing_registration' => 1,
2830
-                        'event_id'                => $this->_reg_event->ID(),
2831
-                        'uts'                     => time(),
2832
-                    );
2833
-                    $this->_redirect_after_action(
2834
-                        false,
2835
-                        '',
2836
-                        '',
2837
-                        $query_args,
2838
-                        true
2839
-                    );
2840
-                }
2841
-                break;
2842
-            case 'questions' :
2843
-                if (! isset(
2844
-                    $this->_req_data['txn_reg_status_change'],
2845
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
2846
-                ) {
2847
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2848
-                }
2849
-                //process registration
2850
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2851
-                if ($cart instanceof EE_Cart) {
2852
-                    $grand_total = $cart->get_cart_grand_total();
2853
-                    if ($grand_total instanceof EE_Line_Item) {
2854
-                        $grand_total->save_this_and_descendants_to_txn();
2855
-                    }
2856
-                }
2857
-                if ( ! $transaction instanceof EE_Transaction) {
2858
-                    $query_args = array(
2859
-                        'action'                  => 'new_registration',
2860
-                        'processing_registration' => 2,
2861
-                        'event_id'                => $this->_reg_event->ID(),
2862
-                        'uts'                     => time(),
2863
-                    );
2864
-                    if (defined('DOING_AJAX')) {
2865
-                        //display registration form again because there are errors (maybe validation?)
2866
-                        $this->new_registration();
2867
-                        return;
2868
-                    } else {
2869
-                        $this->_redirect_after_action(
2870
-                            false,
2871
-                            '',
2872
-                            '',
2873
-                            $query_args,
2874
-                            true
2875
-                        );
2876
-                        return;
2877
-                    }
2878
-                }
2879
-                // maybe update status, and make sure to save transaction if not done already
2880
-                if ( ! $transaction->update_status_based_on_total_paid()) {
2881
-                    $transaction->save();
2882
-                }
2883
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2884
-                $this->_req_data = array();
2885
-                $query_args      = array(
2886
-                    'action'        => 'redirect_to_txn',
2887
-                    'TXN_ID'        => $transaction->ID(),
2888
-                    'EVT_ID'        => $this->_reg_event->ID(),
2889
-                    'event_name'    => urlencode($this->_reg_event->name()),
2890
-                    'redirect_from' => 'new_registration',
2891
-                );
2892
-                $this->_redirect_after_action(false, '', '', $query_args, true);
2893
-                break;
2894
-        }
2895
-        //what are you looking here for?  Should be nothing to do at this point.
2896
-    }
2897
-
2898
-
2899
-    /**
2900
-     * redirect_to_txn
2901
-     *
2902
-     * @access public
2903
-     * @return void
2904
-     * @throws EE_Error
2905
-     */
2906
-    public function redirect_to_txn()
2907
-    {
2908
-        EE_System::do_not_cache();
2909
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2910
-        $query_args = array(
2911
-            'action' => 'view_transaction',
2912
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2913
-            'page'   => 'espresso_transactions',
2914
-        );
2915
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2916
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2917
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
2918
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
2919
-        }
2920
-        EE_Error::add_success(
2921
-            esc_html__(
2922
-                'Registration Created.  Please review the transaction and add any payments as necessary',
2923
-                'event_espresso'
2924
-            )
2925
-        );
2926
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2927
-    }
2928
-
2929
-
2930
-    /**
2931
-     *        generates HTML for the Attendee Contact List
2932
-     *
2933
-     * @access protected
2934
-     * @return void
2935
-     */
2936
-    protected function _attendee_contact_list_table()
2937
-    {
2938
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2939
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
2940
-        $this->display_admin_list_table_page_with_no_sidebar();
2941
-    }
2942
-
2943
-
2944
-    /**
2945
-     *        get_attendees
2946
-     *
2947
-     * @param      $per_page
2948
-     * @param bool $count whether to return count or data.
2949
-     * @param bool $trash
2950
-     * @return array
2951
-     * @throws EE_Error
2952
-     * @access public
2953
-     */
2954
-    public function get_attendees($per_page, $count = false, $trash = false)
2955
-    {
2956
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2957
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2958
-        $ATT_MDL                    = EEM_Attendee::instance();
2959
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2960
-        switch ($this->_req_data['orderby']) {
2961
-            case 'ATT_ID':
2962
-                $orderby = 'ATT_ID';
2963
-                break;
2964
-            case 'ATT_fname':
2965
-                $orderby = 'ATT_fname';
2966
-                break;
2967
-            case 'ATT_email':
2968
-                $orderby = 'ATT_email';
2969
-                break;
2970
-            case 'ATT_city':
2971
-                $orderby = 'ATT_city';
2972
-                break;
2973
-            case 'STA_ID':
2974
-                $orderby = 'STA_ID';
2975
-                break;
2976
-            case 'CNT_ID':
2977
-                $orderby = 'CNT_ID';
2978
-                break;
2979
-            default:
2980
-                $orderby = 'ATT_lname';
2981
-        }
2982
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
2983
-            ? $this->_req_data['order']
2984
-            : 'ASC';
2985
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2986
-            ? $this->_req_data['paged']
2987
-            : 1;
2988
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2989
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2990
-            ? $this->_req_data['perpage']
2991
-            : $per_page;
2992
-        $_where       = array();
2993
-        if ( ! empty($this->_req_data['s'])) {
2994
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2995
-            $_where['OR'] = array(
2996
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2997
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
2998
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
2999
-                'ATT_fname'                         => array('LIKE', $sstr),
3000
-                'ATT_lname'                         => array('LIKE', $sstr),
3001
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3002
-                'ATT_email'                         => array('LIKE', $sstr),
3003
-                'ATT_address'                       => array('LIKE', $sstr),
3004
-                'ATT_address2'                      => array('LIKE', $sstr),
3005
-                'ATT_city'                          => array('LIKE', $sstr),
3006
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3007
-                'State.STA_name'                    => array('LIKE', $sstr),
3008
-                'ATT_phone'                         => array('LIKE', $sstr),
3009
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3010
-                'Registration.REG_code'             => array('LIKE', $sstr),
3011
-                'Registration.REG_count'            => array('LIKE', $sstr),
3012
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3013
-            );
3014
-        }
3015
-        $offset = ($current_page - 1) * $per_page;
3016
-        $limit  = $count ? null : array($offset, $per_page);
3017
-        if ($trash) {
3018
-            $_where['status'] = array('!=', 'publish');
3019
-            $all_attendees    = $count
3020
-                ? $ATT_MDL->count(array(
3021
-                    $_where,
3022
-                    'order_by' => array($orderby => $sort),
3023
-                    'limit'    => $limit,
3024
-                ), 'ATT_ID', true)
3025
-                : $ATT_MDL->get_all(array(
3026
-                    $_where,
3027
-                    'order_by' => array($orderby => $sort),
3028
-                    'limit'    => $limit,
3029
-                ));
3030
-        } else {
3031
-            $_where['status'] = array('IN', array('publish'));
3032
-            $all_attendees    = $count
3033
-                ? $ATT_MDL->count(array(
3034
-                    $_where,
3035
-                    'order_by' => array($orderby => $sort),
3036
-                    'limit'    => $limit,
3037
-                ), 'ATT_ID', true)
3038
-                : $ATT_MDL->get_all(array(
3039
-                    $_where,
3040
-                    'order_by' => array($orderby => $sort),
3041
-                    'limit'    => $limit,
3042
-                ));
3043
-        }
3044
-        return $all_attendees;
3045
-    }
3046
-
3047
-
3048
-    /**
3049
-     * This is just taking care of resending the registration confirmation
3050
-     *
3051
-     * @access protected
3052
-     * @return void
3053
-     */
3054
-    protected function _resend_registration()
3055
-    {
3056
-        $this->_process_resend_registration();
3057
-        $query_args = isset($this->_req_data['redirect_to'])
3058
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3059
-            : array('action' => 'default');
3060
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3061
-    }
3062
-
3063
-    /**
3064
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3065
-     * to use when selecting registrations
3066
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3067
-     *                                                     the query parameters from the request
3068
-     * @return void ends the request with a redirect or download
3069
-     */
3070
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3071
-    {
3072
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3073
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3074
-                array(
3075
-                    'page'        => 'espresso_batch',
3076
-                    'batch'       => 'file',
3077
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3078
-                    'filters'     => urlencode(
3079
-                        serialize(
3080
-                            call_user_func(
3081
-                                array( $this, $method_name_for_getting_query_params ),
3082
-                                EEH_Array::is_set(
3083
-                                    $this->_req_data,
3084
-                                    'filters',
3085
-                                    array()
3086
-                                )
3087
-                            )
3088
-                        )
3089
-                ),
3090
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3091
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3092
-                'return_url'  => urlencode($this->_req_data['return_url']),
3093
-            )));
3094
-        } else {
3095
-            $new_request_args = array(
3096
-                'export' => 'report',
3097
-                'action' => 'registrations_report_for_event',
3098
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3099
-            );
3100
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3101
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3102
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3103
-                $EE_Export = EE_Export::instance($this->_req_data);
3104
-                $EE_Export->export();
3105
-            }
3106
-        }
3107
-    }
3108
-
3109
-
3110
-
3111
-    /**
3112
-     * Creates a registration report using only query parameters in the request
3113
-     * @return void
3114
-     */
3115
-    public function _registrations_report()
3116
-    {
3117
-        $this->_registrations_report_base('_get_registration_query_parameters');
3118
-    }
3119
-
3120
-
3121
-    public function _contact_list_export()
3122
-    {
3123
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3124
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3125
-            $EE_Export = EE_Export::instance($this->_req_data);
3126
-            $EE_Export->export_attendees();
3127
-        }
3128
-    }
3129
-
3130
-
3131
-    public function _contact_list_report()
3132
-    {
3133
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3134
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3135
-                'page'        => 'espresso_batch',
3136
-                'batch'       => 'file',
3137
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3138
-                'return_url'  => urlencode($this->_req_data['return_url']),
3139
-            )));
3140
-        } else {
3141
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3142
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3143
-                $EE_Export = EE_Export::instance($this->_req_data);
3144
-                $EE_Export->report_attendees();
3145
-            }
3146
-        }
3147
-    }
3148
-
3149
-
3150
-
3151
-
3152
-
3153
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3154
-    /**
3155
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3156
-     *
3157
-     * @return void
3158
-     * @throws EE_Error
3159
-     */
3160
-    protected function _duplicate_attendee()
3161
-    {
3162
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3163
-        //verify we have necessary info
3164
-        if (empty($this->_req_data['_REG_ID'])) {
3165
-            EE_Error::add_error(
3166
-                esc_html__(
3167
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3168
-                    'event_espresso'
3169
-                ), __FILE__, __LINE__, __FUNCTION__
3170
-            );
3171
-            $query_args = array('action' => $action);
3172
-            $this->_redirect_after_action('', '', '', $query_args, true);
3173
-        }
3174
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3175
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3176
-        $attendee     = $registration->attendee();
3177
-        //remove relation of existing attendee on registration
3178
-        $registration->_remove_relation_to($attendee, 'Attendee');
3179
-        //new attendee
3180
-        $new_attendee = clone $attendee;
3181
-        $new_attendee->set('ATT_ID', 0);
3182
-        $new_attendee->save();
3183
-        //add new attendee to reg
3184
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3185
-        EE_Error::add_success(
3186
-            esc_html__(
3187
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3188
-                'event_espresso'
3189
-            )
3190
-        );
3191
-        //redirect to edit page for attendee
3192
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3193
-        $this->_redirect_after_action('', '', '', $query_args, true);
3194
-    }
3195
-
3196
-
3197
-    //related to cpt routes
3198
-    protected function _insert_update_cpt_item($post_id, $post)
3199
-    {
3200
-        $success  = true;
3201
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3202
-        //for attendee updates
3203
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3204
-            //note we should only be UPDATING attendees at this point.
3205
-            $updated_fields = array(
3206
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3207
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3208
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3209
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3210
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3211
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3212
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3213
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3214
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3215
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3216
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3217
-            );
3218
-            foreach ($updated_fields as $field => $value) {
3219
-                $attendee->set($field, $value);
3220
-            }
3221
-            $success                   = $attendee->save();
3222
-            $attendee_update_callbacks = apply_filters(
3223
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3224
-                array()
3225
-            );
3226
-            foreach ($attendee_update_callbacks as $a_callback) {
3227
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3228
-                    throw new EE_Error(
3229
-                        sprintf(
3230
-                            esc_html__(
3231
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3232
-                                'event_espresso'
3233
-                            ),
3234
-                            $a_callback
3235
-                        )
3236
-                    );
3237
-                }
3238
-            }
3239
-        }
3240
-        if ($success === false) {
3241
-            EE_Error::add_error(
3242
-                esc_html__(
3243
-                    'Something went wrong with updating the meta table data for the registration.',
3244
-                    'event_espresso'
3245
-                ),
3246
-                __FILE__, __FUNCTION__, __LINE__
3247
-            );
3248
-        }
3249
-    }
3250
-
3251
-
3252
-    public function trash_cpt_item($post_id)
3253
-    {
3254
-    }
3255
-
3256
-
3257
-    public function delete_cpt_item($post_id)
3258
-    {
3259
-    }
3260
-
3261
-
3262
-    public function restore_cpt_item($post_id)
3263
-    {
3264
-    }
3265
-
3266
-
3267
-    protected function _restore_cpt_item($post_id, $revision_id)
3268
-    {
3269
-    }
3270
-
3271
-
3272
-    public function attendee_editor_metaboxes()
3273
-    {
3274
-        $this->verify_cpt_object();
3275
-        remove_meta_box(
3276
-            'postexcerpt',
3277
-            esc_html__('Excerpt', 'event_espresso'),
3278
-            'post_excerpt_meta_box',
3279
-            $this->_cpt_routes[$this->_req_action],
3280
-            'normal',
3281
-            'core'
3282
-        );
3283
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3284
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3285
-            add_meta_box(
3286
-                'postexcerpt',
3287
-                esc_html__('Short Biography', 'event_espresso'),
3288
-                'post_excerpt_meta_box',
3289
-                $this->_cpt_routes[$this->_req_action],
3290
-                'normal'
3291
-            );
3292
-        }
3293
-        if (post_type_supports('espresso_attendees', 'comments')) {
3294
-            add_meta_box(
3295
-                'commentsdiv',
3296
-                esc_html__('Notes on the Contact', 'event_espresso'),
3297
-                'post_comment_meta_box',
3298
-                $this->_cpt_routes[$this->_req_action],
3299
-                'normal',
3300
-                'core'
3301
-            );
3302
-        }
3303
-        add_meta_box(
3304
-            'attendee_contact_info',
3305
-            esc_html__('Contact Info', 'event_espresso'),
3306
-            array($this, 'attendee_contact_info'),
3307
-            $this->_cpt_routes[$this->_req_action],
3308
-            'side',
3309
-            'core'
3310
-        );
3311
-        add_meta_box(
3312
-            'attendee_details_address',
3313
-            esc_html__('Address Details', 'event_espresso'),
3314
-            array($this, 'attendee_address_details'),
3315
-            $this->_cpt_routes[$this->_req_action],
3316
-            'normal',
3317
-            'core'
3318
-        );
3319
-        add_meta_box(
3320
-            'attendee_registrations',
3321
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3322
-            array($this, 'attendee_registrations_meta_box'),
3323
-            $this->_cpt_routes[$this->_req_action],
3324
-            'normal',
3325
-            'high'
3326
-        );
3327
-    }
3328
-
3329
-
3330
-    /**
3331
-     * Metabox for attendee contact info
3332
-     *
3333
-     * @param  WP_Post $post wp post object
3334
-     * @return string attendee contact info ( and form )
3335
-     * @throws DomainException
3336
-     */
3337
-    public function attendee_contact_info($post)
3338
-    {
3339
-        //get attendee object ( should already have it )
3340
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3341
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3342
-        EEH_Template::display_template($template, $this->_template_args);
3343
-    }
3344
-
3345
-
3346
-    /**
3347
-     * Metabox for attendee details
3348
-     *
3349
-     * @param  WP_Post $post wp post object
3350
-     * @return string attendee address details (and form)
3351
-     * @throws DomainException
3352
-     */
3353
-    public function attendee_address_details($post)
3354
-    {
3355
-        //get attendee object (should already have it)
3356
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3357
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3358
-            new EE_Question_Form_Input(
3359
-                EE_Question::new_instance(
3360
-                    array(
3361
-                        'QST_ID'           => 0,
3362
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3363
-                        'QST_system'       => 'admin-state',
3364
-                    )
3365
-                ),
3366
-                EE_Answer::new_instance(
3367
-                    array(
3368
-                        'ANS_ID'    => 0,
3369
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3370
-                    )
3371
-                ),
3372
-                array(
3373
-                    'input_id'       => 'STA_ID',
3374
-                    'input_name'     => 'STA_ID',
3375
-                    'input_prefix'   => '',
3376
-                    'append_qstn_id' => false,
3377
-                )
3378
-            )
3379
-        );
3380
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3381
-            new EE_Question_Form_Input(
3382
-                EE_Question::new_instance(
3383
-                    array(
3384
-                        'QST_ID'           => 0,
3385
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3386
-                        'QST_system'       => 'admin-country',
3387
-                    )
3388
-                ),
3389
-                EE_Answer::new_instance(
3390
-                    array(
3391
-                        'ANS_ID'    => 0,
3392
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3393
-                    )
3394
-                ),
3395
-                array(
3396
-                    'input_id'       => 'CNT_ISO',
3397
-                    'input_name'     => 'CNT_ISO',
3398
-                    'input_prefix'   => '',
3399
-                    'append_qstn_id' => false,
3400
-                )
3401
-            )
3402
-        );
3403
-        $template                             =
3404
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3405
-        EEH_Template::display_template($template, $this->_template_args);
3406
-    }
3407
-
3408
-
3409
-    /**
3410
-     *        _attendee_details
3411
-     *
3412
-     * @access protected
3413
-     * @param $post
3414
-     * @return void
3415
-     * @throws DomainException
3416
-     * @throws EE_Error
3417
-     */
3418
-    public function attendee_registrations_meta_box($post)
3419
-    {
3420
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3421
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3422
-        $template                              =
3423
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3424
-        EEH_Template::display_template($template, $this->_template_args);
3425
-    }
3426
-
3427
-
3428
-    /**
3429
-     * add in the form fields for the attendee edit
3430
-     *
3431
-     * @param  WP_Post $post wp post object
3432
-     * @return string html for new form.
3433
-     * @throws DomainException
3434
-     */
3435
-    public function after_title_form_fields($post)
3436
-    {
3437
-        if ($post->post_type == 'espresso_attendees') {
3438
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3439
-            $template_args['attendee'] = $this->_cpt_model_obj;
3440
-            EEH_Template::display_template($template, $template_args);
3441
-        }
3442
-    }
3443
-
3444
-
3445
-    /**
3446
-     *        _trash_or_restore_attendee
3447
-     *
3448
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3449
-     * @return void
3450
-     * @throws EE_Error
3451
-     * @access protected
3452
-     */
3453
-    protected function _trash_or_restore_attendees($trash = true)
3454
-    {
3455
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3456
-        $ATT_MDL = EEM_Attendee::instance();
3457
-        $success = 1;
3458
-        //Checkboxes
3459
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3460
-            // if array has more than one element than success message should be plural
3461
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3462
-            // cycle thru checkboxes
3463
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3464
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3465
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3466
-                if ( ! $updated) {
3467
-                    $success = 0;
3468
-                }
3469
-            }
3470
-        } else {
3471
-            // grab single id and delete
3472
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3473
-            //get attendee
3474
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3475
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3476
-            $updated = $att->save();
3477
-            if ( ! $updated) {
3478
-                $success = 0;
3479
-            }
3480
-        }
3481
-        $what        = $success > 1
3482
-            ? esc_html__('Contacts', 'event_espresso')
3483
-            : esc_html__('Contact', 'event_espresso');
3484
-        $action_desc = $trash
3485
-            ? esc_html__('moved to the trash', 'event_espresso')
3486
-            : esc_html__('restored', 'event_espresso');
3487
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3488
-    }
2702
+		}
2703
+		$template_args = array(
2704
+			'title'                    => '',
2705
+			'content'                  => '',
2706
+			'step_button_text'         => '',
2707
+			'show_notification_toggle' => false,
2708
+		);
2709
+		//to indicate we're processing a new registration
2710
+		$hidden_fields = array(
2711
+			'processing_registration' => array(
2712
+				'type'  => 'hidden',
2713
+				'value' => 0,
2714
+			),
2715
+			'event_id'                => array(
2716
+				'type'  => 'hidden',
2717
+				'value' => $this->_reg_event->ID(),
2718
+			),
2719
+		);
2720
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2721
+		$cart = EE_Registry::instance()->SSN->cart();
2722
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2723
+		switch ($step) {
2724
+			case 'ticket' :
2725
+				$hidden_fields['processing_registration']['value'] = 1;
2726
+				$template_args['title']                            = esc_html__(
2727
+					'Step One: Select the Ticket for this registration',
2728
+					'event_espresso'
2729
+				);
2730
+				$template_args['content']                          =
2731
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2732
+				$template_args['step_button_text']                 = esc_html__(
2733
+					'Add Tickets and Continue to Registrant Details',
2734
+					'event_espresso'
2735
+				);
2736
+				$template_args['show_notification_toggle']         = false;
2737
+				break;
2738
+			case 'questions' :
2739
+				$hidden_fields['processing_registration']['value'] = 2;
2740
+				$template_args['title']                            = esc_html__(
2741
+					'Step Two: Add Registrant Details for this Registration',
2742
+					'event_espresso'
2743
+				);
2744
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2745
+				// properly by the first process_reg_step run.
2746
+				$template_args['content']                  =
2747
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2748
+				$template_args['step_button_text']         = esc_html__(
2749
+					'Save Registration and Continue to Details',
2750
+					'event_espresso'
2751
+				);
2752
+				$template_args['show_notification_toggle'] = true;
2753
+				break;
2754
+		}
2755
+		//we come back to the process_registration_step route.
2756
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2757
+		return EEH_Template::display_template(
2758
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2759
+			$template_args,
2760
+			true
2761
+		);
2762
+	}
2763
+
2764
+
2765
+	/**
2766
+	 *        set_reg_event
2767
+	 *
2768
+	 * @access private
2769
+	 * @return bool
2770
+	 * @throws EE_Error
2771
+	 */
2772
+	private function _set_reg_event()
2773
+	{
2774
+		if (is_object($this->_reg_event)) {
2775
+			return true;
2776
+		}
2777
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2778
+		if ( ! $EVT_ID) {
2779
+			return false;
2780
+		}
2781
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2782
+		return true;
2783
+	}
2784
+
2785
+
2786
+	/**
2787
+	 * process_reg_step
2788
+	 *
2789
+	 * @access        public
2790
+	 * @return string
2791
+	 * @throws DomainException
2792
+	 * @throws EE_Error
2793
+	 * @throws RuntimeException
2794
+	 */
2795
+	public function process_reg_step()
2796
+	{
2797
+		EE_System::do_not_cache();
2798
+		$this->_set_reg_event();
2799
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2800
+		EE_Registry::instance()->REQ->set('uts', time());
2801
+		//what step are we on?
2802
+		$cart = EE_Registry::instance()->SSN->cart();
2803
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2804
+		//if doing ajax then we need to verify the nonce
2805
+		if (defined('DOING_AJAX')) {
2806
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2807
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2808
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2809
+		}
2810
+		switch ($step) {
2811
+			case 'ticket' :
2812
+				//process ticket selection
2813
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2814
+				if ($success) {
2815
+					EE_Error::add_success(
2816
+						esc_html__(
2817
+							'Tickets Selected. Now complete the registration.',
2818
+							'event_espresso'
2819
+						)
2820
+					);
2821
+				} else {
2822
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2823
+				}
2824
+				if (defined('DOING_AJAX')) {
2825
+					$this->new_registration(); //display next step
2826
+				} else {
2827
+					$query_args = array(
2828
+						'action'                  => 'new_registration',
2829
+						'processing_registration' => 1,
2830
+						'event_id'                => $this->_reg_event->ID(),
2831
+						'uts'                     => time(),
2832
+					);
2833
+					$this->_redirect_after_action(
2834
+						false,
2835
+						'',
2836
+						'',
2837
+						$query_args,
2838
+						true
2839
+					);
2840
+				}
2841
+				break;
2842
+			case 'questions' :
2843
+				if (! isset(
2844
+					$this->_req_data['txn_reg_status_change'],
2845
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
2846
+				) {
2847
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2848
+				}
2849
+				//process registration
2850
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2851
+				if ($cart instanceof EE_Cart) {
2852
+					$grand_total = $cart->get_cart_grand_total();
2853
+					if ($grand_total instanceof EE_Line_Item) {
2854
+						$grand_total->save_this_and_descendants_to_txn();
2855
+					}
2856
+				}
2857
+				if ( ! $transaction instanceof EE_Transaction) {
2858
+					$query_args = array(
2859
+						'action'                  => 'new_registration',
2860
+						'processing_registration' => 2,
2861
+						'event_id'                => $this->_reg_event->ID(),
2862
+						'uts'                     => time(),
2863
+					);
2864
+					if (defined('DOING_AJAX')) {
2865
+						//display registration form again because there are errors (maybe validation?)
2866
+						$this->new_registration();
2867
+						return;
2868
+					} else {
2869
+						$this->_redirect_after_action(
2870
+							false,
2871
+							'',
2872
+							'',
2873
+							$query_args,
2874
+							true
2875
+						);
2876
+						return;
2877
+					}
2878
+				}
2879
+				// maybe update status, and make sure to save transaction if not done already
2880
+				if ( ! $transaction->update_status_based_on_total_paid()) {
2881
+					$transaction->save();
2882
+				}
2883
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2884
+				$this->_req_data = array();
2885
+				$query_args      = array(
2886
+					'action'        => 'redirect_to_txn',
2887
+					'TXN_ID'        => $transaction->ID(),
2888
+					'EVT_ID'        => $this->_reg_event->ID(),
2889
+					'event_name'    => urlencode($this->_reg_event->name()),
2890
+					'redirect_from' => 'new_registration',
2891
+				);
2892
+				$this->_redirect_after_action(false, '', '', $query_args, true);
2893
+				break;
2894
+		}
2895
+		//what are you looking here for?  Should be nothing to do at this point.
2896
+	}
2897
+
2898
+
2899
+	/**
2900
+	 * redirect_to_txn
2901
+	 *
2902
+	 * @access public
2903
+	 * @return void
2904
+	 * @throws EE_Error
2905
+	 */
2906
+	public function redirect_to_txn()
2907
+	{
2908
+		EE_System::do_not_cache();
2909
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2910
+		$query_args = array(
2911
+			'action' => 'view_transaction',
2912
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2913
+			'page'   => 'espresso_transactions',
2914
+		);
2915
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2916
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2917
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
2918
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
2919
+		}
2920
+		EE_Error::add_success(
2921
+			esc_html__(
2922
+				'Registration Created.  Please review the transaction and add any payments as necessary',
2923
+				'event_espresso'
2924
+			)
2925
+		);
2926
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2927
+	}
2928
+
2929
+
2930
+	/**
2931
+	 *        generates HTML for the Attendee Contact List
2932
+	 *
2933
+	 * @access protected
2934
+	 * @return void
2935
+	 */
2936
+	protected function _attendee_contact_list_table()
2937
+	{
2938
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2939
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
2940
+		$this->display_admin_list_table_page_with_no_sidebar();
2941
+	}
2942
+
2943
+
2944
+	/**
2945
+	 *        get_attendees
2946
+	 *
2947
+	 * @param      $per_page
2948
+	 * @param bool $count whether to return count or data.
2949
+	 * @param bool $trash
2950
+	 * @return array
2951
+	 * @throws EE_Error
2952
+	 * @access public
2953
+	 */
2954
+	public function get_attendees($per_page, $count = false, $trash = false)
2955
+	{
2956
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2957
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2958
+		$ATT_MDL                    = EEM_Attendee::instance();
2959
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2960
+		switch ($this->_req_data['orderby']) {
2961
+			case 'ATT_ID':
2962
+				$orderby = 'ATT_ID';
2963
+				break;
2964
+			case 'ATT_fname':
2965
+				$orderby = 'ATT_fname';
2966
+				break;
2967
+			case 'ATT_email':
2968
+				$orderby = 'ATT_email';
2969
+				break;
2970
+			case 'ATT_city':
2971
+				$orderby = 'ATT_city';
2972
+				break;
2973
+			case 'STA_ID':
2974
+				$orderby = 'STA_ID';
2975
+				break;
2976
+			case 'CNT_ID':
2977
+				$orderby = 'CNT_ID';
2978
+				break;
2979
+			default:
2980
+				$orderby = 'ATT_lname';
2981
+		}
2982
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
2983
+			? $this->_req_data['order']
2984
+			: 'ASC';
2985
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2986
+			? $this->_req_data['paged']
2987
+			: 1;
2988
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2989
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2990
+			? $this->_req_data['perpage']
2991
+			: $per_page;
2992
+		$_where       = array();
2993
+		if ( ! empty($this->_req_data['s'])) {
2994
+			$sstr         = '%' . $this->_req_data['s'] . '%';
2995
+			$_where['OR'] = array(
2996
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2997
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
2998
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
2999
+				'ATT_fname'                         => array('LIKE', $sstr),
3000
+				'ATT_lname'                         => array('LIKE', $sstr),
3001
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3002
+				'ATT_email'                         => array('LIKE', $sstr),
3003
+				'ATT_address'                       => array('LIKE', $sstr),
3004
+				'ATT_address2'                      => array('LIKE', $sstr),
3005
+				'ATT_city'                          => array('LIKE', $sstr),
3006
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3007
+				'State.STA_name'                    => array('LIKE', $sstr),
3008
+				'ATT_phone'                         => array('LIKE', $sstr),
3009
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3010
+				'Registration.REG_code'             => array('LIKE', $sstr),
3011
+				'Registration.REG_count'            => array('LIKE', $sstr),
3012
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3013
+			);
3014
+		}
3015
+		$offset = ($current_page - 1) * $per_page;
3016
+		$limit  = $count ? null : array($offset, $per_page);
3017
+		if ($trash) {
3018
+			$_where['status'] = array('!=', 'publish');
3019
+			$all_attendees    = $count
3020
+				? $ATT_MDL->count(array(
3021
+					$_where,
3022
+					'order_by' => array($orderby => $sort),
3023
+					'limit'    => $limit,
3024
+				), 'ATT_ID', true)
3025
+				: $ATT_MDL->get_all(array(
3026
+					$_where,
3027
+					'order_by' => array($orderby => $sort),
3028
+					'limit'    => $limit,
3029
+				));
3030
+		} else {
3031
+			$_where['status'] = array('IN', array('publish'));
3032
+			$all_attendees    = $count
3033
+				? $ATT_MDL->count(array(
3034
+					$_where,
3035
+					'order_by' => array($orderby => $sort),
3036
+					'limit'    => $limit,
3037
+				), 'ATT_ID', true)
3038
+				: $ATT_MDL->get_all(array(
3039
+					$_where,
3040
+					'order_by' => array($orderby => $sort),
3041
+					'limit'    => $limit,
3042
+				));
3043
+		}
3044
+		return $all_attendees;
3045
+	}
3046
+
3047
+
3048
+	/**
3049
+	 * This is just taking care of resending the registration confirmation
3050
+	 *
3051
+	 * @access protected
3052
+	 * @return void
3053
+	 */
3054
+	protected function _resend_registration()
3055
+	{
3056
+		$this->_process_resend_registration();
3057
+		$query_args = isset($this->_req_data['redirect_to'])
3058
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3059
+			: array('action' => 'default');
3060
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3061
+	}
3062
+
3063
+	/**
3064
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3065
+	 * to use when selecting registrations
3066
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3067
+	 *                                                     the query parameters from the request
3068
+	 * @return void ends the request with a redirect or download
3069
+	 */
3070
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3071
+	{
3072
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3073
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3074
+				array(
3075
+					'page'        => 'espresso_batch',
3076
+					'batch'       => 'file',
3077
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3078
+					'filters'     => urlencode(
3079
+						serialize(
3080
+							call_user_func(
3081
+								array( $this, $method_name_for_getting_query_params ),
3082
+								EEH_Array::is_set(
3083
+									$this->_req_data,
3084
+									'filters',
3085
+									array()
3086
+								)
3087
+							)
3088
+						)
3089
+				),
3090
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3091
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3092
+				'return_url'  => urlencode($this->_req_data['return_url']),
3093
+			)));
3094
+		} else {
3095
+			$new_request_args = array(
3096
+				'export' => 'report',
3097
+				'action' => 'registrations_report_for_event',
3098
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3099
+			);
3100
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3101
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3102
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3103
+				$EE_Export = EE_Export::instance($this->_req_data);
3104
+				$EE_Export->export();
3105
+			}
3106
+		}
3107
+	}
3108
+
3109
+
3110
+
3111
+	/**
3112
+	 * Creates a registration report using only query parameters in the request
3113
+	 * @return void
3114
+	 */
3115
+	public function _registrations_report()
3116
+	{
3117
+		$this->_registrations_report_base('_get_registration_query_parameters');
3118
+	}
3119
+
3120
+
3121
+	public function _contact_list_export()
3122
+	{
3123
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3124
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3125
+			$EE_Export = EE_Export::instance($this->_req_data);
3126
+			$EE_Export->export_attendees();
3127
+		}
3128
+	}
3129
+
3130
+
3131
+	public function _contact_list_report()
3132
+	{
3133
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3134
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3135
+				'page'        => 'espresso_batch',
3136
+				'batch'       => 'file',
3137
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3138
+				'return_url'  => urlencode($this->_req_data['return_url']),
3139
+			)));
3140
+		} else {
3141
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3142
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3143
+				$EE_Export = EE_Export::instance($this->_req_data);
3144
+				$EE_Export->report_attendees();
3145
+			}
3146
+		}
3147
+	}
3148
+
3149
+
3150
+
3151
+
3152
+
3153
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3154
+	/**
3155
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3156
+	 *
3157
+	 * @return void
3158
+	 * @throws EE_Error
3159
+	 */
3160
+	protected function _duplicate_attendee()
3161
+	{
3162
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3163
+		//verify we have necessary info
3164
+		if (empty($this->_req_data['_REG_ID'])) {
3165
+			EE_Error::add_error(
3166
+				esc_html__(
3167
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3168
+					'event_espresso'
3169
+				), __FILE__, __LINE__, __FUNCTION__
3170
+			);
3171
+			$query_args = array('action' => $action);
3172
+			$this->_redirect_after_action('', '', '', $query_args, true);
3173
+		}
3174
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3175
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3176
+		$attendee     = $registration->attendee();
3177
+		//remove relation of existing attendee on registration
3178
+		$registration->_remove_relation_to($attendee, 'Attendee');
3179
+		//new attendee
3180
+		$new_attendee = clone $attendee;
3181
+		$new_attendee->set('ATT_ID', 0);
3182
+		$new_attendee->save();
3183
+		//add new attendee to reg
3184
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3185
+		EE_Error::add_success(
3186
+			esc_html__(
3187
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3188
+				'event_espresso'
3189
+			)
3190
+		);
3191
+		//redirect to edit page for attendee
3192
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3193
+		$this->_redirect_after_action('', '', '', $query_args, true);
3194
+	}
3195
+
3196
+
3197
+	//related to cpt routes
3198
+	protected function _insert_update_cpt_item($post_id, $post)
3199
+	{
3200
+		$success  = true;
3201
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3202
+		//for attendee updates
3203
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3204
+			//note we should only be UPDATING attendees at this point.
3205
+			$updated_fields = array(
3206
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3207
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3208
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3209
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3210
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3211
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3212
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3213
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3214
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3215
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3216
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3217
+			);
3218
+			foreach ($updated_fields as $field => $value) {
3219
+				$attendee->set($field, $value);
3220
+			}
3221
+			$success                   = $attendee->save();
3222
+			$attendee_update_callbacks = apply_filters(
3223
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3224
+				array()
3225
+			);
3226
+			foreach ($attendee_update_callbacks as $a_callback) {
3227
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3228
+					throw new EE_Error(
3229
+						sprintf(
3230
+							esc_html__(
3231
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3232
+								'event_espresso'
3233
+							),
3234
+							$a_callback
3235
+						)
3236
+					);
3237
+				}
3238
+			}
3239
+		}
3240
+		if ($success === false) {
3241
+			EE_Error::add_error(
3242
+				esc_html__(
3243
+					'Something went wrong with updating the meta table data for the registration.',
3244
+					'event_espresso'
3245
+				),
3246
+				__FILE__, __FUNCTION__, __LINE__
3247
+			);
3248
+		}
3249
+	}
3250
+
3251
+
3252
+	public function trash_cpt_item($post_id)
3253
+	{
3254
+	}
3255
+
3256
+
3257
+	public function delete_cpt_item($post_id)
3258
+	{
3259
+	}
3260
+
3261
+
3262
+	public function restore_cpt_item($post_id)
3263
+	{
3264
+	}
3265
+
3266
+
3267
+	protected function _restore_cpt_item($post_id, $revision_id)
3268
+	{
3269
+	}
3270
+
3271
+
3272
+	public function attendee_editor_metaboxes()
3273
+	{
3274
+		$this->verify_cpt_object();
3275
+		remove_meta_box(
3276
+			'postexcerpt',
3277
+			esc_html__('Excerpt', 'event_espresso'),
3278
+			'post_excerpt_meta_box',
3279
+			$this->_cpt_routes[$this->_req_action],
3280
+			'normal',
3281
+			'core'
3282
+		);
3283
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3284
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3285
+			add_meta_box(
3286
+				'postexcerpt',
3287
+				esc_html__('Short Biography', 'event_espresso'),
3288
+				'post_excerpt_meta_box',
3289
+				$this->_cpt_routes[$this->_req_action],
3290
+				'normal'
3291
+			);
3292
+		}
3293
+		if (post_type_supports('espresso_attendees', 'comments')) {
3294
+			add_meta_box(
3295
+				'commentsdiv',
3296
+				esc_html__('Notes on the Contact', 'event_espresso'),
3297
+				'post_comment_meta_box',
3298
+				$this->_cpt_routes[$this->_req_action],
3299
+				'normal',
3300
+				'core'
3301
+			);
3302
+		}
3303
+		add_meta_box(
3304
+			'attendee_contact_info',
3305
+			esc_html__('Contact Info', 'event_espresso'),
3306
+			array($this, 'attendee_contact_info'),
3307
+			$this->_cpt_routes[$this->_req_action],
3308
+			'side',
3309
+			'core'
3310
+		);
3311
+		add_meta_box(
3312
+			'attendee_details_address',
3313
+			esc_html__('Address Details', 'event_espresso'),
3314
+			array($this, 'attendee_address_details'),
3315
+			$this->_cpt_routes[$this->_req_action],
3316
+			'normal',
3317
+			'core'
3318
+		);
3319
+		add_meta_box(
3320
+			'attendee_registrations',
3321
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3322
+			array($this, 'attendee_registrations_meta_box'),
3323
+			$this->_cpt_routes[$this->_req_action],
3324
+			'normal',
3325
+			'high'
3326
+		);
3327
+	}
3328
+
3329
+
3330
+	/**
3331
+	 * Metabox for attendee contact info
3332
+	 *
3333
+	 * @param  WP_Post $post wp post object
3334
+	 * @return string attendee contact info ( and form )
3335
+	 * @throws DomainException
3336
+	 */
3337
+	public function attendee_contact_info($post)
3338
+	{
3339
+		//get attendee object ( should already have it )
3340
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3341
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3342
+		EEH_Template::display_template($template, $this->_template_args);
3343
+	}
3344
+
3345
+
3346
+	/**
3347
+	 * Metabox for attendee details
3348
+	 *
3349
+	 * @param  WP_Post $post wp post object
3350
+	 * @return string attendee address details (and form)
3351
+	 * @throws DomainException
3352
+	 */
3353
+	public function attendee_address_details($post)
3354
+	{
3355
+		//get attendee object (should already have it)
3356
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3357
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3358
+			new EE_Question_Form_Input(
3359
+				EE_Question::new_instance(
3360
+					array(
3361
+						'QST_ID'           => 0,
3362
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3363
+						'QST_system'       => 'admin-state',
3364
+					)
3365
+				),
3366
+				EE_Answer::new_instance(
3367
+					array(
3368
+						'ANS_ID'    => 0,
3369
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3370
+					)
3371
+				),
3372
+				array(
3373
+					'input_id'       => 'STA_ID',
3374
+					'input_name'     => 'STA_ID',
3375
+					'input_prefix'   => '',
3376
+					'append_qstn_id' => false,
3377
+				)
3378
+			)
3379
+		);
3380
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3381
+			new EE_Question_Form_Input(
3382
+				EE_Question::new_instance(
3383
+					array(
3384
+						'QST_ID'           => 0,
3385
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3386
+						'QST_system'       => 'admin-country',
3387
+					)
3388
+				),
3389
+				EE_Answer::new_instance(
3390
+					array(
3391
+						'ANS_ID'    => 0,
3392
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3393
+					)
3394
+				),
3395
+				array(
3396
+					'input_id'       => 'CNT_ISO',
3397
+					'input_name'     => 'CNT_ISO',
3398
+					'input_prefix'   => '',
3399
+					'append_qstn_id' => false,
3400
+				)
3401
+			)
3402
+		);
3403
+		$template                             =
3404
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3405
+		EEH_Template::display_template($template, $this->_template_args);
3406
+	}
3407
+
3408
+
3409
+	/**
3410
+	 *        _attendee_details
3411
+	 *
3412
+	 * @access protected
3413
+	 * @param $post
3414
+	 * @return void
3415
+	 * @throws DomainException
3416
+	 * @throws EE_Error
3417
+	 */
3418
+	public function attendee_registrations_meta_box($post)
3419
+	{
3420
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3421
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3422
+		$template                              =
3423
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3424
+		EEH_Template::display_template($template, $this->_template_args);
3425
+	}
3426
+
3427
+
3428
+	/**
3429
+	 * add in the form fields for the attendee edit
3430
+	 *
3431
+	 * @param  WP_Post $post wp post object
3432
+	 * @return string html for new form.
3433
+	 * @throws DomainException
3434
+	 */
3435
+	public function after_title_form_fields($post)
3436
+	{
3437
+		if ($post->post_type == 'espresso_attendees') {
3438
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3439
+			$template_args['attendee'] = $this->_cpt_model_obj;
3440
+			EEH_Template::display_template($template, $template_args);
3441
+		}
3442
+	}
3443
+
3444
+
3445
+	/**
3446
+	 *        _trash_or_restore_attendee
3447
+	 *
3448
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3449
+	 * @return void
3450
+	 * @throws EE_Error
3451
+	 * @access protected
3452
+	 */
3453
+	protected function _trash_or_restore_attendees($trash = true)
3454
+	{
3455
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3456
+		$ATT_MDL = EEM_Attendee::instance();
3457
+		$success = 1;
3458
+		//Checkboxes
3459
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3460
+			// if array has more than one element than success message should be plural
3461
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3462
+			// cycle thru checkboxes
3463
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3464
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3465
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3466
+				if ( ! $updated) {
3467
+					$success = 0;
3468
+				}
3469
+			}
3470
+		} else {
3471
+			// grab single id and delete
3472
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3473
+			//get attendee
3474
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3475
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3476
+			$updated = $att->save();
3477
+			if ( ! $updated) {
3478
+				$success = 0;
3479
+			}
3480
+		}
3481
+		$what        = $success > 1
3482
+			? esc_html__('Contacts', 'event_espresso')
3483
+			: esc_html__('Contact', 'event_espresso');
3484
+		$action_desc = $trash
3485
+			? esc_html__('moved to the trash', 'event_espresso')
3486
+			: esc_html__('restored', 'event_espresso');
3487
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3488
+	}
3489 3489
 
3490 3490
 }
Please login to merge, or discard this patch.
core/helpers/EEH_DTT_Helper.helper.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
      * this method will add that "1" into your date regardless of the format.
945 945
      *
946 946
      * @param string $month
947
-     * @return string
947
+     * @return integer
948 948
      */
949 949
     public static function first_of_month_timestamp($month = '')
950 950
     {
@@ -1105,7 +1105,7 @@  discard block
 block discarded – undo
1105 1105
     /**
1106 1106
      * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1107 1107
      *
1108
-     * @param int|WP_User $user_id
1108
+     * @param integer $user_id
1109 1109
      * @return string
1110 1110
      */
1111 1111
     public static function get_user_locale($user_id = 0)
Please login to merge, or discard this patch.
Indentation   +1046 added lines, -1046 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -26,233 +26,233 @@  discard block
 block discarded – undo
26 26
 {
27 27
 
28 28
 
29
-    /**
30
-     * return the timezone set for the WP install
31
-     *
32
-     * @return string valid timezone string for PHP DateTimeZone() class
33
-     */
34
-    public static function get_timezone()
35
-    {
36
-        return EEH_DTT_Helper::get_valid_timezone_string();
37
-    }
38
-
39
-
40
-    /**
41
-     * get_valid_timezone_string
42
-     *    ensures that a valid timezone string is returned
43
-     *
44
-     * @access protected
45
-     * @param string $timezone_string
46
-     * @return string
47
-     * @throws \EE_Error
48
-     */
49
-    public static function get_valid_timezone_string($timezone_string = '')
50
-    {
51
-        // if passed a value, then use that, else get WP option
52
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
53
-        // value from above exists, use that, else get timezone string from gmt_offset
54
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset();
55
-        EEH_DTT_Helper::validate_timezone($timezone_string);
56
-        return $timezone_string;
57
-    }
58
-
59
-
60
-    /**
61
-     * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
62
-     *
63
-     * @static
64
-     * @access public
65
-     * @param  string $timezone_string Timezone string to check
66
-     * @param bool    $throw_error
67
-     * @return bool
68
-     * @throws \EE_Error
69
-     */
70
-    public static function validate_timezone($timezone_string, $throw_error = true)
71
-    {
72
-        // easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it
73
-        try {
74
-            new DateTimeZone($timezone_string);
75
-        } catch (Exception $e) {
76
-            // sometimes we take exception to exceptions
77
-            if (! $throw_error) {
78
-                return false;
79
-            }
80
-            throw new EE_Error(
81
-                sprintf(
82
-                    __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
83
-                        'event_espresso'),
84
-                    $timezone_string,
85
-                    '<a href="http://www.php.net/manual/en/timezones.php">',
86
-                    '</a>'
87
-                )
88
-            );
89
-        }
90
-        return true;
91
-    }
92
-
93
-
94
-    /**
95
-     * _create_timezone_object_from_timezone_name
96
-     *
97
-     * @access protected
98
-     * @param string $gmt_offset
99
-     * @return string
100
-     */
101
-    public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
102
-    {
103
-        $timezone_string = 'UTC';
104
-        $gmt_offset      = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset');
105
-        if ($gmt_offset !== '') {
106
-            // convert GMT offset to seconds
107
-            $gmt_offset = $gmt_offset * HOUR_IN_SECONDS;
108
-            // account for WP offsets that aren't valid UTC
109
-            $gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset);
110
-            // although we don't know the TZ abbreviation, we know the UTC offset
111
-            $timezone_string = timezone_name_from_abbr(null, $gmt_offset);
112
-        }
113
-        // better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()...
114
-        $timezone_string = $timezone_string !== false
115
-            ? $timezone_string
116
-            : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset);
117
-        return $timezone_string;
118
-    }
119
-
120
-    /**
121
-     * Gets the site's GMT offset based on either the timezone string
122
-     * (in which case teh gmt offset will vary depending on the location's
123
-     * observance of daylight savings time) or the gmt_offset wp option
124
-     *
125
-     * @return int seconds offset
126
-     */
127
-    public static function get_site_timezone_gmt_offset()
128
-    {
129
-        $timezone_string = get_option('timezone_string');
130
-        if ($timezone_string) {
131
-            try {
132
-                $timezone = new DateTimeZone($timezone_string);
133
-                return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC
134
-            } catch (Exception $e) {
135
-            }
136
-        }
137
-        $offset = get_option('gmt_offset');
138
-        return (int)($offset * HOUR_IN_SECONDS);
139
-    }
140
-
141
-
142
-    /**
143
-     * _create_timezone_object_from_timezone_name
144
-     *
145
-     * @access public
146
-     * @param int $gmt_offset
147
-     * @return int
148
-     */
149
-    public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
150
-    {
151
-        //make sure $gmt_offset is int
152
-        $gmt_offset = (int)$gmt_offset;
153
-        switch ($gmt_offset) {
154
-
155
-            //			case -30600 :
156
-            //				$gmt_offset = -28800;
157
-            //				break;
158
-
159
-            case -27000 :
160
-                $gmt_offset = -25200;
161
-                break;
162
-
163
-            case -23400 :
164
-                $gmt_offset = -21600;
165
-                break;
166
-
167
-            case -19800 :
168
-                $gmt_offset = -18000;
169
-                break;
170
-
171
-            case -9000 :
172
-                $gmt_offset = -7200;
173
-                break;
174
-
175
-            case -5400 :
176
-                $gmt_offset = -3600;
177
-                break;
178
-
179
-            case -1800 :
180
-                $gmt_offset = 0;
181
-                break;
182
-
183
-            case 1800 :
184
-                $gmt_offset = 3600;
185
-                break;
186
-
187
-            case 49500 :
188
-                $gmt_offset = 50400;
189
-                break;
190
-
191
-        }
192
-        return $gmt_offset;
193
-    }
194
-
195
-
196
-    /**
197
-     * get_timezone_string_from_abbreviations_list
198
-     *
199
-     * @access public
200
-     * @param int $gmt_offset
201
-     * @return string
202
-     * @throws \EE_Error
203
-     */
204
-    public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0)
205
-    {
206
-        $abbreviations = timezone_abbreviations_list();
207
-        foreach ($abbreviations as $abbreviation) {
208
-            foreach ($abbreviation as $city) {
209
-                if ($city['offset'] === $gmt_offset && $city['dst'] === false) {
210
-                    // check if the timezone is valid but don't throw any errors if it isn't
211
-                    if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) {
212
-                        return $city['timezone_id'];
213
-                    }
214
-                }
215
-            }
216
-        }
217
-        throw new EE_Error(
218
-            sprintf(
219
-                __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
220
-                    'event_espresso'),
221
-                $gmt_offset,
222
-                '<a href="http://www.php.net/manual/en/timezones.php">',
223
-                '</a>'
224
-            )
225
-        );
226
-    }
227
-
228
-
229
-    /**
230
-     * @access public
231
-     * @param string $timezone_string
232
-     */
233
-    public static function timezone_select_input($timezone_string = '')
234
-    {
235
-        // get WP date time format
236
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
237
-        // if passed a value, then use that, else get WP option
238
-        $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
239
-        // check if the timezone is valid but don't throw any errors if it isn't
240
-        $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false);
241
-        $gmt_offset      = get_option('gmt_offset');
242
-
243
-        $check_zone_info = true;
244
-        if (empty($timezone_string)) {
245
-            // Create a UTC+- zone if no timezone string exists
246
-            $check_zone_info = false;
247
-            if ($gmt_offset > 0) {
248
-                $timezone_string = 'UTC+' . $gmt_offset;
249
-            } elseif ($gmt_offset < 0) {
250
-                $timezone_string = 'UTC' . $gmt_offset;
251
-            } else {
252
-                $timezone_string = 'UTC';
253
-            }
254
-        }
255
-        ?>
29
+	/**
30
+	 * return the timezone set for the WP install
31
+	 *
32
+	 * @return string valid timezone string for PHP DateTimeZone() class
33
+	 */
34
+	public static function get_timezone()
35
+	{
36
+		return EEH_DTT_Helper::get_valid_timezone_string();
37
+	}
38
+
39
+
40
+	/**
41
+	 * get_valid_timezone_string
42
+	 *    ensures that a valid timezone string is returned
43
+	 *
44
+	 * @access protected
45
+	 * @param string $timezone_string
46
+	 * @return string
47
+	 * @throws \EE_Error
48
+	 */
49
+	public static function get_valid_timezone_string($timezone_string = '')
50
+	{
51
+		// if passed a value, then use that, else get WP option
52
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
53
+		// value from above exists, use that, else get timezone string from gmt_offset
54
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset();
55
+		EEH_DTT_Helper::validate_timezone($timezone_string);
56
+		return $timezone_string;
57
+	}
58
+
59
+
60
+	/**
61
+	 * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone.
62
+	 *
63
+	 * @static
64
+	 * @access public
65
+	 * @param  string $timezone_string Timezone string to check
66
+	 * @param bool    $throw_error
67
+	 * @return bool
68
+	 * @throws \EE_Error
69
+	 */
70
+	public static function validate_timezone($timezone_string, $throw_error = true)
71
+	{
72
+		// easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it
73
+		try {
74
+			new DateTimeZone($timezone_string);
75
+		} catch (Exception $e) {
76
+			// sometimes we take exception to exceptions
77
+			if (! $throw_error) {
78
+				return false;
79
+			}
80
+			throw new EE_Error(
81
+				sprintf(
82
+					__('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
83
+						'event_espresso'),
84
+					$timezone_string,
85
+					'<a href="http://www.php.net/manual/en/timezones.php">',
86
+					'</a>'
87
+				)
88
+			);
89
+		}
90
+		return true;
91
+	}
92
+
93
+
94
+	/**
95
+	 * _create_timezone_object_from_timezone_name
96
+	 *
97
+	 * @access protected
98
+	 * @param string $gmt_offset
99
+	 * @return string
100
+	 */
101
+	public static function get_timezone_string_from_gmt_offset($gmt_offset = '')
102
+	{
103
+		$timezone_string = 'UTC';
104
+		$gmt_offset      = ! empty($gmt_offset) ? $gmt_offset : get_option('gmt_offset');
105
+		if ($gmt_offset !== '') {
106
+			// convert GMT offset to seconds
107
+			$gmt_offset = $gmt_offset * HOUR_IN_SECONDS;
108
+			// account for WP offsets that aren't valid UTC
109
+			$gmt_offset = EEH_DTT_Helper::adjust_invalid_gmt_offsets($gmt_offset);
110
+			// although we don't know the TZ abbreviation, we know the UTC offset
111
+			$timezone_string = timezone_name_from_abbr(null, $gmt_offset);
112
+		}
113
+		// better have a valid timezone string by now, but if not, sigh... loop thru  the timezone_abbreviations_list()...
114
+		$timezone_string = $timezone_string !== false
115
+			? $timezone_string
116
+			: EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset);
117
+		return $timezone_string;
118
+	}
119
+
120
+	/**
121
+	 * Gets the site's GMT offset based on either the timezone string
122
+	 * (in which case teh gmt offset will vary depending on the location's
123
+	 * observance of daylight savings time) or the gmt_offset wp option
124
+	 *
125
+	 * @return int seconds offset
126
+	 */
127
+	public static function get_site_timezone_gmt_offset()
128
+	{
129
+		$timezone_string = get_option('timezone_string');
130
+		if ($timezone_string) {
131
+			try {
132
+				$timezone = new DateTimeZone($timezone_string);
133
+				return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC
134
+			} catch (Exception $e) {
135
+			}
136
+		}
137
+		$offset = get_option('gmt_offset');
138
+		return (int)($offset * HOUR_IN_SECONDS);
139
+	}
140
+
141
+
142
+	/**
143
+	 * _create_timezone_object_from_timezone_name
144
+	 *
145
+	 * @access public
146
+	 * @param int $gmt_offset
147
+	 * @return int
148
+	 */
149
+	public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
150
+	{
151
+		//make sure $gmt_offset is int
152
+		$gmt_offset = (int)$gmt_offset;
153
+		switch ($gmt_offset) {
154
+
155
+			//			case -30600 :
156
+			//				$gmt_offset = -28800;
157
+			//				break;
158
+
159
+			case -27000 :
160
+				$gmt_offset = -25200;
161
+				break;
162
+
163
+			case -23400 :
164
+				$gmt_offset = -21600;
165
+				break;
166
+
167
+			case -19800 :
168
+				$gmt_offset = -18000;
169
+				break;
170
+
171
+			case -9000 :
172
+				$gmt_offset = -7200;
173
+				break;
174
+
175
+			case -5400 :
176
+				$gmt_offset = -3600;
177
+				break;
178
+
179
+			case -1800 :
180
+				$gmt_offset = 0;
181
+				break;
182
+
183
+			case 1800 :
184
+				$gmt_offset = 3600;
185
+				break;
186
+
187
+			case 49500 :
188
+				$gmt_offset = 50400;
189
+				break;
190
+
191
+		}
192
+		return $gmt_offset;
193
+	}
194
+
195
+
196
+	/**
197
+	 * get_timezone_string_from_abbreviations_list
198
+	 *
199
+	 * @access public
200
+	 * @param int $gmt_offset
201
+	 * @return string
202
+	 * @throws \EE_Error
203
+	 */
204
+	public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0)
205
+	{
206
+		$abbreviations = timezone_abbreviations_list();
207
+		foreach ($abbreviations as $abbreviation) {
208
+			foreach ($abbreviation as $city) {
209
+				if ($city['offset'] === $gmt_offset && $city['dst'] === false) {
210
+					// check if the timezone is valid but don't throw any errors if it isn't
211
+					if (EEH_DTT_Helper::validate_timezone($city['timezone_id'], false)) {
212
+						return $city['timezone_id'];
213
+					}
214
+				}
215
+			}
216
+		}
217
+		throw new EE_Error(
218
+			sprintf(
219
+				__('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used',
220
+					'event_espresso'),
221
+				$gmt_offset,
222
+				'<a href="http://www.php.net/manual/en/timezones.php">',
223
+				'</a>'
224
+			)
225
+		);
226
+	}
227
+
228
+
229
+	/**
230
+	 * @access public
231
+	 * @param string $timezone_string
232
+	 */
233
+	public static function timezone_select_input($timezone_string = '')
234
+	{
235
+		// get WP date time format
236
+		$datetime_format = get_option('date_format') . ' ' . get_option('time_format');
237
+		// if passed a value, then use that, else get WP option
238
+		$timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
239
+		// check if the timezone is valid but don't throw any errors if it isn't
240
+		$timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false);
241
+		$gmt_offset      = get_option('gmt_offset');
242
+
243
+		$check_zone_info = true;
244
+		if (empty($timezone_string)) {
245
+			// Create a UTC+- zone if no timezone string exists
246
+			$check_zone_info = false;
247
+			if ($gmt_offset > 0) {
248
+				$timezone_string = 'UTC+' . $gmt_offset;
249
+			} elseif ($gmt_offset < 0) {
250
+				$timezone_string = 'UTC' . $gmt_offset;
251
+			} else {
252
+				$timezone_string = 'UTC';
253
+			}
254
+		}
255
+		?>
256 256
 
257 257
         <p>
258 258
             <label for="timezone_string"><?php _e('timezone'); ?></label>
@@ -265,13 +265,13 @@  discard block
 block discarded – undo
265 265
 
266 266
         <p>
267 267
         <span><?php
268
-            printf(
269
-                __('%1$sUTC%2$s time is %3$s'),
270
-                '<abbr title="Coordinated Universal Time">',
271
-                '</abbr>',
272
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
273
-            );
274
-            ?></span>
268
+			printf(
269
+				__('%1$sUTC%2$s time is %3$s'),
270
+				'<abbr title="Coordinated Universal Time">',
271
+				'</abbr>',
272
+				'<code>' . date_i18n($datetime_format, false, true) . '</code>'
273
+			);
274
+			?></span>
275 275
         <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
276 276
         <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
277 277
     <?php endif; ?>
@@ -280,693 +280,693 @@  discard block
 block discarded – undo
280 280
         <br/>
281 281
         <span>
282 282
 					<?php
283
-                    // Set TZ so localtime works.
284
-                    date_default_timezone_set($timezone_string);
285
-                    $now = localtime(time(), true);
286
-                    if ($now['tm_isdst']) {
287
-                        _e('This timezone is currently in daylight saving time.');
288
-                    } else {
289
-                        _e('This timezone is currently in standard time.');
290
-                    }
291
-                    ?>
283
+					// Set TZ so localtime works.
284
+					date_default_timezone_set($timezone_string);
285
+					$now = localtime(time(), true);
286
+					if ($now['tm_isdst']) {
287
+						_e('This timezone is currently in daylight saving time.');
288
+					} else {
289
+						_e('This timezone is currently in standard time.');
290
+					}
291
+					?>
292 292
             <br/>
293 293
             <?php
294
-            if (function_exists('timezone_transitions_get')) {
295
-                $found                   = false;
296
-                $date_time_zone_selected = new DateTimeZone($timezone_string);
297
-                $tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
298
-                $right_now               = time();
299
-                $tr['isdst']             = false;
300
-                foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
301
-                    if ($tr['ts'] > $right_now) {
302
-                        $found = true;
303
-                        break;
304
-                    }
305
-                }
306
-
307
-                if ($found) {
308
-                    $message = $tr['isdst'] ?
309
-                        __(' Daylight saving time begins on: %s.') :
310
-                        __(' Standard time begins  on: %s.');
311
-                    // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
312
-                    printf($message,
313
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
314
-                } else {
315
-                    _e('This timezone does not observe daylight saving time.');
316
-                }
317
-            }
318
-            // Set back to UTC.
319
-            date_default_timezone_set('UTC');
320
-            ?>
294
+			if (function_exists('timezone_transitions_get')) {
295
+				$found                   = false;
296
+				$date_time_zone_selected = new DateTimeZone($timezone_string);
297
+				$tz_offset               = timezone_offset_get($date_time_zone_selected, date_create());
298
+				$right_now               = time();
299
+				$tr['isdst']             = false;
300
+				foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
301
+					if ($tr['ts'] > $right_now) {
302
+						$found = true;
303
+						break;
304
+					}
305
+				}
306
+
307
+				if ($found) {
308
+					$message = $tr['isdst'] ?
309
+						__(' Daylight saving time begins on: %s.') :
310
+						__(' Standard time begins  on: %s.');
311
+					// Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
312
+					printf($message,
313
+						'<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
314
+				} else {
315
+					_e('This timezone does not observe daylight saving time.');
316
+				}
317
+			}
318
+			// Set back to UTC.
319
+			date_default_timezone_set('UTC');
320
+			?>
321 321
 				</span></p>
322 322
         <?php
323
-    endif;
324
-    }
325
-
326
-
327
-    /**
328
-     * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
329
-     * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
330
-     * the site is used.
331
-     * This is used typically when using a Unix timestamp any core WP functions that expect their specially
332
-     * computed timestamp (i.e. date_i18n() )
333
-     *
334
-     * @param int    $unix_timestamp                  if 0, then time() will be used.
335
-     * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
336
-     *                                                site will be used.
337
-     * @return int      $unix_timestamp with the offset applied for the given timezone.
338
-     */
339
-    public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
340
-    {
341
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
342
-        $timezone_string = self::get_valid_timezone_string($timezone_string);
343
-        $TimeZone        = new DateTimeZone($timezone_string);
344
-
345
-        $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
346
-        $offset   = timezone_offset_get($TimeZone, $DateTime);
347
-        return (int)$DateTime->format('U') + (int)$offset;
348
-    }
349
-
350
-
351
-    /**
352
-     *    _set_date_time_field
353
-     *    modifies EE_Base_Class EE_Datetime_Field objects
354
-     *
355
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
356
-     * @param    DateTime    $DateTime            PHP DateTime object
357
-     * @param  string        $datetime_field_name the datetime fieldname to be manipulated
358
-     * @return    EE_Base_Class
359
-     */
360
-    protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
361
-    {
362
-        // grab current datetime format
363
-        $current_format = $obj->get_format();
364
-        // set new full timestamp format
365
-        $obj->set_date_format(EE_Datetime_Field::mysql_date_format);
366
-        $obj->set_time_format(EE_Datetime_Field::mysql_time_format);
367
-        // set the new date value using a full timestamp format so that no data is lost
368
-        $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
369
-        // reset datetime formats
370
-        $obj->set_date_format($current_format[0]);
371
-        $obj->set_time_format($current_format[1]);
372
-        return $obj;
373
-    }
374
-
375
-
376
-    /**
377
-     *    date_time_add
378
-     *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
379
-     *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
380
-     *
381
-     * @param  EE_Base_Class $obj                 EE_Base_Class object
382
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
383
-     * @param  string        $period              what you are adding. The options are (years, months, days, hours,
384
-     *                                            minutes, seconds) defaults to years
385
-     * @param  integer       $value               what you want to increment the time by
386
-     * @return EE_Base_Class           return the EE_Base_Class object so right away you can do something with it
387
-     *                                 (chaining)
388
-     */
389
-    public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
390
-    {
391
-        //get the raw UTC date.
392
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
393
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
394
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
395
-    }
396
-
397
-
398
-    /**
399
-     *    date_time_subtract
400
-     *    same as date_time_add except subtracting value instead of adding.
401
-     *
402
-     * @param \EE_Base_Class $obj
403
-     * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
404
-     * @param string         $period
405
-     * @param int            $value
406
-     * @return \EE_Base_Class
407
-     */
408
-    public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
409
-    {
410
-        //get the raw UTC date
411
-        $DateTime = $obj->get_DateTime_object($datetime_field_name);
412
-        $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
413
-        return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
414
-    }
415
-
416
-
417
-    /**
418
-     * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
419
-     *
420
-     * @param  DateTime $DateTime DateTime object
421
-     * @param  string   $period   a value to indicate what interval is being used in the calculation. The options are
422
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
423
-     * @param  integer  $value    What you want to increment the date by
424
-     * @param  string   $operand  What operand you wish to use for the calculation
425
-     * @return \DateTime return whatever type came in.
426
-     * @throws \EE_Error
427
-     */
428
-    protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
429
-    {
430
-        if (! $DateTime instanceof DateTime) {
431
-            throw new EE_Error(
432
-                sprintf(
433
-                    __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
434
-                    print_r($DateTime, true)
435
-                )
436
-            );
437
-        }
438
-        switch ($period) {
439
-            case 'years' :
440
-                $value = 'P' . $value . 'Y';
441
-                break;
442
-            case 'months' :
443
-                $value = 'P' . $value . 'M';
444
-                break;
445
-            case 'weeks' :
446
-                $value = 'P' . $value . 'W';
447
-                break;
448
-            case 'days' :
449
-                $value = 'P' . $value . 'D';
450
-                break;
451
-            case 'hours' :
452
-                $value = 'PT' . $value . 'H';
453
-                break;
454
-            case 'minutes' :
455
-                $value = 'PT' . $value . 'M';
456
-                break;
457
-            case 'seconds' :
458
-                $value = 'PT' . $value . 'S';
459
-                break;
460
-        }
461
-        switch ($operand) {
462
-            case '+':
463
-                $DateTime->add(new DateInterval($value));
464
-                break;
465
-            case '-':
466
-                $DateTime->sub(new DateInterval($value));
467
-                break;
468
-        }
469
-        return $DateTime;
470
-    }
471
-
472
-
473
-    /**
474
-     * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
475
-     *
476
-     * @param  int     $timestamp Unix timestamp
477
-     * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
478
-     *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
479
-     * @param  integer $value     What you want to increment the date by
480
-     * @param  string  $operand   What operand you wish to use for the calculation
481
-     * @return \DateTime return whatever type came in.
482
-     * @throws \EE_Error
483
-     */
484
-    protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
485
-    {
486
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
487
-            throw new EE_Error(
488
-                sprintf(
489
-                    __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
490
-                    print_r($timestamp, true)
491
-                )
492
-            );
493
-        }
494
-        switch ($period) {
495
-            case 'years' :
496
-                $value = YEAR_IN_SECONDS * $value;
497
-                break;
498
-            case 'months' :
499
-                $value = YEAR_IN_SECONDS / 12 * $value;
500
-                break;
501
-            case 'weeks' :
502
-                $value = WEEK_IN_SECONDS * $value;
503
-                break;
504
-            case 'days' :
505
-                $value = DAY_IN_SECONDS * $value;
506
-                break;
507
-            case 'hours' :
508
-                $value = HOUR_IN_SECONDS * $value;
509
-                break;
510
-            case 'minutes' :
511
-                $value = MINUTE_IN_SECONDS * $value;
512
-                break;
513
-        }
514
-        switch ($operand) {
515
-            case '+':
516
-                $timestamp += $value;
517
-                break;
518
-            case '-':
519
-                $timestamp -= $value;
520
-                break;
521
-        }
522
-        return $timestamp;
523
-    }
524
-
525
-
526
-    /**
527
-     * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
528
-     * parameters and returns the new timestamp or DateTime.
529
-     *
530
-     * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
531
-     * @param  string         $period                a value to indicate what interval is being used in the
532
-     *                                               calculation. The options are 'years', 'months', 'days', 'hours',
533
-     *                                               'minutes', 'seconds'. Defaults to years.
534
-     * @param  integer        $value                 What you want to increment the date by
535
-     * @param  string         $operand               What operand you wish to use for the calculation
536
-     * @return mixed string|DateTime          return whatever type came in.
537
-     */
538
-    public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
539
-    {
540
-        if ($DateTime_or_timestamp instanceof DateTime) {
541
-            return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand);
542
-        } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
543
-            return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand);
544
-        } else {
545
-            //error
546
-            return $DateTime_or_timestamp;
547
-        }
548
-    }
549
-
550
-
551
-    /**
552
-     * The purpose of this helper method is to receive an incoming format string in php date/time format
553
-     * and spit out the js and moment.js equivalent formats.
554
-     * Note, if no format string is given, then it is assumed the user wants what is set for WP.
555
-     * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
556
-     * time picker.
557
-     *
558
-     * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
559
-     * @param null $date_format_string
560
-     * @param null $time_format_string
561
-     * @return array
562
-     *                array(
563
-     *                'js' => array (
564
-     *                'date' => //date format
565
-     *                'time' => //time format
566
-     *                ),
567
-     *                'moment' => //date and time format.
568
-     *                )
569
-     */
570
-    public static function convert_php_to_js_and_moment_date_formats(
571
-        $date_format_string = null,
572
-        $time_format_string = null
573
-    ) {
574
-        if ($date_format_string === null) {
575
-            $date_format_string = get_option('date_format');
576
-        }
577
-
578
-        if ($time_format_string === null) {
579
-            $time_format_string = get_option('time_format');
580
-        }
581
-
582
-        $date_format = self::_php_to_js_moment_converter($date_format_string);
583
-        $time_format = self::_php_to_js_moment_converter($time_format_string);
584
-
585
-        return array(
586
-            'js'     => array(
587
-                'date' => $date_format['js'],
588
-                'time' => $time_format['js'],
589
-            ),
590
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
591
-        );
592
-    }
593
-
594
-
595
-    /**
596
-     * This converts incoming format string into js and moment variations.
597
-     *
598
-     * @param string $format_string incoming php format string
599
-     * @return array js and moment formats.
600
-     */
601
-    protected static function _php_to_js_moment_converter($format_string)
602
-    {
603
-        /**
604
-         * This is a map of symbols for formats.
605
-         * The index is the php symbol, the equivalent values are in the array.
606
-         *
607
-         * @var array
608
-         */
609
-        $symbols_map      = array(
610
-            // Day
611
-            //01
612
-            'd' => array(
613
-                'js'     => 'dd',
614
-                'moment' => 'DD',
615
-            ),
616
-            //Mon
617
-            'D' => array(
618
-                'js'     => 'D',
619
-                'moment' => 'ddd',
620
-            ),
621
-            //1,2,...31
622
-            'j' => array(
623
-                'js'     => 'd',
624
-                'moment' => 'D',
625
-            ),
626
-            //Monday
627
-            'l' => array(
628
-                'js'     => 'DD',
629
-                'moment' => 'dddd',
630
-            ),
631
-            //ISO numeric representation of the day of the week (1-6)
632
-            'N' => array(
633
-                'js'     => '',
634
-                'moment' => 'E',
635
-            ),
636
-            //st,nd.rd
637
-            'S' => array(
638
-                'js'     => '',
639
-                'moment' => 'o',
640
-            ),
641
-            //numeric representation of day of week (0-6)
642
-            'w' => array(
643
-                'js'     => '',
644
-                'moment' => 'd',
645
-            ),
646
-            //day of year starting from 0 (0-365)
647
-            'z' => array(
648
-                'js'     => 'o',
649
-                'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1
650
-            ),
651
-            // Week
652
-            //ISO-8601 week number of year (weeks starting on monday)
653
-            'W' => array(
654
-                'js'     => '',
655
-                'moment' => 'w',
656
-            ),
657
-            // Month
658
-            // January...December
659
-            'F' => array(
660
-                'js'     => 'MM',
661
-                'moment' => 'MMMM',
662
-            ),
663
-            //01...12
664
-            'm' => array(
665
-                'js'     => 'mm',
666
-                'moment' => 'MM',
667
-            ),
668
-            //Jan...Dec
669
-            'M' => array(
670
-                'js'     => 'M',
671
-                'moment' => 'MMM',
672
-            ),
673
-            //1-12
674
-            'n' => array(
675
-                'js'     => 'm',
676
-                'moment' => 'M',
677
-            ),
678
-            //number of days in given month
679
-            't' => array(
680
-                'js'     => '',
681
-                'moment' => '',
682
-            ),
683
-            // Year
684
-            //whether leap year or not 1/0
685
-            'L' => array(
686
-                'js'     => '',
687
-                'moment' => '',
688
-            ),
689
-            //ISO-8601 year number
690
-            'o' => array(
691
-                'js'     => '',
692
-                'moment' => 'GGGG',
693
-            ),
694
-            //1999...2003
695
-            'Y' => array(
696
-                'js'     => 'yy',
697
-                'moment' => 'YYYY',
698
-            ),
699
-            //99...03
700
-            'y' => array(
701
-                'js'     => 'y',
702
-                'moment' => 'YY',
703
-            ),
704
-            // Time
705
-            // am/pm
706
-            'a' => array(
707
-                'js'     => 'tt',
708
-                'moment' => 'a',
709
-            ),
710
-            // AM/PM
711
-            'A' => array(
712
-                'js'     => 'TT',
713
-                'moment' => 'A',
714
-            ),
715
-            // Swatch Internet Time?!?
716
-            'B' => array(
717
-                'js'     => '',
718
-                'moment' => '',
719
-            ),
720
-            //1...12
721
-            'g' => array(
722
-                'js'     => 'h',
723
-                'moment' => 'h',
724
-            ),
725
-            //0...23
726
-            'G' => array(
727
-                'js'     => 'H',
728
-                'moment' => 'H',
729
-            ),
730
-            //01...12
731
-            'h' => array(
732
-                'js'     => 'hh',
733
-                'moment' => 'hh',
734
-            ),
735
-            //00...23
736
-            'H' => array(
737
-                'js'     => 'HH',
738
-                'moment' => 'HH',
739
-            ),
740
-            //00..59
741
-            'i' => array(
742
-                'js'     => 'mm',
743
-                'moment' => 'mm',
744
-            ),
745
-            //seconds... 00...59
746
-            's' => array(
747
-                'js'     => 'ss',
748
-                'moment' => 'ss',
749
-            ),
750
-            //microseconds
751
-            'u' => array(
752
-                'js'     => '',
753
-                'moment' => '',
754
-            ),
755
-        );
756
-        $jquery_ui_format = "";
757
-        $moment_format    = "";
758
-        $escaping         = false;
759
-        for ($i = 0; $i < strlen($format_string); $i++) {
760
-            $char = $format_string[$i];
761
-            if ($char === '\\') { // PHP date format escaping character
762
-                $i++;
763
-                if ($escaping) {
764
-                    $jquery_ui_format .= $format_string[$i];
765
-                    $moment_format .= $format_string[$i];
766
-                } else {
767
-                    $jquery_ui_format .= '\'' . $format_string[$i];
768
-                    $moment_format .= $format_string[$i];
769
-                }
770
-                $escaping = true;
771
-            } else {
772
-                if ($escaping) {
773
-                    $jquery_ui_format .= "'";
774
-                    $moment_format .= "'";
775
-                    $escaping = false;
776
-                }
777
-                if (isset($symbols_map[$char])) {
778
-                    $jquery_ui_format .= $symbols_map[$char]['js'];
779
-                    $moment_format .= $symbols_map[$char]['moment'];
780
-                } else {
781
-                    $jquery_ui_format .= $char;
782
-                    $moment_format .= $char;
783
-                }
784
-            }
785
-        }
786
-        return array('js' => $jquery_ui_format, 'moment' => $moment_format);
787
-    }
788
-
789
-
790
-    /**
791
-     * This takes an incoming format string and validates it to ensure it will work fine with PHP.
792
-     *
793
-     * @param string $format_string   Incoming format string for php date().
794
-     * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
795
-     *                                errors is returned.  So for client code calling, check for is_array() to
796
-     *                                indicate failed validations.
797
-     */
798
-    public static function validate_format_string($format_string)
799
-    {
800
-        $error_msg = array();
801
-        //time format checks
802
-        switch (true) {
803
-            case   strpos($format_string, 'h') !== false  :
804
-            case   strpos($format_string, 'g') !== false :
805
-                /**
806
-                 * if the time string has a lowercase 'h' which == 12 hour time format and there
807
-                 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
808
-                 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
809
-                 */
810
-                if (strpos(strtoupper($format_string), 'A') === false) {
811
-                    $error_msg[] = __('There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
812
-                        'event_espresso');
813
-                }
814
-                break;
815
-
816
-        }
817
-
818
-        return empty($error_msg) ? true : $error_msg;
819
-    }
820
-
821
-
822
-    /**
823
-     *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
824
-     *     very next day then this method will return true.
825
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
826
-     *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
827
-     *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
828
-     *
829
-     * @param mixed $date_1
830
-     * @param mixed $date_2
831
-     * @return bool
832
-     */
833
-    public static function dates_represent_one_24_hour_date($date_1, $date_2)
834
-    {
835
-
836
-        if (
837
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
838
-            ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
839
-        ) {
840
-            return false;
841
-        }
842
-        return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false;
843
-    }
844
-
845
-
846
-    /**
847
-     * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
848
-     * Functions.
849
-     *
850
-     * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
851
-     * @param string $field_for_interval The Database field that is the interval is applied to in the query.
852
-     * @return string
853
-     */
854
-    public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
855
-    {
856
-        try {
857
-            /** need to account for timezone offset on the selects */
858
-            $DateTimeZone = new DateTimeZone($timezone_string);
859
-        } catch (Exception $e) {
860
-            $DateTimeZone = null;
861
-        }
862
-
863
-        /**
864
-         * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
865
-         * Hence we do the calc for DateTimeZone::getOffset.
866
-         */
867
-        $offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
868
-        $query_interval = $offset < 0
869
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
870
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
871
-        return $query_interval;
872
-    }
873
-
874
-    /**
875
-     * Retrieves the site's default timezone and returns it formatted so it's ready for display
876
-     * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
877
-     * and 'gmt_offset' WordPress options directly; or use the filter
878
-     * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
879
-     * (although note that we remove any HTML that may be added)
880
-     *
881
-     * @return string
882
-     */
883
-    public static function get_timezone_string_for_display()
884
-    {
885
-        $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
886
-        if (! empty($pretty_timezone)) {
887
-            return esc_html($pretty_timezone);
888
-        }
889
-        $timezone_string = get_option('timezone_string');
890
-        if ($timezone_string) {
891
-            static $mo_loaded = false;
892
-            // Load translations for continents and cities just like wp_timezone_choice does
893
-            if (! $mo_loaded) {
894
-                $locale = get_locale();
895
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
896
-                load_textdomain('continents-cities', $mofile);
897
-                $mo_loaded = true;
898
-            }
899
-            //well that was easy.
900
-            $parts = explode('/', $timezone_string);
901
-            //remove the continent
902
-            unset($parts[0]);
903
-            $t_parts = array();
904
-            foreach ($parts as $part) {
905
-                $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
906
-            }
907
-            return implode(' - ', $t_parts);
908
-        }
909
-        //they haven't set the timezone string, so let's return a string like "UTC+1"
910
-        $gmt_offset = get_option('gmt_offset');
911
-        if (intval($gmt_offset) >= 0) {
912
-            $prefix = '+';
913
-        } else {
914
-            $prefix = '';
915
-        }
916
-        $parts = explode('.', (string)$gmt_offset);
917
-        if (count($parts) === 1) {
918
-            $parts[1] = '00';
919
-        } else {
920
-            //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
921
-            //to minutes, eg 30 or 15, respectively
922
-            $hour_fraction = (float)('0.' . $parts[1]);
923
-            $parts[1]      = (string)$hour_fraction * 60;
924
-        }
925
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
926
-    }
927
-
928
-
929
-
930
-    /**
931
-     * So PHP does this awesome thing where if you are trying to get a timestamp
932
-     * for a month using a string like "February" or "February 2017",
933
-     * and you don't specify a day as part of your string,
934
-     * then PHP will use whatever the current day of the month is.
935
-     * IF the current day of the month happens to be the 30th or 31st,
936
-     * then PHP gets really confused by a date like February 30,
937
-     * so instead of saying
938
-     *      "Hey February only has 28 days (this year)...
939
-     *      ...you must have meant the last day of the month!"
940
-     * PHP does the next most logical thing, and bumps the date up to March 2nd,
941
-     * because someone requesting February 30th obviously meant March 1st!
942
-     * The way around this is to always set the day to the first,
943
-     * so that the month will stay on the month you wanted.
944
-     * this method will add that "1" into your date regardless of the format.
945
-     *
946
-     * @param string $month
947
-     * @return string
948
-     */
949
-    public static function first_of_month_timestamp($month = '')
950
-    {
951
-        $month = (string)$month;
952
-        $year = '';
953
-        // check if the incoming string has a year in it or not
954
-       if (preg_match('/\b\d{4}\b/', $month, $matches)) {
955
-           $year = $matches[0];
956
-           // ten remove that from the month string as well as any spaces
957
-           $month = trim(str_replace($year, '', $month));
958
-           // add a space before the year
959
-           $year = " {$year}";
960
-        }
961
-        // return timestamp for something like "February 1 2017"
962
-        return strtotime("{$month} 1{$year}");
963
-    }
323
+	endif;
324
+	}
325
+
326
+
327
+	/**
328
+	 * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string.
329
+	 * If no unix timestamp is given then time() is used.  If no timezone is given then the set timezone string for
330
+	 * the site is used.
331
+	 * This is used typically when using a Unix timestamp any core WP functions that expect their specially
332
+	 * computed timestamp (i.e. date_i18n() )
333
+	 *
334
+	 * @param int    $unix_timestamp                  if 0, then time() will be used.
335
+	 * @param string $timezone_string                 timezone_string. If empty, then the current set timezone for the
336
+	 *                                                site will be used.
337
+	 * @return int      $unix_timestamp with the offset applied for the given timezone.
338
+	 */
339
+	public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
340
+	{
341
+		$unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
342
+		$timezone_string = self::get_valid_timezone_string($timezone_string);
343
+		$TimeZone        = new DateTimeZone($timezone_string);
344
+
345
+		$DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
346
+		$offset   = timezone_offset_get($TimeZone, $DateTime);
347
+		return (int)$DateTime->format('U') + (int)$offset;
348
+	}
349
+
350
+
351
+	/**
352
+	 *    _set_date_time_field
353
+	 *    modifies EE_Base_Class EE_Datetime_Field objects
354
+	 *
355
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
356
+	 * @param    DateTime    $DateTime            PHP DateTime object
357
+	 * @param  string        $datetime_field_name the datetime fieldname to be manipulated
358
+	 * @return    EE_Base_Class
359
+	 */
360
+	protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name)
361
+	{
362
+		// grab current datetime format
363
+		$current_format = $obj->get_format();
364
+		// set new full timestamp format
365
+		$obj->set_date_format(EE_Datetime_Field::mysql_date_format);
366
+		$obj->set_time_format(EE_Datetime_Field::mysql_time_format);
367
+		// set the new date value using a full timestamp format so that no data is lost
368
+		$obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format));
369
+		// reset datetime formats
370
+		$obj->set_date_format($current_format[0]);
371
+		$obj->set_time_format($current_format[1]);
372
+		return $obj;
373
+	}
374
+
375
+
376
+	/**
377
+	 *    date_time_add
378
+	 *    helper for doing simple datetime calculations on a given datetime from EE_Base_Class
379
+	 *    and modifying it IN the EE_Base_Class so you don't have to do anything else.
380
+	 *
381
+	 * @param  EE_Base_Class $obj                 EE_Base_Class object
382
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
383
+	 * @param  string        $period              what you are adding. The options are (years, months, days, hours,
384
+	 *                                            minutes, seconds) defaults to years
385
+	 * @param  integer       $value               what you want to increment the time by
386
+	 * @return EE_Base_Class           return the EE_Base_Class object so right away you can do something with it
387
+	 *                                 (chaining)
388
+	 */
389
+	public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
390
+	{
391
+		//get the raw UTC date.
392
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
393
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value);
394
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
395
+	}
396
+
397
+
398
+	/**
399
+	 *    date_time_subtract
400
+	 *    same as date_time_add except subtracting value instead of adding.
401
+	 *
402
+	 * @param \EE_Base_Class $obj
403
+	 * @param  string        $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated
404
+	 * @param string         $period
405
+	 * @param int            $value
406
+	 * @return \EE_Base_Class
407
+	 */
408
+	public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1)
409
+	{
410
+		//get the raw UTC date
411
+		$DateTime = $obj->get_DateTime_object($datetime_field_name);
412
+		$DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-');
413
+		return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name);
414
+	}
415
+
416
+
417
+	/**
418
+	 * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters
419
+	 *
420
+	 * @param  DateTime $DateTime DateTime object
421
+	 * @param  string   $period   a value to indicate what interval is being used in the calculation. The options are
422
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
423
+	 * @param  integer  $value    What you want to increment the date by
424
+	 * @param  string   $operand  What operand you wish to use for the calculation
425
+	 * @return \DateTime return whatever type came in.
426
+	 * @throws \EE_Error
427
+	 */
428
+	protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
429
+	{
430
+		if (! $DateTime instanceof DateTime) {
431
+			throw new EE_Error(
432
+				sprintf(
433
+					__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
434
+					print_r($DateTime, true)
435
+				)
436
+			);
437
+		}
438
+		switch ($period) {
439
+			case 'years' :
440
+				$value = 'P' . $value . 'Y';
441
+				break;
442
+			case 'months' :
443
+				$value = 'P' . $value . 'M';
444
+				break;
445
+			case 'weeks' :
446
+				$value = 'P' . $value . 'W';
447
+				break;
448
+			case 'days' :
449
+				$value = 'P' . $value . 'D';
450
+				break;
451
+			case 'hours' :
452
+				$value = 'PT' . $value . 'H';
453
+				break;
454
+			case 'minutes' :
455
+				$value = 'PT' . $value . 'M';
456
+				break;
457
+			case 'seconds' :
458
+				$value = 'PT' . $value . 'S';
459
+				break;
460
+		}
461
+		switch ($operand) {
462
+			case '+':
463
+				$DateTime->add(new DateInterval($value));
464
+				break;
465
+			case '-':
466
+				$DateTime->sub(new DateInterval($value));
467
+				break;
468
+		}
469
+		return $DateTime;
470
+	}
471
+
472
+
473
+	/**
474
+	 * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters
475
+	 *
476
+	 * @param  int     $timestamp Unix timestamp
477
+	 * @param  string  $period    a value to indicate what interval is being used in the calculation. The options are
478
+	 *                            'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years.
479
+	 * @param  integer $value     What you want to increment the date by
480
+	 * @param  string  $operand   What operand you wish to use for the calculation
481
+	 * @return \DateTime return whatever type came in.
482
+	 * @throws \EE_Error
483
+	 */
484
+	protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
485
+	{
486
+		if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
487
+			throw new EE_Error(
488
+				sprintf(
489
+					__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
490
+					print_r($timestamp, true)
491
+				)
492
+			);
493
+		}
494
+		switch ($period) {
495
+			case 'years' :
496
+				$value = YEAR_IN_SECONDS * $value;
497
+				break;
498
+			case 'months' :
499
+				$value = YEAR_IN_SECONDS / 12 * $value;
500
+				break;
501
+			case 'weeks' :
502
+				$value = WEEK_IN_SECONDS * $value;
503
+				break;
504
+			case 'days' :
505
+				$value = DAY_IN_SECONDS * $value;
506
+				break;
507
+			case 'hours' :
508
+				$value = HOUR_IN_SECONDS * $value;
509
+				break;
510
+			case 'minutes' :
511
+				$value = MINUTE_IN_SECONDS * $value;
512
+				break;
513
+		}
514
+		switch ($operand) {
515
+			case '+':
516
+				$timestamp += $value;
517
+				break;
518
+			case '-':
519
+				$timestamp -= $value;
520
+				break;
521
+		}
522
+		return $timestamp;
523
+	}
524
+
964 525
 
965 526
 	/**
966
-     * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
967
-	* for this sites timezone, but the timestamp could be some other time GMT.
968
-    */
969
-    public static function tomorrow()
527
+	 * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming
528
+	 * parameters and returns the new timestamp or DateTime.
529
+	 *
530
+	 * @param  int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp
531
+	 * @param  string         $period                a value to indicate what interval is being used in the
532
+	 *                                               calculation. The options are 'years', 'months', 'days', 'hours',
533
+	 *                                               'minutes', 'seconds'. Defaults to years.
534
+	 * @param  integer        $value                 What you want to increment the date by
535
+	 * @param  string         $operand               What operand you wish to use for the calculation
536
+	 * @return mixed string|DateTime          return whatever type came in.
537
+	 */
538
+	public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+')
539
+	{
540
+		if ($DateTime_or_timestamp instanceof DateTime) {
541
+			return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand);
542
+		} else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) {
543
+			return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand);
544
+		} else {
545
+			//error
546
+			return $DateTime_or_timestamp;
547
+		}
548
+	}
549
+
550
+
551
+	/**
552
+	 * The purpose of this helper method is to receive an incoming format string in php date/time format
553
+	 * and spit out the js and moment.js equivalent formats.
554
+	 * Note, if no format string is given, then it is assumed the user wants what is set for WP.
555
+	 * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date-
556
+	 * time picker.
557
+	 *
558
+	 * @see http://stackoverflow.com/posts/16725290/ for the code inspiration.
559
+	 * @param null $date_format_string
560
+	 * @param null $time_format_string
561
+	 * @return array
562
+	 *                array(
563
+	 *                'js' => array (
564
+	 *                'date' => //date format
565
+	 *                'time' => //time format
566
+	 *                ),
567
+	 *                'moment' => //date and time format.
568
+	 *                )
569
+	 */
570
+	public static function convert_php_to_js_and_moment_date_formats(
571
+		$date_format_string = null,
572
+		$time_format_string = null
573
+	) {
574
+		if ($date_format_string === null) {
575
+			$date_format_string = get_option('date_format');
576
+		}
577
+
578
+		if ($time_format_string === null) {
579
+			$time_format_string = get_option('time_format');
580
+		}
581
+
582
+		$date_format = self::_php_to_js_moment_converter($date_format_string);
583
+		$time_format = self::_php_to_js_moment_converter($time_format_string);
584
+
585
+		return array(
586
+			'js'     => array(
587
+				'date' => $date_format['js'],
588
+				'time' => $time_format['js'],
589
+			),
590
+			'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
591
+		);
592
+	}
593
+
594
+
595
+	/**
596
+	 * This converts incoming format string into js and moment variations.
597
+	 *
598
+	 * @param string $format_string incoming php format string
599
+	 * @return array js and moment formats.
600
+	 */
601
+	protected static function _php_to_js_moment_converter($format_string)
602
+	{
603
+		/**
604
+		 * This is a map of symbols for formats.
605
+		 * The index is the php symbol, the equivalent values are in the array.
606
+		 *
607
+		 * @var array
608
+		 */
609
+		$symbols_map      = array(
610
+			// Day
611
+			//01
612
+			'd' => array(
613
+				'js'     => 'dd',
614
+				'moment' => 'DD',
615
+			),
616
+			//Mon
617
+			'D' => array(
618
+				'js'     => 'D',
619
+				'moment' => 'ddd',
620
+			),
621
+			//1,2,...31
622
+			'j' => array(
623
+				'js'     => 'd',
624
+				'moment' => 'D',
625
+			),
626
+			//Monday
627
+			'l' => array(
628
+				'js'     => 'DD',
629
+				'moment' => 'dddd',
630
+			),
631
+			//ISO numeric representation of the day of the week (1-6)
632
+			'N' => array(
633
+				'js'     => '',
634
+				'moment' => 'E',
635
+			),
636
+			//st,nd.rd
637
+			'S' => array(
638
+				'js'     => '',
639
+				'moment' => 'o',
640
+			),
641
+			//numeric representation of day of week (0-6)
642
+			'w' => array(
643
+				'js'     => '',
644
+				'moment' => 'd',
645
+			),
646
+			//day of year starting from 0 (0-365)
647
+			'z' => array(
648
+				'js'     => 'o',
649
+				'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1
650
+			),
651
+			// Week
652
+			//ISO-8601 week number of year (weeks starting on monday)
653
+			'W' => array(
654
+				'js'     => '',
655
+				'moment' => 'w',
656
+			),
657
+			// Month
658
+			// January...December
659
+			'F' => array(
660
+				'js'     => 'MM',
661
+				'moment' => 'MMMM',
662
+			),
663
+			//01...12
664
+			'm' => array(
665
+				'js'     => 'mm',
666
+				'moment' => 'MM',
667
+			),
668
+			//Jan...Dec
669
+			'M' => array(
670
+				'js'     => 'M',
671
+				'moment' => 'MMM',
672
+			),
673
+			//1-12
674
+			'n' => array(
675
+				'js'     => 'm',
676
+				'moment' => 'M',
677
+			),
678
+			//number of days in given month
679
+			't' => array(
680
+				'js'     => '',
681
+				'moment' => '',
682
+			),
683
+			// Year
684
+			//whether leap year or not 1/0
685
+			'L' => array(
686
+				'js'     => '',
687
+				'moment' => '',
688
+			),
689
+			//ISO-8601 year number
690
+			'o' => array(
691
+				'js'     => '',
692
+				'moment' => 'GGGG',
693
+			),
694
+			//1999...2003
695
+			'Y' => array(
696
+				'js'     => 'yy',
697
+				'moment' => 'YYYY',
698
+			),
699
+			//99...03
700
+			'y' => array(
701
+				'js'     => 'y',
702
+				'moment' => 'YY',
703
+			),
704
+			// Time
705
+			// am/pm
706
+			'a' => array(
707
+				'js'     => 'tt',
708
+				'moment' => 'a',
709
+			),
710
+			// AM/PM
711
+			'A' => array(
712
+				'js'     => 'TT',
713
+				'moment' => 'A',
714
+			),
715
+			// Swatch Internet Time?!?
716
+			'B' => array(
717
+				'js'     => '',
718
+				'moment' => '',
719
+			),
720
+			//1...12
721
+			'g' => array(
722
+				'js'     => 'h',
723
+				'moment' => 'h',
724
+			),
725
+			//0...23
726
+			'G' => array(
727
+				'js'     => 'H',
728
+				'moment' => 'H',
729
+			),
730
+			//01...12
731
+			'h' => array(
732
+				'js'     => 'hh',
733
+				'moment' => 'hh',
734
+			),
735
+			//00...23
736
+			'H' => array(
737
+				'js'     => 'HH',
738
+				'moment' => 'HH',
739
+			),
740
+			//00..59
741
+			'i' => array(
742
+				'js'     => 'mm',
743
+				'moment' => 'mm',
744
+			),
745
+			//seconds... 00...59
746
+			's' => array(
747
+				'js'     => 'ss',
748
+				'moment' => 'ss',
749
+			),
750
+			//microseconds
751
+			'u' => array(
752
+				'js'     => '',
753
+				'moment' => '',
754
+			),
755
+		);
756
+		$jquery_ui_format = "";
757
+		$moment_format    = "";
758
+		$escaping         = false;
759
+		for ($i = 0; $i < strlen($format_string); $i++) {
760
+			$char = $format_string[$i];
761
+			if ($char === '\\') { // PHP date format escaping character
762
+				$i++;
763
+				if ($escaping) {
764
+					$jquery_ui_format .= $format_string[$i];
765
+					$moment_format .= $format_string[$i];
766
+				} else {
767
+					$jquery_ui_format .= '\'' . $format_string[$i];
768
+					$moment_format .= $format_string[$i];
769
+				}
770
+				$escaping = true;
771
+			} else {
772
+				if ($escaping) {
773
+					$jquery_ui_format .= "'";
774
+					$moment_format .= "'";
775
+					$escaping = false;
776
+				}
777
+				if (isset($symbols_map[$char])) {
778
+					$jquery_ui_format .= $symbols_map[$char]['js'];
779
+					$moment_format .= $symbols_map[$char]['moment'];
780
+				} else {
781
+					$jquery_ui_format .= $char;
782
+					$moment_format .= $char;
783
+				}
784
+			}
785
+		}
786
+		return array('js' => $jquery_ui_format, 'moment' => $moment_format);
787
+	}
788
+
789
+
790
+	/**
791
+	 * This takes an incoming format string and validates it to ensure it will work fine with PHP.
792
+	 *
793
+	 * @param string $format_string   Incoming format string for php date().
794
+	 * @return mixed bool|array  If all is okay then TRUE is returned.  Otherwise an array of validation
795
+	 *                                errors is returned.  So for client code calling, check for is_array() to
796
+	 *                                indicate failed validations.
797
+	 */
798
+	public static function validate_format_string($format_string)
799
+	{
800
+		$error_msg = array();
801
+		//time format checks
802
+		switch (true) {
803
+			case   strpos($format_string, 'h') !== false  :
804
+			case   strpos($format_string, 'g') !== false :
805
+				/**
806
+				 * if the time string has a lowercase 'h' which == 12 hour time format and there
807
+				 * is not any ante meridiem format ('a' or 'A').  Then throw an error because its
808
+				 * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am.
809
+				 */
810
+				if (strpos(strtoupper($format_string), 'A') === false) {
811
+					$error_msg[] = __('There is a  time format for 12 hour time but no  "a" or "A" to indicate am/pm.  Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".',
812
+						'event_espresso');
813
+				}
814
+				break;
815
+
816
+		}
817
+
818
+		return empty($error_msg) ? true : $error_msg;
819
+	}
820
+
821
+
822
+	/**
823
+	 *     If the the first date starts at midnight on one day, and the next date ends at midnight on the
824
+	 *     very next day then this method will return true.
825
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true.
826
+	 *    If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false.
827
+	 *    If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true.
828
+	 *
829
+	 * @param mixed $date_1
830
+	 * @param mixed $date_2
831
+	 * @return bool
832
+	 */
833
+	public static function dates_represent_one_24_hour_date($date_1, $date_2)
834
+	{
835
+
836
+		if (
837
+			(! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
838
+			($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
839
+		) {
840
+			return false;
841
+		}
842
+		return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false;
843
+	}
844
+
845
+
846
+	/**
847
+	 * This returns the appropriate query interval string that can be used in sql queries involving mysql Date
848
+	 * Functions.
849
+	 *
850
+	 * @param string $timezone_string    A timezone string in a valid format to instantiate a DateTimeZone object.
851
+	 * @param string $field_for_interval The Database field that is the interval is applied to in the query.
852
+	 * @return string
853
+	 */
854
+	public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval)
855
+	{
856
+		try {
857
+			/** need to account for timezone offset on the selects */
858
+			$DateTimeZone = new DateTimeZone($timezone_string);
859
+		} catch (Exception $e) {
860
+			$DateTimeZone = null;
861
+		}
862
+
863
+		/**
864
+		 * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds.
865
+		 * Hence we do the calc for DateTimeZone::getOffset.
866
+		 */
867
+		$offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
868
+		$query_interval = $offset < 0
869
+			? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
870
+			: 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
871
+		return $query_interval;
872
+	}
873
+
874
+	/**
875
+	 * Retrieves the site's default timezone and returns it formatted so it's ready for display
876
+	 * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string'
877
+	 * and 'gmt_offset' WordPress options directly; or use the filter
878
+	 * FHEE__EEH_DTT_Helper__get_timezone_string_for_display
879
+	 * (although note that we remove any HTML that may be added)
880
+	 *
881
+	 * @return string
882
+	 */
883
+	public static function get_timezone_string_for_display()
884
+	{
885
+		$pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
886
+		if (! empty($pretty_timezone)) {
887
+			return esc_html($pretty_timezone);
888
+		}
889
+		$timezone_string = get_option('timezone_string');
890
+		if ($timezone_string) {
891
+			static $mo_loaded = false;
892
+			// Load translations for continents and cities just like wp_timezone_choice does
893
+			if (! $mo_loaded) {
894
+				$locale = get_locale();
895
+				$mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
896
+				load_textdomain('continents-cities', $mofile);
897
+				$mo_loaded = true;
898
+			}
899
+			//well that was easy.
900
+			$parts = explode('/', $timezone_string);
901
+			//remove the continent
902
+			unset($parts[0]);
903
+			$t_parts = array();
904
+			foreach ($parts as $part) {
905
+				$t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities');
906
+			}
907
+			return implode(' - ', $t_parts);
908
+		}
909
+		//they haven't set the timezone string, so let's return a string like "UTC+1"
910
+		$gmt_offset = get_option('gmt_offset');
911
+		if (intval($gmt_offset) >= 0) {
912
+			$prefix = '+';
913
+		} else {
914
+			$prefix = '';
915
+		}
916
+		$parts = explode('.', (string)$gmt_offset);
917
+		if (count($parts) === 1) {
918
+			$parts[1] = '00';
919
+		} else {
920
+			//convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
921
+			//to minutes, eg 30 or 15, respectively
922
+			$hour_fraction = (float)('0.' . $parts[1]);
923
+			$parts[1]      = (string)$hour_fraction * 60;
924
+		}
925
+		return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
926
+	}
927
+
928
+
929
+
930
+	/**
931
+	 * So PHP does this awesome thing where if you are trying to get a timestamp
932
+	 * for a month using a string like "February" or "February 2017",
933
+	 * and you don't specify a day as part of your string,
934
+	 * then PHP will use whatever the current day of the month is.
935
+	 * IF the current day of the month happens to be the 30th or 31st,
936
+	 * then PHP gets really confused by a date like February 30,
937
+	 * so instead of saying
938
+	 *      "Hey February only has 28 days (this year)...
939
+	 *      ...you must have meant the last day of the month!"
940
+	 * PHP does the next most logical thing, and bumps the date up to March 2nd,
941
+	 * because someone requesting February 30th obviously meant March 1st!
942
+	 * The way around this is to always set the day to the first,
943
+	 * so that the month will stay on the month you wanted.
944
+	 * this method will add that "1" into your date regardless of the format.
945
+	 *
946
+	 * @param string $month
947
+	 * @return string
948
+	 */
949
+	public static function first_of_month_timestamp($month = '')
950
+	{
951
+		$month = (string)$month;
952
+		$year = '';
953
+		// check if the incoming string has a year in it or not
954
+	   if (preg_match('/\b\d{4}\b/', $month, $matches)) {
955
+		   $year = $matches[0];
956
+		   // ten remove that from the month string as well as any spaces
957
+		   $month = trim(str_replace($year, '', $month));
958
+		   // add a space before the year
959
+		   $year = " {$year}";
960
+		}
961
+		// return timestamp for something like "February 1 2017"
962
+		return strtotime("{$month} 1{$year}");
963
+	}
964
+
965
+	/**
966
+	 * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone.  So it may be midnight
967
+	 * for this sites timezone, but the timestamp could be some other time GMT.
968
+	 */
969
+	public static function tomorrow()
970 970
 	{
971 971
 		//The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive
972 972
 		//before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
@@ -976,135 +976,135 @@  discard block
 block discarded – undo
976 976
 	}
977 977
 
978 978
 
979
-    /**
980
-     * **
981
-     * Gives a nicely-formatted list of timezone strings.
982
-     * Copied from the core wp function by the same name so we could customize to remove UTC offsets.
983
-     *
984
-     * @since     4.9.40.rc.008
985
-     * @staticvar bool $mo_loaded
986
-     * @staticvar string $locale_loaded
987
-     * @param string $selected_zone Selected timezone.
988
-     * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
989
-     * @return string
990
-     */
991
-    public static function wp_timezone_choice($selected_zone, $locale = null)
992
-    {
993
-        static $mo_loaded = false, $locale_loaded = null;
994
-
995
-        $continents = array(
996
-            'Africa',
997
-            'America',
998
-            'Antarctica',
999
-            'Arctic',
1000
-            'Asia',
1001
-            'Atlantic',
1002
-            'Australia',
1003
-            'Europe',
1004
-            'Indian',
1005
-            'Pacific',
1006
-        );
1007
-
1008
-        // Load translations for continents and cities.
1009
-        if (! $mo_loaded || $locale !== $locale_loaded) {
1010
-            $locale_loaded = $locale ? $locale : get_locale();
1011
-            $mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
1012
-            unload_textdomain('continents-cities');
1013
-            load_textdomain('continents-cities', $mofile);
1014
-            $mo_loaded = true;
1015
-        }
1016
-
1017
-        $zonen = array();
1018
-        foreach (timezone_identifiers_list() as $zone) {
1019
-            $zone = explode('/', $zone);
1020
-            if (! in_array($zone[0], $continents)) {
1021
-                continue;
1022
-            }
1023
-
1024
-            // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
1025
-            $exists    = array(
1026
-                0 => (isset($zone[0]) && $zone[0]),
1027
-                1 => (isset($zone[1]) && $zone[1]),
1028
-                2 => (isset($zone[2]) && $zone[2]),
1029
-            );
1030
-            $exists[3] = ($exists[0] && 'Etc' !== $zone[0]);
1031
-            $exists[4] = ($exists[1] && $exists[3]);
1032
-            $exists[5] = ($exists[2] && $exists[3]);
1033
-
1034
-            $zonen[] = array(
1035
-                'continent'   => ($exists[0] ? $zone[0] : ''),
1036
-                'city'        => ($exists[1] ? $zone[1] : ''),
1037
-                'subcity'     => ($exists[2] ? $zone[2] : ''),
1038
-                't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''),
1039
-                't_city'      => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''),
1040
-                't_subcity'   => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''),
1041
-            );
1042
-        }
1043
-        usort($zonen, '_wp_timezone_choice_usort_callback');
1044
-
1045
-        $structure = array();
1046
-
1047
-        if (empty($selected_zone)) {
1048
-            $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>';
1049
-        }
1050
-
1051
-        foreach ($zonen as $key => $zone) {
1052
-            // Build value in an array to join later
1053
-            $value = array($zone['continent']);
1054
-
1055
-            if (empty($zone['city'])) {
1056
-                // It's at the continent level (generally won't happen)
1057
-                $display = $zone['t_continent'];
1058
-            } else {
1059
-                // It's inside a continent group
1060
-
1061
-                // Continent optgroup
1062
-                if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) {
1063
-                    $label       = $zone['t_continent'];
1064
-                    $structure[] = '<optgroup label="' . esc_attr($label) . '">';
1065
-                }
1066
-
1067
-                // Add the city to the value
1068
-                $value[] = $zone['city'];
1069
-
1070
-                $display = $zone['t_city'];
1071
-                if (! empty($zone['subcity'])) {
1072
-                    // Add the subcity to the value
1073
-                    $value[] = $zone['subcity'];
1074
-                    $display .= ' - ' . $zone['t_subcity'];
1075
-                }
1076
-            }
1077
-
1078
-            // Build the value
1079
-            $value    = join('/', $value);
1080
-            $selected = '';
1081
-            if ($value === $selected_zone) {
1082
-                $selected = 'selected="selected" ';
1083
-            }
1084
-            $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>";
1085
-
1086
-            // Close continent optgroup
1087
-            if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) {
1088
-                $structure[] = '</optgroup>';
1089
-            }
1090
-        }
1091
-
1092
-        return join("\n", $structure);
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1098
-     *
1099
-     * @param int|WP_User $user_id
1100
-     * @return string
1101
-     */
1102
-    public static function get_user_locale($user_id = 0)
1103
-    {
1104
-        if (function_exists('get_user_locale')) {
1105
-            return get_user_locale($user_id);
1106
-        }
1107
-        return get_locale();
1108
-    }
979
+	/**
980
+	 * **
981
+	 * Gives a nicely-formatted list of timezone strings.
982
+	 * Copied from the core wp function by the same name so we could customize to remove UTC offsets.
983
+	 *
984
+	 * @since     4.9.40.rc.008
985
+	 * @staticvar bool $mo_loaded
986
+	 * @staticvar string $locale_loaded
987
+	 * @param string $selected_zone Selected timezone.
988
+	 * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
989
+	 * @return string
990
+	 */
991
+	public static function wp_timezone_choice($selected_zone, $locale = null)
992
+	{
993
+		static $mo_loaded = false, $locale_loaded = null;
994
+
995
+		$continents = array(
996
+			'Africa',
997
+			'America',
998
+			'Antarctica',
999
+			'Arctic',
1000
+			'Asia',
1001
+			'Atlantic',
1002
+			'Australia',
1003
+			'Europe',
1004
+			'Indian',
1005
+			'Pacific',
1006
+		);
1007
+
1008
+		// Load translations for continents and cities.
1009
+		if (! $mo_loaded || $locale !== $locale_loaded) {
1010
+			$locale_loaded = $locale ? $locale : get_locale();
1011
+			$mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
1012
+			unload_textdomain('continents-cities');
1013
+			load_textdomain('continents-cities', $mofile);
1014
+			$mo_loaded = true;
1015
+		}
1016
+
1017
+		$zonen = array();
1018
+		foreach (timezone_identifiers_list() as $zone) {
1019
+			$zone = explode('/', $zone);
1020
+			if (! in_array($zone[0], $continents)) {
1021
+				continue;
1022
+			}
1023
+
1024
+			// This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
1025
+			$exists    = array(
1026
+				0 => (isset($zone[0]) && $zone[0]),
1027
+				1 => (isset($zone[1]) && $zone[1]),
1028
+				2 => (isset($zone[2]) && $zone[2]),
1029
+			);
1030
+			$exists[3] = ($exists[0] && 'Etc' !== $zone[0]);
1031
+			$exists[4] = ($exists[1] && $exists[3]);
1032
+			$exists[5] = ($exists[2] && $exists[3]);
1033
+
1034
+			$zonen[] = array(
1035
+				'continent'   => ($exists[0] ? $zone[0] : ''),
1036
+				'city'        => ($exists[1] ? $zone[1] : ''),
1037
+				'subcity'     => ($exists[2] ? $zone[2] : ''),
1038
+				't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''),
1039
+				't_city'      => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''),
1040
+				't_subcity'   => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''),
1041
+			);
1042
+		}
1043
+		usort($zonen, '_wp_timezone_choice_usort_callback');
1044
+
1045
+		$structure = array();
1046
+
1047
+		if (empty($selected_zone)) {
1048
+			$structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>';
1049
+		}
1050
+
1051
+		foreach ($zonen as $key => $zone) {
1052
+			// Build value in an array to join later
1053
+			$value = array($zone['continent']);
1054
+
1055
+			if (empty($zone['city'])) {
1056
+				// It's at the continent level (generally won't happen)
1057
+				$display = $zone['t_continent'];
1058
+			} else {
1059
+				// It's inside a continent group
1060
+
1061
+				// Continent optgroup
1062
+				if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) {
1063
+					$label       = $zone['t_continent'];
1064
+					$structure[] = '<optgroup label="' . esc_attr($label) . '">';
1065
+				}
1066
+
1067
+				// Add the city to the value
1068
+				$value[] = $zone['city'];
1069
+
1070
+				$display = $zone['t_city'];
1071
+				if (! empty($zone['subcity'])) {
1072
+					// Add the subcity to the value
1073
+					$value[] = $zone['subcity'];
1074
+					$display .= ' - ' . $zone['t_subcity'];
1075
+				}
1076
+			}
1077
+
1078
+			// Build the value
1079
+			$value    = join('/', $value);
1080
+			$selected = '';
1081
+			if ($value === $selected_zone) {
1082
+				$selected = 'selected="selected" ';
1083
+			}
1084
+			$structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>";
1085
+
1086
+			// Close continent optgroup
1087
+			if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) {
1088
+				$structure[] = '</optgroup>';
1089
+			}
1090
+		}
1091
+
1092
+		return join("\n", $structure);
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0
1098
+	 *
1099
+	 * @param int|WP_User $user_id
1100
+	 * @return string
1101
+	 */
1102
+	public static function get_user_locale($user_id = 0)
1103
+	{
1104
+		if (function_exists('get_user_locale')) {
1105
+			return get_user_locale($user_id);
1106
+		}
1107
+		return get_locale();
1108
+	}
1109 1109
 
1110 1110
 }// end class EEH_DTT_Helper
Please login to merge, or discard this patch.
Spacing   +50 added lines, -51 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
             new DateTimeZone($timezone_string);
75 75
         } catch (Exception $e) {
76 76
             // sometimes we take exception to exceptions
77
-            if (! $throw_error) {
77
+            if ( ! $throw_error) {
78 78
                 return false;
79 79
             }
80 80
             throw new EE_Error(
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
             }
136 136
         }
137 137
         $offset = get_option('gmt_offset');
138
-        return (int)($offset * HOUR_IN_SECONDS);
138
+        return (int) ($offset * HOUR_IN_SECONDS);
139 139
     }
140 140
 
141 141
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     public static function adjust_invalid_gmt_offsets($gmt_offset = 0)
150 150
     {
151 151
         //make sure $gmt_offset is int
152
-        $gmt_offset = (int)$gmt_offset;
152
+        $gmt_offset = (int) $gmt_offset;
153 153
         switch ($gmt_offset) {
154 154
 
155 155
             //			case -30600 :
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
     public static function timezone_select_input($timezone_string = '')
234 234
     {
235 235
         // get WP date time format
236
-        $datetime_format = get_option('date_format') . ' ' . get_option('time_format');
236
+        $datetime_format = get_option('date_format').' '.get_option('time_format');
237 237
         // if passed a value, then use that, else get WP option
238 238
         $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string');
239 239
         // check if the timezone is valid but don't throw any errors if it isn't
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
             // Create a UTC+- zone if no timezone string exists
246 246
             $check_zone_info = false;
247 247
             if ($gmt_offset > 0) {
248
-                $timezone_string = 'UTC+' . $gmt_offset;
248
+                $timezone_string = 'UTC+'.$gmt_offset;
249 249
             } elseif ($gmt_offset < 0) {
250
-                $timezone_string = 'UTC' . $gmt_offset;
250
+                $timezone_string = 'UTC'.$gmt_offset;
251 251
             } else {
252 252
                 $timezone_string = 'UTC';
253 253
             }
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
                 __('%1$sUTC%2$s time is %3$s'),
270 270
                 '<abbr title="Coordinated Universal Time">',
271 271
                 '</abbr>',
272
-                '<code>' . date_i18n($datetime_format, false, true) . '</code>'
272
+                '<code>'.date_i18n($datetime_format, false, true).'</code>'
273 273
             );
274 274
             ?></span>
275
-        <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?>
276
-        <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span>
275
+        <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?>
276
+        <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span>
277 277
     <?php endif; ?>
278 278
 
279 279
         <?php if ($check_zone_info && $timezone_string) : ?>
@@ -306,11 +306,10 @@  discard block
 block discarded – undo
306 306
 
307 307
                 if ($found) {
308 308
                     $message = $tr['isdst'] ?
309
-                        __(' Daylight saving time begins on: %s.') :
310
-                        __(' Standard time begins  on: %s.');
309
+                        __(' Daylight saving time begins on: %s.') : __(' Standard time begins  on: %s.');
311 310
                     // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n().
312 311
                     printf($message,
313
-                        '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >');
312
+                        '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >');
314 313
                 } else {
315 314
                     _e('This timezone does not observe daylight saving time.');
316 315
                 }
@@ -338,13 +337,13 @@  discard block
 block discarded – undo
338 337
      */
339 338
     public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '')
340 339
     {
341
-        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int)$unix_timestamp;
340
+        $unix_timestamp  = $unix_timestamp === 0 ? time() : (int) $unix_timestamp;
342 341
         $timezone_string = self::get_valid_timezone_string($timezone_string);
343 342
         $TimeZone        = new DateTimeZone($timezone_string);
344 343
 
345
-        $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone);
344
+        $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone);
346 345
         $offset   = timezone_offset_get($TimeZone, $DateTime);
347
-        return (int)$DateTime->format('U') + (int)$offset;
346
+        return (int) $DateTime->format('U') + (int) $offset;
348 347
     }
349 348
 
350 349
 
@@ -427,7 +426,7 @@  discard block
 block discarded – undo
427 426
      */
428 427
     protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+')
429 428
     {
430
-        if (! $DateTime instanceof DateTime) {
429
+        if ( ! $DateTime instanceof DateTime) {
431 430
             throw new EE_Error(
432 431
                 sprintf(
433 432
                     __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'),
@@ -437,25 +436,25 @@  discard block
 block discarded – undo
437 436
         }
438 437
         switch ($period) {
439 438
             case 'years' :
440
-                $value = 'P' . $value . 'Y';
439
+                $value = 'P'.$value.'Y';
441 440
                 break;
442 441
             case 'months' :
443
-                $value = 'P' . $value . 'M';
442
+                $value = 'P'.$value.'M';
444 443
                 break;
445 444
             case 'weeks' :
446
-                $value = 'P' . $value . 'W';
445
+                $value = 'P'.$value.'W';
447 446
                 break;
448 447
             case 'days' :
449
-                $value = 'P' . $value . 'D';
448
+                $value = 'P'.$value.'D';
450 449
                 break;
451 450
             case 'hours' :
452
-                $value = 'PT' . $value . 'H';
451
+                $value = 'PT'.$value.'H';
453 452
                 break;
454 453
             case 'minutes' :
455
-                $value = 'PT' . $value . 'M';
454
+                $value = 'PT'.$value.'M';
456 455
                 break;
457 456
             case 'seconds' :
458
-                $value = 'PT' . $value . 'S';
457
+                $value = 'PT'.$value.'S';
459 458
                 break;
460 459
         }
461 460
         switch ($operand) {
@@ -483,7 +482,7 @@  discard block
 block discarded – undo
483 482
      */
484 483
     protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+')
485 484
     {
486
-        if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
485
+        if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) {
487 486
             throw new EE_Error(
488 487
                 sprintf(
489 488
                     __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'),
@@ -587,7 +586,7 @@  discard block
 block discarded – undo
587 586
                 'date' => $date_format['js'],
588 587
                 'time' => $time_format['js'],
589 588
             ),
590
-            'moment' => $date_format['moment'] . ' ' . $time_format['moment'],
589
+            'moment' => $date_format['moment'].' '.$time_format['moment'],
591 590
         );
592 591
     }
593 592
 
@@ -606,7 +605,7 @@  discard block
 block discarded – undo
606 605
          *
607 606
          * @var array
608 607
          */
609
-        $symbols_map      = array(
608
+        $symbols_map = array(
610 609
             // Day
611 610
             //01
612 611
             'd' => array(
@@ -764,7 +763,7 @@  discard block
 block discarded – undo
764 763
                     $jquery_ui_format .= $format_string[$i];
765 764
                     $moment_format .= $format_string[$i];
766 765
                 } else {
767
-                    $jquery_ui_format .= '\'' . $format_string[$i];
766
+                    $jquery_ui_format .= '\''.$format_string[$i];
768 767
                     $moment_format .= $format_string[$i];
769 768
                 }
770 769
                 $escaping = true;
@@ -834,7 +833,7 @@  discard block
 block discarded – undo
834 833
     {
835 834
 
836 835
         if (
837
-            (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
836
+            ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) ||
838 837
             ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00')
839 838
         ) {
840 839
             return false;
@@ -866,8 +865,8 @@  discard block
 block discarded – undo
866 865
          */
867 866
         $offset         = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset');
868 867
         $query_interval = $offset < 0
869
-            ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)'
870
-            : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)';
868
+            ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)'
869
+            : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)';
871 870
         return $query_interval;
872 871
     }
873 872
 
@@ -883,16 +882,16 @@  discard block
 block discarded – undo
883 882
     public static function get_timezone_string_for_display()
884 883
     {
885 884
         $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', '');
886
-        if (! empty($pretty_timezone)) {
885
+        if ( ! empty($pretty_timezone)) {
887 886
             return esc_html($pretty_timezone);
888 887
         }
889 888
         $timezone_string = get_option('timezone_string');
890 889
         if ($timezone_string) {
891 890
             static $mo_loaded = false;
892 891
             // Load translations for continents and cities just like wp_timezone_choice does
893
-            if (! $mo_loaded) {
892
+            if ( ! $mo_loaded) {
894 893
                 $locale = get_locale();
895
-                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
894
+                $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo';
896 895
                 load_textdomain('continents-cities', $mofile);
897 896
                 $mo_loaded = true;
898 897
             }
@@ -913,16 +912,16 @@  discard block
 block discarded – undo
913 912
         } else {
914 913
             $prefix = '';
915 914
         }
916
-        $parts = explode('.', (string)$gmt_offset);
915
+        $parts = explode('.', (string) $gmt_offset);
917 916
         if (count($parts) === 1) {
918 917
             $parts[1] = '00';
919 918
         } else {
920 919
             //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25)
921 920
             //to minutes, eg 30 or 15, respectively
922
-            $hour_fraction = (float)('0.' . $parts[1]);
923
-            $parts[1]      = (string)$hour_fraction * 60;
921
+            $hour_fraction = (float) ('0.'.$parts[1]);
922
+            $parts[1]      = (string) $hour_fraction * 60;
924 923
         }
925
-        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts));
924
+        return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts));
926 925
     }
927 926
 
928 927
 
@@ -948,7 +947,7 @@  discard block
 block discarded – undo
948 947
      */
949 948
     public static function first_of_month_timestamp($month = '')
950 949
     {
951
-        $month = (string)$month;
950
+        $month = (string) $month;
952 951
         $year = '';
953 952
         // check if the incoming string has a year in it or not
954 953
        if (preg_match('/\b\d{4}\b/', $month, $matches)) {
@@ -972,7 +971,7 @@  discard block
 block discarded – undo
972 971
 		//before adding to the timestamp.  Why? Because we want tomorrow to be for midnight the next day in THIS timezone
973 972
 		//not an offset from midnight in UTC.  So if we're starting with UTC 00:00:00, then we want to make sure the
974 973
 		//final timestamp is equivalent to midnight in this timezone as represented in GMT.
975
-		return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset()*-1);
974
+		return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1);
976 975
 	}
977 976
 
978 977
 
@@ -1006,9 +1005,9 @@  discard block
 block discarded – undo
1006 1005
         );
1007 1006
 
1008 1007
         // Load translations for continents and cities.
1009
-        if (! $mo_loaded || $locale !== $locale_loaded) {
1008
+        if ( ! $mo_loaded || $locale !== $locale_loaded) {
1010 1009
             $locale_loaded = $locale ? $locale : get_locale();
1011
-            $mofile        = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
1010
+            $mofile        = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo';
1012 1011
             unload_textdomain('continents-cities');
1013 1012
             load_textdomain('continents-cities', $mofile);
1014 1013
             $mo_loaded = true;
@@ -1017,12 +1016,12 @@  discard block
 block discarded – undo
1017 1016
         $zonen = array();
1018 1017
         foreach (timezone_identifiers_list() as $zone) {
1019 1018
             $zone = explode('/', $zone);
1020
-            if (! in_array($zone[0], $continents)) {
1019
+            if ( ! in_array($zone[0], $continents)) {
1021 1020
                 continue;
1022 1021
             }
1023 1022
 
1024 1023
             // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later
1025
-            $exists    = array(
1024
+            $exists = array(
1026 1025
                 0 => (isset($zone[0]) && $zone[0]),
1027 1026
                 1 => (isset($zone[1]) && $zone[1]),
1028 1027
                 2 => (isset($zone[2]) && $zone[2]),
@@ -1045,7 +1044,7 @@  discard block
 block discarded – undo
1045 1044
         $structure = array();
1046 1045
 
1047 1046
         if (empty($selected_zone)) {
1048
-            $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>';
1047
+            $structure[] = '<option selected="selected" value="">'.__('Select a city').'</option>';
1049 1048
         }
1050 1049
 
1051 1050
         foreach ($zonen as $key => $zone) {
@@ -1059,19 +1058,19 @@  discard block
 block discarded – undo
1059 1058
                 // It's inside a continent group
1060 1059
 
1061 1060
                 // Continent optgroup
1062
-                if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) {
1061
+                if ( ! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) {
1063 1062
                     $label       = $zone['t_continent'];
1064
-                    $structure[] = '<optgroup label="' . esc_attr($label) . '">';
1063
+                    $structure[] = '<optgroup label="'.esc_attr($label).'">';
1065 1064
                 }
1066 1065
 
1067 1066
                 // Add the city to the value
1068 1067
                 $value[] = $zone['city'];
1069 1068
 
1070 1069
                 $display = $zone['t_city'];
1071
-                if (! empty($zone['subcity'])) {
1070
+                if ( ! empty($zone['subcity'])) {
1072 1071
                     // Add the subcity to the value
1073 1072
                     $value[] = $zone['subcity'];
1074
-                    $display .= ' - ' . $zone['t_subcity'];
1073
+                    $display .= ' - '.$zone['t_subcity'];
1075 1074
                 }
1076 1075
             }
1077 1076
 
@@ -1081,10 +1080,10 @@  discard block
 block discarded – undo
1081 1080
             if ($value === $selected_zone) {
1082 1081
                 $selected = 'selected="selected" ';
1083 1082
             }
1084
-            $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>";
1083
+            $structure[] = '<option '.$selected.'value="'.esc_attr($value).'">'.esc_html($display)."</option>";
1085 1084
 
1086 1085
             // Close continent optgroup
1087
-            if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) {
1086
+            if ( ! empty($zone['city']) && ( ! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) {
1088 1087
                 $structure[] = '</optgroup>';
1089 1088
             }
1090 1089
         }
Please login to merge, or discard this patch.
caffeinated/modules/event_single_caff/EED_Event_Single_Caff.module.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -118,40 +118,40 @@
 block discarded – undo
118 118
 	 * @return EE_Template_Config
119 119
 	 */
120 120
 	public static function update_template_settings(EE_Template_Config $CFG, $REQ ) {
121
-	    if(! $CFG->EED_Event_Single instanceof EE_Event_Single_Config){
122
-            $CFG->EED_Event_Single = new EE_Event_Single_Config();
123
-        }
124
-        $display_order_event = $CFG->EED_Event_Single->display_order_event !== null
125
-            ? $CFG->EED_Event_Single->display_order_event
126
-            : EED_Event_Single::EVENT_DETAILS_PRIORITY;
121
+		if(! $CFG->EED_Event_Single instanceof EE_Event_Single_Config){
122
+			$CFG->EED_Event_Single = new EE_Event_Single_Config();
123
+		}
124
+		$display_order_event = $CFG->EED_Event_Single->display_order_event !== null
125
+			? $CFG->EED_Event_Single->display_order_event
126
+			: EED_Event_Single::EVENT_DETAILS_PRIORITY;
127 127
 		$display_order_datetimes = $CFG->EED_Event_Single->display_order_datetimes !== null
128
-            ? $CFG->EED_Event_Single->display_order_datetimes
129
-            : EED_Event_Single::EVENT_DATETIMES_PRIORITY;
130
-        $display_order_tickets = $CFG->EED_Event_Single->display_order_tickets !== null
131
-            ? $CFG->EED_Event_Single->display_order_tickets
132
-            : EED_Event_Single::EVENT_TICKETS_PRIORITY;
128
+			? $CFG->EED_Event_Single->display_order_datetimes
129
+			: EED_Event_Single::EVENT_DATETIMES_PRIORITY;
130
+		$display_order_tickets = $CFG->EED_Event_Single->display_order_tickets !== null
131
+			? $CFG->EED_Event_Single->display_order_tickets
132
+			: EED_Event_Single::EVENT_TICKETS_PRIORITY;
133 133
 		$display_order_venue = $CFG->EED_Event_Single->display_order_venue !== null
134
-            ? $CFG->EED_Event_Single->display_order_venue
135
-            : EED_Event_Single::EVENT_VENUES_PRIORITY;
134
+			? $CFG->EED_Event_Single->display_order_venue
135
+			: EED_Event_Single::EVENT_VENUES_PRIORITY;
136 136
 		$CFG->EED_Event_Single = new EE_Event_Single_Config();
137 137
 		$CFG->EED_Event_Single->display_status_banner_single = ! empty( $REQ['display_status_banner_single'] )
138
-            && $REQ['display_status_banner_single'];
138
+			&& $REQ['display_status_banner_single'];
139 139
 		$CFG->EED_Event_Single->display_venue = ! empty( $REQ['display_venue'] ) && $REQ['display_venue'];
140 140
 		$CFG->EED_Event_Single->use_sortable_display_order = ! empty( $REQ[ 'EED_Events_Single_use_sortable_display_order' ] )
141
-            ? absint( $REQ[ 'EED_Events_Single_use_sortable_display_order' ] )
142
-            : 0;
141
+			? absint( $REQ[ 'EED_Events_Single_use_sortable_display_order' ] )
142
+			: 0;
143 143
 		$CFG->EED_Event_Single->display_order_event = $CFG->EED_Event_Single->use_sortable_display_order
144
-            ? $display_order_event
145
-            : EED_Event_Single::EVENT_DETAILS_PRIORITY;
144
+			? $display_order_event
145
+			: EED_Event_Single::EVENT_DETAILS_PRIORITY;
146 146
 		$CFG->EED_Event_Single->display_order_datetimes = $CFG->EED_Event_Single->use_sortable_display_order
147
-            ? $display_order_datetimes
148
-            : EED_Event_Single::EVENT_DATETIMES_PRIORITY;
147
+			? $display_order_datetimes
148
+			: EED_Event_Single::EVENT_DATETIMES_PRIORITY;
149 149
 		$CFG->EED_Event_Single->display_order_tickets = $CFG->EED_Event_Single->use_sortable_display_order
150
-            ? $display_order_tickets
151
-            : EED_Event_Single::EVENT_TICKETS_PRIORITY;
150
+			? $display_order_tickets
151
+			: EED_Event_Single::EVENT_TICKETS_PRIORITY;
152 152
 		$CFG->EED_Event_Single->display_order_venue = $CFG->EED_Event_Single->use_sortable_display_order
153
-            ? $display_order_venue
154
-            : EED_Event_Single::EVENT_VENUES_PRIORITY;
153
+			? $display_order_venue
154
+			: EED_Event_Single::EVENT_VENUES_PRIORITY;
155 155
 		do_action( 'AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ );
156 156
 		return $CFG;
157 157
 	}
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @return EED_Event_Single_Caff
30 30
 	 */
31 31
 	public static function instance() {
32
-		return parent::get_instance( __CLASS__ );
32
+		return parent::get_instance(__CLASS__);
33 33
 	}
34 34
 
35 35
 
@@ -50,34 +50,34 @@  discard block
 block discarded – undo
50 50
 	 *  @return 	void
51 51
 	 */
52 52
 	public static function set_hooks_admin() {
53
-		define( 'EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path( __FILE__ ) . 'templates' . DS );
54
-		define( 'EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
53
+		define('EVENT_SINGLE_CAFF_TEMPLATES_PATH', plugin_dir_path(__FILE__).'templates'.DS);
54
+		define('EVENT_SINGLE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
55 55
 		add_action(
56 56
 			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__template_settings',
57
-			array( 'EED_Event_Single_Caff', 'load_scripts_styles' ),
57
+			array('EED_Event_Single_Caff', 'load_scripts_styles'),
58 58
 			10
59 59
 		);
60
-		add_action( 'AHEE__template_settings__template__before_settings_form', array( 'EED_Event_Single_Caff', 'template_settings_form' ), 10 );
61
-		add_filter( 'FHEE__General_Settings_Admin_Page__update_template_settings__data', array( 'EED_Event_Single_Caff', 'update_template_settings' ), 10, 2 );
60
+		add_action('AHEE__template_settings__template__before_settings_form', array('EED_Event_Single_Caff', 'template_settings_form'), 10);
61
+		add_filter('FHEE__General_Settings_Admin_Page__update_template_settings__data', array('EED_Event_Single_Caff', 'update_template_settings'), 10, 2);
62 62
 		// AJAX
63
-		add_action( 'wp_ajax_espresso_update_event_single_order', array( 'EED_Event_Single_Caff', 'update_event_single_order' ) );
64
-		add_action( 'wp_ajax_nopriv_espresso_update_event_single_order', array( 'EED_Event_Single_Caff', 'update_event_single_order' ) );
63
+		add_action('wp_ajax_espresso_update_event_single_order', array('EED_Event_Single_Caff', 'update_event_single_order'));
64
+		add_action('wp_ajax_nopriv_espresso_update_event_single_order', array('EED_Event_Single_Caff', 'update_event_single_order'));
65 65
 
66 66
 	}
67 67
 
68 68
 
69 69
 
70 70
 	public static function load_scripts_styles() {
71
-		add_action( 'admin_enqueue_scripts', array( 'EED_Event_Single_Caff', 'enqueue_scripts_styles' ), 10 );
71
+		add_action('admin_enqueue_scripts', array('EED_Event_Single_Caff', 'enqueue_scripts_styles'), 10);
72 72
 	}
73 73
 
74 74
 
75 75
 
76 76
 	public static function enqueue_scripts_styles() {
77
-		wp_register_style( 'eed-event-single-sortable', EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.css', array(), EVENT_ESPRESSO_VERSION );
78
-		wp_enqueue_style( 'eed-event-single-sortable' );
79
-		wp_register_script( 'eed-event-single-sortable', EVENT_SINGLE_CAFF_ASSETS_URL . 'eed_event_single_sortable.js', array( 'jquery-ui-sortable' ), EVENT_ESPRESSO_VERSION, true );
80
-		wp_enqueue_script( 'eed-event-single-sortable' );
77
+		wp_register_style('eed-event-single-sortable', EVENT_SINGLE_CAFF_ASSETS_URL.'eed_event_single_sortable.css', array(), EVENT_ESPRESSO_VERSION);
78
+		wp_enqueue_style('eed-event-single-sortable');
79
+		wp_register_script('eed-event-single-sortable', EVENT_SINGLE_CAFF_ASSETS_URL.'eed_event_single_sortable.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true);
80
+		wp_enqueue_script('eed-event-single-sortable');
81 81
 	}
82 82
 
83 83
 
@@ -91,21 +91,21 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public static function template_settings_form() {
93 93
 		$config = EE_Registry::instance()->CFG->template_settings;
94
-		$config = isset( $config->EED_Event_Single ) && $config->EED_Event_Single instanceof EE_Event_Single_Config ? $config->EED_Event_Single : new EE_Event_Single_Config();
95
-		$config->use_sortable_display_order = isset( $config->use_sortable_display_order ) ? $config->use_sortable_display_order : false;
96
-		$config = apply_filters( 'FHEE__EED_Event_Single__template_settings_form__event_list_config', $config );
94
+		$config = isset($config->EED_Event_Single) && $config->EED_Event_Single instanceof EE_Event_Single_Config ? $config->EED_Event_Single : new EE_Event_Single_Config();
95
+		$config->use_sortable_display_order = isset($config->use_sortable_display_order) ? $config->use_sortable_display_order : false;
96
+		$config = apply_filters('FHEE__EED_Event_Single__template_settings_form__event_list_config', $config);
97 97
 
98 98
 		$event_single_order_array = array();
99
-		$event_single_order_array[ $config->display_order_tickets ] = 'tickets';
100
-		$event_single_order_array[ $config->display_order_datetimes ] = 'datetimes';
101
-		$event_single_order_array[ $config->display_order_event ] = 'event';
102
-		$event_single_order_array[ $config->display_order_venue ] = 'venue';
99
+		$event_single_order_array[$config->display_order_tickets] = 'tickets';
100
+		$event_single_order_array[$config->display_order_datetimes] = 'datetimes';
101
+		$event_single_order_array[$config->display_order_event] = 'event';
102
+		$event_single_order_array[$config->display_order_venue] = 'venue';
103 103
 		// get template parts
104
-		$template_parts = EED_Event_Single::instance()->initialize_template_parts( $config );
104
+		$template_parts = EED_Event_Single::instance()->initialize_template_parts($config);
105 105
 		// convert to array so that we can add more properties
106
-		$config = get_object_vars( $config );
107
-		$config[ 'event_single_display_order' ] = $template_parts->generate_sortable_list_of_template_parts( 'event-single-sortable-js', '', 'single-sortable-li single-sortable-js' );
108
-		EEH_Template::display_template( EVENT_SINGLE_CAFF_TEMPLATES_PATH . 'admin-event-single-settings.template.php', $config );
106
+		$config = get_object_vars($config);
107
+		$config['event_single_display_order'] = $template_parts->generate_sortable_list_of_template_parts('event-single-sortable-js', '', 'single-sortable-li single-sortable-js');
108
+		EEH_Template::display_template(EVENT_SINGLE_CAFF_TEMPLATES_PATH.'admin-event-single-settings.template.php', $config);
109 109
 	}
110 110
 
111 111
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 * @param array $REQ
118 118
 	 * @return EE_Template_Config
119 119
 	 */
120
-	public static function update_template_settings(EE_Template_Config $CFG, $REQ ) {
121
-	    if(! $CFG->EED_Event_Single instanceof EE_Event_Single_Config){
120
+	public static function update_template_settings(EE_Template_Config $CFG, $REQ) {
121
+	    if ( ! $CFG->EED_Event_Single instanceof EE_Event_Single_Config) {
122 122
             $CFG->EED_Event_Single = new EE_Event_Single_Config();
123 123
         }
124 124
         $display_order_event = $CFG->EED_Event_Single->display_order_event !== null
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
             ? $CFG->EED_Event_Single->display_order_venue
135 135
             : EED_Event_Single::EVENT_VENUES_PRIORITY;
136 136
 		$CFG->EED_Event_Single = new EE_Event_Single_Config();
137
-		$CFG->EED_Event_Single->display_status_banner_single = ! empty( $REQ['display_status_banner_single'] )
137
+		$CFG->EED_Event_Single->display_status_banner_single = ! empty($REQ['display_status_banner_single'])
138 138
             && $REQ['display_status_banner_single'];
139
-		$CFG->EED_Event_Single->display_venue = ! empty( $REQ['display_venue'] ) && $REQ['display_venue'];
140
-		$CFG->EED_Event_Single->use_sortable_display_order = ! empty( $REQ[ 'EED_Events_Single_use_sortable_display_order' ] )
141
-            ? absint( $REQ[ 'EED_Events_Single_use_sortable_display_order' ] )
139
+		$CFG->EED_Event_Single->display_venue = ! empty($REQ['display_venue']) && $REQ['display_venue'];
140
+		$CFG->EED_Event_Single->use_sortable_display_order = ! empty($REQ['EED_Events_Single_use_sortable_display_order'])
141
+            ? absint($REQ['EED_Events_Single_use_sortable_display_order'])
142 142
             : 0;
143 143
 		$CFG->EED_Event_Single->display_order_event = $CFG->EED_Event_Single->use_sortable_display_order
144 144
             ? $display_order_event
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 		$CFG->EED_Event_Single->display_order_venue = $CFG->EED_Event_Single->use_sortable_display_order
153 153
             ? $display_order_venue
154 154
             : EED_Event_Single::EVENT_VENUES_PRIORITY;
155
-		do_action( 'AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ );
155
+		do_action('AHEE__EED_Event_Single__update_template_settings__after_update', $CFG, $REQ);
156 156
 		return $CFG;
157 157
 	}
158 158
 
@@ -166,23 +166,23 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	public static function update_event_single_order() {
168 168
 		$config_saved = false;
169
-		$template_parts = sanitize_text_field( $_POST[ 'elements' ] );
170
-		if ( ! empty( $template_parts ) ) {
171
-			$template_parts = explode( ',', trim( $template_parts, ',' ) );
172
-			foreach ( $template_parts as $key => $template_part ) {
169
+		$template_parts = sanitize_text_field($_POST['elements']);
170
+		if ( ! empty($template_parts)) {
171
+			$template_parts = explode(',', trim($template_parts, ','));
172
+			foreach ($template_parts as $key => $template_part) {
173 173
 				$template_part = "display_order_$template_part";
174
-				$priority = ( $key * 10 ) + EED_Event_Single::EVENT_DETAILS_PRIORITY;
174
+				$priority = ($key * 10) + EED_Event_Single::EVENT_DETAILS_PRIORITY;
175 175
 				EE_Registry::instance()->CFG->template_settings->EED_Event_Single->{$template_part} = $priority;
176
-				do_action( "AHEE__EED_Event_Single__update_event_single_order__$template_part", $priority );
176
+				do_action("AHEE__EED_Event_Single__update_event_single_order__$template_part", $priority);
177 177
 			}
178
-			$config_saved = EE_Registry::instance()->CFG->update_espresso_config( false, false );
178
+			$config_saved = EE_Registry::instance()->CFG->update_espresso_config(false, false);
179 179
 		}
180
-		if ( $config_saved ) {
181
-			EE_Error::add_success( __( 'Display Order has been successfully updated.', 'event_espresso' ) );
180
+		if ($config_saved) {
181
+			EE_Error::add_success(__('Display Order has been successfully updated.', 'event_espresso'));
182 182
 		} else {
183
-			EE_Error::add_error( __( 'Display Order was not updated.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
183
+			EE_Error::add_error(__('Display Order was not updated.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
184 184
 		}
185
-		echo wp_json_encode( EE_Error::get_notices( false ));
185
+		echo wp_json_encode(EE_Error::get_notices(false));
186 186
 		exit();
187 187
 	}
188 188
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @param WP $WP
196 196
 	 * @return    void
197 197
 	 */
198
-	public function run( $WP ) {
198
+	public function run($WP) {
199 199
 	}
200 200
 
201 201
 
Please login to merge, or discard this patch.
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 2 patches
Indentation   +606 added lines, -606 removed lines patch added patch discarded remove patch
@@ -16,612 +16,612 @@
 block discarded – undo
16 16
 class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display
17 17
 {
18 18
 
19
-    /**
20
-     * array of events
21
-     *
22
-     * @type EE_Line_Item[] $_events
23
-     */
24
-    private $_events = array();
25
-
26
-    /**
27
-     * whether to display the taxes row or not
28
-     *
29
-     * @type bool $_show_taxes
30
-     */
31
-    private $_show_taxes = false;
32
-
33
-    /**
34
-     * html for any tax rows
35
-     *
36
-     * @type string $_show_taxes
37
-     */
38
-    private $_taxes_html = '';
39
-
40
-    /**
41
-     * total amount including tax we can bill for at this time
42
-     *
43
-     * @type float $_grand_total
44
-     */
45
-    private $_grand_total = 0.00;
46
-
47
-    /**
48
-     * total number of items being billed for
49
-     *
50
-     * @type int $_total_items
51
-     */
52
-    private $_total_items = 0;
53
-
54
-
55
-
56
-    /**
57
-     * @return float
58
-     */
59
-    public function grand_total()
60
-    {
61
-        return $this->_grand_total;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * @return int
68
-     */
69
-    public function total_items()
70
-    {
71
-        return $this->_total_items;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @param EE_Line_Item $line_item
78
-     * @param array        $options
79
-     * @param EE_Line_Item $parent_line_item
80
-     * @return mixed
81
-     * @throws EE_Error
82
-     */
83
-    public function display_line_item(
84
-        EE_Line_Item $line_item,
85
-        $options = array(),
86
-        EE_Line_Item $parent_line_item = null
87
-    ) {
88
-        $html = '';
89
-        // set some default options and merge with incoming
90
-        $default_options = array(
91
-            'show_desc' => true,  // 	true 		false
92
-            'odd'       => false,
93
-        );
94
-        $options = array_merge($default_options, (array)$options);
95
-        switch ($line_item->type()) {
96
-            case EEM_Line_Item::type_line_item:
97
-                $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
98
-                if ($line_item->OBJ_type() === 'Ticket') {
99
-                    // item row
100
-                    $html .= $this->_ticket_row($line_item, $options);
101
-                } else {
102
-                    // item row
103
-                    $html .= $this->_item_row($line_item, $options);
104
-                }
105
-                if (
106
-                apply_filters(
107
-                    'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
108
-                    true
109
-                )
110
-                ) {
111
-                    // got any kids?
112
-                    foreach ($line_item->children() as $child_line_item) {
113
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
114
-                    }
115
-                }
116
-                break;
117
-            case EEM_Line_Item::type_sub_line_item:
118
-                $html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
119
-                break;
120
-            case EEM_Line_Item::type_sub_total:
121
-                static $sub_total = 0;
122
-                $event_sub_total = 0;
123
-                $text = esc_html__('Sub-Total', 'event_espresso');
124
-                if ($line_item->OBJ_type() === 'Event') {
125
-                    $options['event_id'] = $event_id = $line_item->OBJ_ID();
126
-                    if (! isset($this->_events[$options['event_id']])) {
127
-                        $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128
-                        // if event has default reg status of Not Approved, then don't display info on it
129
-                        if (
130
-                            $event instanceof EE_Event
131
-                            && $event->default_registration_status() === EEM_Registration::status_id_not_approved
132
-                        ) {
133
-                            $display_event = false;
134
-                            // unless there are registrations for it that are returning to pay
135
-                            if (isset($options['registrations']) && is_array($options['registrations'])) {
136
-                                foreach ($options['registrations'] as $registration) {
137
-                                    if (! $registration instanceof EE_Registration) {
138
-                                        continue;
139
-                                    }
140
-                                    $display_event = $registration->event_ID() === $options['event_id']
141
-                                                     && $registration->status_ID() !== EEM_Registration::status_id_not_approved
142
-                                        ? true
143
-                                        : $display_event;
144
-                                }
145
-                            }
146
-                            if (! $display_event) {
147
-                                return '';
148
-                            }
149
-                        }
150
-                        $this->_events[$options['event_id']] = 0;
151
-                        $html .= $this->_event_row($line_item);
152
-                        $text = esc_html__('Event Sub-Total', 'event_espresso');
153
-                    }
154
-                }
155
-                $child_line_items = $line_item->children();
156
-                // loop thru children
157
-                foreach ($child_line_items as $child_line_item) {
158
-                    // recursively feed children back into this method
159
-                    $html .= $this->display_line_item($child_line_item, $options, $line_item);
160
-                }
161
-                $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
162
-                $sub_total += $event_sub_total;
163
-                if (
164
-                    (
165
-                        // event subtotals
166
-                        $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
167
-                    )
168
-                    || (
169
-                        // pre-tax subtotals
170
-                        $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
171
-                    )
172
-                ) {
173
-                    $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
174
-                    $html .= $this->_sub_total_row($line_item, $text, $options);
175
-                }
176
-                break;
177
-            case EEM_Line_Item::type_tax:
178
-                if ($this->_show_taxes) {
179
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
180
-                }
181
-                break;
182
-            case EEM_Line_Item::type_tax_sub_total:
183
-                if ($this->_show_taxes) {
184
-                    $child_line_items = $line_item->children();
185
-                    // loop thru children
186
-                    foreach ($child_line_items as $child_line_item) {
187
-                        // recursively feed children back into this method
188
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
189
-                    }
190
-                    if (count($child_line_items) > 1) {
191
-                        $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
192
-                    }
193
-                }
194
-                break;
195
-            case EEM_Line_Item::type_total:
196
-                // get all child line items
197
-                $children = $line_item->children();
198
-                // loop thru all non-tax child line items
199
-                foreach ($children as $child_line_item) {
200
-                    if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
201
-                        // recursively feed children back into this method
202
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
203
-                    }
204
-                }
205
-                // now loop thru  tax child line items
206
-                foreach ($children as $child_line_item) {
207
-                    if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
208
-                        // recursively feed children back into this method
209
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
210
-                    }
211
-                }
212
-                $html .= $this->_taxes_html;
213
-                $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
214
-                $html .= $this->_payments_and_amount_owing_rows($line_item, $options);
215
-                break;
216
-        }
217
-        return $html;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * _event_row - basically a Heading row displayed once above each event's ticket rows
224
-     *
225
-     * @param EE_Line_Item $line_item
226
-     * @return mixed
227
-     */
228
-    private function _event_row(EE_Line_Item $line_item)
229
-    {
230
-        // start of row
231
-        $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
232
-        // event name td
233
-        $html .= EEH_HTML::td(
234
-            EEH_HTML::strong($line_item->name()),
235
-            '',
236
-            'event-header',
237
-            '',
238
-            ' colspan="4"'
239
-        );
240
-        // end of row
241
-        $html .= EEH_HTML::trx();
242
-        return $html;
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * _ticket_row
249
-     *
250
-     * @param EE_Line_Item $line_item
251
-     * @param array        $options
252
-     * @return mixed
253
-     * @throws EE_Error
254
-     */
255
-    private function _ticket_row(EE_Line_Item $line_item, $options = array())
256
-    {
257
-        // start of row
258
-        $row_class = $options['odd'] ? 'item odd' : 'item';
259
-        $html = EEH_HTML::tr('', '', $row_class);
260
-        // name && desc
261
-        $name_and_desc = apply_filters(
262
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
263
-            $line_item->name(),
264
-            $line_item
265
-        );
266
-        $name_and_desc .= apply_filters(
267
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268
-            (
269
-                $options['show_desc']
270
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
271
-                    : ''
272
-            ),
273
-            $line_item,
274
-            $options
275
-        );
276
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
277
-        // name td
278
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
279
-            $name_and_desc, '', 'item_l');
280
-        // price td
281
-        $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
282
-        // quantity td
283
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
284
-        $this->_total_items += $line_item->quantity();
285
-        // determine total for line item
286
-        $total = $line_item->total();
287
-        $this->_events[$options['event_id']] += $total;
288
-        // total td
289
-        $html .= EEH_HTML::td(
290
-            EEH_Template::format_currency($total, false, false),
291
-            '',
292
-            'item_r jst-rght'
293
-        );
294
-        // end of row
295
-        $html .= EEH_HTML::trx();
296
-        return $html;
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * _item_row
303
-     *
304
-     * @param EE_Line_Item $line_item
305
-     * @param array        $options
306
-     * @return mixed
307
-     * @throws EE_Error
308
-     */
309
-    private function _item_row(EE_Line_Item $line_item, $options = array())
310
-    {
311
-        // start of row
312
-        $row_class = $options['odd'] ? 'item odd' : 'item';
313
-        $html = EEH_HTML::tr('', '', $row_class);
314
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
315
-        // name && desc
316
-        $name_and_desc = apply_filters(
317
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
-            $obj_name . $line_item->name(),
319
-            $line_item
320
-        );
321
-        $name_and_desc .= apply_filters(
322
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323
-            (
324
-                $options['show_desc']
325
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
326
-                : ''
327
-            ),
328
-            $line_item,
329
-            $options
330
-        );
331
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
332
-        // name td
333
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334
-        // price td
335
-        if ($line_item->is_percent()) {
336
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
337
-        } else {
338
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339
-        }
340
-        // quantity td
341
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
342
-        //$total = $line_item->total() * $line_item->quantity();
343
-        $total = $line_item->total();
344
-        if (isset($options['event_id'], $this->_events[$options['event_id']])) {
345
-            $this->_events[$options['event_id']] += $total;
346
-        }
347
-        // total td
348
-        $html .= EEH_HTML::td(
349
-            EEH_Template::format_currency($total, false, false),
350
-            '',
351
-            'item_r jst-rght'
352
-        );
353
-        // end of row
354
-        $html .= EEH_HTML::trx();
355
-        return $html;
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     * _sub_item_row
362
-     *
363
-     * @param EE_Line_Item $line_item
364
-     * @param array        $options
365
-     * @param EE_Line_Item $parent_line_item
366
-     * @return mixed
367
-     * @throws EE_Error
368
-     */
369
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370
-    {
371
-        if($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
372
-            return '';
373
-        }
374
-        // start of row
375
-        $html = EEH_HTML::tr('', '', 'item sub-item-row');
376
-        // name && desc
377
-        $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
378
-                         . $line_item->name();
379
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
380
-                                                  . $line_item->desc()
381
-                                                  . '</span>' : '';
382
-        // name td
383
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
384
-        $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
385
-        // discount/surcharge td
386
-        if ($line_item->is_percent()) {
387
-            $html .= EEH_HTML::td(
388
-                EEH_Template::format_currency(
389
-                    $line_item->total() / $qty,
390
-                    false, false
391
-                ),
392
-                '', 'item_c jst-rght'
393
-            );
394
-        } else {
395
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
396
-        }
397
-        // no quantity td
398
-        $html .= EEH_HTML::td();
399
-        // no total td
400
-        $html .= EEH_HTML::td();
401
-        // end of row
402
-        $html .= EEH_HTML::trx();
403
-        return $html;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * _tax_row
410
-     *
411
-     * @param EE_Line_Item $line_item
412
-     * @param array        $options
413
-     * @return mixed
414
-     * @throws EE_Error
415
-     */
416
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
417
-    {
418
-        // start of row
419
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
420
-        // name && desc
421
-        $name_and_desc = $line_item->name();
422
-        $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
423
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
424
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
425
-        // name td
426
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
427
-            $name_and_desc, '', 'item_l sub-item');
428
-        // percent td
429
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
430
-        // empty td (price)
431
-        $html .= EEH_HTML::td(EEH_HTML::nbsp());
432
-        // total td
433
-        $html .= EEH_HTML::td(EEH_Template::format_currency(
434
-            $line_item->total(), false, false),
435
-            '',
436
-            'item_r jst-rght'
437
-        );
438
-        // end of row
439
-        $html .= EEH_HTML::trx();
440
-        return $html;
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     * _total_row
447
-     *
448
-     * @param EE_Line_Item $line_item
449
-     * @param string       $text
450
-     * @return mixed
451
-     * @throws EE_Error
452
-     */
453
-    private function _total_tax_row(EE_Line_Item $line_item, $text = '')
454
-    {
455
-        $html = '';
456
-        if ($line_item->total()) {
457
-            // start of row
458
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
459
-            // total td
460
-            $html .= EEH_HTML::td(
461
-                $text,
462
-                '',
463
-                'total_currency total jst-rght',
464
-                '',
465
-                ' colspan="2"'
466
-            );
467
-            // empty td (price)
468
-            $html .= EEH_HTML::td(EEH_HTML::nbsp());
469
-            // total td
470
-            $html .= EEH_HTML::td(
471
-                EEH_Template::format_currency($line_item->total(), false, false),
472
-                '',
473
-                'total jst-rght'
474
-            );
475
-            // end of row
476
-            $html .= EEH_HTML::trx();
477
-        }
478
-        return $html;
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * _total_row
485
-     *
486
-     * @param EE_Line_Item $line_item
487
-     * @param string       $text
488
-     * @param array        $options
489
-     * @return mixed
490
-     * @throws EE_Error
491
-     */
492
-    private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
493
-    {
494
-        $html = '';
495
-        if ($line_item->total()) {
496
-            // start of row
497
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
498
-            // total td
499
-            $html .= EEH_HTML::td(
500
-                $text,
501
-                '',
502
-                'total_currency total jst-rght',
503
-                '',
504
-                ' colspan="3"'
505
-            );
506
-            // total td
507
-            $html .= EEH_HTML::td(
508
-                EEH_Template::format_currency($options['sub_total'], false, false),
509
-                '',
510
-                'total jst-rght'
511
-            );
512
-            // end of row
513
-            $html .= EEH_HTML::trx();
514
-        }
515
-        return $html;
516
-    }
517
-
518
-
519
-
520
-    /**
521
-     * _total_row
522
-     *
523
-     * @param EE_Line_Item $line_item
524
-     * @param string       $text
525
-     * @return mixed
526
-     * @throws EE_Error
527
-     */
528
-    private function _total_row(EE_Line_Item $line_item, $text = '')
529
-    {
530
-        // start of row
531
-        $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
532
-        // total td
533
-        $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
534
-        // total td
535
-        $html .= EEH_HTML::td(
536
-            EEH_Template::format_currency($line_item->total(), false, false),
537
-            '',
538
-            'total jst-rght'
539
-        );
540
-        // end of row
541
-        $html .= EEH_HTML::trx();
542
-        return $html;
543
-    }
544
-
545
-
546
-
547
-    /**
548
-     * _payments_and_amount_owing_rows
549
-     *
550
-     * @param EE_Line_Item $line_item
551
-     * @param array        $options
552
-     * @return mixed
553
-     * @throws EE_Error
554
-     */
555
-    private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
556
-    {
557
-        $html = '';
558
-        $owing = $line_item->total();
559
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
560
-        if ($transaction instanceof EE_Transaction) {
561
-            $registration_payments = array();
562
-            $registrations = ! empty($options['registrations'])
563
-                ? $options['registrations']
564
-                : $transaction->registrations();
565
-            foreach ($registrations as $registration) {
566
-                if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
567
-                    $registration_payments += $registration->registration_payments();
568
-                }
569
-            }
570
-            if (! empty($registration_payments)) {
571
-                foreach ($registration_payments as $registration_payment) {
572
-                    if ($registration_payment instanceof EE_Registration_Payment) {
573
-                        $owing -= $registration_payment->amount();
574
-                        $payment = $registration_payment->payment();
575
-                        $payment_desc = '';
576
-                        if ($payment instanceof EE_Payment) {
577
-                            $payment_desc = sprintf(
578
-                                esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
579
-                                $payment->txn_id_chq_nmbr() !== ''
580
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
581
-                                    : '',
582
-                                $payment->timestamp()
583
-                            );
584
-                        }
585
-                        // start of row
586
-                        $html .= EEH_HTML::tr('', '', 'total_tr odd');
587
-                        // payment desc
588
-                        $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
589
-                        // total td
590
-                        $html .= EEH_HTML::td(
591
-                            EEH_Template::format_currency(
592
-                                $registration_payment->amount(),
593
-                                false,
594
-                                false
595
-                            ),
596
-                            '',
597
-                            'total jst-rght'
598
-                        );
599
-                        // end of row
600
-                        $html .= EEH_HTML::trx();
601
-                    }
602
-                }
603
-                if ($line_item->total()) {
604
-                    // start of row
605
-                    $html .= EEH_HTML::tr('', '', 'total_tr odd');
606
-                    // total td
607
-                    $html .= EEH_HTML::td(
608
-                        esc_html__('Amount Owing', 'event_espresso'),
609
-                        '', 'total_currency total jst-rght', '', ' colspan="3"'
610
-                    );
611
-                    // total td
612
-                    $html .= EEH_HTML::td(
613
-                        EEH_Template::format_currency($owing, false, false),
614
-                        '',
615
-                        'total jst-rght'
616
-                    );
617
-                    // end of row
618
-                    $html .= EEH_HTML::trx();
619
-                }
620
-            }
621
-        }
622
-        $this->_grand_total = $owing;
623
-        return $html;
624
-    }
19
+	/**
20
+	 * array of events
21
+	 *
22
+	 * @type EE_Line_Item[] $_events
23
+	 */
24
+	private $_events = array();
25
+
26
+	/**
27
+	 * whether to display the taxes row or not
28
+	 *
29
+	 * @type bool $_show_taxes
30
+	 */
31
+	private $_show_taxes = false;
32
+
33
+	/**
34
+	 * html for any tax rows
35
+	 *
36
+	 * @type string $_show_taxes
37
+	 */
38
+	private $_taxes_html = '';
39
+
40
+	/**
41
+	 * total amount including tax we can bill for at this time
42
+	 *
43
+	 * @type float $_grand_total
44
+	 */
45
+	private $_grand_total = 0.00;
46
+
47
+	/**
48
+	 * total number of items being billed for
49
+	 *
50
+	 * @type int $_total_items
51
+	 */
52
+	private $_total_items = 0;
53
+
54
+
55
+
56
+	/**
57
+	 * @return float
58
+	 */
59
+	public function grand_total()
60
+	{
61
+		return $this->_grand_total;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * @return int
68
+	 */
69
+	public function total_items()
70
+	{
71
+		return $this->_total_items;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @param EE_Line_Item $line_item
78
+	 * @param array        $options
79
+	 * @param EE_Line_Item $parent_line_item
80
+	 * @return mixed
81
+	 * @throws EE_Error
82
+	 */
83
+	public function display_line_item(
84
+		EE_Line_Item $line_item,
85
+		$options = array(),
86
+		EE_Line_Item $parent_line_item = null
87
+	) {
88
+		$html = '';
89
+		// set some default options and merge with incoming
90
+		$default_options = array(
91
+			'show_desc' => true,  // 	true 		false
92
+			'odd'       => false,
93
+		);
94
+		$options = array_merge($default_options, (array)$options);
95
+		switch ($line_item->type()) {
96
+			case EEM_Line_Item::type_line_item:
97
+				$this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
98
+				if ($line_item->OBJ_type() === 'Ticket') {
99
+					// item row
100
+					$html .= $this->_ticket_row($line_item, $options);
101
+				} else {
102
+					// item row
103
+					$html .= $this->_item_row($line_item, $options);
104
+				}
105
+				if (
106
+				apply_filters(
107
+					'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
108
+					true
109
+				)
110
+				) {
111
+					// got any kids?
112
+					foreach ($line_item->children() as $child_line_item) {
113
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
114
+					}
115
+				}
116
+				break;
117
+			case EEM_Line_Item::type_sub_line_item:
118
+				$html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
119
+				break;
120
+			case EEM_Line_Item::type_sub_total:
121
+				static $sub_total = 0;
122
+				$event_sub_total = 0;
123
+				$text = esc_html__('Sub-Total', 'event_espresso');
124
+				if ($line_item->OBJ_type() === 'Event') {
125
+					$options['event_id'] = $event_id = $line_item->OBJ_ID();
126
+					if (! isset($this->_events[$options['event_id']])) {
127
+						$event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128
+						// if event has default reg status of Not Approved, then don't display info on it
129
+						if (
130
+							$event instanceof EE_Event
131
+							&& $event->default_registration_status() === EEM_Registration::status_id_not_approved
132
+						) {
133
+							$display_event = false;
134
+							// unless there are registrations for it that are returning to pay
135
+							if (isset($options['registrations']) && is_array($options['registrations'])) {
136
+								foreach ($options['registrations'] as $registration) {
137
+									if (! $registration instanceof EE_Registration) {
138
+										continue;
139
+									}
140
+									$display_event = $registration->event_ID() === $options['event_id']
141
+													 && $registration->status_ID() !== EEM_Registration::status_id_not_approved
142
+										? true
143
+										: $display_event;
144
+								}
145
+							}
146
+							if (! $display_event) {
147
+								return '';
148
+							}
149
+						}
150
+						$this->_events[$options['event_id']] = 0;
151
+						$html .= $this->_event_row($line_item);
152
+						$text = esc_html__('Event Sub-Total', 'event_espresso');
153
+					}
154
+				}
155
+				$child_line_items = $line_item->children();
156
+				// loop thru children
157
+				foreach ($child_line_items as $child_line_item) {
158
+					// recursively feed children back into this method
159
+					$html .= $this->display_line_item($child_line_item, $options, $line_item);
160
+				}
161
+				$event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
162
+				$sub_total += $event_sub_total;
163
+				if (
164
+					(
165
+						// event subtotals
166
+						$line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
167
+					)
168
+					|| (
169
+						// pre-tax subtotals
170
+						$line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
171
+					)
172
+				) {
173
+					$options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
174
+					$html .= $this->_sub_total_row($line_item, $text, $options);
175
+				}
176
+				break;
177
+			case EEM_Line_Item::type_tax:
178
+				if ($this->_show_taxes) {
179
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
180
+				}
181
+				break;
182
+			case EEM_Line_Item::type_tax_sub_total:
183
+				if ($this->_show_taxes) {
184
+					$child_line_items = $line_item->children();
185
+					// loop thru children
186
+					foreach ($child_line_items as $child_line_item) {
187
+						// recursively feed children back into this method
188
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
189
+					}
190
+					if (count($child_line_items) > 1) {
191
+						$this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
192
+					}
193
+				}
194
+				break;
195
+			case EEM_Line_Item::type_total:
196
+				// get all child line items
197
+				$children = $line_item->children();
198
+				// loop thru all non-tax child line items
199
+				foreach ($children as $child_line_item) {
200
+					if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
201
+						// recursively feed children back into this method
202
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
203
+					}
204
+				}
205
+				// now loop thru  tax child line items
206
+				foreach ($children as $child_line_item) {
207
+					if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
208
+						// recursively feed children back into this method
209
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
210
+					}
211
+				}
212
+				$html .= $this->_taxes_html;
213
+				$html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
214
+				$html .= $this->_payments_and_amount_owing_rows($line_item, $options);
215
+				break;
216
+		}
217
+		return $html;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * _event_row - basically a Heading row displayed once above each event's ticket rows
224
+	 *
225
+	 * @param EE_Line_Item $line_item
226
+	 * @return mixed
227
+	 */
228
+	private function _event_row(EE_Line_Item $line_item)
229
+	{
230
+		// start of row
231
+		$html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
232
+		// event name td
233
+		$html .= EEH_HTML::td(
234
+			EEH_HTML::strong($line_item->name()),
235
+			'',
236
+			'event-header',
237
+			'',
238
+			' colspan="4"'
239
+		);
240
+		// end of row
241
+		$html .= EEH_HTML::trx();
242
+		return $html;
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * _ticket_row
249
+	 *
250
+	 * @param EE_Line_Item $line_item
251
+	 * @param array        $options
252
+	 * @return mixed
253
+	 * @throws EE_Error
254
+	 */
255
+	private function _ticket_row(EE_Line_Item $line_item, $options = array())
256
+	{
257
+		// start of row
258
+		$row_class = $options['odd'] ? 'item odd' : 'item';
259
+		$html = EEH_HTML::tr('', '', $row_class);
260
+		// name && desc
261
+		$name_and_desc = apply_filters(
262
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
263
+			$line_item->name(),
264
+			$line_item
265
+		);
266
+		$name_and_desc .= apply_filters(
267
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268
+			(
269
+				$options['show_desc']
270
+					? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
271
+					: ''
272
+			),
273
+			$line_item,
274
+			$options
275
+		);
276
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
277
+		// name td
278
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
279
+			$name_and_desc, '', 'item_l');
280
+		// price td
281
+		$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
282
+		// quantity td
283
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
284
+		$this->_total_items += $line_item->quantity();
285
+		// determine total for line item
286
+		$total = $line_item->total();
287
+		$this->_events[$options['event_id']] += $total;
288
+		// total td
289
+		$html .= EEH_HTML::td(
290
+			EEH_Template::format_currency($total, false, false),
291
+			'',
292
+			'item_r jst-rght'
293
+		);
294
+		// end of row
295
+		$html .= EEH_HTML::trx();
296
+		return $html;
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * _item_row
303
+	 *
304
+	 * @param EE_Line_Item $line_item
305
+	 * @param array        $options
306
+	 * @return mixed
307
+	 * @throws EE_Error
308
+	 */
309
+	private function _item_row(EE_Line_Item $line_item, $options = array())
310
+	{
311
+		// start of row
312
+		$row_class = $options['odd'] ? 'item odd' : 'item';
313
+		$html = EEH_HTML::tr('', '', $row_class);
314
+		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
315
+		// name && desc
316
+		$name_and_desc = apply_filters(
317
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
+			$obj_name . $line_item->name(),
319
+			$line_item
320
+		);
321
+		$name_and_desc .= apply_filters(
322
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323
+			(
324
+				$options['show_desc']
325
+				? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
326
+				: ''
327
+			),
328
+			$line_item,
329
+			$options
330
+		);
331
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
332
+		// name td
333
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334
+		// price td
335
+		if ($line_item->is_percent()) {
336
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
337
+		} else {
338
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339
+		}
340
+		// quantity td
341
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
342
+		//$total = $line_item->total() * $line_item->quantity();
343
+		$total = $line_item->total();
344
+		if (isset($options['event_id'], $this->_events[$options['event_id']])) {
345
+			$this->_events[$options['event_id']] += $total;
346
+		}
347
+		// total td
348
+		$html .= EEH_HTML::td(
349
+			EEH_Template::format_currency($total, false, false),
350
+			'',
351
+			'item_r jst-rght'
352
+		);
353
+		// end of row
354
+		$html .= EEH_HTML::trx();
355
+		return $html;
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 * _sub_item_row
362
+	 *
363
+	 * @param EE_Line_Item $line_item
364
+	 * @param array        $options
365
+	 * @param EE_Line_Item $parent_line_item
366
+	 * @return mixed
367
+	 * @throws EE_Error
368
+	 */
369
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370
+	{
371
+		if($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
372
+			return '';
373
+		}
374
+		// start of row
375
+		$html = EEH_HTML::tr('', '', 'item sub-item-row');
376
+		// name && desc
377
+		$name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
378
+						 . $line_item->name();
379
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
380
+												  . $line_item->desc()
381
+												  . '</span>' : '';
382
+		// name td
383
+		$html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
384
+		$qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
385
+		// discount/surcharge td
386
+		if ($line_item->is_percent()) {
387
+			$html .= EEH_HTML::td(
388
+				EEH_Template::format_currency(
389
+					$line_item->total() / $qty,
390
+					false, false
391
+				),
392
+				'', 'item_c jst-rght'
393
+			);
394
+		} else {
395
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
396
+		}
397
+		// no quantity td
398
+		$html .= EEH_HTML::td();
399
+		// no total td
400
+		$html .= EEH_HTML::td();
401
+		// end of row
402
+		$html .= EEH_HTML::trx();
403
+		return $html;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * _tax_row
410
+	 *
411
+	 * @param EE_Line_Item $line_item
412
+	 * @param array        $options
413
+	 * @return mixed
414
+	 * @throws EE_Error
415
+	 */
416
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
417
+	{
418
+		// start of row
419
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
420
+		// name && desc
421
+		$name_and_desc = $line_item->name();
422
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
423
+						  . esc_html__(' * taxable items', 'event_espresso') . '</span>';
424
+		$name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
425
+		// name td
426
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
427
+			$name_and_desc, '', 'item_l sub-item');
428
+		// percent td
429
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
430
+		// empty td (price)
431
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
432
+		// total td
433
+		$html .= EEH_HTML::td(EEH_Template::format_currency(
434
+			$line_item->total(), false, false),
435
+			'',
436
+			'item_r jst-rght'
437
+		);
438
+		// end of row
439
+		$html .= EEH_HTML::trx();
440
+		return $html;
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 * _total_row
447
+	 *
448
+	 * @param EE_Line_Item $line_item
449
+	 * @param string       $text
450
+	 * @return mixed
451
+	 * @throws EE_Error
452
+	 */
453
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '')
454
+	{
455
+		$html = '';
456
+		if ($line_item->total()) {
457
+			// start of row
458
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
459
+			// total td
460
+			$html .= EEH_HTML::td(
461
+				$text,
462
+				'',
463
+				'total_currency total jst-rght',
464
+				'',
465
+				' colspan="2"'
466
+			);
467
+			// empty td (price)
468
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
469
+			// total td
470
+			$html .= EEH_HTML::td(
471
+				EEH_Template::format_currency($line_item->total(), false, false),
472
+				'',
473
+				'total jst-rght'
474
+			);
475
+			// end of row
476
+			$html .= EEH_HTML::trx();
477
+		}
478
+		return $html;
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * _total_row
485
+	 *
486
+	 * @param EE_Line_Item $line_item
487
+	 * @param string       $text
488
+	 * @param array        $options
489
+	 * @return mixed
490
+	 * @throws EE_Error
491
+	 */
492
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
493
+	{
494
+		$html = '';
495
+		if ($line_item->total()) {
496
+			// start of row
497
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
498
+			// total td
499
+			$html .= EEH_HTML::td(
500
+				$text,
501
+				'',
502
+				'total_currency total jst-rght',
503
+				'',
504
+				' colspan="3"'
505
+			);
506
+			// total td
507
+			$html .= EEH_HTML::td(
508
+				EEH_Template::format_currency($options['sub_total'], false, false),
509
+				'',
510
+				'total jst-rght'
511
+			);
512
+			// end of row
513
+			$html .= EEH_HTML::trx();
514
+		}
515
+		return $html;
516
+	}
517
+
518
+
519
+
520
+	/**
521
+	 * _total_row
522
+	 *
523
+	 * @param EE_Line_Item $line_item
524
+	 * @param string       $text
525
+	 * @return mixed
526
+	 * @throws EE_Error
527
+	 */
528
+	private function _total_row(EE_Line_Item $line_item, $text = '')
529
+	{
530
+		// start of row
531
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
532
+		// total td
533
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
534
+		// total td
535
+		$html .= EEH_HTML::td(
536
+			EEH_Template::format_currency($line_item->total(), false, false),
537
+			'',
538
+			'total jst-rght'
539
+		);
540
+		// end of row
541
+		$html .= EEH_HTML::trx();
542
+		return $html;
543
+	}
544
+
545
+
546
+
547
+	/**
548
+	 * _payments_and_amount_owing_rows
549
+	 *
550
+	 * @param EE_Line_Item $line_item
551
+	 * @param array        $options
552
+	 * @return mixed
553
+	 * @throws EE_Error
554
+	 */
555
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
556
+	{
557
+		$html = '';
558
+		$owing = $line_item->total();
559
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
560
+		if ($transaction instanceof EE_Transaction) {
561
+			$registration_payments = array();
562
+			$registrations = ! empty($options['registrations'])
563
+				? $options['registrations']
564
+				: $transaction->registrations();
565
+			foreach ($registrations as $registration) {
566
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
567
+					$registration_payments += $registration->registration_payments();
568
+				}
569
+			}
570
+			if (! empty($registration_payments)) {
571
+				foreach ($registration_payments as $registration_payment) {
572
+					if ($registration_payment instanceof EE_Registration_Payment) {
573
+						$owing -= $registration_payment->amount();
574
+						$payment = $registration_payment->payment();
575
+						$payment_desc = '';
576
+						if ($payment instanceof EE_Payment) {
577
+							$payment_desc = sprintf(
578
+								esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
579
+								$payment->txn_id_chq_nmbr() !== ''
580
+									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
581
+									: '',
582
+								$payment->timestamp()
583
+							);
584
+						}
585
+						// start of row
586
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
587
+						// payment desc
588
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
589
+						// total td
590
+						$html .= EEH_HTML::td(
591
+							EEH_Template::format_currency(
592
+								$registration_payment->amount(),
593
+								false,
594
+								false
595
+							),
596
+							'',
597
+							'total jst-rght'
598
+						);
599
+						// end of row
600
+						$html .= EEH_HTML::trx();
601
+					}
602
+				}
603
+				if ($line_item->total()) {
604
+					// start of row
605
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
606
+					// total td
607
+					$html .= EEH_HTML::td(
608
+						esc_html__('Amount Owing', 'event_espresso'),
609
+						'', 'total_currency total jst-rght', '', ' colspan="3"'
610
+					);
611
+					// total td
612
+					$html .= EEH_HTML::td(
613
+						EEH_Template::format_currency($owing, false, false),
614
+						'',
615
+						'total jst-rght'
616
+					);
617
+					// end of row
618
+					$html .= EEH_HTML::trx();
619
+				}
620
+			}
621
+		}
622
+		$this->_grand_total = $owing;
623
+		return $html;
624
+	}
625 625
 
626 626
 
627 627
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -88,10 +88,10 @@  discard block
 block discarded – undo
88 88
         $html = '';
89 89
         // set some default options and merge with incoming
90 90
         $default_options = array(
91
-            'show_desc' => true,  // 	true 		false
91
+            'show_desc' => true, // 	true 		false
92 92
             'odd'       => false,
93 93
         );
94
-        $options = array_merge($default_options, (array)$options);
94
+        $options = array_merge($default_options, (array) $options);
95 95
         switch ($line_item->type()) {
96 96
             case EEM_Line_Item::type_line_item:
97 97
                 $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                 $text = esc_html__('Sub-Total', 'event_espresso');
124 124
                 if ($line_item->OBJ_type() === 'Event') {
125 125
                     $options['event_id'] = $event_id = $line_item->OBJ_ID();
126
-                    if (! isset($this->_events[$options['event_id']])) {
126
+                    if ( ! isset($this->_events[$options['event_id']])) {
127 127
                         $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128 128
                         // if event has default reg status of Not Approved, then don't display info on it
129 129
                         if (
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                             // unless there are registrations for it that are returning to pay
135 135
                             if (isset($options['registrations']) && is_array($options['registrations'])) {
136 136
                                 foreach ($options['registrations'] as $registration) {
137
-                                    if (! $registration instanceof EE_Registration) {
137
+                                    if ( ! $registration instanceof EE_Registration) {
138 138
                                         continue;
139 139
                                     }
140 140
                                     $display_event = $registration->event_ID() === $options['event_id']
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
                                         : $display_event;
144 144
                                 }
145 145
                             }
146
-                            if (! $display_event) {
146
+                            if ( ! $display_event) {
147 147
                                 return '';
148 148
                             }
149 149
                         }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268 268
             (
269 269
                 $options['show_desc']
270
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
270
+                    ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
271 271
                     : ''
272 272
             ),
273 273
             $line_item,
@@ -311,18 +311,18 @@  discard block
 block discarded – undo
311 311
         // start of row
312 312
         $row_class = $options['odd'] ? 'item odd' : 'item';
313 313
         $html = EEH_HTML::tr('', '', $row_class);
314
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
314
+        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : '';
315 315
         // name && desc
316 316
         $name_and_desc = apply_filters(
317 317
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
-            $obj_name . $line_item->name(),
318
+            $obj_name.$line_item->name(),
319 319
             $line_item
320 320
         );
321 321
         $name_and_desc .= apply_filters(
322 322
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323 323
             (
324 324
                 $options['show_desc']
325
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
325
+                ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
326 326
                 : ''
327 327
             ),
328 328
             $line_item,
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
         $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334 334
         // price td
335 335
         if ($line_item->is_percent()) {
336
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
336
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght');
337 337
         } else {
338 338
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339 339
         }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      */
369 369
     private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370 370
     {
371
-        if($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
371
+        if ($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
372 372
             return '';
373 373
         }
374 374
         // start of row
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
                                                   . $line_item->desc()
381 381
                                                   . '</span>' : '';
382 382
         // name td
383
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
383
+        $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
384 384
         $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
385 385
         // discount/surcharge td
386 386
         if ($line_item->is_percent()) {
@@ -420,13 +420,13 @@  discard block
 block discarded – undo
420 420
         // name && desc
421 421
         $name_and_desc = $line_item->name();
422 422
         $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
423
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
424
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
423
+                          . esc_html__(' * taxable items', 'event_espresso').'</span>';
424
+        $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : '';
425 425
         // name td
426 426
         $html .= EEH_HTML::td( /*__FUNCTION__ .*/
427 427
             $name_and_desc, '', 'item_l sub-item');
428 428
         // percent td
429
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
429
+        $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', '');
430 430
         // empty td (price)
431 431
         $html .= EEH_HTML::td(EEH_HTML::nbsp());
432 432
         // total td
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
                     $registration_payments += $registration->registration_payments();
568 568
                 }
569 569
             }
570
-            if (! empty($registration_payments)) {
570
+            if ( ! empty($registration_payments)) {
571 571
                 foreach ($registration_payments as $registration_payment) {
572 572
                     if ($registration_payment instanceof EE_Registration_Payment) {
573 573
                         $owing -= $registration_payment->amount();
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
                             $payment_desc = sprintf(
578 578
                                 esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
579 579
                                 $payment->txn_id_chq_nmbr() !== ''
580
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
580
+                                    ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> '
581 581
                                     : '',
582 582
                                 $payment->timestamp()
583 583
                             );
Please login to merge, or discard this patch.
core/EE_Encryption.core.php 2 patches
Indentation   +663 added lines, -663 removed lines patch added patch discarded remove patch
@@ -16,669 +16,669 @@
 block discarded – undo
16 16
 class EE_Encryption
17 17
 {
18 18
 
19
-    /**
20
-     * key used for saving the encryption key to the wp_options table
21
-     */
22
-    const ENCRYPTION_OPTION_KEY = 'ee_encryption_key';
23
-
24
-    /**
25
-     * the OPENSSL cipher method used
26
-     */
27
-    const OPENSSL_CIPHER_METHOD = 'AES-128-CBC';
28
-
29
-    /**
30
-     * WP "options_name" used to store a verified available cipher method
31
-     */
32
-    const OPENSSL_CIPHER_METHOD_OPTION_NAME = 'ee_openssl_cipher_method';
33
-
34
-    /**
35
-     * the OPENSSL digest method used
36
-     */
37
-    const OPENSSL_DIGEST_METHOD = 'sha512';
38
-
39
-    /**
40
-     * separates the encrypted text from the initialization vector
41
-     */
42
-    const OPENSSL_IV_DELIMITER = ':iv:';
43
-
44
-    /**
45
-     * appended to text encrypted using the acme encryption
46
-     */
47
-    const ACME_ENCRYPTION_FLAG = '::ae';
48
-
49
-
50
-
51
-    /**
52
-     * instance of the EE_Encryption object
53
-     */
54
-    protected static $_instance;
55
-
56
-    /**
57
-     * @var string $_encryption_key
58
-     */
59
-    protected $_encryption_key;
60
-
61
-    /**
62
-     * @var string $cipher_method
63
-     */
64
-    private $cipher_method = '';
65
-
66
-    /**
67
-     * @var array $cipher_methods
68
-     */
69
-    private $cipher_methods = array();
70
-
71
-    /**
72
-     * @var array $digest_methods
73
-     */
74
-    private $digest_methods = array();
75
-
76
-    /**
77
-     * @var boolean $_use_openssl_encrypt
78
-     */
79
-    protected $_use_openssl_encrypt = false;
80
-
81
-    /**
82
-     * @var boolean $_use_mcrypt
83
-     */
84
-    protected $_use_mcrypt = false;
85
-
86
-    /**
87
-     * @var boolean $_use_base64_encode
88
-     */
89
-    protected $_use_base64_encode = false;
90
-
91
-
92
-
93
-    /**
94
-     * protected constructor to prevent direct creation
95
-     */
96
-    protected function __construct()
97
-    {
98
-        if (! defined('ESPRESSO_ENCRYPT')) {
99
-            define('ESPRESSO_ENCRYPT', true);
100
-        }
101
-        if (extension_loaded('openssl')) {
102
-            $this->_use_openssl_encrypt = true;
103
-        } else if (extension_loaded('mcrypt')) {
104
-            $this->_use_mcrypt = true;
105
-        }
106
-        if (function_exists('base64_encode')) {
107
-            $this->_use_base64_encode = true;
108
-        }
109
-    }
110
-
111
-
112
-
113
-    /**
114
-     * singleton method used to instantiate class object
115
-     *
116
-     * @return EE_Encryption
117
-     */
118
-    public static function instance()
119
-    {
120
-        // check if class object is instantiated
121
-        if (! self::$_instance instanceof EE_Encryption) {
122
-            self::$_instance = new self();
123
-        }
124
-        return self::$_instance;
125
-    }
126
-
127
-
128
-
129
-    /**
130
-     * get encryption key
131
-     *
132
-     * @return string
133
-     */
134
-    public function get_encryption_key()
135
-    {
136
-        // if encryption key has not been set
137
-        if (empty($this->_encryption_key)) {
138
-            // retrieve encryption_key from db
139
-            $this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, '');
140
-            // WHAT?? No encryption_key in the db ??
141
-            if ($this->_encryption_key === '') {
142
-                // let's make one. And md5 it to make it just the right size for a key
143
-                $new_key = md5($this->generate_random_string());
144
-                // now save it to the db for later
145
-                add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key);
146
-                // here's the key - FINALLY !
147
-                $this->_encryption_key = $new_key;
148
-            }
149
-        }
150
-        return $this->_encryption_key;
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * encrypts data
157
-     *
158
-     * @param string $text_string - the text to be encrypted
159
-     * @return string
160
-     * @throws RuntimeException
161
-     */
162
-    public function encrypt($text_string = '')
163
-    {
164
-        // you give me nothing??? GET OUT !
165
-        if (empty($text_string)) {
166
-            return $text_string;
167
-        }
168
-        if ($this->_use_openssl_encrypt) {
169
-            $encrypted_text = $this->openssl_encrypt($text_string);
170
-        } else {
171
-            $encrypted_text = $this->acme_encrypt($text_string);
172
-        }
173
-        return $encrypted_text;
174
-    }
175
-
176
-
177
-
178
-    /**
179
-     * decrypts data
180
-     *
181
-     * @param string $encrypted_text - the text to be decrypted
182
-     * @return string
183
-     * @throws RuntimeException
184
-     */
185
-    public function decrypt($encrypted_text = '')
186
-    {
187
-        // you give me nothing??? GET OUT !
188
-        if (empty($encrypted_text)) {
189
-            return $encrypted_text;
190
-        }
191
-        // if PHP's mcrypt functions are installed then we'll use them
192
-        if ($this->_use_openssl_encrypt) {
193
-            $decrypted_text = $this->openssl_decrypt($encrypted_text);
194
-        } else {
195
-            $decrypted_text = $this->acme_decrypt($encrypted_text);
196
-        }
197
-        return $decrypted_text;
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * encodes string with PHP's base64 encoding
204
-     *
205
-     * @see http://php.net/manual/en/function.base64-encode.php
206
-     * @param string $text_string the text to be encoded
207
-     * @return string
208
-     */
209
-    public function base64_string_encode($text_string = '')
210
-    {
211
-        // you give me nothing??? GET OUT !
212
-        if (empty($text_string) || ! $this->_use_base64_encode) {
213
-            return $text_string;
214
-        }
215
-        // encode
216
-        return base64_encode($text_string);
217
-    }
218
-
219
-
220
-
221
-    /**
222
-     * decodes string that has been encoded with PHP's base64 encoding
223
-     *
224
-     * @see http://php.net/manual/en/function.base64-encode.php
225
-     * @param string $encoded_string the text to be decoded
226
-     * @return string
227
-     */
228
-    public function base64_string_decode($encoded_string = '')
229
-    {
230
-        // you give me nothing??? GET OUT !
231
-        if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
232
-            return $encoded_string;
233
-        }
234
-        // decode
235
-        return base64_decode($encoded_string);
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * encodes  url string with PHP's base64 encoding
242
-     *
243
-     * @see http://php.net/manual/en/function.base64-encode.php
244
-     * @param string $text_string the text to be encoded
245
-     * @return string
246
-     */
247
-    public function base64_url_encode($text_string = '')
248
-    {
249
-        // you give me nothing??? GET OUT !
250
-        if (empty($text_string) || ! $this->_use_base64_encode) {
251
-            return $text_string;
252
-        }
253
-        // encode
254
-        $encoded_string = base64_encode($text_string);
255
-        // remove chars to make encoding more URL friendly
256
-        return strtr($encoded_string, '+/=', '-_,');
257
-    }
258
-
259
-
260
-
261
-    /**
262
-     * decodes  url string that has been encoded with PHP's base64 encoding
263
-     *
264
-     * @see http://php.net/manual/en/function.base64-encode.php
265
-     * @param string $encoded_string the text to be decoded
266
-     * @return string
267
-     */
268
-    public function base64_url_decode($encoded_string = '')
269
-    {
270
-        // you give me nothing??? GET OUT !
271
-        if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
272
-            return $encoded_string;
273
-        }
274
-        // replace previously removed characters
275
-        $encoded_string = strtr($encoded_string, '-_,', '+/=');
276
-        // decode
277
-        return base64_decode($encoded_string);
278
-    }
279
-
280
-
281
-
282
-    /**
283
-     * encrypts data using PHP's openssl functions
284
-     *
285
-     * @param string $text_string the text to be encrypted
286
-     * @return string
287
-     * @throws RuntimeException
288
-     */
289
-    protected function openssl_encrypt($text_string = '')
290
-    {
291
-        // you give me nothing??? GET OUT !
292
-        if (empty($text_string)) {
293
-            return $text_string;
294
-        }
295
-        $this->cipher_method = $this->getCipherMethod();
296
-        // get initialization vector size
297
-        $iv_size = openssl_cipher_iv_length($this->cipher_method);
298
-        // generate initialization vector.
299
-        // The second parameter ("crypto_strong") is passed by reference,
300
-        // and is used to determines if the algorithm used was "cryptographically strong"
301
-        // openssl_random_pseudo_bytes() will toggle it to either true or false
302
-        $iv = openssl_random_pseudo_bytes($iv_size, $is_strong);
303
-        if ($iv === false || $is_strong === false) {
304
-            throw new RuntimeException(
305
-                esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
306
-            );
307
-        }
308
-        // encrypt it
309
-        $encrypted_text = openssl_encrypt(
310
-            $text_string,
311
-            $this->cipher_method,
312
-            $this->getDigestHashValue(),
313
-            0,
314
-            $iv
315
-        );
316
-        // append the initialization vector
317
-        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
318
-        // trim and maybe encode
319
-        return $this->_use_base64_encode
320
-            ? trim(base64_encode($encrypted_text))
321
-            : trim($encrypted_text);
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * Returns a cipher method that has been verified to work.
328
-     * First checks if the cached cipher has been set already and if so, returns that.
329
-     * Then tests the incoming default and returns that if it's good.
330
-     * If not, then it retrieves the previously tested and saved cipher method.
331
-     * But if that doesn't exist, then calls getAvailableCipherMethod()
332
-     * to see what is available on the server, and returns the results.
333
-     *
334
-     * @param string $cipher_method
335
-     * @return string
336
-     * @throws RuntimeException
337
-     */
338
-    protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD)
339
-    {
340
-        if($this->cipher_method !== ''){
341
-            return $this->cipher_method;
342
-        }
343
-        // verify that the default cipher method can produce an initialization vector
344
-        if (openssl_cipher_iv_length($cipher_method) === false) {
345
-            // nope? okay let's get what we found in the past to work
346
-            $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, '');
347
-            // oops... haven't tested available cipher methods yet
348
-            if($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) {
349
-                $cipher_method = $this->getAvailableCipherMethod($cipher_method);
350
-            }
351
-        }
352
-        return $cipher_method;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * @param string $cipher_method
359
-     * @return string
360
-     * @throws \RuntimeException
361
-     */
362
-    protected function getAvailableCipherMethod($cipher_method)
363
-    {
364
-        // verify that the incoming cipher method can produce an initialization vector
365
-        if (openssl_cipher_iv_length($cipher_method) === false) {
366
-            // nope? then check the next cipher in the list of available cipher methods
367
-            $cipher_method = next($this->cipher_methods);
368
-            // what? there's no list? then generate that list and cache it,
369
-            if (empty($this->cipher_methods)) {
370
-                $this->cipher_methods = openssl_get_cipher_methods();
371
-                // then grab the first item from the list
372
-                $cipher_method = reset($this->cipher_methods);
373
-            }
374
-            if($cipher_method === false){
375
-                throw new RuntimeException(
376
-                    esc_html__(
377
-                        'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.',
378
-                        'event_espresso'
379
-                    )
380
-                );
381
-            }
382
-            // verify that the next cipher method works
383
-            return $this->getAvailableCipherMethod($cipher_method);
384
-        }
385
-        // if we've gotten this far, then we found an available cipher method that works
386
-        // so save that for next time
387
-        update_option(
388
-            EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME,
389
-            $cipher_method
390
-        );
391
-        return $cipher_method;
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     * decrypts data that has been encrypted with PHP's openssl functions
398
-     *
399
-     * @param string $encrypted_text the text to be decrypted
400
-     * @return string
401
-     * @throws RuntimeException
402
-     */
403
-    protected function openssl_decrypt($encrypted_text = '')
404
-    {
405
-        // you give me nothing??? GET OUT !
406
-        if (empty($encrypted_text)) {
407
-            return $encrypted_text;
408
-        }
409
-        // decode
410
-        $encrypted_text = $this->valid_base_64($encrypted_text)
411
-            ? base64_decode($encrypted_text)
412
-            : $encrypted_text;
413
-        $encrypted_components = explode(
414
-            EE_Encryption::OPENSSL_IV_DELIMITER,
415
-            $encrypted_text,
416
-            2
417
-        );
418
-        // check that iv exists, and if not, maybe text was encoded using mcrypt?
419
-        if ($this->_use_mcrypt && ! isset($encrypted_components[1])) {
420
-            return $this->m_decrypt($encrypted_text);
421
-        }
422
-        // decrypt it
423
-        $decrypted_text = openssl_decrypt(
424
-            $encrypted_components[0],
425
-            $this->getCipherMethod(),
426
-            $this->getDigestHashValue(),
427
-            0,
428
-            $encrypted_components[1]
429
-        );
430
-        $decrypted_text = trim($decrypted_text);
431
-        return $decrypted_text;
432
-    }
433
-
434
-
435
-
436
-    /**
437
-     * Computes the digest hash value using the specified digest method.
438
-     * If that digest method fails to produce a valid hash value,
439
-     * then we'll grab the next digest method and recursively try again until something works.
440
-     *
441
-     * @param string $digest_method
442
-     * @return string
443
-     * @throws RuntimeException
444
-     */
445
-    protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD){
446
-        $digest_hash_value = openssl_digest($this->get_encryption_key(), $digest_method);
447
-        if ($digest_hash_value === false) {
448
-            return $this->getDigestHashValue($this->getDigestMethod());
449
-        }
450
-        return $digest_hash_value;
451
-    }
452
-
453
-
454
-
455
-    /**
456
-     * Returns the NEXT element in the $digest_methods array.
457
-     * If the $digest_methods array is empty, then we populate it
458
-     * with the available values returned from openssl_get_md_methods().
459
-     *
460
-     * @return string
461
-     * @throws \RuntimeException
462
-     */
463
-    protected function getDigestMethod(){
464
-        $digest_method = prev($this->digest_methods);
465
-        if (empty($this->digest_methods)) {
466
-            $this->digest_methods = openssl_get_md_methods();
467
-            $digest_method = end($this->digest_methods);
468
-        }
469
-        if ($digest_method === false) {
470
-            throw new RuntimeException(
471
-                esc_html__(
472
-                    'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.',
473
-                    'event_espresso'
474
-                )
475
-            );
476
-        }
477
-        return $digest_method;
478
-    }
479
-
480
-
481
-    /**
482
-     * encrypts data for acme servers that didn't bother to install PHP mcrypt
483
-     *
484
-     * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
485
-     * @param string $text_string the text to be decrypted
486
-     * @return string
487
-     */
488
-    protected function acme_encrypt($text_string = '')
489
-    {
490
-        // you give me nothing??? GET OUT !
491
-        if (empty($text_string)) {
492
-            return $text_string;
493
-        }
494
-        $key_bits = str_split(
495
-            str_pad(
496
-                '',
497
-                strlen($text_string),
498
-                $this->get_encryption_key(),
499
-                STR_PAD_RIGHT
500
-            )
501
-        );
502
-        $string_bits = str_split($text_string);
503
-        foreach ($string_bits as $k => $v) {
504
-            $temp = ord($v) + ord($key_bits[$k]);
505
-            $string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp);
506
-        }
507
-        $encrypted_text = implode('', $string_bits);
508
-        $encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG;
509
-        return $this->_use_base64_encode
510
-            ? base64_encode($encrypted_text)
511
-            : $encrypted_text;
512
-    }
513
-
514
-
515
-
516
-    /**
517
-     * decrypts data for acme servers that didn't bother to install PHP mcrypt
518
-     *
519
-     * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
520
-     * @param string $encrypted_text the text to be decrypted
521
-     * @return string
522
-     * @throws RuntimeException
523
-     */
524
-    protected function acme_decrypt($encrypted_text = '')
525
-    {
526
-        // you give me nothing??? GET OUT !
527
-        if (empty($encrypted_text)) {
528
-            return $encrypted_text;
529
-        }
530
-        // decode the data ?
531
-        $encrypted_text = $this->valid_base_64($encrypted_text)
532
-            ? base64_decode($encrypted_text)
533
-            : $encrypted_text;
534
-        if (
535
-            $this->_use_mcrypt
536
-            && strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false
537
-        ){
538
-            return $this->m_decrypt($encrypted_text);
539
-        }
540
-        $encrypted_text = substr($encrypted_text, 0, -4);
541
-        $key_bits = str_split(
542
-            str_pad(
543
-                '',
544
-                strlen($encrypted_text),
545
-                $this->get_encryption_key(),
546
-                STR_PAD_RIGHT
547
-            )
548
-        );
549
-        $string_bits = str_split($encrypted_text);
550
-        foreach ($string_bits as $k => $v) {
551
-            $temp = ord($v) - ord($key_bits[$k]);
552
-            $string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp);
553
-        }
554
-        return implode('', $string_bits);
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
561
-     * @param $string
562
-     * @return bool
563
-     */
564
-    protected function valid_base_64($string)
565
-    {
566
-        // ensure data is a string
567
-        if (! is_string($string) || ! $this->_use_base64_encode) {
568
-            return false;
569
-        }
570
-        $decoded = base64_decode($string, true);
571
-        // Check if there is no invalid character in string
572
-        if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
573
-            return false;
574
-        }
575
-        // Decode the string in strict mode and send the response
576
-        if (! base64_decode($string, true)) {
577
-            return false;
578
-        }
579
-        // Encode and compare it to original one
580
-        return base64_encode($decoded) === $string;
581
-    }
582
-
583
-
584
-
585
-    /**
586
-     * generate random string
587
-     *
588
-     * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
589
-     * @param int $length number of characters for random string
590
-     * @return string
591
-     */
592
-    public function generate_random_string($length = 40)
593
-    {
594
-        $iterations = ceil($length / 40);
595
-        $random_string = '';
596
-        for ($i = 0; $i < $iterations; $i++) {
597
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
598
-        }
599
-        $random_string = substr($random_string, 0, $length);
600
-        return $random_string;
601
-    }
602
-
603
-
604
-
605
-    /**
606
-     * encrypts data using PHP's mcrypt functions
607
-     *
608
-     * @deprecated 4.9.39
609
-     * @param string $text_string
610
-     * @internal   param $string - the text to be encrypted
611
-     * @return string
612
-     * @throws RuntimeException
613
-     */
614
-    protected function m_encrypt($text_string = '')
615
-    {
616
-        // you give me nothing??? GET OUT !
617
-        if (empty($text_string)) {
618
-            return $text_string;
619
-        }
620
-        // get the initialization vector size
621
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
622
-        // initialization vector
623
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
624
-        if ($iv === false) {
625
-            throw new RuntimeException(
626
-                esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
627
-            );
628
-        }
629
-        // encrypt it
630
-        $encrypted_text = mcrypt_encrypt(
631
-            MCRYPT_RIJNDAEL_256,
632
-            $this->get_encryption_key(),
633
-            $text_string,
634
-            MCRYPT_MODE_ECB,
635
-            $iv
636
-        );
637
-        // trim and maybe encode
638
-        return $this->_use_base64_encode
639
-            ? trim(base64_encode($encrypted_text))
640
-            : trim($encrypted_text);
641
-    }
642
-
643
-
644
-
645
-    /**
646
-     * decrypts data that has been encrypted with PHP's mcrypt functions
647
-     *
648
-     * @deprecated 4.9.39
649
-     * @param string $encrypted_text the text to be decrypted
650
-     * @return string
651
-     * @throws RuntimeException
652
-     */
653
-    protected function m_decrypt($encrypted_text = '')
654
-    {
655
-        // you give me nothing??? GET OUT !
656
-        if (empty($encrypted_text)) {
657
-            return $encrypted_text;
658
-        }
659
-        // decode
660
-        $encrypted_text = $this->valid_base_64($encrypted_text)
661
-            ? base64_decode($encrypted_text)
662
-            : $encrypted_text;
663
-        // get the initialization vector size
664
-        $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
665
-        $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
666
-        if ($iv === false) {
667
-            throw new RuntimeException(
668
-                esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
669
-            );
670
-        }
671
-        // decrypt it
672
-        $decrypted_text = mcrypt_decrypt(
673
-            MCRYPT_RIJNDAEL_256,
674
-            $this->get_encryption_key(),
675
-            $encrypted_text,
676
-            MCRYPT_MODE_ECB,
677
-            $iv
678
-        );
679
-        $decrypted_text = trim($decrypted_text);
680
-        return $decrypted_text;
681
-    }
19
+	/**
20
+	 * key used for saving the encryption key to the wp_options table
21
+	 */
22
+	const ENCRYPTION_OPTION_KEY = 'ee_encryption_key';
23
+
24
+	/**
25
+	 * the OPENSSL cipher method used
26
+	 */
27
+	const OPENSSL_CIPHER_METHOD = 'AES-128-CBC';
28
+
29
+	/**
30
+	 * WP "options_name" used to store a verified available cipher method
31
+	 */
32
+	const OPENSSL_CIPHER_METHOD_OPTION_NAME = 'ee_openssl_cipher_method';
33
+
34
+	/**
35
+	 * the OPENSSL digest method used
36
+	 */
37
+	const OPENSSL_DIGEST_METHOD = 'sha512';
38
+
39
+	/**
40
+	 * separates the encrypted text from the initialization vector
41
+	 */
42
+	const OPENSSL_IV_DELIMITER = ':iv:';
43
+
44
+	/**
45
+	 * appended to text encrypted using the acme encryption
46
+	 */
47
+	const ACME_ENCRYPTION_FLAG = '::ae';
48
+
49
+
50
+
51
+	/**
52
+	 * instance of the EE_Encryption object
53
+	 */
54
+	protected static $_instance;
55
+
56
+	/**
57
+	 * @var string $_encryption_key
58
+	 */
59
+	protected $_encryption_key;
60
+
61
+	/**
62
+	 * @var string $cipher_method
63
+	 */
64
+	private $cipher_method = '';
65
+
66
+	/**
67
+	 * @var array $cipher_methods
68
+	 */
69
+	private $cipher_methods = array();
70
+
71
+	/**
72
+	 * @var array $digest_methods
73
+	 */
74
+	private $digest_methods = array();
75
+
76
+	/**
77
+	 * @var boolean $_use_openssl_encrypt
78
+	 */
79
+	protected $_use_openssl_encrypt = false;
80
+
81
+	/**
82
+	 * @var boolean $_use_mcrypt
83
+	 */
84
+	protected $_use_mcrypt = false;
85
+
86
+	/**
87
+	 * @var boolean $_use_base64_encode
88
+	 */
89
+	protected $_use_base64_encode = false;
90
+
91
+
92
+
93
+	/**
94
+	 * protected constructor to prevent direct creation
95
+	 */
96
+	protected function __construct()
97
+	{
98
+		if (! defined('ESPRESSO_ENCRYPT')) {
99
+			define('ESPRESSO_ENCRYPT', true);
100
+		}
101
+		if (extension_loaded('openssl')) {
102
+			$this->_use_openssl_encrypt = true;
103
+		} else if (extension_loaded('mcrypt')) {
104
+			$this->_use_mcrypt = true;
105
+		}
106
+		if (function_exists('base64_encode')) {
107
+			$this->_use_base64_encode = true;
108
+		}
109
+	}
110
+
111
+
112
+
113
+	/**
114
+	 * singleton method used to instantiate class object
115
+	 *
116
+	 * @return EE_Encryption
117
+	 */
118
+	public static function instance()
119
+	{
120
+		// check if class object is instantiated
121
+		if (! self::$_instance instanceof EE_Encryption) {
122
+			self::$_instance = new self();
123
+		}
124
+		return self::$_instance;
125
+	}
126
+
127
+
128
+
129
+	/**
130
+	 * get encryption key
131
+	 *
132
+	 * @return string
133
+	 */
134
+	public function get_encryption_key()
135
+	{
136
+		// if encryption key has not been set
137
+		if (empty($this->_encryption_key)) {
138
+			// retrieve encryption_key from db
139
+			$this->_encryption_key = get_option(EE_Encryption::ENCRYPTION_OPTION_KEY, '');
140
+			// WHAT?? No encryption_key in the db ??
141
+			if ($this->_encryption_key === '') {
142
+				// let's make one. And md5 it to make it just the right size for a key
143
+				$new_key = md5($this->generate_random_string());
144
+				// now save it to the db for later
145
+				add_option(EE_Encryption::ENCRYPTION_OPTION_KEY, $new_key);
146
+				// here's the key - FINALLY !
147
+				$this->_encryption_key = $new_key;
148
+			}
149
+		}
150
+		return $this->_encryption_key;
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * encrypts data
157
+	 *
158
+	 * @param string $text_string - the text to be encrypted
159
+	 * @return string
160
+	 * @throws RuntimeException
161
+	 */
162
+	public function encrypt($text_string = '')
163
+	{
164
+		// you give me nothing??? GET OUT !
165
+		if (empty($text_string)) {
166
+			return $text_string;
167
+		}
168
+		if ($this->_use_openssl_encrypt) {
169
+			$encrypted_text = $this->openssl_encrypt($text_string);
170
+		} else {
171
+			$encrypted_text = $this->acme_encrypt($text_string);
172
+		}
173
+		return $encrypted_text;
174
+	}
175
+
176
+
177
+
178
+	/**
179
+	 * decrypts data
180
+	 *
181
+	 * @param string $encrypted_text - the text to be decrypted
182
+	 * @return string
183
+	 * @throws RuntimeException
184
+	 */
185
+	public function decrypt($encrypted_text = '')
186
+	{
187
+		// you give me nothing??? GET OUT !
188
+		if (empty($encrypted_text)) {
189
+			return $encrypted_text;
190
+		}
191
+		// if PHP's mcrypt functions are installed then we'll use them
192
+		if ($this->_use_openssl_encrypt) {
193
+			$decrypted_text = $this->openssl_decrypt($encrypted_text);
194
+		} else {
195
+			$decrypted_text = $this->acme_decrypt($encrypted_text);
196
+		}
197
+		return $decrypted_text;
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * encodes string with PHP's base64 encoding
204
+	 *
205
+	 * @see http://php.net/manual/en/function.base64-encode.php
206
+	 * @param string $text_string the text to be encoded
207
+	 * @return string
208
+	 */
209
+	public function base64_string_encode($text_string = '')
210
+	{
211
+		// you give me nothing??? GET OUT !
212
+		if (empty($text_string) || ! $this->_use_base64_encode) {
213
+			return $text_string;
214
+		}
215
+		// encode
216
+		return base64_encode($text_string);
217
+	}
218
+
219
+
220
+
221
+	/**
222
+	 * decodes string that has been encoded with PHP's base64 encoding
223
+	 *
224
+	 * @see http://php.net/manual/en/function.base64-encode.php
225
+	 * @param string $encoded_string the text to be decoded
226
+	 * @return string
227
+	 */
228
+	public function base64_string_decode($encoded_string = '')
229
+	{
230
+		// you give me nothing??? GET OUT !
231
+		if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
232
+			return $encoded_string;
233
+		}
234
+		// decode
235
+		return base64_decode($encoded_string);
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * encodes  url string with PHP's base64 encoding
242
+	 *
243
+	 * @see http://php.net/manual/en/function.base64-encode.php
244
+	 * @param string $text_string the text to be encoded
245
+	 * @return string
246
+	 */
247
+	public function base64_url_encode($text_string = '')
248
+	{
249
+		// you give me nothing??? GET OUT !
250
+		if (empty($text_string) || ! $this->_use_base64_encode) {
251
+			return $text_string;
252
+		}
253
+		// encode
254
+		$encoded_string = base64_encode($text_string);
255
+		// remove chars to make encoding more URL friendly
256
+		return strtr($encoded_string, '+/=', '-_,');
257
+	}
258
+
259
+
260
+
261
+	/**
262
+	 * decodes  url string that has been encoded with PHP's base64 encoding
263
+	 *
264
+	 * @see http://php.net/manual/en/function.base64-encode.php
265
+	 * @param string $encoded_string the text to be decoded
266
+	 * @return string
267
+	 */
268
+	public function base64_url_decode($encoded_string = '')
269
+	{
270
+		// you give me nothing??? GET OUT !
271
+		if (empty($encoded_string) || ! $this->valid_base_64($encoded_string)) {
272
+			return $encoded_string;
273
+		}
274
+		// replace previously removed characters
275
+		$encoded_string = strtr($encoded_string, '-_,', '+/=');
276
+		// decode
277
+		return base64_decode($encoded_string);
278
+	}
279
+
280
+
281
+
282
+	/**
283
+	 * encrypts data using PHP's openssl functions
284
+	 *
285
+	 * @param string $text_string the text to be encrypted
286
+	 * @return string
287
+	 * @throws RuntimeException
288
+	 */
289
+	protected function openssl_encrypt($text_string = '')
290
+	{
291
+		// you give me nothing??? GET OUT !
292
+		if (empty($text_string)) {
293
+			return $text_string;
294
+		}
295
+		$this->cipher_method = $this->getCipherMethod();
296
+		// get initialization vector size
297
+		$iv_size = openssl_cipher_iv_length($this->cipher_method);
298
+		// generate initialization vector.
299
+		// The second parameter ("crypto_strong") is passed by reference,
300
+		// and is used to determines if the algorithm used was "cryptographically strong"
301
+		// openssl_random_pseudo_bytes() will toggle it to either true or false
302
+		$iv = openssl_random_pseudo_bytes($iv_size, $is_strong);
303
+		if ($iv === false || $is_strong === false) {
304
+			throw new RuntimeException(
305
+				esc_html__('Failed to generate OpenSSL initialization vector.', 'event_espresso')
306
+			);
307
+		}
308
+		// encrypt it
309
+		$encrypted_text = openssl_encrypt(
310
+			$text_string,
311
+			$this->cipher_method,
312
+			$this->getDigestHashValue(),
313
+			0,
314
+			$iv
315
+		);
316
+		// append the initialization vector
317
+		$encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
318
+		// trim and maybe encode
319
+		return $this->_use_base64_encode
320
+			? trim(base64_encode($encrypted_text))
321
+			: trim($encrypted_text);
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * Returns a cipher method that has been verified to work.
328
+	 * First checks if the cached cipher has been set already and if so, returns that.
329
+	 * Then tests the incoming default and returns that if it's good.
330
+	 * If not, then it retrieves the previously tested and saved cipher method.
331
+	 * But if that doesn't exist, then calls getAvailableCipherMethod()
332
+	 * to see what is available on the server, and returns the results.
333
+	 *
334
+	 * @param string $cipher_method
335
+	 * @return string
336
+	 * @throws RuntimeException
337
+	 */
338
+	protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD)
339
+	{
340
+		if($this->cipher_method !== ''){
341
+			return $this->cipher_method;
342
+		}
343
+		// verify that the default cipher method can produce an initialization vector
344
+		if (openssl_cipher_iv_length($cipher_method) === false) {
345
+			// nope? okay let's get what we found in the past to work
346
+			$cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, '');
347
+			// oops... haven't tested available cipher methods yet
348
+			if($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) {
349
+				$cipher_method = $this->getAvailableCipherMethod($cipher_method);
350
+			}
351
+		}
352
+		return $cipher_method;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * @param string $cipher_method
359
+	 * @return string
360
+	 * @throws \RuntimeException
361
+	 */
362
+	protected function getAvailableCipherMethod($cipher_method)
363
+	{
364
+		// verify that the incoming cipher method can produce an initialization vector
365
+		if (openssl_cipher_iv_length($cipher_method) === false) {
366
+			// nope? then check the next cipher in the list of available cipher methods
367
+			$cipher_method = next($this->cipher_methods);
368
+			// what? there's no list? then generate that list and cache it,
369
+			if (empty($this->cipher_methods)) {
370
+				$this->cipher_methods = openssl_get_cipher_methods();
371
+				// then grab the first item from the list
372
+				$cipher_method = reset($this->cipher_methods);
373
+			}
374
+			if($cipher_method === false){
375
+				throw new RuntimeException(
376
+					esc_html__(
377
+						'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.',
378
+						'event_espresso'
379
+					)
380
+				);
381
+			}
382
+			// verify that the next cipher method works
383
+			return $this->getAvailableCipherMethod($cipher_method);
384
+		}
385
+		// if we've gotten this far, then we found an available cipher method that works
386
+		// so save that for next time
387
+		update_option(
388
+			EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME,
389
+			$cipher_method
390
+		);
391
+		return $cipher_method;
392
+	}
393
+
394
+
395
+
396
+	/**
397
+	 * decrypts data that has been encrypted with PHP's openssl functions
398
+	 *
399
+	 * @param string $encrypted_text the text to be decrypted
400
+	 * @return string
401
+	 * @throws RuntimeException
402
+	 */
403
+	protected function openssl_decrypt($encrypted_text = '')
404
+	{
405
+		// you give me nothing??? GET OUT !
406
+		if (empty($encrypted_text)) {
407
+			return $encrypted_text;
408
+		}
409
+		// decode
410
+		$encrypted_text = $this->valid_base_64($encrypted_text)
411
+			? base64_decode($encrypted_text)
412
+			: $encrypted_text;
413
+		$encrypted_components = explode(
414
+			EE_Encryption::OPENSSL_IV_DELIMITER,
415
+			$encrypted_text,
416
+			2
417
+		);
418
+		// check that iv exists, and if not, maybe text was encoded using mcrypt?
419
+		if ($this->_use_mcrypt && ! isset($encrypted_components[1])) {
420
+			return $this->m_decrypt($encrypted_text);
421
+		}
422
+		// decrypt it
423
+		$decrypted_text = openssl_decrypt(
424
+			$encrypted_components[0],
425
+			$this->getCipherMethod(),
426
+			$this->getDigestHashValue(),
427
+			0,
428
+			$encrypted_components[1]
429
+		);
430
+		$decrypted_text = trim($decrypted_text);
431
+		return $decrypted_text;
432
+	}
433
+
434
+
435
+
436
+	/**
437
+	 * Computes the digest hash value using the specified digest method.
438
+	 * If that digest method fails to produce a valid hash value,
439
+	 * then we'll grab the next digest method and recursively try again until something works.
440
+	 *
441
+	 * @param string $digest_method
442
+	 * @return string
443
+	 * @throws RuntimeException
444
+	 */
445
+	protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD){
446
+		$digest_hash_value = openssl_digest($this->get_encryption_key(), $digest_method);
447
+		if ($digest_hash_value === false) {
448
+			return $this->getDigestHashValue($this->getDigestMethod());
449
+		}
450
+		return $digest_hash_value;
451
+	}
452
+
453
+
454
+
455
+	/**
456
+	 * Returns the NEXT element in the $digest_methods array.
457
+	 * If the $digest_methods array is empty, then we populate it
458
+	 * with the available values returned from openssl_get_md_methods().
459
+	 *
460
+	 * @return string
461
+	 * @throws \RuntimeException
462
+	 */
463
+	protected function getDigestMethod(){
464
+		$digest_method = prev($this->digest_methods);
465
+		if (empty($this->digest_methods)) {
466
+			$this->digest_methods = openssl_get_md_methods();
467
+			$digest_method = end($this->digest_methods);
468
+		}
469
+		if ($digest_method === false) {
470
+			throw new RuntimeException(
471
+				esc_html__(
472
+					'OpenSSL support appears to be enabled on the server, but no digest methods are available. Please contact the server administrator.',
473
+					'event_espresso'
474
+				)
475
+			);
476
+		}
477
+		return $digest_method;
478
+	}
479
+
480
+
481
+	/**
482
+	 * encrypts data for acme servers that didn't bother to install PHP mcrypt
483
+	 *
484
+	 * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
485
+	 * @param string $text_string the text to be decrypted
486
+	 * @return string
487
+	 */
488
+	protected function acme_encrypt($text_string = '')
489
+	{
490
+		// you give me nothing??? GET OUT !
491
+		if (empty($text_string)) {
492
+			return $text_string;
493
+		}
494
+		$key_bits = str_split(
495
+			str_pad(
496
+				'',
497
+				strlen($text_string),
498
+				$this->get_encryption_key(),
499
+				STR_PAD_RIGHT
500
+			)
501
+		);
502
+		$string_bits = str_split($text_string);
503
+		foreach ($string_bits as $k => $v) {
504
+			$temp = ord($v) + ord($key_bits[$k]);
505
+			$string_bits[$k] = chr($temp > 255 ? ($temp - 256) : $temp);
506
+		}
507
+		$encrypted_text = implode('', $string_bits);
508
+		$encrypted_text .= EE_Encryption::ACME_ENCRYPTION_FLAG;
509
+		return $this->_use_base64_encode
510
+			? base64_encode($encrypted_text)
511
+			: $encrypted_text;
512
+	}
513
+
514
+
515
+
516
+	/**
517
+	 * decrypts data for acme servers that didn't bother to install PHP mcrypt
518
+	 *
519
+	 * @see http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php
520
+	 * @param string $encrypted_text the text to be decrypted
521
+	 * @return string
522
+	 * @throws RuntimeException
523
+	 */
524
+	protected function acme_decrypt($encrypted_text = '')
525
+	{
526
+		// you give me nothing??? GET OUT !
527
+		if (empty($encrypted_text)) {
528
+			return $encrypted_text;
529
+		}
530
+		// decode the data ?
531
+		$encrypted_text = $this->valid_base_64($encrypted_text)
532
+			? base64_decode($encrypted_text)
533
+			: $encrypted_text;
534
+		if (
535
+			$this->_use_mcrypt
536
+			&& strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false
537
+		){
538
+			return $this->m_decrypt($encrypted_text);
539
+		}
540
+		$encrypted_text = substr($encrypted_text, 0, -4);
541
+		$key_bits = str_split(
542
+			str_pad(
543
+				'',
544
+				strlen($encrypted_text),
545
+				$this->get_encryption_key(),
546
+				STR_PAD_RIGHT
547
+			)
548
+		);
549
+		$string_bits = str_split($encrypted_text);
550
+		foreach ($string_bits as $k => $v) {
551
+			$temp = ord($v) - ord($key_bits[$k]);
552
+			$string_bits[$k] = chr($temp < 0 ? ($temp + 256) : $temp);
553
+		}
554
+		return implode('', $string_bits);
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * @see http://stackoverflow.com/questions/2556345/detect-base64-encoding-in-php#30231906
561
+	 * @param $string
562
+	 * @return bool
563
+	 */
564
+	protected function valid_base_64($string)
565
+	{
566
+		// ensure data is a string
567
+		if (! is_string($string) || ! $this->_use_base64_encode) {
568
+			return false;
569
+		}
570
+		$decoded = base64_decode($string, true);
571
+		// Check if there is no invalid character in string
572
+		if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
573
+			return false;
574
+		}
575
+		// Decode the string in strict mode and send the response
576
+		if (! base64_decode($string, true)) {
577
+			return false;
578
+		}
579
+		// Encode and compare it to original one
580
+		return base64_encode($decoded) === $string;
581
+	}
582
+
583
+
584
+
585
+	/**
586
+	 * generate random string
587
+	 *
588
+	 * @see http://stackoverflow.com/questions/637278/what-is-the-best-way-to-generate-a-random-key-within-php
589
+	 * @param int $length number of characters for random string
590
+	 * @return string
591
+	 */
592
+	public function generate_random_string($length = 40)
593
+	{
594
+		$iterations = ceil($length / 40);
595
+		$random_string = '';
596
+		for ($i = 0; $i < $iterations; $i++) {
597
+			$random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
598
+		}
599
+		$random_string = substr($random_string, 0, $length);
600
+		return $random_string;
601
+	}
602
+
603
+
604
+
605
+	/**
606
+	 * encrypts data using PHP's mcrypt functions
607
+	 *
608
+	 * @deprecated 4.9.39
609
+	 * @param string $text_string
610
+	 * @internal   param $string - the text to be encrypted
611
+	 * @return string
612
+	 * @throws RuntimeException
613
+	 */
614
+	protected function m_encrypt($text_string = '')
615
+	{
616
+		// you give me nothing??? GET OUT !
617
+		if (empty($text_string)) {
618
+			return $text_string;
619
+		}
620
+		// get the initialization vector size
621
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
622
+		// initialization vector
623
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
624
+		if ($iv === false) {
625
+			throw new RuntimeException(
626
+				esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
627
+			);
628
+		}
629
+		// encrypt it
630
+		$encrypted_text = mcrypt_encrypt(
631
+			MCRYPT_RIJNDAEL_256,
632
+			$this->get_encryption_key(),
633
+			$text_string,
634
+			MCRYPT_MODE_ECB,
635
+			$iv
636
+		);
637
+		// trim and maybe encode
638
+		return $this->_use_base64_encode
639
+			? trim(base64_encode($encrypted_text))
640
+			: trim($encrypted_text);
641
+	}
642
+
643
+
644
+
645
+	/**
646
+	 * decrypts data that has been encrypted with PHP's mcrypt functions
647
+	 *
648
+	 * @deprecated 4.9.39
649
+	 * @param string $encrypted_text the text to be decrypted
650
+	 * @return string
651
+	 * @throws RuntimeException
652
+	 */
653
+	protected function m_decrypt($encrypted_text = '')
654
+	{
655
+		// you give me nothing??? GET OUT !
656
+		if (empty($encrypted_text)) {
657
+			return $encrypted_text;
658
+		}
659
+		// decode
660
+		$encrypted_text = $this->valid_base_64($encrypted_text)
661
+			? base64_decode($encrypted_text)
662
+			: $encrypted_text;
663
+		// get the initialization vector size
664
+		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
665
+		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
666
+		if ($iv === false) {
667
+			throw new RuntimeException(
668
+				esc_html__('Failed to generate mcrypt initialization vector.', 'event_espresso')
669
+			);
670
+		}
671
+		// decrypt it
672
+		$decrypted_text = mcrypt_decrypt(
673
+			MCRYPT_RIJNDAEL_256,
674
+			$this->get_encryption_key(),
675
+			$encrypted_text,
676
+			MCRYPT_MODE_ECB,
677
+			$iv
678
+		);
679
+		$decrypted_text = trim($decrypted_text);
680
+		return $decrypted_text;
681
+	}
682 682
 
683 683
 }
684 684
 /* End of file EE_Encryption.class.php */
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      */
96 96
     protected function __construct()
97 97
     {
98
-        if (! defined('ESPRESSO_ENCRYPT')) {
98
+        if ( ! defined('ESPRESSO_ENCRYPT')) {
99 99
             define('ESPRESSO_ENCRYPT', true);
100 100
         }
101 101
         if (extension_loaded('openssl')) {
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     public static function instance()
119 119
     {
120 120
         // check if class object is instantiated
121
-        if (! self::$_instance instanceof EE_Encryption) {
121
+        if ( ! self::$_instance instanceof EE_Encryption) {
122 122
             self::$_instance = new self();
123 123
         }
124 124
         return self::$_instance;
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
             $iv
315 315
         );
316 316
         // append the initialization vector
317
-        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER . $iv;
317
+        $encrypted_text .= EE_Encryption::OPENSSL_IV_DELIMITER.$iv;
318 318
         // trim and maybe encode
319 319
         return $this->_use_base64_encode
320 320
             ? trim(base64_encode($encrypted_text))
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
      */
338 338
     protected function getCipherMethod($cipher_method = EE_Encryption::OPENSSL_CIPHER_METHOD)
339 339
     {
340
-        if($this->cipher_method !== ''){
340
+        if ($this->cipher_method !== '') {
341 341
             return $this->cipher_method;
342 342
         }
343 343
         // verify that the default cipher method can produce an initialization vector
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
             // nope? okay let's get what we found in the past to work
346 346
             $cipher_method = get_option(EE_Encryption::OPENSSL_CIPHER_METHOD_OPTION_NAME, '');
347 347
             // oops... haven't tested available cipher methods yet
348
-            if($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) {
348
+            if ($cipher_method === '' || openssl_cipher_iv_length($cipher_method) === false) {
349 349
                 $cipher_method = $this->getAvailableCipherMethod($cipher_method);
350 350
             }
351 351
         }
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
                 // then grab the first item from the list
372 372
                 $cipher_method = reset($this->cipher_methods);
373 373
             }
374
-            if($cipher_method === false){
374
+            if ($cipher_method === false) {
375 375
                 throw new RuntimeException(
376 376
                     esc_html__(
377 377
                         'OpenSSL support appears to be enabled on the server, but no cipher methods are available. Please contact the server administrator.',
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
      * @return string
443 443
      * @throws RuntimeException
444 444
      */
445
-    protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD){
445
+    protected function getDigestHashValue($digest_method = EE_Encryption::OPENSSL_DIGEST_METHOD) {
446 446
         $digest_hash_value = openssl_digest($this->get_encryption_key(), $digest_method);
447 447
         if ($digest_hash_value === false) {
448 448
             return $this->getDigestHashValue($this->getDigestMethod());
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
      * @return string
461 461
      * @throws \RuntimeException
462 462
      */
463
-    protected function getDigestMethod(){
463
+    protected function getDigestMethod() {
464 464
         $digest_method = prev($this->digest_methods);
465 465
         if (empty($this->digest_methods)) {
466 466
             $this->digest_methods = openssl_get_md_methods();
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
         if (
535 535
             $this->_use_mcrypt
536 536
             && strpos($encrypted_text, EE_Encryption::ACME_ENCRYPTION_FLAG) === false
537
-        ){
537
+        ) {
538 538
             return $this->m_decrypt($encrypted_text);
539 539
         }
540 540
         $encrypted_text = substr($encrypted_text, 0, -4);
@@ -564,16 +564,16 @@  discard block
 block discarded – undo
564 564
     protected function valid_base_64($string)
565 565
     {
566 566
         // ensure data is a string
567
-        if (! is_string($string) || ! $this->_use_base64_encode) {
567
+        if ( ! is_string($string) || ! $this->_use_base64_encode) {
568 568
             return false;
569 569
         }
570 570
         $decoded = base64_decode($string, true);
571 571
         // Check if there is no invalid character in string
572
-        if (! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
572
+        if ( ! preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $string)) {
573 573
             return false;
574 574
         }
575 575
         // Decode the string in strict mode and send the response
576
-        if (! base64_decode($string, true)) {
576
+        if ( ! base64_decode($string, true)) {
577 577
             return false;
578 578
         }
579 579
         // Encode and compare it to original one
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
         $iterations = ceil($length / 40);
595 595
         $random_string = '';
596 596
         for ($i = 0; $i < $iterations; $i++) {
597
-            $random_string .= sha1(microtime(true) . mt_rand(10000, 90000));
597
+            $random_string .= sha1(microtime(true).mt_rand(10000, 90000));
598 598
         }
599 599
         $random_string = substr($random_string, 0, $length);
600 600
         return $random_string;
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_CPT.core.php 2 patches
Indentation   +1374 added lines, -1374 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
 /**
@@ -24,445 +24,445 @@  discard block
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * This gets set in _setup_cpt
29
-     * It will contain the object for the custom post type.
30
-     *
31
-     * @var object
32
-     */
33
-    protected $_cpt_object;
34
-
35
-
36
-
37
-    /**
38
-     * a boolean flag to set whether the current route is a cpt route or not.
39
-     *
40
-     * @var bool
41
-     */
42
-    protected $_cpt_route = false;
43
-
44
-
45
-
46
-    /**
47
-     * This property allows cpt classes to define multiple routes as cpt routes.
48
-     * //in this array we define what the custom post type for this route is.
49
-     * array(
50
-     * 'route_name' => 'custom_post_type_slug'
51
-     * )
52
-     *
53
-     * @var array
54
-     */
55
-    protected $_cpt_routes = array();
56
-
27
+	/**
28
+	 * This gets set in _setup_cpt
29
+	 * It will contain the object for the custom post type.
30
+	 *
31
+	 * @var object
32
+	 */
33
+	protected $_cpt_object;
34
+
35
+
36
+
37
+	/**
38
+	 * a boolean flag to set whether the current route is a cpt route or not.
39
+	 *
40
+	 * @var bool
41
+	 */
42
+	protected $_cpt_route = false;
43
+
44
+
45
+
46
+	/**
47
+	 * This property allows cpt classes to define multiple routes as cpt routes.
48
+	 * //in this array we define what the custom post type for this route is.
49
+	 * array(
50
+	 * 'route_name' => 'custom_post_type_slug'
51
+	 * )
52
+	 *
53
+	 * @var array
54
+	 */
55
+	protected $_cpt_routes = array();
56
+
57 57
 
58 58
 
59
-    /**
60
-     * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
-     * in this format:
62
-     * array(
63
-     * 'post_type_slug' => 'edit_route'
64
-     * )
65
-     *
66
-     * @var array
67
-     */
68
-    protected $_cpt_edit_routes = array();
69
-
70
-
71
-
72
-    /**
73
-     * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
-     * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
-     * _cpt_model_names property should be in the following format: array(
76
-     * 'route_defined_by_action_param' => 'Model_Name')
77
-     *
78
-     * @var array $_cpt_model_names
79
-     */
80
-    protected $_cpt_model_names = array();
81
-
82
-
83
-    /**
84
-     * @var EE_CPT_Base
85
-     */
86
-    protected $_cpt_model_obj = false;
87
-
88
-
89
-
90
-    /**
91
-     * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
-     * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
-     * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
-     * Registration of containers should be done before load_page_dependencies() is run.
95
-     *
96
-     * @var array()
97
-     */
98
-    protected $_autosave_containers = array();
99
-    protected $_autosave_fields = array();
100
-
101
-    /**
102
-     * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
-     * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
-     *
105
-     * @var array
106
-     */
107
-    protected $_pagenow_map = null;
108
-
109
-
110
-
111
-    /**
112
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
-     * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
-     * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
-     * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
-     *
118
-     * @access protected
119
-     * @abstract
120
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
-     * @param  object $post    The post object of the cpt that was saved.
122
-     * @return void
123
-     */
124
-    abstract protected function _insert_update_cpt_item($post_id, $post);
125
-
126
-
127
-
128
-    /**
129
-     * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
-     *
131
-     * @abstract
132
-     * @access public
133
-     * @param  string $post_id The ID of the cpt that was trashed
134
-     * @return void
135
-     */
136
-    abstract public function trash_cpt_item($post_id);
137
-
138
-
139
-
140
-    /**
141
-     * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
-     *
143
-     * @param  string $post_id theID of the cpt that was untrashed
144
-     * @return void
145
-     */
146
-    abstract public function restore_cpt_item($post_id);
147
-
148
-
149
-
150
-    /**
151
-     * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
-     * from the db
153
-     *
154
-     * @param  string $post_id the ID of the cpt that was deleted
155
-     * @return void
156
-     */
157
-    abstract public function delete_cpt_item($post_id);
158
-
159
-
160
-
161
-    /**
162
-     * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
-     *
164
-     * @access protected
165
-     * @return void
166
-     */
167
-    protected function _before_page_setup()
168
-    {
169
-        $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
-        $this->_cpt_routes = array_merge(array(
171
-            'create_new' => $this->page_slug,
172
-            'edit'       => $this->page_slug,
173
-            'trash'      => $this->page_slug,
174
-        ), $this->_cpt_routes);
175
-        //let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
-        $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
-            ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
-            : get_post_type_object($page);
179
-        //tweak pagenow for page loading.
180
-        if ( ! $this->_pagenow_map) {
181
-            $this->_pagenow_map = array(
182
-                'create_new' => 'post-new.php',
183
-                'edit'       => 'post.php',
184
-                'trash'      => 'post.php',
185
-            );
186
-        }
187
-        add_action('current_screen', array($this, 'modify_pagenow'));
188
-        //TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
-        //get current page from autosave
190
-        $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
-            ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
-            : null;
193
-        $this->_current_page = isset($this->_req_data['current_page'])
194
-            ? $this->_req_data['current_page']
195
-            : $current_page;
196
-        //autosave... make sure its only for the correct page
197
-        if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
-            //setup autosave ajax hook
199
-            //add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
-        }
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Simply ensure that we simulate the correct post route for cpt screens
207
-     *
208
-     * @param WP_Screen $current_screen
209
-     * @return void
210
-     */
211
-    public function modify_pagenow($current_screen)
212
-    {
213
-        global $pagenow, $hook_suffix;
214
-        //possibly reset pagenow.
215
-        if ( ! empty($this->_req_data['page'])
216
-             && $this->_req_data['page'] == $this->page_slug
217
-             && ! empty($this->_req_data['action'])
218
-             && isset($this->_pagenow_map[$this->_req_data['action']])
219
-        ) {
220
-            $pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
-            $hook_suffix = $pagenow;
222
-        }
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     * This method is used to register additional autosave containers to the _autosave_containers property.
229
-     *
230
-     * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
-     *       automatically register the id for the post metabox as a container.
232
-     * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
-     *                    you would send along the id of a metabox container.
234
-     * @return void
235
-     */
236
-    protected function _register_autosave_containers($ids)
237
-    {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
-     * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
-     */
247
-    protected function _set_autosave_containers()
248
-    {
249
-        global $wp_meta_boxes;
250
-        $containers = array();
251
-        if (empty($wp_meta_boxes)) {
252
-            return;
253
-        }
254
-        $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
-        foreach ($current_metaboxes as $box_context) {
256
-            foreach ($box_context as $box_details) {
257
-                foreach ($box_details as $box) {
258
-                    if (is_array($box['callback'])
259
-                        && ($box['callback'][0] instanceof EE_Admin_Page
260
-                            || $box['callback'][0] instanceof EE_Admin_Hooks)
261
-                    ) {
262
-                        $containers[] = $box['id'];
263
-                    }
264
-                }
265
-            }
266
-        }
267
-        $this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
268
-        //add hidden inputs container
269
-        $this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
270
-    }
271
-
272
-
273
-
274
-    protected function _load_autosave_scripts_styles()
275
-    {
276
-        /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
59
+	/**
60
+	 * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update.
61
+	 * in this format:
62
+	 * array(
63
+	 * 'post_type_slug' => 'edit_route'
64
+	 * )
65
+	 *
66
+	 * @var array
67
+	 */
68
+	protected $_cpt_edit_routes = array();
69
+
70
+
71
+
72
+	/**
73
+	 * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will
74
+	 * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the
75
+	 * _cpt_model_names property should be in the following format: array(
76
+	 * 'route_defined_by_action_param' => 'Model_Name')
77
+	 *
78
+	 * @var array $_cpt_model_names
79
+	 */
80
+	protected $_cpt_model_names = array();
81
+
82
+
83
+	/**
84
+	 * @var EE_CPT_Base
85
+	 */
86
+	protected $_cpt_model_obj = false;
87
+
88
+
89
+
90
+	/**
91
+	 * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP
92
+	 * autosave so we can save our inputs on the save_post hook!  Children classes should add to this array by using
93
+	 * the _register_autosave_containers() method so that we don't override any other containers already registered.
94
+	 * Registration of containers should be done before load_page_dependencies() is run.
95
+	 *
96
+	 * @var array()
97
+	 */
98
+	protected $_autosave_containers = array();
99
+	protected $_autosave_fields = array();
100
+
101
+	/**
102
+	 * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits
103
+	 * a page for an action, it will appear as if they were visiting the wp core page for that custom post type
104
+	 *
105
+	 * @var array
106
+	 */
107
+	protected $_pagenow_map = null;
108
+
109
+
110
+
111
+	/**
112
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
113
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
114
+	 * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important.  When a
115
+	 * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data
116
+	 * containing any extra info you may have from other meta saves.  So MAKE sure that you handle this accordingly.
117
+	 *
118
+	 * @access protected
119
+	 * @abstract
120
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
121
+	 * @param  object $post    The post object of the cpt that was saved.
122
+	 * @return void
123
+	 */
124
+	abstract protected function _insert_update_cpt_item($post_id, $post);
125
+
126
+
127
+
128
+	/**
129
+	 * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed.
130
+	 *
131
+	 * @abstract
132
+	 * @access public
133
+	 * @param  string $post_id The ID of the cpt that was trashed
134
+	 * @return void
135
+	 */
136
+	abstract public function trash_cpt_item($post_id);
137
+
138
+
139
+
140
+	/**
141
+	 * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed
142
+	 *
143
+	 * @param  string $post_id theID of the cpt that was untrashed
144
+	 * @return void
145
+	 */
146
+	abstract public function restore_cpt_item($post_id);
147
+
148
+
149
+
150
+	/**
151
+	 * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted
152
+	 * from the db
153
+	 *
154
+	 * @param  string $post_id the ID of the cpt that was deleted
155
+	 * @return void
156
+	 */
157
+	abstract public function delete_cpt_item($post_id);
158
+
159
+
160
+
161
+	/**
162
+	 * Just utilizing the method EE_Admin exposes for doing things before page setup.
163
+	 *
164
+	 * @access protected
165
+	 * @return void
166
+	 */
167
+	protected function _before_page_setup()
168
+	{
169
+		$page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug;
170
+		$this->_cpt_routes = array_merge(array(
171
+			'create_new' => $this->page_slug,
172
+			'edit'       => $this->page_slug,
173
+			'trash'      => $this->page_slug,
174
+		), $this->_cpt_routes);
175
+		//let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page
176
+		$this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']])
177
+			? get_post_type_object($this->_cpt_routes[$this->_req_data['action']])
178
+			: get_post_type_object($page);
179
+		//tweak pagenow for page loading.
180
+		if ( ! $this->_pagenow_map) {
181
+			$this->_pagenow_map = array(
182
+				'create_new' => 'post-new.php',
183
+				'edit'       => 'post.php',
184
+				'trash'      => 'post.php',
185
+			);
186
+		}
187
+		add_action('current_screen', array($this, 'modify_pagenow'));
188
+		//TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param.
189
+		//get current page from autosave
190
+		$current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'])
191
+			? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']
192
+			: null;
193
+		$this->_current_page = isset($this->_req_data['current_page'])
194
+			? $this->_req_data['current_page']
195
+			: $current_page;
196
+		//autosave... make sure its only for the correct page
197
+		if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) {
198
+			//setup autosave ajax hook
199
+			//add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented
200
+		}
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Simply ensure that we simulate the correct post route for cpt screens
207
+	 *
208
+	 * @param WP_Screen $current_screen
209
+	 * @return void
210
+	 */
211
+	public function modify_pagenow($current_screen)
212
+	{
213
+		global $pagenow, $hook_suffix;
214
+		//possibly reset pagenow.
215
+		if ( ! empty($this->_req_data['page'])
216
+			 && $this->_req_data['page'] == $this->page_slug
217
+			 && ! empty($this->_req_data['action'])
218
+			 && isset($this->_pagenow_map[$this->_req_data['action']])
219
+		) {
220
+			$pagenow = $this->_pagenow_map[$this->_req_data['action']];
221
+			$hook_suffix = $pagenow;
222
+		}
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 * This method is used to register additional autosave containers to the _autosave_containers property.
229
+	 *
230
+	 * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we
231
+	 *       automatically register the id for the post metabox as a container.
232
+	 * @param  array $ids an array of ids for containers that hold form inputs we want autosave to pickup.  Typically
233
+	 *                    you would send along the id of a metabox container.
234
+	 * @return void
235
+	 */
236
+	protected function _register_autosave_containers($ids)
237
+	{
238
+		$this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * Something nifty.  We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of
245
+	 * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array.
246
+	 */
247
+	protected function _set_autosave_containers()
248
+	{
249
+		global $wp_meta_boxes;
250
+		$containers = array();
251
+		if (empty($wp_meta_boxes)) {
252
+			return;
253
+		}
254
+		$current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array();
255
+		foreach ($current_metaboxes as $box_context) {
256
+			foreach ($box_context as $box_details) {
257
+				foreach ($box_details as $box) {
258
+					if (is_array($box['callback'])
259
+						&& ($box['callback'][0] instanceof EE_Admin_Page
260
+							|| $box['callback'][0] instanceof EE_Admin_Hooks)
261
+					) {
262
+						$containers[] = $box['id'];
263
+					}
264
+				}
265
+			}
266
+		}
267
+		$this->_autosave_containers = array_merge($this->_autosave_containers, $containers);
268
+		//add hidden inputs container
269
+		$this->_autosave_containers[] = 'ee-cpt-hidden-inputs';
270
+	}
271
+
272
+
273
+
274
+	protected function _load_autosave_scripts_styles()
275
+	{
276
+		/*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE );
277 277
         wp_enqueue_script('cpt-autosave');/**/ //todo re-enable when we start doing autosave again in 4.2
278 278
 
279
-        //filter _autosave_containers
280
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281
-            $this->_autosave_containers, $this);
282
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
283
-            $containers, $this);
284
-
285
-        wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
286
-            $containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
287
-
288
-        $unsaved_data_msg = array(
289
-            'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
290
-                'event_espresso'), $this->_cpt_object->labels->singular_name),
291
-            'inputChanged' => 0,
292
-        );
293
-        wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
294
-    }
295
-
296
-
297
-
298
-    public function load_page_dependencies()
299
-    {
300
-        try {
301
-            $this->_load_page_dependencies();
302
-        } catch (EE_Error $e) {
303
-            $e->get_error();
304
-        }
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
311
-     *
312
-     * @access protected
313
-     * @return void
314
-     */
315
-    protected function _load_page_dependencies()
316
-    {
317
-        //we only add stuff if this is a cpt_route!
318
-        if ( ! $this->_cpt_route) {
319
-            parent::_load_page_dependencies();
320
-            return;
321
-        }
322
-        //now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place.
323
-        //the following filters are for setting all the redirects on DEFAULT WP custom post type actions
324
-        //let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects!  Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
325
-        add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
326
-        //inject our Admin page nav tabs...
327
-        //let's make sure the nav tabs are set if they aren't already
328
-        //if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
329
-        add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
330
-        //modify the post_updated messages array
331
-        add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
332
-        //add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts!
333
-        add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
334
-        //This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
335
-        if ( ! empty($this->_labels['publishbox'])) {
336
-            $box_label = is_array($this->_labels['publishbox'])
337
-                         && isset($this->_labels['publishbox'][$this->_req_action])
338
-                ? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
339
-            remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
340
-                'side', 'core');
341
-            add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
342
-                'side', 'core');
343
-        }
344
-        //let's add page_templates metabox if this cpt added support for it.
345
-        if ($this->_supports_page_templates($this->_cpt_object->name)) {
346
-            add_meta_box('page_templates', __('Page Template', 'event_espresso'),
347
-                array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default');
348
-        }
349
-        //this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
350
-        if (method_exists($this, 'extra_permalink_field_buttons')) {
351
-            add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
352
-        }
353
-        //add preview button
354
-        add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
355
-        //insert our own post_stati dropdown
356
-        add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
357
-        //This allows adding additional information to the publish post submitbox on the wp post edit form
358
-        if (method_exists($this, 'extra_misc_actions_publish_box')) {
359
-            add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
360
-        }
361
-        //This allows for adding additional stuff after the title field on the wp post edit form.  This is also before the wp_editor for post description field.
362
-        if (method_exists($this, 'edit_form_after_title')) {
363
-            add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
364
-        }
365
-        /**
366
-         * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
367
-         */
368
-        add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
369
-        parent::_load_page_dependencies();
370
-        //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371
-        global $pagenow;
372
-        do_action('load-' . $pagenow);
373
-        $this->modify_current_screen();
374
-        add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375
-        //we route REALLY early.
376
-        try {
377
-            $this->_route_admin_request();
378
-        } catch (EE_Error $e) {
379
-            $e->get_error();
380
-        }
381
-    }
382
-
383
-
384
-
385
-    /**
386
-     * Since we don't want users going to default core wp routes, this will check any wp urls run through the
387
-     * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
388
-     * route instead.
389
-     *
390
-     * @param string $good_protocol_url The escaped url.
391
-     * @param string $original_url      The original url.
392
-     * @param string $_context          The context sendt to the esc_url method.
393
-     * @return string possibly a new url for our route.
394
-     */
395
-    public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
396
-    {
397
-        $routes_to_match = array(
398
-            0 => array(
399
-                'edit.php?post_type=espresso_attendees',
400
-                'admin.php?page=espresso_registrations&action=contact_list',
401
-            ),
402
-            1 => array(
403
-                'edit.php?post_type=' . $this->_cpt_object->name,
404
-                'admin.php?page=' . $this->_cpt_object->name,
405
-            ),
406
-        );
407
-        foreach ($routes_to_match as $route_matches) {
408
-            if (strpos($good_protocol_url, $route_matches[0]) !== false) {
409
-                return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
410
-            }
411
-        }
412
-        return $good_protocol_url;
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * Determine whether the current cpt supports page templates or not.
419
-     *
420
-     * @since %VER%
421
-     * @param string $cpt_name The cpt slug we're checking on.
422
-     * @return bool True supported, false not.
423
-     */
424
-    private function _supports_page_templates($cpt_name)
425
-    {
426
-
427
-        $cpt_args = EE_Register_CPTs::get_CPTs();
428
-        $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
429
-        $cpt_has_support = ! empty($cpt_args['page_templates']);
430
-
431
-        //if the installed version of WP is > 4.7 we do some additional checks.
432
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
433
-            $post_templates = wp_get_theme()->get_post_templates();
434
-            //if there are $post_templates for this cpt, then we return false for this method because
435
-            //that means we aren't going to load our page template manager and leave that up to the native
436
-            //cpt template manager.
437
-            $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
438
-        }
439
-
440
-        return $cpt_has_support;
441
-    }
442
-
443
-
444
-    /**
445
-     * Callback for the page_templates metabox selector.
446
-     *
447
-     * @since %VER%
448
-     * @return string html
449
-     */
450
-    public function page_template_meta_box()
451
-    {
452
-        global $post;
453
-        $template = '';
454
-
455
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
456
-            $page_template_count = count(get_page_templates());
457
-        } else {
458
-            $page_template_count = count(get_page_templates($post));
459
-        };
460
-
461
-        if ($page_template_count) {
462
-            $page_template = get_post_meta($post->ID, '_wp_page_template', true);
463
-            $template      = ! empty($page_template) ? $page_template : '';
464
-        }
465
-        ?>
279
+		//filter _autosave_containers
280
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281
+			$this->_autosave_containers, $this);
282
+		$containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
283
+			$containers, $this);
284
+
285
+		wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
286
+			$containers); //todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave"
287
+
288
+		$unsaved_data_msg = array(
289
+			'eventmsg'     => sprintf(__("The changes you made to this %s will be lost if you navigate away from this page.",
290
+				'event_espresso'), $this->_cpt_object->labels->singular_name),
291
+			'inputChanged' => 0,
292
+		);
293
+		wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg);
294
+	}
295
+
296
+
297
+
298
+	public function load_page_dependencies()
299
+	{
300
+		try {
301
+			$this->_load_page_dependencies();
302
+		} catch (EE_Error $e) {
303
+			$e->get_error();
304
+		}
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately
311
+	 *
312
+	 * @access protected
313
+	 * @return void
314
+	 */
315
+	protected function _load_page_dependencies()
316
+	{
317
+		//we only add stuff if this is a cpt_route!
318
+		if ( ! $this->_cpt_route) {
319
+			parent::_load_page_dependencies();
320
+			return;
321
+		}
322
+		//now let's do some automatic filters into the wp_system and we'll check to make sure the CHILD class automatically has the required methods in place.
323
+		//the following filters are for setting all the redirects on DEFAULT WP custom post type actions
324
+		//let's add a hidden input to the post-edit form so we know when we have to trigger our custom redirects!  Otherwise the redirects will happen on ALL post saves which wouldn't be good of course!
325
+		add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input'));
326
+		//inject our Admin page nav tabs...
327
+		//let's make sure the nav tabs are set if they aren't already
328
+		//if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs();
329
+		add_action('post_edit_form_tag', array($this, 'inject_nav_tabs'));
330
+		//modify the post_updated messages array
331
+		add_action('post_updated_messages', array($this, 'post_update_messages'), 10);
332
+		//add shortlink button to cpt edit screens.  We can do this as a universal thing BECAUSE, cpts use the same format for shortlinks as posts!
333
+		add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4);
334
+		//This basically allows us to change the title of the "publish" metabox area on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class.
335
+		if ( ! empty($this->_labels['publishbox'])) {
336
+			$box_label = is_array($this->_labels['publishbox'])
337
+						 && isset($this->_labels['publishbox'][$this->_req_action])
338
+				? $this->_labels['publishbox'][$this->_req_action] : $this->_labels['publishbox'];
339
+			remove_meta_box('submitdiv', __('Publish'), 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
340
+				'side', 'core');
341
+			add_meta_box('submitdiv', $box_label, 'post_submit_meta_box', $this->_cpt_routes[$this->_req_action],
342
+				'side', 'core');
343
+		}
344
+		//let's add page_templates metabox if this cpt added support for it.
345
+		if ($this->_supports_page_templates($this->_cpt_object->name)) {
346
+			add_meta_box('page_templates', __('Page Template', 'event_espresso'),
347
+				array($this, 'page_template_meta_box'), $this->_cpt_routes[$this->_req_action], 'side', 'default');
348
+		}
349
+		//this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form
350
+		if (method_exists($this, 'extra_permalink_field_buttons')) {
351
+			add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4);
352
+		}
353
+		//add preview button
354
+		add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4);
355
+		//insert our own post_stati dropdown
356
+		add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10);
357
+		//This allows adding additional information to the publish post submitbox on the wp post edit form
358
+		if (method_exists($this, 'extra_misc_actions_publish_box')) {
359
+			add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10);
360
+		}
361
+		//This allows for adding additional stuff after the title field on the wp post edit form.  This is also before the wp_editor for post description field.
362
+		if (method_exists($this, 'edit_form_after_title')) {
363
+			add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10);
364
+		}
365
+		/**
366
+		 * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route.
367
+		 */
368
+		add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3);
369
+		parent::_load_page_dependencies();
370
+		//notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371
+		global $pagenow;
372
+		do_action('load-' . $pagenow);
373
+		$this->modify_current_screen();
374
+		add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375
+		//we route REALLY early.
376
+		try {
377
+			$this->_route_admin_request();
378
+		} catch (EE_Error $e) {
379
+			$e->get_error();
380
+		}
381
+	}
382
+
383
+
384
+
385
+	/**
386
+	 * Since we don't want users going to default core wp routes, this will check any wp urls run through the
387
+	 * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR
388
+	 * route instead.
389
+	 *
390
+	 * @param string $good_protocol_url The escaped url.
391
+	 * @param string $original_url      The original url.
392
+	 * @param string $_context          The context sendt to the esc_url method.
393
+	 * @return string possibly a new url for our route.
394
+	 */
395
+	public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context)
396
+	{
397
+		$routes_to_match = array(
398
+			0 => array(
399
+				'edit.php?post_type=espresso_attendees',
400
+				'admin.php?page=espresso_registrations&action=contact_list',
401
+			),
402
+			1 => array(
403
+				'edit.php?post_type=' . $this->_cpt_object->name,
404
+				'admin.php?page=' . $this->_cpt_object->name,
405
+			),
406
+		);
407
+		foreach ($routes_to_match as $route_matches) {
408
+			if (strpos($good_protocol_url, $route_matches[0]) !== false) {
409
+				return str_replace($route_matches[0], $route_matches[1], $good_protocol_url);
410
+			}
411
+		}
412
+		return $good_protocol_url;
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * Determine whether the current cpt supports page templates or not.
419
+	 *
420
+	 * @since %VER%
421
+	 * @param string $cpt_name The cpt slug we're checking on.
422
+	 * @return bool True supported, false not.
423
+	 */
424
+	private function _supports_page_templates($cpt_name)
425
+	{
426
+
427
+		$cpt_args = EE_Register_CPTs::get_CPTs();
428
+		$cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array();
429
+		$cpt_has_support = ! empty($cpt_args['page_templates']);
430
+
431
+		//if the installed version of WP is > 4.7 we do some additional checks.
432
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
433
+			$post_templates = wp_get_theme()->get_post_templates();
434
+			//if there are $post_templates for this cpt, then we return false for this method because
435
+			//that means we aren't going to load our page template manager and leave that up to the native
436
+			//cpt template manager.
437
+			$cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false;
438
+		}
439
+
440
+		return $cpt_has_support;
441
+	}
442
+
443
+
444
+	/**
445
+	 * Callback for the page_templates metabox selector.
446
+	 *
447
+	 * @since %VER%
448
+	 * @return string html
449
+	 */
450
+	public function page_template_meta_box()
451
+	{
452
+		global $post;
453
+		$template = '';
454
+
455
+		if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
456
+			$page_template_count = count(get_page_templates());
457
+		} else {
458
+			$page_template_count = count(get_page_templates($post));
459
+		};
460
+
461
+		if ($page_template_count) {
462
+			$page_template = get_post_meta($post->ID, '_wp_page_template', true);
463
+			$template      = ! empty($page_template) ? $page_template : '';
464
+		}
465
+		?>
466 466
         <p><strong><?php _e('Template') ?></strong></p>
467 467
         <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select
468 468
             name="page_template" id="page_template">
@@ -470,435 +470,435 @@  discard block
 block discarded – undo
470 470
         <?php page_template_dropdown($template); ?>
471 471
     </select>
472 472
         <?php
473
-    }
474
-
475
-
476
-
477
-    /**
478
-     * if this post is a draft or scheduled post then we provide a preview button for user to click
479
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
480
-     *
481
-     * @param  string $return    the current html
482
-     * @param  int    $id        the post id for the page
483
-     * @param  string $new_title What the title is
484
-     * @param  string $new_slug  what the slug is
485
-     * @return string            The new html string for the permalink area
486
-     */
487
-    public function preview_button_html($return, $id, $new_title, $new_slug)
488
-    {
489
-        $post = get_post($id);
490
-        if ('publish' != get_post_status($post)) {
491
-            //include shims for the `get_preview_post_link` function
492
-            require_once( EE_CORE . 'wordpress-shims.php' );
493
-            $return .= '<span_id="view-post-btn"><a target="_blank" href="'
494
-                       . get_preview_post_link($id)
495
-                       . '" class="button button-small">'
496
-                       . __('Preview', 'event_espresso')
497
-                       . '</a></span>'
498
-                       . "\n";
499
-        }
500
-        return $return;
501
-    }
502
-
503
-
504
-
505
-    /**
506
-     * add our custom post stati dropdown on the wp post page for this cpt
507
-     *
508
-     * @return string html for dropdown
509
-     */
510
-    public function custom_post_stati_dropdown()
511
-    {
512
-
513
-        $statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
514
-        $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
515
-            ? $statuses[$this->_cpt_model_obj->status()]
516
-            : '';
517
-        $template_args    = array(
518
-            'cur_status'            => $this->_cpt_model_obj->status(),
519
-            'statuses'              => $statuses,
520
-            'cur_status_label'      => $cur_status_label,
521
-            'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
522
-        );
523
-        //we'll add a trash post status (WP doesn't add one for some reason)
524
-        if ($this->_cpt_model_obj->status() == 'trash') {
525
-            $template_args['cur_status_label'] = __('Trashed', 'event_espresso');
526
-            $statuses['trash']                 = __('Trashed', 'event_espresso');
527
-            $template_args['statuses']         = $statuses;
528
-        }
529
-
530
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
531
-        EEH_Template::display_template($template, $template_args);
532
-    }
533
-
534
-
535
-
536
-    public function setup_autosave_hooks()
537
-    {
538
-        $this->_set_autosave_containers();
539
-        $this->_load_autosave_scripts_styles();
540
-    }
541
-
542
-
543
-
544
-    /**
545
-     * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
546
-     * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
547
-     * for the nonce in here, but then this method looks for two things:
548
-     * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
549
-     * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
550
-     * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
551
-     * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
552
-     * template args.
553
-     *    1. $template_args['error'] = IF there is an error you can add the message in here.
554
-     *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
555
-     *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
556
-     *    $this->_template_args['data']['items'] = array(
557
-     *        'event-datetime-ids' => '1,2,3';
558
-     *    );
559
-     *    Keep in mind the following things:
560
-     *    - "where" index is for the input with the id as that string.
561
-     *    - "what" index is what will be used for the value of that input.
562
-     *
563
-     * @return void
564
-     */
565
-    public function do_extra_autosave_stuff()
566
-    {
567
-        //next let's check for the autosave nonce (we'll use _verify_nonce )
568
-        $nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null;
569
-        $this->_verify_nonce($nonce, 'autosave');
570
-        //make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
571
-        if ( ! defined('DOING_AUTOSAVE')) {
572
-            define('DOING_AUTOSAVE', true);
573
-        }
574
-        //if we made it here then the nonce checked out.  Let's run our methods and actions
575
-        if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
-            call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
577
-        } else {
578
-            $this->_template_args['success'] = true;
579
-        }
580
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
582
-        //now let's return json
583
-        $this->_return_json();
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     * This takes care of setting up default routes and pages that utilize the core WP admin pages.
590
-     * Child classes can override the defaults (in cases for adding metaboxes etc.)
591
-     * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
592
-     *
593
-     * @access protected
594
-     * @throws EE_Error
595
-     * @return void
596
-     */
597
-    protected function _extend_page_config_for_cpt()
598
-    {
599
-        //before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
600
-        if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) {
601
-            return;
602
-        }
603
-        //set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
604
-        if ( ! empty($this->_cpt_object)) {
605
-            $this->_page_routes = array_merge(array(
606
-                'create_new' => '_create_new_cpt_item',
607
-                'edit'       => '_edit_cpt_item',
608
-            ), $this->_page_routes);
609
-            $this->_page_config = array_merge(array(
610
-                'create_new' => array(
611
-                    'nav'           => array(
612
-                        'label' => $this->_cpt_object->labels->add_new_item,
613
-                        'order' => 5,
614
-                    ),
615
-                    'require_nonce' => false,
616
-                ),
617
-                'edit'       => array(
618
-                    'nav'           => array(
619
-                        'label'      => $this->_cpt_object->labels->edit_item,
620
-                        'order'      => 5,
621
-                        'persistent' => false,
622
-                        'url'        => '',
623
-                    ),
624
-                    'require_nonce' => false,
625
-                ),
626
-            ),
627
-                $this->_page_config
628
-            );
629
-        }
630
-        //load the next section only if this is a matching cpt route as set in the cpt routes array.
631
-        if ( ! isset($this->_cpt_routes[$this->_req_action])) {
632
-            return;
633
-        }
634
-        $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
635
-        //add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
636
-        if (empty($this->_cpt_object)) {
637
-            $msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
638
-                $this->page_slug, $this->_req_action, get_class($this));
639
-            throw new EE_Error($msg);
640
-        }
641
-        if ($this->_cpt_route) {
642
-            $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
643
-            $this->_set_model_object($id);
644
-        }
645
-    }
646
-
647
-
648
-
649
-    /**
650
-     * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
651
-     *
652
-     * @access protected
653
-     * @param int  $id The id to retrieve the model object for. If empty we set a default object.
654
-     * @param bool $ignore_route_check
655
-     */
656
-    protected function _set_model_object($id = null, $ignore_route_check = false)
657
-    {
658
-        $model = null;
659
-        if (
660
-            empty($this->_cpt_model_names)
661
-            || (
662
-                ! $ignore_route_check
663
-                && ! isset($this->_cpt_routes[$this->_req_action])
664
-            ) || (
665
-                $this->_cpt_model_obj instanceof EE_CPT_Base
666
-                && $this->_cpt_model_obj->ID() === $id
667
-            )
668
-        ) {
669
-            //get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
670
-            return;
671
-        }
672
-        //if ignore_route_check is true, then get the model name via EE_Register_CPTs
673
-        if ($ignore_route_check) {
674
-            $model_names = EE_Register_CPTs::get_cpt_model_names();
675
-            $post_type   = get_post_type($id);
676
-            if (isset($model_names[$post_type])) {
677
-                $model = EE_Registry::instance()->load_model($model_names[$post_type]);
678
-            }
679
-        } else {
680
-            $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
681
-        }
682
-        if ($model instanceof EEM_Base) {
683
-            $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
684
-        }
685
-        do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * admin_init_global
692
-     * This runs all the code that we want executed within the WP admin_init hook.
693
-     * This method executes for ALL EE Admin pages.
694
-     *
695
-     * @access public
696
-     * @return void
697
-     */
698
-    public function admin_init_global()
699
-    {
700
-        $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
701
-        //its possible this is a new save so let's catch that instead
702
-        $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
703
-        $post_type = $post ? $post->post_type : false;
704
-        $current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route']
705
-            : 'shouldneverwork';
706
-        $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route]
707
-            : '';
708
-        add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
709
-        add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
710
-        if ($post_type === $route_to_check) {
711
-            add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
712
-        }
713
-        //now let's filter redirect if we're on a revision page and the revision is for an event CPT.
714
-        $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
715
-        if ( ! empty($revision)) {
716
-            $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
717
-            //doing a restore?
718
-            if ( ! empty($action) && $action == 'restore') {
719
-                //get post for revision
720
-                $rev_post = get_post($revision);
721
-                $rev_parent = get_post($rev_post->post_parent);
722
-                //only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
723
-                if ($rev_parent && $rev_parent->post_type == $this->page_slug) {
724
-                    add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
725
-                    //restores of revisions
726
-                    add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
727
-                }
728
-            }
729
-        }
730
-        //NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
731
-        if ($post_type && $post_type === $route_to_check) {
732
-            //$post_id, $post
733
-            add_action('save_post', array($this, 'insert_update'), 10, 3);
734
-            //$post_id
735
-            add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
736
-            add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
737
-            add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
738
-            add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
739
-        }
740
-    }
741
-
742
-
743
-
744
-    /**
745
-     * Callback for the WordPress trashed_post hook.
746
-     * Execute some basic checks before calling the trash_cpt_item declared in the child class.
747
-     *
748
-     * @param int $post_id
749
-     */
750
-    public function before_trash_cpt_item($post_id)
751
-    {
752
-        $this->_set_model_object($post_id, true);
753
-        //if our cpt object isn't existent then get out immediately.
754
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
755
-            return;
756
-        }
757
-        $this->trash_cpt_item($post_id);
758
-    }
759
-
760
-
761
-
762
-    /**
763
-     * Callback for the WordPress untrashed_post hook.
764
-     * Execute some basic checks before calling the restore_cpt_method in the child class.
765
-     *
766
-     * @param $post_id
767
-     */
768
-    public function before_restore_cpt_item($post_id)
769
-    {
770
-        $this->_set_model_object($post_id, true);
771
-        //if our cpt object isn't existent then get out immediately.
772
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
773
-            return;
774
-        }
775
-        $this->restore_cpt_item($post_id);
776
-    }
777
-
778
-
779
-
780
-    /**
781
-     * Callback for the WordPress after_delete_post hook.
782
-     * Execute some basic checks before calling the delete_cpt_item method in the child class.
783
-     *
784
-     * @param $post_id
785
-     */
786
-    public function before_delete_cpt_item($post_id)
787
-    {
788
-        $this->_set_model_object($post_id, true);
789
-        //if our cpt object isn't existent then get out immediately.
790
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
791
-            return;
792
-        }
793
-        $this->delete_cpt_item($post_id);
794
-    }
795
-
796
-
797
-
798
-    /**
799
-     * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
800
-     * accordingly.
801
-     *
802
-     * @access public
803
-     * @throws EE_Error
804
-     * @return void
805
-     */
806
-    public function verify_cpt_object()
807
-    {
808
-        $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
809
-        // verify event object
810
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
811
-            throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
812
-                'event_espresso'), $label));
813
-        }
814
-        //if auto-draft then throw an error
815
-        if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
816
-            EE_Error::overwrite_errors();
817
-            EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
818
-                $label), __FILE__, __FUNCTION__, __LINE__);
819
-        }
820
-    }
821
-
822
-
823
-
824
-    /**
825
-     * admin_footer_scripts_global
826
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
827
-     * will apply on ALL EE_Admin pages.
828
-     *
829
-     * @access public
830
-     * @return void
831
-     */
832
-    public function admin_footer_scripts_global()
833
-    {
834
-        $this->_add_admin_page_ajax_loading_img();
835
-        $this->_add_admin_page_overlay();
836
-    }
837
-
838
-
839
-
840
-    /**
841
-     * add in any global scripts for cpt routes
842
-     *
843
-     * @return void
844
-     */
845
-    public function load_global_scripts_styles()
846
-    {
847
-        parent::load_global_scripts_styles();
848
-        if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
849
-            //setup custom post status object for localize script but only if we've got a cpt object
850
-            $statuses = $this->_cpt_model_obj->get_custom_post_statuses();
851
-            if ( ! empty($statuses)) {
852
-                //get ALL statuses!
853
-                $statuses = $this->_cpt_model_obj->get_all_post_statuses();
854
-                //setup object
855
-                $ee_cpt_statuses = array();
856
-                foreach ($statuses as $status => $label) {
857
-                    $ee_cpt_statuses[$status] = array(
858
-                        'label'      => $label,
859
-                        'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
860
-                    );
861
-                }
862
-                wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
863
-            }
864
-        }
865
-    }
866
-
867
-
868
-
869
-    /**
870
-     * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
871
-     * insert/updates
872
-     *
873
-     * @param  int     $post_id ID of post being updated
874
-     * @param  WP_Post $post    Post object from WP
875
-     * @param  bool    $update  Whether this is an update or a new save.
876
-     * @return void
877
-     */
878
-    public function insert_update($post_id, $post, $update)
879
-    {
880
-        //make sure that if this is a revision OR trash action that we don't do any updates!
881
-        if (
882
-            isset($this->_req_data['action'])
883
-            && (
884
-                $this->_req_data['action'] == 'restore'
885
-                || $this->_req_data['action'] == 'trash'
886
-            )
887
-        ) {
888
-            return;
889
-        }
890
-        $this->_set_model_object($post_id, true);
891
-        //if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
892
-        if ($update
893
-            && (
894
-                ! $this->_cpt_model_obj instanceof EE_CPT_Base
895
-                || $this->_cpt_model_obj->ID() !== $post_id
896
-            )
897
-        ) {
898
-            return;
899
-        }
900
-        //check for autosave and update our req_data property accordingly.
901
-        /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
473
+	}
474
+
475
+
476
+
477
+	/**
478
+	 * if this post is a draft or scheduled post then we provide a preview button for user to click
479
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
480
+	 *
481
+	 * @param  string $return    the current html
482
+	 * @param  int    $id        the post id for the page
483
+	 * @param  string $new_title What the title is
484
+	 * @param  string $new_slug  what the slug is
485
+	 * @return string            The new html string for the permalink area
486
+	 */
487
+	public function preview_button_html($return, $id, $new_title, $new_slug)
488
+	{
489
+		$post = get_post($id);
490
+		if ('publish' != get_post_status($post)) {
491
+			//include shims for the `get_preview_post_link` function
492
+			require_once( EE_CORE . 'wordpress-shims.php' );
493
+			$return .= '<span_id="view-post-btn"><a target="_blank" href="'
494
+					   . get_preview_post_link($id)
495
+					   . '" class="button button-small">'
496
+					   . __('Preview', 'event_espresso')
497
+					   . '</a></span>'
498
+					   . "\n";
499
+		}
500
+		return $return;
501
+	}
502
+
503
+
504
+
505
+	/**
506
+	 * add our custom post stati dropdown on the wp post page for this cpt
507
+	 *
508
+	 * @return string html for dropdown
509
+	 */
510
+	public function custom_post_stati_dropdown()
511
+	{
512
+
513
+		$statuses         = $this->_cpt_model_obj->get_custom_post_statuses();
514
+		$cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses)
515
+			? $statuses[$this->_cpt_model_obj->status()]
516
+			: '';
517
+		$template_args    = array(
518
+			'cur_status'            => $this->_cpt_model_obj->status(),
519
+			'statuses'              => $statuses,
520
+			'cur_status_label'      => $cur_status_label,
521
+			'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label),
522
+		);
523
+		//we'll add a trash post status (WP doesn't add one for some reason)
524
+		if ($this->_cpt_model_obj->status() == 'trash') {
525
+			$template_args['cur_status_label'] = __('Trashed', 'event_espresso');
526
+			$statuses['trash']                 = __('Trashed', 'event_espresso');
527
+			$template_args['statuses']         = $statuses;
528
+		}
529
+
530
+		$template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
531
+		EEH_Template::display_template($template, $template_args);
532
+	}
533
+
534
+
535
+
536
+	public function setup_autosave_hooks()
537
+	{
538
+		$this->_set_autosave_containers();
539
+		$this->_load_autosave_scripts_styles();
540
+	}
541
+
542
+
543
+
544
+	/**
545
+	 * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available
546
+	 * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check
547
+	 * for the nonce in here, but then this method looks for two things:
548
+	 * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR
549
+	 * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an
550
+	 * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the
551
+	 * $_template_args property should be used to hold the $data array.  We're expecting the following things set in
552
+	 * template args.
553
+	 *    1. $template_args['error'] = IF there is an error you can add the message in here.
554
+	 *    2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go'
555
+	 *    => 'values_to_add'.  In other words, for the datetime metabox we'll have something like
556
+	 *    $this->_template_args['data']['items'] = array(
557
+	 *        'event-datetime-ids' => '1,2,3';
558
+	 *    );
559
+	 *    Keep in mind the following things:
560
+	 *    - "where" index is for the input with the id as that string.
561
+	 *    - "what" index is what will be used for the value of that input.
562
+	 *
563
+	 * @return void
564
+	 */
565
+	public function do_extra_autosave_stuff()
566
+	{
567
+		//next let's check for the autosave nonce (we'll use _verify_nonce )
568
+		$nonce = isset($this->_req_data['autosavenonce']) ? $this->_req_data['autosavenonce'] : null;
569
+		$this->_verify_nonce($nonce, 'autosave');
570
+		//make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it)
571
+		if ( ! defined('DOING_AUTOSAVE')) {
572
+			define('DOING_AUTOSAVE', true);
573
+		}
574
+		//if we made it here then the nonce checked out.  Let's run our methods and actions
575
+		if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
+			call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
577
+		} else {
578
+			$this->_template_args['success'] = true;
579
+		}
580
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
+		do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
582
+		//now let's return json
583
+		$this->_return_json();
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 * This takes care of setting up default routes and pages that utilize the core WP admin pages.
590
+	 * Child classes can override the defaults (in cases for adding metaboxes etc.)
591
+	 * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work!
592
+	 *
593
+	 * @access protected
594
+	 * @throws EE_Error
595
+	 * @return void
596
+	 */
597
+	protected function _extend_page_config_for_cpt()
598
+	{
599
+		//before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug
600
+		if ((isset($this->_req_data['page']) && $this->_req_data['page'] != $this->page_slug)) {
601
+			return;
602
+		}
603
+		//set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes
604
+		if ( ! empty($this->_cpt_object)) {
605
+			$this->_page_routes = array_merge(array(
606
+				'create_new' => '_create_new_cpt_item',
607
+				'edit'       => '_edit_cpt_item',
608
+			), $this->_page_routes);
609
+			$this->_page_config = array_merge(array(
610
+				'create_new' => array(
611
+					'nav'           => array(
612
+						'label' => $this->_cpt_object->labels->add_new_item,
613
+						'order' => 5,
614
+					),
615
+					'require_nonce' => false,
616
+				),
617
+				'edit'       => array(
618
+					'nav'           => array(
619
+						'label'      => $this->_cpt_object->labels->edit_item,
620
+						'order'      => 5,
621
+						'persistent' => false,
622
+						'url'        => '',
623
+					),
624
+					'require_nonce' => false,
625
+				),
626
+			),
627
+				$this->_page_config
628
+			);
629
+		}
630
+		//load the next section only if this is a matching cpt route as set in the cpt routes array.
631
+		if ( ! isset($this->_cpt_routes[$this->_req_action])) {
632
+			return;
633
+		}
634
+		$this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false;
635
+		//add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') );
636
+		if (empty($this->_cpt_object)) {
637
+			$msg = sprintf(__('This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this:  1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).'),
638
+				$this->page_slug, $this->_req_action, get_class($this));
639
+			throw new EE_Error($msg);
640
+		}
641
+		if ($this->_cpt_route) {
642
+			$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
643
+			$this->_set_model_object($id);
644
+		}
645
+	}
646
+
647
+
648
+
649
+	/**
650
+	 * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id.
651
+	 *
652
+	 * @access protected
653
+	 * @param int  $id The id to retrieve the model object for. If empty we set a default object.
654
+	 * @param bool $ignore_route_check
655
+	 */
656
+	protected function _set_model_object($id = null, $ignore_route_check = false)
657
+	{
658
+		$model = null;
659
+		if (
660
+			empty($this->_cpt_model_names)
661
+			|| (
662
+				! $ignore_route_check
663
+				&& ! isset($this->_cpt_routes[$this->_req_action])
664
+			) || (
665
+				$this->_cpt_model_obj instanceof EE_CPT_Base
666
+				&& $this->_cpt_model_obj->ID() === $id
667
+			)
668
+		) {
669
+			//get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent.
670
+			return;
671
+		}
672
+		//if ignore_route_check is true, then get the model name via EE_Register_CPTs
673
+		if ($ignore_route_check) {
674
+			$model_names = EE_Register_CPTs::get_cpt_model_names();
675
+			$post_type   = get_post_type($id);
676
+			if (isset($model_names[$post_type])) {
677
+				$model = EE_Registry::instance()->load_model($model_names[$post_type]);
678
+			}
679
+		} else {
680
+			$model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]);
681
+		}
682
+		if ($model instanceof EEM_Base) {
683
+			$this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object();
684
+		}
685
+		do_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object');
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * admin_init_global
692
+	 * This runs all the code that we want executed within the WP admin_init hook.
693
+	 * This method executes for ALL EE Admin pages.
694
+	 *
695
+	 * @access public
696
+	 * @return void
697
+	 */
698
+	public function admin_init_global()
699
+	{
700
+		$post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null;
701
+		//its possible this is a new save so let's catch that instead
702
+		$post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post;
703
+		$post_type = $post ? $post->post_type : false;
704
+		$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route']
705
+			: 'shouldneverwork';
706
+		$route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route]
707
+			: '';
708
+		add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3);
709
+		add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3);
710
+		if ($post_type === $route_to_check) {
711
+			add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2);
712
+		}
713
+		//now let's filter redirect if we're on a revision page and the revision is for an event CPT.
714
+		$revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
715
+		if ( ! empty($revision)) {
716
+			$action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null;
717
+			//doing a restore?
718
+			if ( ! empty($action) && $action == 'restore') {
719
+				//get post for revision
720
+				$rev_post = get_post($revision);
721
+				$rev_parent = get_post($rev_post->post_parent);
722
+				//only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts.
723
+				if ($rev_parent && $rev_parent->post_type == $this->page_slug) {
724
+					add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2);
725
+					//restores of revisions
726
+					add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2);
727
+				}
728
+			}
729
+		}
730
+		//NOTE we ONLY want to run these hooks if we're on the right class for the given post type.  Otherwise we could see some really freaky things happen!
731
+		if ($post_type && $post_type === $route_to_check) {
732
+			//$post_id, $post
733
+			add_action('save_post', array($this, 'insert_update'), 10, 3);
734
+			//$post_id
735
+			add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10);
736
+			add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10);
737
+			add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10);
738
+			add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10);
739
+		}
740
+	}
741
+
742
+
743
+
744
+	/**
745
+	 * Callback for the WordPress trashed_post hook.
746
+	 * Execute some basic checks before calling the trash_cpt_item declared in the child class.
747
+	 *
748
+	 * @param int $post_id
749
+	 */
750
+	public function before_trash_cpt_item($post_id)
751
+	{
752
+		$this->_set_model_object($post_id, true);
753
+		//if our cpt object isn't existent then get out immediately.
754
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
755
+			return;
756
+		}
757
+		$this->trash_cpt_item($post_id);
758
+	}
759
+
760
+
761
+
762
+	/**
763
+	 * Callback for the WordPress untrashed_post hook.
764
+	 * Execute some basic checks before calling the restore_cpt_method in the child class.
765
+	 *
766
+	 * @param $post_id
767
+	 */
768
+	public function before_restore_cpt_item($post_id)
769
+	{
770
+		$this->_set_model_object($post_id, true);
771
+		//if our cpt object isn't existent then get out immediately.
772
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
773
+			return;
774
+		}
775
+		$this->restore_cpt_item($post_id);
776
+	}
777
+
778
+
779
+
780
+	/**
781
+	 * Callback for the WordPress after_delete_post hook.
782
+	 * Execute some basic checks before calling the delete_cpt_item method in the child class.
783
+	 *
784
+	 * @param $post_id
785
+	 */
786
+	public function before_delete_cpt_item($post_id)
787
+	{
788
+		$this->_set_model_object($post_id, true);
789
+		//if our cpt object isn't existent then get out immediately.
790
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) {
791
+			return;
792
+		}
793
+		$this->delete_cpt_item($post_id);
794
+	}
795
+
796
+
797
+
798
+	/**
799
+	 * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message
800
+	 * accordingly.
801
+	 *
802
+	 * @access public
803
+	 * @throws EE_Error
804
+	 * @return void
805
+	 */
806
+	public function verify_cpt_object()
807
+	{
808
+		$label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label;
809
+		// verify event object
810
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
811
+			throw new EE_Error(sprintf(__('Something has gone wrong with the page load because we are unable to set up the object for the %1$s.  This usually happens when the given id for the page route is NOT for the correct custom post type for this page',
812
+				'event_espresso'), $label));
813
+		}
814
+		//if auto-draft then throw an error
815
+		if ($this->_cpt_model_obj->get('status') == 'auto-draft') {
816
+			EE_Error::overwrite_errors();
817
+			EE_Error::add_error(sprintf(__('This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly.  All autodrafts will show up in the "draft" view of your event list table.  You can delete them from there. Please click the "Add %1$s" button to refresh and restart.'),
818
+				$label), __FILE__, __FUNCTION__, __LINE__);
819
+		}
820
+	}
821
+
822
+
823
+
824
+	/**
825
+	 * admin_footer_scripts_global
826
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
827
+	 * will apply on ALL EE_Admin pages.
828
+	 *
829
+	 * @access public
830
+	 * @return void
831
+	 */
832
+	public function admin_footer_scripts_global()
833
+	{
834
+		$this->_add_admin_page_ajax_loading_img();
835
+		$this->_add_admin_page_overlay();
836
+	}
837
+
838
+
839
+
840
+	/**
841
+	 * add in any global scripts for cpt routes
842
+	 *
843
+	 * @return void
844
+	 */
845
+	public function load_global_scripts_styles()
846
+	{
847
+		parent::load_global_scripts_styles();
848
+		if ($this->_cpt_model_obj instanceof EE_CPT_Base) {
849
+			//setup custom post status object for localize script but only if we've got a cpt object
850
+			$statuses = $this->_cpt_model_obj->get_custom_post_statuses();
851
+			if ( ! empty($statuses)) {
852
+				//get ALL statuses!
853
+				$statuses = $this->_cpt_model_obj->get_all_post_statuses();
854
+				//setup object
855
+				$ee_cpt_statuses = array();
856
+				foreach ($statuses as $status => $label) {
857
+					$ee_cpt_statuses[$status] = array(
858
+						'label'      => $label,
859
+						'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label),
860
+					);
861
+				}
862
+				wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses);
863
+			}
864
+		}
865
+	}
866
+
867
+
868
+
869
+	/**
870
+	 * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL
871
+	 * insert/updates
872
+	 *
873
+	 * @param  int     $post_id ID of post being updated
874
+	 * @param  WP_Post $post    Post object from WP
875
+	 * @param  bool    $update  Whether this is an update or a new save.
876
+	 * @return void
877
+	 */
878
+	public function insert_update($post_id, $post, $update)
879
+	{
880
+		//make sure that if this is a revision OR trash action that we don't do any updates!
881
+		if (
882
+			isset($this->_req_data['action'])
883
+			&& (
884
+				$this->_req_data['action'] == 'restore'
885
+				|| $this->_req_data['action'] == 'trash'
886
+			)
887
+		) {
888
+			return;
889
+		}
890
+		$this->_set_model_object($post_id, true);
891
+		//if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit.
892
+		if ($update
893
+			&& (
894
+				! $this->_cpt_model_obj instanceof EE_CPT_Base
895
+				|| $this->_cpt_model_obj->ID() !== $post_id
896
+			)
897
+		) {
898
+			return;
899
+		}
900
+		//check for autosave and update our req_data property accordingly.
901
+		/*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) {
902 902
             foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) {
903 903
 
904 904
                 foreach ( (array) $values as $key => $value ) {
@@ -908,524 +908,524 @@  discard block
 block discarded – undo
908 908
 
909 909
         }/**/ //TODO reactivate after autosave is implemented in 4.2
910 910
 
911
-        //take care of updating any selected page_template IF this cpt supports it.
912
-        if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
913
-            //wp version aware.
914
-            if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
915
-                $page_templates = wp_get_theme()->get_page_templates();
916
-            } else {
917
-                $post->page_template = $this->_req_data['page_template'];
918
-                $page_templates      = wp_get_theme()->get_page_templates($post);
919
-            }
920
-            if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
921
-                EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
922
-            } else {
923
-                update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
924
-            }
925
-        }
926
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
927
-            return;
928
-        } //TODO we'll remove this after reimplementing autosave in 4.2
929
-        $this->_insert_update_cpt_item($post_id, $post);
930
-    }
931
-
932
-
933
-
934
-    /**
935
-     * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
936
-     * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
937
-     * so we don't have to check for our CPT.
938
-     *
939
-     * @param  int $post_id ID of the post
940
-     * @return void
941
-     */
942
-    public function dont_permanently_delete_ee_cpts($post_id)
943
-    {
944
-        //only do this if we're actually processing one of our CPTs
945
-        //if our cpt object isn't existent then get out immediately.
946
-        if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
947
-            return;
948
-        }
949
-        delete_post_meta($post_id, '_wp_trash_meta_status');
950
-        delete_post_meta($post_id, '_wp_trash_meta_time');
951
-        //our cpts may have comments so let's take care of that too
952
-        delete_post_meta($post_id, '_wp_trash_meta_comments_status');
953
-    }
954
-
955
-
956
-
957
-    /**
958
-     * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
959
-     * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
960
-     * in them.  We also have our OWN action in here so addons can hook into the restore process easily.
961
-     *
962
-     * @param  int $post_id     ID of cpt item
963
-     * @param  int $revision_id ID of revision being restored
964
-     * @return void
965
-     */
966
-    public function restore_revision($post_id, $revision_id)
967
-    {
968
-        $this->_restore_cpt_item($post_id, $revision_id);
969
-        //global action
970
-        do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
971
-        //class specific action so you can limit hooking into a specific page.
972
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
973
-    }
974
-
975
-
976
-
977
-    /**
978
-     * @see restore_revision() for details
979
-     * @param  int $post_id     ID of cpt item
980
-     * @param  int $revision_id ID of revision for item
981
-     * @return void
982
-     */
983
-    abstract protected function _restore_cpt_item($post_id, $revision_id);
984
-
985
-
986
-
987
-    /**
988
-     * Execution of this method is added to the end of the load_page_dependencies method in the parent
989
-     * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
990
-     * To fix we have to reset the current_screen using the page_slug
991
-     * (which is identical - or should be - to our registered_post_type id.)
992
-     * Also, since the core WP file loads the admin_header.php for WP
993
-     * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
994
-     * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
995
-     *
996
-     * @return void
997
-     */
998
-    public function modify_current_screen()
999
-    {
1000
-        //ONLY do this if the current page_route IS a cpt route
1001
-        if ( ! $this->_cpt_route) {
1002
-            return;
1003
-        }
1004
-        //routing things REALLY early b/c this is a cpt admin page
1005
-        set_current_screen($this->_cpt_routes[$this->_req_action]);
1006
-        $this->_current_screen       = get_current_screen();
1007
-        $this->_current_screen->base = 'event-espresso';
1008
-        $this->_add_help_tabs(); //we make sure we add any help tabs back in!
1009
-        /*try {
911
+		//take care of updating any selected page_template IF this cpt supports it.
912
+		if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) {
913
+			//wp version aware.
914
+			if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
915
+				$page_templates = wp_get_theme()->get_page_templates();
916
+			} else {
917
+				$post->page_template = $this->_req_data['page_template'];
918
+				$page_templates      = wp_get_theme()->get_page_templates($post);
919
+			}
920
+			if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) {
921
+				EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
922
+			} else {
923
+				update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']);
924
+			}
925
+		}
926
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
927
+			return;
928
+		} //TODO we'll remove this after reimplementing autosave in 4.2
929
+		$this->_insert_update_cpt_item($post_id, $post);
930
+	}
931
+
932
+
933
+
934
+	/**
935
+	 * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time`
936
+	 * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes
937
+	 * so we don't have to check for our CPT.
938
+	 *
939
+	 * @param  int $post_id ID of the post
940
+	 * @return void
941
+	 */
942
+	public function dont_permanently_delete_ee_cpts($post_id)
943
+	{
944
+		//only do this if we're actually processing one of our CPTs
945
+		//if our cpt object isn't existent then get out immediately.
946
+		if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) {
947
+			return;
948
+		}
949
+		delete_post_meta($post_id, '_wp_trash_meta_status');
950
+		delete_post_meta($post_id, '_wp_trash_meta_time');
951
+		//our cpts may have comments so let's take care of that too
952
+		delete_post_meta($post_id, '_wp_trash_meta_comments_status');
953
+	}
954
+
955
+
956
+
957
+	/**
958
+	 * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is
959
+	 * triggered that we restore related items.  In order to work cpt classes MUST have a restore_cpt_revision method
960
+	 * in them.  We also have our OWN action in here so addons can hook into the restore process easily.
961
+	 *
962
+	 * @param  int $post_id     ID of cpt item
963
+	 * @param  int $revision_id ID of revision being restored
964
+	 * @return void
965
+	 */
966
+	public function restore_revision($post_id, $revision_id)
967
+	{
968
+		$this->_restore_cpt_item($post_id, $revision_id);
969
+		//global action
970
+		do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
971
+		//class specific action so you can limit hooking into a specific page.
972
+		do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
973
+	}
974
+
975
+
976
+
977
+	/**
978
+	 * @see restore_revision() for details
979
+	 * @param  int $post_id     ID of cpt item
980
+	 * @param  int $revision_id ID of revision for item
981
+	 * @return void
982
+	 */
983
+	abstract protected function _restore_cpt_item($post_id, $revision_id);
984
+
985
+
986
+
987
+	/**
988
+	 * Execution of this method is added to the end of the load_page_dependencies method in the parent
989
+	 * so that we can fix a bug where default core metaboxes were not being called in the sidebar.
990
+	 * To fix we have to reset the current_screen using the page_slug
991
+	 * (which is identical - or should be - to our registered_post_type id.)
992
+	 * Also, since the core WP file loads the admin_header.php for WP
993
+	 * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early)
994
+	 * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set).
995
+	 *
996
+	 * @return void
997
+	 */
998
+	public function modify_current_screen()
999
+	{
1000
+		//ONLY do this if the current page_route IS a cpt route
1001
+		if ( ! $this->_cpt_route) {
1002
+			return;
1003
+		}
1004
+		//routing things REALLY early b/c this is a cpt admin page
1005
+		set_current_screen($this->_cpt_routes[$this->_req_action]);
1006
+		$this->_current_screen       = get_current_screen();
1007
+		$this->_current_screen->base = 'event-espresso';
1008
+		$this->_add_help_tabs(); //we make sure we add any help tabs back in!
1009
+		/*try {
1010 1010
             $this->_route_admin_request();
1011 1011
         } catch ( EE_Error $e ) {
1012 1012
             $e->get_error();
1013 1013
         }/**/
1014
-    }
1015
-
1016
-
1017
-
1018
-    /**
1019
-     * This allows child classes to modify the default editor title that appears when people add a new or edit an
1020
-     * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1021
-     * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1022
-     * default to be.
1023
-     *
1024
-     * @param string $title The new title (or existing if there is no editor_title defined)
1025
-     * @return string
1026
-     */
1027
-    public function add_custom_editor_default_title($title)
1028
-    {
1029
-        return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1030
-            ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1031
-            : $title;
1032
-    }
1033
-
1034
-
1035
-
1036
-    /**
1037
-     * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1038
-     *
1039
-     * @param string $shortlink   The already generated shortlink
1040
-     * @param int    $id          Post ID for this item
1041
-     * @param string $context     The context for the link
1042
-     * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1043
-     * @return string
1044
-     */
1045
-    public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1046
-    {
1047
-        if ( ! empty($id) && '' != get_option('permalink_structure')) {
1048
-            $post = get_post($id);
1049
-            if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1050
-                $shortlink = home_url('?p=' . $post->ID);
1051
-            }
1052
-        }
1053
-        return $shortlink;
1054
-    }
1055
-
1056
-
1057
-
1058
-    /**
1059
-     * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1060
-     * already run in modify_current_screen())
1061
-     *
1062
-     * @return void
1063
-     */
1064
-    public function route_admin_request()
1065
-    {
1066
-        if ($this->_cpt_route) {
1067
-            return;
1068
-        }
1069
-        try {
1070
-            $this->_route_admin_request();
1071
-        } catch (EE_Error $e) {
1072
-            $e->get_error();
1073
-        }
1074
-    }
1075
-
1076
-
1077
-
1078
-    /**
1079
-     * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1080
-     *
1081
-     * @return string html
1082
-     */
1083
-    public function cpt_post_form_hidden_input()
1084
-    {
1085
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1086
-        //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1087
-        echo '<div id="ee-cpt-hidden-inputs">';
1088
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1089
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1090
-        echo '</div>';
1091
-    }
1092
-
1093
-
1094
-
1095
-    /**
1096
-     * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1097
-     *
1098
-     * @param  string $location Original location url
1099
-     * @param  int    $status   Status for http header
1100
-     * @return string           new (or original) url to redirect to.
1101
-     */
1102
-    public function revision_redirect($location, $status)
1103
-    {
1104
-        //get revision
1105
-        $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1106
-        //can't do anything without revision so let's get out if not present
1107
-        if (empty($rev_id)) {
1108
-            return $location;
1109
-        }
1110
-        //get rev_post_data
1111
-        $rev = get_post($rev_id);
1112
-        $admin_url = $this->_admin_base_url;
1113
-        $query_args = array(
1114
-            'action'   => 'edit',
1115
-            'post'     => $rev->post_parent,
1116
-            'revision' => $rev_id,
1117
-            'message'  => 5,
1118
-        );
1119
-        $this->_process_notices($query_args, true);
1120
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1121
-    }
1122
-
1123
-
1124
-
1125
-    /**
1126
-     * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1127
-     *
1128
-     * @param  string $link    the original generated link
1129
-     * @param  int    $id      post id
1130
-     * @param  string $context optional, defaults to display.  How to write the '&'
1131
-     * @return string          the link
1132
-     */
1133
-    public function modify_edit_post_link($link, $id, $context)
1134
-    {
1135
-        $post = get_post($id);
1136
-        if ( ! isset($this->_req_data['action'])
1137
-             || ! isset($this->_cpt_routes[$this->_req_data['action']])
1138
-             || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1139
-        ) {
1140
-            return $link;
1141
-        }
1142
-        $query_args = array(
1143
-            'action' => isset($this->_cpt_edit_routes[$post->post_type])
1144
-                ? $this->_cpt_edit_routes[$post->post_type]
1145
-                : 'edit',
1146
-            'post'   => $id,
1147
-        );
1148
-        return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1149
-    }
1150
-
1151
-
1152
-    /**
1153
-     * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1154
-     * our routes.
1155
-     *
1156
-     * @param  string $delete_link  original delete link
1157
-     * @param  int    $post_id      id of cpt object
1158
-     * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1159
-     * @return string new delete link
1160
-     * @throws EE_Error
1161
-     */
1162
-    public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1163
-    {
1164
-        $post = get_post($post_id);
1165
-        if (! isset($this->_req_data['action'], $this->_req_data['post'])
1166
-             || (isset($this->_cpt_routes[$this->_req_data['action']])
1167
-                 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1168
-        ) {
1169
-            return $delete_link;
1170
-        }
1171
-        $this->_set_model_object($this->_req_data['post'], true);
1172
-        //returns something like `trash_event` or `trash_attendee` or `trash_venue`
1173
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1174
-
1175
-        return EE_Admin_Page::add_query_args_and_nonce(
1176
-            array(
1177
-                'page' => $this->_req_data['page'],
1178
-                'action' => $action,
1179
-                $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1180
-                    => $this->_req_data['post']
1181
-            ),
1182
-            admin_url()
1183
-        );
1184
-    }
1185
-
1186
-
1187
-
1188
-    /**
1189
-     * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1190
-     * so that we can hijack the default redirect locations for wp custom post types
1191
-     * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1192
-     *
1193
-     * @param  string $location This is the incoming currently set redirect location
1194
-     * @param  string $post_id  This is the 'ID' value of the wp_posts table
1195
-     * @return string           the new location to redirect to
1196
-     */
1197
-    public function cpt_post_location_redirect($location, $post_id)
1198
-    {
1199
-        //we DO have a match so let's setup the url
1200
-        //we have to get the post to determine our route
1201
-        $post       = get_post($post_id);
1202
-        $edit_route = $this->_cpt_edit_routes[$post->post_type];
1203
-        //shared query_args
1204
-        $query_args = array('action' => $edit_route, 'post' => $post_id);
1205
-        $admin_url  = $this->_admin_base_url;
1206
-        if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1207
-            $status = get_post_status($post_id);
1208
-            if (isset($this->_req_data['publish'])) {
1209
-                switch ($status) {
1210
-                    case 'pending':
1211
-                        $message = 8;
1212
-                        break;
1213
-                    case 'future':
1214
-                        $message = 9;
1215
-                        break;
1216
-                    default:
1217
-                        $message = 6;
1218
-                }
1219
-            } else {
1220
-                $message = 'draft' == $status ? 10 : 1;
1221
-            }
1222
-        } else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1223
-            $message = 2;
1224
-            //			$append = '#postcustom';
1225
-        } else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1226
-            $message = 3;
1227
-            //			$append = '#postcustom';
1228
-        } elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') {
1229
-            $message = 7;
1230
-        } else {
1231
-            $message = 4;
1232
-        }
1233
-        //change the message if the post type is not viewable on the frontend
1234
-        $this->_cpt_object = get_post_type_object($post->post_type);
1235
-        $message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1236
-        $query_args = array_merge(array('message' => $message), $query_args);
1237
-        $this->_process_notices($query_args, true);
1238
-        return self::add_query_args_and_nonce($query_args, $admin_url);
1239
-    }
1240
-
1241
-
1242
-
1243
-    /**
1244
-     * This method is called to inject nav tabs on core WP cpt pages
1245
-     *
1246
-     * @access public
1247
-     * @return string html
1248
-     */
1249
-    public function inject_nav_tabs()
1250
-    {
1251
-        //can we hijack and insert the nav_tabs?
1252
-        $nav_tabs = $this->_get_main_nav_tabs();
1253
-        //first close off existing form tag
1254
-        $html = '>';
1255
-        $html .= $nav_tabs;
1256
-        //now let's handle the remaining tag ( missing ">" is CORRECT )
1257
-        $html .= '<span></span';
1258
-        echo $html;
1259
-    }
1260
-
1261
-
1262
-
1263
-    /**
1264
-     * This just sets up the post update messages when an update form is loaded
1265
-     *
1266
-     * @access public
1267
-     * @param  array $messages the original messages array
1268
-     * @return array           the new messages array
1269
-     */
1270
-    public function post_update_messages($messages)
1271
-    {
1272
-        global $post;
1273
-        $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1274
-        $id = empty($id) && is_object($post) ? $post->ID : null;
1275
-        //		$post_type = $post ? $post->post_type : false;
1276
-        /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1014
+	}
1015
+
1016
+
1017
+
1018
+	/**
1019
+	 * This allows child classes to modify the default editor title that appears when people add a new or edit an
1020
+	 * existing CPT item.     * This uses the _labels property set by the child class via _define_page_props. Just make
1021
+	 * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the
1022
+	 * default to be.
1023
+	 *
1024
+	 * @param string $title The new title (or existing if there is no editor_title defined)
1025
+	 * @return string
1026
+	 */
1027
+	public function add_custom_editor_default_title($title)
1028
+	{
1029
+		return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]])
1030
+			? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]
1031
+			: $title;
1032
+	}
1033
+
1034
+
1035
+
1036
+	/**
1037
+	 * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated
1038
+	 *
1039
+	 * @param string $shortlink   The already generated shortlink
1040
+	 * @param int    $id          Post ID for this item
1041
+	 * @param string $context     The context for the link
1042
+	 * @param bool   $allow_slugs Whether to allow post slugs in the shortlink.
1043
+	 * @return string
1044
+	 */
1045
+	public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs)
1046
+	{
1047
+		if ( ! empty($id) && '' != get_option('permalink_structure')) {
1048
+			$post = get_post($id);
1049
+			if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1050
+				$shortlink = home_url('?p=' . $post->ID);
1051
+			}
1052
+		}
1053
+		return $shortlink;
1054
+	}
1055
+
1056
+
1057
+
1058
+	/**
1059
+	 * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's
1060
+	 * already run in modify_current_screen())
1061
+	 *
1062
+	 * @return void
1063
+	 */
1064
+	public function route_admin_request()
1065
+	{
1066
+		if ($this->_cpt_route) {
1067
+			return;
1068
+		}
1069
+		try {
1070
+			$this->_route_admin_request();
1071
+		} catch (EE_Error $e) {
1072
+			$e->get_error();
1073
+		}
1074
+	}
1075
+
1076
+
1077
+
1078
+	/**
1079
+	 * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves
1080
+	 *
1081
+	 * @return string html
1082
+	 */
1083
+	public function cpt_post_form_hidden_input()
1084
+	{
1085
+		echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1086
+		//we're also going to add the route value and the current page so we can direct autosave parsing correctly
1087
+		echo '<div id="ee-cpt-hidden-inputs">';
1088
+		echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1089
+		echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1090
+		echo '</div>';
1091
+	}
1092
+
1093
+
1094
+
1095
+	/**
1096
+	 * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes.
1097
+	 *
1098
+	 * @param  string $location Original location url
1099
+	 * @param  int    $status   Status for http header
1100
+	 * @return string           new (or original) url to redirect to.
1101
+	 */
1102
+	public function revision_redirect($location, $status)
1103
+	{
1104
+		//get revision
1105
+		$rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null;
1106
+		//can't do anything without revision so let's get out if not present
1107
+		if (empty($rev_id)) {
1108
+			return $location;
1109
+		}
1110
+		//get rev_post_data
1111
+		$rev = get_post($rev_id);
1112
+		$admin_url = $this->_admin_base_url;
1113
+		$query_args = array(
1114
+			'action'   => 'edit',
1115
+			'post'     => $rev->post_parent,
1116
+			'revision' => $rev_id,
1117
+			'message'  => 5,
1118
+		);
1119
+		$this->_process_notices($query_args, true);
1120
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1121
+	}
1122
+
1123
+
1124
+
1125
+	/**
1126
+	 * Modify the edit post link generated by wp core function so that EE CPTs get setup differently.
1127
+	 *
1128
+	 * @param  string $link    the original generated link
1129
+	 * @param  int    $id      post id
1130
+	 * @param  string $context optional, defaults to display.  How to write the '&'
1131
+	 * @return string          the link
1132
+	 */
1133
+	public function modify_edit_post_link($link, $id, $context)
1134
+	{
1135
+		$post = get_post($id);
1136
+		if ( ! isset($this->_req_data['action'])
1137
+			 || ! isset($this->_cpt_routes[$this->_req_data['action']])
1138
+			 || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']]
1139
+		) {
1140
+			return $link;
1141
+		}
1142
+		$query_args = array(
1143
+			'action' => isset($this->_cpt_edit_routes[$post->post_type])
1144
+				? $this->_cpt_edit_routes[$post->post_type]
1145
+				: 'edit',
1146
+			'post'   => $id,
1147
+		);
1148
+		return self::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1149
+	}
1150
+
1151
+
1152
+	/**
1153
+	 * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on
1154
+	 * our routes.
1155
+	 *
1156
+	 * @param  string $delete_link  original delete link
1157
+	 * @param  int    $post_id      id of cpt object
1158
+	 * @param  bool   $force_delete whether this is forcing a hard delete instead of trash
1159
+	 * @return string new delete link
1160
+	 * @throws EE_Error
1161
+	 */
1162
+	public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1163
+	{
1164
+		$post = get_post($post_id);
1165
+		if (! isset($this->_req_data['action'], $this->_req_data['post'])
1166
+			 || (isset($this->_cpt_routes[$this->_req_data['action']])
1167
+				 && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1168
+		) {
1169
+			return $delete_link;
1170
+		}
1171
+		$this->_set_model_object($this->_req_data['post'], true);
1172
+		//returns something like `trash_event` or `trash_attendee` or `trash_venue`
1173
+		$action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1174
+
1175
+		return EE_Admin_Page::add_query_args_and_nonce(
1176
+			array(
1177
+				'page' => $this->_req_data['page'],
1178
+				'action' => $action,
1179
+				$this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name()
1180
+					=> $this->_req_data['post']
1181
+			),
1182
+			admin_url()
1183
+		);
1184
+	}
1185
+
1186
+
1187
+
1188
+	/**
1189
+	 * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php
1190
+	 * so that we can hijack the default redirect locations for wp custom post types
1191
+	 * that WE'RE using and send back to OUR routes.  This should only be hooked in on the right route.
1192
+	 *
1193
+	 * @param  string $location This is the incoming currently set redirect location
1194
+	 * @param  string $post_id  This is the 'ID' value of the wp_posts table
1195
+	 * @return string           the new location to redirect to
1196
+	 */
1197
+	public function cpt_post_location_redirect($location, $post_id)
1198
+	{
1199
+		//we DO have a match so let's setup the url
1200
+		//we have to get the post to determine our route
1201
+		$post       = get_post($post_id);
1202
+		$edit_route = $this->_cpt_edit_routes[$post->post_type];
1203
+		//shared query_args
1204
+		$query_args = array('action' => $edit_route, 'post' => $post_id);
1205
+		$admin_url  = $this->_admin_base_url;
1206
+		if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) {
1207
+			$status = get_post_status($post_id);
1208
+			if (isset($this->_req_data['publish'])) {
1209
+				switch ($status) {
1210
+					case 'pending':
1211
+						$message = 8;
1212
+						break;
1213
+					case 'future':
1214
+						$message = 9;
1215
+						break;
1216
+					default:
1217
+						$message = 6;
1218
+				}
1219
+			} else {
1220
+				$message = 'draft' == $status ? 10 : 1;
1221
+			}
1222
+		} else if (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) {
1223
+			$message = 2;
1224
+			//			$append = '#postcustom';
1225
+		} else if (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) {
1226
+			$message = 3;
1227
+			//			$append = '#postcustom';
1228
+		} elseif ($this->_req_data['action'] == 'post-quickpress-save-cont') {
1229
+			$message = 7;
1230
+		} else {
1231
+			$message = 4;
1232
+		}
1233
+		//change the message if the post type is not viewable on the frontend
1234
+		$this->_cpt_object = get_post_type_object($post->post_type);
1235
+		$message           = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message;
1236
+		$query_args = array_merge(array('message' => $message), $query_args);
1237
+		$this->_process_notices($query_args, true);
1238
+		return self::add_query_args_and_nonce($query_args, $admin_url);
1239
+	}
1240
+
1241
+
1242
+
1243
+	/**
1244
+	 * This method is called to inject nav tabs on core WP cpt pages
1245
+	 *
1246
+	 * @access public
1247
+	 * @return string html
1248
+	 */
1249
+	public function inject_nav_tabs()
1250
+	{
1251
+		//can we hijack and insert the nav_tabs?
1252
+		$nav_tabs = $this->_get_main_nav_tabs();
1253
+		//first close off existing form tag
1254
+		$html = '>';
1255
+		$html .= $nav_tabs;
1256
+		//now let's handle the remaining tag ( missing ">" is CORRECT )
1257
+		$html .= '<span></span';
1258
+		echo $html;
1259
+	}
1260
+
1261
+
1262
+
1263
+	/**
1264
+	 * This just sets up the post update messages when an update form is loaded
1265
+	 *
1266
+	 * @access public
1267
+	 * @param  array $messages the original messages array
1268
+	 * @return array           the new messages array
1269
+	 */
1270
+	public function post_update_messages($messages)
1271
+	{
1272
+		global $post;
1273
+		$id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1274
+		$id = empty($id) && is_object($post) ? $post->ID : null;
1275
+		//		$post_type = $post ? $post->post_type : false;
1276
+		/*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork';
1277 1277
 
1278 1278
         $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/
1279
-        $messages[$post->post_type] = array(
1280
-            0 => '', //Unused. Messages start at index 1.
1281
-            1 => sprintf(
1282
-                __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1283
-                $this->_cpt_object->labels->singular_name,
1284
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1285
-                '</a>'
1286
-            ),
1287
-            2 => __('Custom field updated'),
1288
-            3 => __('Custom field deleted.'),
1289
-            4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1290
-            5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1291
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1292
-                : false,
1293
-            6 => sprintf(
1294
-                __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1295
-                $this->_cpt_object->labels->singular_name,
1296
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1297
-                '</a>'
1298
-            ),
1299
-            7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1300
-            8 => sprintf(
1301
-                __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1302
-                $this->_cpt_object->labels->singular_name,
1303
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1304
-                '</a>'
1305
-            ),
1306
-            9 => sprintf(
1307
-                __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1308
-                $this->_cpt_object->labels->singular_name,
1309
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1310
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1311
-                '</a>'
1312
-            ),
1313
-            10 => sprintf(
1314
-                __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1315
-                $this->_cpt_object->labels->singular_name,
1316
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1317
-                '</a>'
1318
-            ),
1319
-        );
1320
-        return $messages;
1321
-    }
1322
-
1323
-
1324
-
1325
-    /**
1326
-     * default method for the 'create_new' route for cpt admin pages.
1327
-     * For reference what to include in here, see wp-admin/post-new.php
1328
-     *
1329
-     * @access  protected
1330
-     * @return string template for add new cpt form
1331
-     */
1332
-    protected function _create_new_cpt_item()
1333
-    {
1334
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1335
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1336
-        $post_type_object = $this->_cpt_object;
1337
-        $title            = $post_type_object->labels->add_new_item;
1338
-        $editing          = true;
1339
-        wp_enqueue_script('autosave');
1340
-        $post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1341
-        $post_ID = $post->ID;
1342
-        $is_IE   = $is_IE;
1343
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1344
-        //modify the default editor title field with default title.
1345
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1346
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1347
-    }
1348
-
1349
-
1350
-
1351
-    public function add_new_admin_page_global()
1352
-    {
1353
-        $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1354
-        ?>
1279
+		$messages[$post->post_type] = array(
1280
+			0 => '', //Unused. Messages start at index 1.
1281
+			1 => sprintf(
1282
+				__('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1283
+				$this->_cpt_object->labels->singular_name,
1284
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1285
+				'</a>'
1286
+			),
1287
+			2 => __('Custom field updated'),
1288
+			3 => __('Custom field deleted.'),
1289
+			4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1290
+			5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1291
+				$this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1292
+				: false,
1293
+			6 => sprintf(
1294
+				__('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1295
+				$this->_cpt_object->labels->singular_name,
1296
+				'<a href="' . esc_url(get_permalink($id)) . '">',
1297
+				'</a>'
1298
+			),
1299
+			7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1300
+			8 => sprintf(
1301
+				__('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1302
+				$this->_cpt_object->labels->singular_name,
1303
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1304
+				'</a>'
1305
+			),
1306
+			9 => sprintf(
1307
+				__('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1308
+				$this->_cpt_object->labels->singular_name,
1309
+				'<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1310
+				'<a target="_blank" href="' . esc_url(get_permalink($id)),
1311
+				'</a>'
1312
+			),
1313
+			10 => sprintf(
1314
+				__('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1315
+				$this->_cpt_object->labels->singular_name,
1316
+				'<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1317
+				'</a>'
1318
+			),
1319
+		);
1320
+		return $messages;
1321
+	}
1322
+
1323
+
1324
+
1325
+	/**
1326
+	 * default method for the 'create_new' route for cpt admin pages.
1327
+	 * For reference what to include in here, see wp-admin/post-new.php
1328
+	 *
1329
+	 * @access  protected
1330
+	 * @return string template for add new cpt form
1331
+	 */
1332
+	protected function _create_new_cpt_item()
1333
+	{
1334
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1335
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1336
+		$post_type_object = $this->_cpt_object;
1337
+		$title            = $post_type_object->labels->add_new_item;
1338
+		$editing          = true;
1339
+		wp_enqueue_script('autosave');
1340
+		$post    = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true);
1341
+		$post_ID = $post->ID;
1342
+		$is_IE   = $is_IE;
1343
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1344
+		//modify the default editor title field with default title.
1345
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1346
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1347
+	}
1348
+
1349
+
1350
+
1351
+	public function add_new_admin_page_global()
1352
+	{
1353
+		$admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php';
1354
+		?>
1355 1355
         <script type="text/javascript">
1356 1356
             adminpage = '<?php echo $admin_page; ?>';
1357 1357
         </script>
1358 1358
         <?php
1359
-    }
1360
-
1361
-
1362
-
1363
-    /**
1364
-     * default method for the 'edit' route for cpt admin pages
1365
-     * For reference on what to put in here, refer to wp-admin/post.php
1366
-     *
1367
-     * @access protected
1368
-     * @return string   template for edit cpt form
1369
-     */
1370
-    protected function _edit_cpt_item()
1371
-    {
1372
-        global $post, $title, $is_IE, $post_type, $post_type_object;
1373
-        $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1374
-        $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1375
-        if (empty ($post)) {
1376
-            wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1377
-        }
1378
-        if ( ! empty($_GET['get-post-lock'])) {
1379
-            wp_set_post_lock($post_id);
1380
-            wp_redirect(get_edit_post_link($post_id, 'url'));
1381
-            exit();
1382
-        }
1383
-
1384
-        // template vars
1385
-        $editing          = true;
1386
-        $post_ID          = $post_id;
1387
-        $post_type        = $this->_cpt_routes[$this->_req_action];
1388
-        $post_type_object = $this->_cpt_object;
1389
-
1390
-        if ( ! wp_check_post_lock($post->ID)) {
1391
-            $active_post_lock = wp_set_post_lock($post->ID);
1392
-            //wp_enqueue_script('autosave');
1393
-        }
1394
-        $title = $this->_cpt_object->labels->edit_item;
1395
-        add_action('admin_footer', '_admin_notice_post_locked');
1396
-        if (isset($this->_cpt_routes[$this->_req_data['action']])
1397
-            && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1398
-        ) {
1399
-            $create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1400
-                'create_new', $this);
1401
-            $post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1402
-                'action' => $create_new_action,
1403
-                'page'   => $this->page_slug,
1404
-            ), 'admin.php');
1405
-        }
1406
-        if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1407
-            wp_enqueue_script('admin-comments');
1408
-            enqueue_comment_hotkeys_js();
1409
-        }
1410
-        add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1411
-        //modify the default editor title field with default title.
1412
-        add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1413
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1414
-    }
1415
-
1416
-
1417
-
1418
-    /**
1419
-     * some getters
1420
-     */
1421
-    /**
1422
-     * This returns the protected _cpt_model_obj property
1423
-     *
1424
-     * @return EE_CPT_Base
1425
-     */
1426
-    public function get_cpt_model_obj()
1427
-    {
1428
-        return $this->_cpt_model_obj;
1429
-    }
1359
+	}
1360
+
1361
+
1362
+
1363
+	/**
1364
+	 * default method for the 'edit' route for cpt admin pages
1365
+	 * For reference on what to put in here, refer to wp-admin/post.php
1366
+	 *
1367
+	 * @access protected
1368
+	 * @return string   template for edit cpt form
1369
+	 */
1370
+	protected function _edit_cpt_item()
1371
+	{
1372
+		global $post, $title, $is_IE, $post_type, $post_type_object;
1373
+		$post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null;
1374
+		$post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null;
1375
+		if (empty ($post)) {
1376
+			wp_die(__('You attempted to edit an item that doesn&#8217;t exist. Perhaps it was deleted?'));
1377
+		}
1378
+		if ( ! empty($_GET['get-post-lock'])) {
1379
+			wp_set_post_lock($post_id);
1380
+			wp_redirect(get_edit_post_link($post_id, 'url'));
1381
+			exit();
1382
+		}
1383
+
1384
+		// template vars
1385
+		$editing          = true;
1386
+		$post_ID          = $post_id;
1387
+		$post_type        = $this->_cpt_routes[$this->_req_action];
1388
+		$post_type_object = $this->_cpt_object;
1389
+
1390
+		if ( ! wp_check_post_lock($post->ID)) {
1391
+			$active_post_lock = wp_set_post_lock($post->ID);
1392
+			//wp_enqueue_script('autosave');
1393
+		}
1394
+		$title = $this->_cpt_object->labels->edit_item;
1395
+		add_action('admin_footer', '_admin_notice_post_locked');
1396
+		if (isset($this->_cpt_routes[$this->_req_data['action']])
1397
+			&& ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']])
1398
+		) {
1399
+			$create_new_action = apply_filters('FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action',
1400
+				'create_new', $this);
1401
+			$post_new_file = EE_Admin_Page::add_query_args_and_nonce(array(
1402
+				'action' => $create_new_action,
1403
+				'page'   => $this->page_slug,
1404
+			), 'admin.php');
1405
+		}
1406
+		if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) {
1407
+			wp_enqueue_script('admin-comments');
1408
+			enqueue_comment_hotkeys_js();
1409
+		}
1410
+		add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1411
+		//modify the default editor title field with default title.
1412
+		add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1413
+		include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1414
+	}
1415
+
1416
+
1417
+
1418
+	/**
1419
+	 * some getters
1420
+	 */
1421
+	/**
1422
+	 * This returns the protected _cpt_model_obj property
1423
+	 *
1424
+	 * @return EE_CPT_Base
1425
+	 */
1426
+	public function get_cpt_model_obj()
1427
+	{
1428
+		return $this->_cpt_model_obj;
1429
+	}
1430 1430
 
1431 1431
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      */
236 236
     protected function _register_autosave_containers($ids)
237 237
     {
238
-        $this->_autosave_containers = array_merge($this->_autosave_fields, (array)$ids);
238
+        $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids);
239 239
     }
240 240
 
241 241
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         //filter _autosave_containers
280 280
         $containers = apply_filters('FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers',
281 281
             $this->_autosave_containers, $this);
282
-        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers',
282
+        $containers = apply_filters('FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers',
283 283
             $containers, $this);
284 284
 
285 285
         wp_localize_script('event_editor_js', 'EE_AUTOSAVE_IDS',
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
         parent::_load_page_dependencies();
370 370
         //notice we are ALSO going to load the pagenow hook set for this route (see _before_page_setup for the reset of the pagenow global ). This is for any plugins that are doing things properly and hooking into the load page hook for core wp cpt routes.
371 371
         global $pagenow;
372
-        do_action('load-' . $pagenow);
372
+        do_action('load-'.$pagenow);
373 373
         $this->modify_current_screen();
374 374
         add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30);
375 375
         //we route REALLY early.
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
                 'admin.php?page=espresso_registrations&action=contact_list',
401 401
             ),
402 402
             1 => array(
403
-                'edit.php?post_type=' . $this->_cpt_object->name,
404
-                'admin.php?page=' . $this->_cpt_object->name,
403
+                'edit.php?post_type='.$this->_cpt_object->name,
404
+                'admin.php?page='.$this->_cpt_object->name,
405 405
             ),
406 406
         );
407 407
         foreach ($routes_to_match as $route_matches) {
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         $cpt_has_support = ! empty($cpt_args['page_templates']);
430 430
 
431 431
         //if the installed version of WP is > 4.7 we do some additional checks.
432
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
432
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
433 433
             $post_templates = wp_get_theme()->get_post_templates();
434 434
             //if there are $post_templates for this cpt, then we return false for this method because
435 435
             //that means we aren't going to load our page template manager and leave that up to the native
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
         global $post;
453 453
         $template = '';
454 454
 
455
-        if (EE_Recommended_Versions::check_wp_version('4.7','>=')) {
455
+        if (EE_Recommended_Versions::check_wp_version('4.7', '>=')) {
456 456
             $page_template_count = count(get_page_templates());
457 457
         } else {
458 458
             $page_template_count = count(get_page_templates($post));
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
         $post = get_post($id);
490 490
         if ('publish' != get_post_status($post)) {
491 491
             //include shims for the `get_preview_post_link` function
492
-            require_once( EE_CORE . 'wordpress-shims.php' );
492
+            require_once(EE_CORE.'wordpress-shims.php');
493 493
             $return .= '<span_id="view-post-btn"><a target="_blank" href="'
494 494
                        . get_preview_post_link($id)
495 495
                        . '" class="button button-small">'
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
             $template_args['statuses']         = $statuses;
528 528
         }
529 529
 
530
-        $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php';
530
+        $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php';
531 531
         EEH_Template::display_template($template, $template_args);
532 532
     }
533 533
 
@@ -572,13 +572,13 @@  discard block
 block discarded – undo
572 572
             define('DOING_AUTOSAVE', true);
573 573
         }
574 574
         //if we made it here then the nonce checked out.  Let's run our methods and actions
575
-        if (method_exists($this, '_ee_autosave_' . $this->_current_view)) {
576
-            call_user_func(array($this, '_ee_autosave_' . $this->_current_view));
575
+        if (method_exists($this, '_ee_autosave_'.$this->_current_view)) {
576
+            call_user_func(array($this, '_ee_autosave_'.$this->_current_view));
577 577
         } else {
578 578
             $this->_template_args['success'] = true;
579 579
         }
580 580
         do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this);
581
-        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this);
581
+        do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this);
582 582
         //now let's return json
583 583
         $this->_return_json();
584 584
     }
@@ -969,7 +969,7 @@  discard block
 block discarded – undo
969 969
         //global action
970 970
         do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id);
971 971
         //class specific action so you can limit hooking into a specific page.
972
-        do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id);
972
+        do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id);
973 973
     }
974 974
 
975 975
 
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
         if ( ! empty($id) && '' != get_option('permalink_structure')) {
1048 1048
             $post = get_post($id);
1049 1049
             if (isset($post->post_type) && $this->page_slug == $post->post_type) {
1050
-                $shortlink = home_url('?p=' . $post->ID);
1050
+                $shortlink = home_url('?p='.$post->ID);
1051 1051
             }
1052 1052
         }
1053 1053
         return $shortlink;
@@ -1082,11 +1082,11 @@  discard block
 block discarded – undo
1082 1082
      */
1083 1083
     public function cpt_post_form_hidden_input()
1084 1084
     {
1085
-        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />';
1085
+        echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />';
1086 1086
         //we're also going to add the route value and the current page so we can direct autosave parsing correctly
1087 1087
         echo '<div id="ee-cpt-hidden-inputs">';
1088
-        echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />';
1089
-        echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />';
1088
+        echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />';
1089
+        echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />';
1090 1090
         echo '</div>';
1091 1091
     }
1092 1092
 
@@ -1162,7 +1162,7 @@  discard block
 block discarded – undo
1162 1162
     public function modify_delete_post_link($delete_link, $post_id, $force_delete)
1163 1163
     {
1164 1164
         $post = get_post($post_id);
1165
-        if (! isset($this->_req_data['action'], $this->_req_data['post'])
1165
+        if ( ! isset($this->_req_data['action'], $this->_req_data['post'])
1166 1166
              || (isset($this->_cpt_routes[$this->_req_data['action']])
1167 1167
                  && $post->post_type !== $this->_cpt_routes[$this->_req_data['action']])
1168 1168
         ) {
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
         }
1171 1171
         $this->_set_model_object($this->_req_data['post'], true);
1172 1172
         //returns something like `trash_event` or `trash_attendee` or `trash_venue`
1173
-        $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1173
+        $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj)));
1174 1174
 
1175 1175
         return EE_Admin_Page::add_query_args_and_nonce(
1176 1176
             array(
@@ -1281,39 +1281,39 @@  discard block
 block discarded – undo
1281 1281
             1 => sprintf(
1282 1282
                 __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'),
1283 1283
                 $this->_cpt_object->labels->singular_name,
1284
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1284
+                '<a href="'.esc_url(get_permalink($id)).'">',
1285 1285
                 '</a>'
1286 1286
             ),
1287 1287
             2 => __('Custom field updated'),
1288 1288
             3 => __('Custom field deleted.'),
1289 1289
             4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1290 1290
             5 => isset($_GET['revision']) ? sprintf(__('%s restored to revision from %s', 'event_espresso'),
1291
-                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int)$_GET['revision'], false))
1291
+                $this->_cpt_object->labels->singular_name, wp_post_revision_title((int) $_GET['revision'], false))
1292 1292
                 : false,
1293 1293
             6 => sprintf(
1294 1294
                 __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'),
1295 1295
                 $this->_cpt_object->labels->singular_name,
1296
-                '<a href="' . esc_url(get_permalink($id)) . '">',
1296
+                '<a href="'.esc_url(get_permalink($id)).'">',
1297 1297
                 '</a>'
1298 1298
             ),
1299 1299
             7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name),
1300 1300
             8 => sprintf(
1301 1301
                 __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'),
1302 1302
                 $this->_cpt_object->labels->singular_name,
1303
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">',
1303
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">',
1304 1304
                 '</a>'
1305 1305
             ),
1306 1306
             9 => sprintf(
1307 1307
                 __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'),
1308 1308
                 $this->_cpt_object->labels->singular_name,
1309
-                '<strong>' . date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)) . '</strong>',
1310
-                '<a target="_blank" href="' . esc_url(get_permalink($id)),
1309
+                '<strong>'.date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)).'</strong>',
1310
+                '<a target="_blank" href="'.esc_url(get_permalink($id)),
1311 1311
                 '</a>'
1312 1312
             ),
1313 1313
             10 => sprintf(
1314 1314
                 __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'),
1315 1315
                 $this->_cpt_object->labels->singular_name,
1316
-                '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1316
+                '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))),
1317 1317
                 '</a>'
1318 1318
             ),
1319 1319
         );
@@ -1343,7 +1343,7 @@  discard block
 block discarded – undo
1343 1343
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1344 1344
         //modify the default editor title field with default title.
1345 1345
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1346
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1346
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1347 1347
     }
1348 1348
 
1349 1349
 
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
         add_action('admin_print_styles', array($this, 'add_new_admin_page_global'));
1411 1411
         //modify the default editor title field with default title.
1412 1412
         add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10);
1413
-        include_once WP_ADMIN_PATH . 'edit-form-advanced.php';
1413
+        include_once WP_ADMIN_PATH.'edit-form-advanced.php';
1414 1414
     }
1415 1415
 
1416 1416
 
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Indentation   +2670 added lines, -2670 removed lines patch added patch discarded remove patch
@@ -15,2677 +15,2677 @@
 block discarded – undo
15 15
 class Events_Admin_Page extends EE_Admin_Page_CPT
16 16
 {
17 17
 
18
-    /**
19
-     * This will hold the event object for event_details screen.
20
-     *
21
-     * @access protected
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-
44
-    /**
45
-     * @var EE_Event
46
-     */
47
-    protected $_cpt_model_obj = false;
48
-
49
-
50
-    /**
51
-     * Initialize page props for this admin page group.
52
-     */
53
-    protected function _init_page_props()
54
-    {
55
-        $this->page_slug = EVENTS_PG_SLUG;
56
-        $this->page_label = EVENTS_LABEL;
57
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
58
-        $this->_admin_base_path = EVENTS_ADMIN;
59
-        $this->_cpt_model_names = array(
60
-            'create_new' => 'EEM_Event',
61
-            'edit'       => 'EEM_Event',
62
-        );
63
-        $this->_cpt_edit_routes = array(
64
-            'espresso_events' => 'edit',
65
-        );
66
-        add_action(
67
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
68
-            array($this, 'verify_event_edit')
69
-        );
70
-    }
71
-
72
-
73
-    /**
74
-     * Sets the ajax hooks used for this admin page group.
75
-     */
76
-    protected function _ajax_hooks()
77
-    {
78
-        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
79
-    }
80
-
81
-
82
-    /**
83
-     * Sets the page properties for this admin page group.
84
-     */
85
-    protected function _define_page_props()
86
-    {
87
-        $this->_admin_page_title = EVENTS_LABEL;
88
-        $this->_labels = array(
89
-            'buttons'      => array(
90
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
91
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
92
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
93
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
94
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
95
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
96
-            ),
97
-            'editor_title' => array(
98
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
99
-            ),
100
-            'publishbox'   => array(
101
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
102
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
103
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
104
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
105
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
106
-            ),
107
-        );
108
-    }
109
-
110
-
111
-    /**
112
-     * Sets the page routes property for this admin page group.
113
-     */
114
-    protected function _set_page_routes()
115
-    {
116
-        //load formatter helper
117
-        //load field generator helper
118
-        //is there a evt_id in the request?
119
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
120
-            ? $this->_req_data['EVT_ID']
121
-            : 0;
122
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
123
-        $this->_page_routes = array(
124
-            'default'                       => array(
125
-                'func'       => '_events_overview_list_table',
126
-                'capability' => 'ee_read_events',
127
-            ),
128
-            'create_new'                    => array(
129
-                'func'       => '_create_new_cpt_item',
130
-                'capability' => 'ee_edit_events',
131
-            ),
132
-            'edit'                          => array(
133
-                'func'       => '_edit_cpt_item',
134
-                'capability' => 'ee_edit_event',
135
-                'obj_id'     => $evt_id,
136
-            ),
137
-            'copy_event'                    => array(
138
-                'func'       => '_copy_events',
139
-                'capability' => 'ee_edit_event',
140
-                'obj_id'     => $evt_id,
141
-                'noheader'   => true,
142
-            ),
143
-            'trash_event'                   => array(
144
-                'func'       => '_trash_or_restore_event',
145
-                'args'       => array('event_status' => 'trash'),
146
-                'capability' => 'ee_delete_event',
147
-                'obj_id'     => $evt_id,
148
-                'noheader'   => true,
149
-            ),
150
-            'trash_events'                  => array(
151
-                'func'       => '_trash_or_restore_events',
152
-                'args'       => array('event_status' => 'trash'),
153
-                'capability' => 'ee_delete_events',
154
-                'noheader'   => true,
155
-            ),
156
-            'restore_event'                 => array(
157
-                'func'       => '_trash_or_restore_event',
158
-                'args'       => array('event_status' => 'draft'),
159
-                'capability' => 'ee_delete_event',
160
-                'obj_id'     => $evt_id,
161
-                'noheader'   => true,
162
-            ),
163
-            'restore_events'                => array(
164
-                'func'       => '_trash_or_restore_events',
165
-                'args'       => array('event_status' => 'draft'),
166
-                'capability' => 'ee_delete_events',
167
-                'noheader'   => true,
168
-            ),
169
-            'delete_event'                  => array(
170
-                'func'       => '_delete_event',
171
-                'capability' => 'ee_delete_event',
172
-                'obj_id'     => $evt_id,
173
-                'noheader'   => true,
174
-            ),
175
-            'delete_events'                 => array(
176
-                'func'       => '_delete_events',
177
-                'capability' => 'ee_delete_events',
178
-                'noheader'   => true,
179
-            ),
180
-            'view_report'                   => array(
181
-                'func'      => '_view_report',
182
-                'capablity' => 'ee_edit_events',
183
-            ),
184
-            'default_event_settings'        => array(
185
-                'func'       => '_default_event_settings',
186
-                'capability' => 'manage_options',
187
-            ),
188
-            'update_default_event_settings' => array(
189
-                'func'       => '_update_default_event_settings',
190
-                'capability' => 'manage_options',
191
-                'noheader'   => true,
192
-            ),
193
-            'template_settings'             => array(
194
-                'func'       => '_template_settings',
195
-                'capability' => 'manage_options',
196
-            ),
197
-            //event category tab related
198
-            'add_category'                  => array(
199
-                'func'       => '_category_details',
200
-                'capability' => 'ee_edit_event_category',
201
-                'args'       => array('add'),
202
-            ),
203
-            'edit_category'                 => array(
204
-                'func'       => '_category_details',
205
-                'capability' => 'ee_edit_event_category',
206
-                'args'       => array('edit'),
207
-            ),
208
-            'delete_categories'             => array(
209
-                'func'       => '_delete_categories',
210
-                'capability' => 'ee_delete_event_category',
211
-                'noheader'   => true,
212
-            ),
213
-            'delete_category'               => array(
214
-                'func'       => '_delete_categories',
215
-                'capability' => 'ee_delete_event_category',
216
-                'noheader'   => true,
217
-            ),
218
-            'insert_category'               => array(
219
-                'func'       => '_insert_or_update_category',
220
-                'args'       => array('new_category' => true),
221
-                'capability' => 'ee_edit_event_category',
222
-                'noheader'   => true,
223
-            ),
224
-            'update_category'               => array(
225
-                'func'       => '_insert_or_update_category',
226
-                'args'       => array('new_category' => false),
227
-                'capability' => 'ee_edit_event_category',
228
-                'noheader'   => true,
229
-            ),
230
-            'category_list'                 => array(
231
-                'func'       => '_category_list_table',
232
-                'capability' => 'ee_manage_event_categories',
233
-            ),
234
-        );
235
-    }
236
-
237
-
238
-    /**
239
-     * Set the _page_config property for this admin page group.
240
-     */
241
-    protected function _set_page_config()
242
-    {
243
-        $this->_page_config = array(
244
-            'default'                => array(
245
-                'nav'           => array(
246
-                    'label' => esc_html__('Overview', 'event_espresso'),
247
-                    'order' => 10,
248
-                ),
249
-                'list_table'    => 'Events_Admin_List_Table',
250
-                'help_tabs'     => array(
251
-                    'events_overview_help_tab'                       => array(
252
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
253
-                        'filename' => 'events_overview',
254
-                    ),
255
-                    'events_overview_table_column_headings_help_tab' => array(
256
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
257
-                        'filename' => 'events_overview_table_column_headings',
258
-                    ),
259
-                    'events_overview_filters_help_tab'               => array(
260
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
261
-                        'filename' => 'events_overview_filters',
262
-                    ),
263
-                    'events_overview_view_help_tab'                  => array(
264
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
265
-                        'filename' => 'events_overview_views',
266
-                    ),
267
-                    'events_overview_other_help_tab'                 => array(
268
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
269
-                        'filename' => 'events_overview_other',
270
-                    ),
271
-                ),
272
-                'help_tour'     => array(
273
-                    'Event_Overview_Help_Tour',
274
-                    //'New_Features_Test_Help_Tour' for testing multiple help tour
275
-                ),
276
-                'qtips'         => array(
277
-                    'EE_Event_List_Table_Tips',
278
-                ),
279
-                'require_nonce' => false,
280
-            ),
281
-            'create_new'             => array(
282
-                'nav'           => array(
283
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
284
-                    'order'      => 5,
285
-                    'persistent' => false,
286
-                ),
287
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
288
-                'help_tabs'     => array(
289
-                    'event_editor_help_tab'                            => array(
290
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
291
-                        'filename' => 'event_editor',
292
-                    ),
293
-                    'event_editor_title_richtexteditor_help_tab'       => array(
294
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
295
-                        'filename' => 'event_editor_title_richtexteditor',
296
-                    ),
297
-                    'event_editor_venue_details_help_tab'              => array(
298
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
299
-                        'filename' => 'event_editor_venue_details',
300
-                    ),
301
-                    'event_editor_event_datetimes_help_tab'            => array(
302
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
303
-                        'filename' => 'event_editor_event_datetimes',
304
-                    ),
305
-                    'event_editor_event_tickets_help_tab'              => array(
306
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
307
-                        'filename' => 'event_editor_event_tickets',
308
-                    ),
309
-                    'event_editor_event_registration_options_help_tab' => array(
310
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
311
-                        'filename' => 'event_editor_event_registration_options',
312
-                    ),
313
-                    'event_editor_tags_categories_help_tab'            => array(
314
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
315
-                        'filename' => 'event_editor_tags_categories',
316
-                    ),
317
-                    'event_editor_questions_registrants_help_tab'      => array(
318
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
319
-                        'filename' => 'event_editor_questions_registrants',
320
-                    ),
321
-                    'event_editor_save_new_event_help_tab'             => array(
322
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
323
-                        'filename' => 'event_editor_save_new_event',
324
-                    ),
325
-                    'event_editor_other_help_tab'                      => array(
326
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
327
-                        'filename' => 'event_editor_other',
328
-                    ),
329
-                ),
330
-                'help_tour'     => array(
331
-                    'Event_Editor_Help_Tour',
332
-                ),
333
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
334
-                'require_nonce' => false,
335
-            ),
336
-            'edit'                   => array(
337
-                'nav'           => array(
338
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
339
-                    'order'      => 5,
340
-                    'persistent' => false,
341
-                    'url'        => isset($this->_req_data['post'])
342
-                        ? EE_Admin_Page::add_query_args_and_nonce(
343
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
344
-                            $this->_current_page_view_url
345
-                        )
346
-                        : $this->_admin_base_url,
347
-                ),
348
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
349
-                'help_tabs'     => array(
350
-                    'event_editor_help_tab'                            => array(
351
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
352
-                        'filename' => 'event_editor',
353
-                    ),
354
-                    'event_editor_title_richtexteditor_help_tab'       => array(
355
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
356
-                        'filename' => 'event_editor_title_richtexteditor',
357
-                    ),
358
-                    'event_editor_venue_details_help_tab'              => array(
359
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
360
-                        'filename' => 'event_editor_venue_details',
361
-                    ),
362
-                    'event_editor_event_datetimes_help_tab'            => array(
363
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
364
-                        'filename' => 'event_editor_event_datetimes',
365
-                    ),
366
-                    'event_editor_event_tickets_help_tab'              => array(
367
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
368
-                        'filename' => 'event_editor_event_tickets',
369
-                    ),
370
-                    'event_editor_event_registration_options_help_tab' => array(
371
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
372
-                        'filename' => 'event_editor_event_registration_options',
373
-                    ),
374
-                    'event_editor_tags_categories_help_tab'            => array(
375
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
376
-                        'filename' => 'event_editor_tags_categories',
377
-                    ),
378
-                    'event_editor_questions_registrants_help_tab'      => array(
379
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
380
-                        'filename' => 'event_editor_questions_registrants',
381
-                    ),
382
-                    'event_editor_save_new_event_help_tab'             => array(
383
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
384
-                        'filename' => 'event_editor_save_new_event',
385
-                    ),
386
-                    'event_editor_other_help_tab'                      => array(
387
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
388
-                        'filename' => 'event_editor_other',
389
-                    ),
390
-                ),
391
-                /*'help_tour' => array(
18
+	/**
19
+	 * This will hold the event object for event_details screen.
20
+	 *
21
+	 * @access protected
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+
44
+	/**
45
+	 * @var EE_Event
46
+	 */
47
+	protected $_cpt_model_obj = false;
48
+
49
+
50
+	/**
51
+	 * Initialize page props for this admin page group.
52
+	 */
53
+	protected function _init_page_props()
54
+	{
55
+		$this->page_slug = EVENTS_PG_SLUG;
56
+		$this->page_label = EVENTS_LABEL;
57
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
58
+		$this->_admin_base_path = EVENTS_ADMIN;
59
+		$this->_cpt_model_names = array(
60
+			'create_new' => 'EEM_Event',
61
+			'edit'       => 'EEM_Event',
62
+		);
63
+		$this->_cpt_edit_routes = array(
64
+			'espresso_events' => 'edit',
65
+		);
66
+		add_action(
67
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
68
+			array($this, 'verify_event_edit')
69
+		);
70
+	}
71
+
72
+
73
+	/**
74
+	 * Sets the ajax hooks used for this admin page group.
75
+	 */
76
+	protected function _ajax_hooks()
77
+	{
78
+		add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
79
+	}
80
+
81
+
82
+	/**
83
+	 * Sets the page properties for this admin page group.
84
+	 */
85
+	protected function _define_page_props()
86
+	{
87
+		$this->_admin_page_title = EVENTS_LABEL;
88
+		$this->_labels = array(
89
+			'buttons'      => array(
90
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
91
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
92
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
93
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
94
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
95
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
96
+			),
97
+			'editor_title' => array(
98
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
99
+			),
100
+			'publishbox'   => array(
101
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
102
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
103
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
104
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
105
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
106
+			),
107
+		);
108
+	}
109
+
110
+
111
+	/**
112
+	 * Sets the page routes property for this admin page group.
113
+	 */
114
+	protected function _set_page_routes()
115
+	{
116
+		//load formatter helper
117
+		//load field generator helper
118
+		//is there a evt_id in the request?
119
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
120
+			? $this->_req_data['EVT_ID']
121
+			: 0;
122
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
123
+		$this->_page_routes = array(
124
+			'default'                       => array(
125
+				'func'       => '_events_overview_list_table',
126
+				'capability' => 'ee_read_events',
127
+			),
128
+			'create_new'                    => array(
129
+				'func'       => '_create_new_cpt_item',
130
+				'capability' => 'ee_edit_events',
131
+			),
132
+			'edit'                          => array(
133
+				'func'       => '_edit_cpt_item',
134
+				'capability' => 'ee_edit_event',
135
+				'obj_id'     => $evt_id,
136
+			),
137
+			'copy_event'                    => array(
138
+				'func'       => '_copy_events',
139
+				'capability' => 'ee_edit_event',
140
+				'obj_id'     => $evt_id,
141
+				'noheader'   => true,
142
+			),
143
+			'trash_event'                   => array(
144
+				'func'       => '_trash_or_restore_event',
145
+				'args'       => array('event_status' => 'trash'),
146
+				'capability' => 'ee_delete_event',
147
+				'obj_id'     => $evt_id,
148
+				'noheader'   => true,
149
+			),
150
+			'trash_events'                  => array(
151
+				'func'       => '_trash_or_restore_events',
152
+				'args'       => array('event_status' => 'trash'),
153
+				'capability' => 'ee_delete_events',
154
+				'noheader'   => true,
155
+			),
156
+			'restore_event'                 => array(
157
+				'func'       => '_trash_or_restore_event',
158
+				'args'       => array('event_status' => 'draft'),
159
+				'capability' => 'ee_delete_event',
160
+				'obj_id'     => $evt_id,
161
+				'noheader'   => true,
162
+			),
163
+			'restore_events'                => array(
164
+				'func'       => '_trash_or_restore_events',
165
+				'args'       => array('event_status' => 'draft'),
166
+				'capability' => 'ee_delete_events',
167
+				'noheader'   => true,
168
+			),
169
+			'delete_event'                  => array(
170
+				'func'       => '_delete_event',
171
+				'capability' => 'ee_delete_event',
172
+				'obj_id'     => $evt_id,
173
+				'noheader'   => true,
174
+			),
175
+			'delete_events'                 => array(
176
+				'func'       => '_delete_events',
177
+				'capability' => 'ee_delete_events',
178
+				'noheader'   => true,
179
+			),
180
+			'view_report'                   => array(
181
+				'func'      => '_view_report',
182
+				'capablity' => 'ee_edit_events',
183
+			),
184
+			'default_event_settings'        => array(
185
+				'func'       => '_default_event_settings',
186
+				'capability' => 'manage_options',
187
+			),
188
+			'update_default_event_settings' => array(
189
+				'func'       => '_update_default_event_settings',
190
+				'capability' => 'manage_options',
191
+				'noheader'   => true,
192
+			),
193
+			'template_settings'             => array(
194
+				'func'       => '_template_settings',
195
+				'capability' => 'manage_options',
196
+			),
197
+			//event category tab related
198
+			'add_category'                  => array(
199
+				'func'       => '_category_details',
200
+				'capability' => 'ee_edit_event_category',
201
+				'args'       => array('add'),
202
+			),
203
+			'edit_category'                 => array(
204
+				'func'       => '_category_details',
205
+				'capability' => 'ee_edit_event_category',
206
+				'args'       => array('edit'),
207
+			),
208
+			'delete_categories'             => array(
209
+				'func'       => '_delete_categories',
210
+				'capability' => 'ee_delete_event_category',
211
+				'noheader'   => true,
212
+			),
213
+			'delete_category'               => array(
214
+				'func'       => '_delete_categories',
215
+				'capability' => 'ee_delete_event_category',
216
+				'noheader'   => true,
217
+			),
218
+			'insert_category'               => array(
219
+				'func'       => '_insert_or_update_category',
220
+				'args'       => array('new_category' => true),
221
+				'capability' => 'ee_edit_event_category',
222
+				'noheader'   => true,
223
+			),
224
+			'update_category'               => array(
225
+				'func'       => '_insert_or_update_category',
226
+				'args'       => array('new_category' => false),
227
+				'capability' => 'ee_edit_event_category',
228
+				'noheader'   => true,
229
+			),
230
+			'category_list'                 => array(
231
+				'func'       => '_category_list_table',
232
+				'capability' => 'ee_manage_event_categories',
233
+			),
234
+		);
235
+	}
236
+
237
+
238
+	/**
239
+	 * Set the _page_config property for this admin page group.
240
+	 */
241
+	protected function _set_page_config()
242
+	{
243
+		$this->_page_config = array(
244
+			'default'                => array(
245
+				'nav'           => array(
246
+					'label' => esc_html__('Overview', 'event_espresso'),
247
+					'order' => 10,
248
+				),
249
+				'list_table'    => 'Events_Admin_List_Table',
250
+				'help_tabs'     => array(
251
+					'events_overview_help_tab'                       => array(
252
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
253
+						'filename' => 'events_overview',
254
+					),
255
+					'events_overview_table_column_headings_help_tab' => array(
256
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
257
+						'filename' => 'events_overview_table_column_headings',
258
+					),
259
+					'events_overview_filters_help_tab'               => array(
260
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
261
+						'filename' => 'events_overview_filters',
262
+					),
263
+					'events_overview_view_help_tab'                  => array(
264
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
265
+						'filename' => 'events_overview_views',
266
+					),
267
+					'events_overview_other_help_tab'                 => array(
268
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
269
+						'filename' => 'events_overview_other',
270
+					),
271
+				),
272
+				'help_tour'     => array(
273
+					'Event_Overview_Help_Tour',
274
+					//'New_Features_Test_Help_Tour' for testing multiple help tour
275
+				),
276
+				'qtips'         => array(
277
+					'EE_Event_List_Table_Tips',
278
+				),
279
+				'require_nonce' => false,
280
+			),
281
+			'create_new'             => array(
282
+				'nav'           => array(
283
+					'label'      => esc_html__('Add Event', 'event_espresso'),
284
+					'order'      => 5,
285
+					'persistent' => false,
286
+				),
287
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
288
+				'help_tabs'     => array(
289
+					'event_editor_help_tab'                            => array(
290
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
291
+						'filename' => 'event_editor',
292
+					),
293
+					'event_editor_title_richtexteditor_help_tab'       => array(
294
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
295
+						'filename' => 'event_editor_title_richtexteditor',
296
+					),
297
+					'event_editor_venue_details_help_tab'              => array(
298
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
299
+						'filename' => 'event_editor_venue_details',
300
+					),
301
+					'event_editor_event_datetimes_help_tab'            => array(
302
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
303
+						'filename' => 'event_editor_event_datetimes',
304
+					),
305
+					'event_editor_event_tickets_help_tab'              => array(
306
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
307
+						'filename' => 'event_editor_event_tickets',
308
+					),
309
+					'event_editor_event_registration_options_help_tab' => array(
310
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
311
+						'filename' => 'event_editor_event_registration_options',
312
+					),
313
+					'event_editor_tags_categories_help_tab'            => array(
314
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
315
+						'filename' => 'event_editor_tags_categories',
316
+					),
317
+					'event_editor_questions_registrants_help_tab'      => array(
318
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
319
+						'filename' => 'event_editor_questions_registrants',
320
+					),
321
+					'event_editor_save_new_event_help_tab'             => array(
322
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
323
+						'filename' => 'event_editor_save_new_event',
324
+					),
325
+					'event_editor_other_help_tab'                      => array(
326
+						'title'    => esc_html__('Event Other', 'event_espresso'),
327
+						'filename' => 'event_editor_other',
328
+					),
329
+				),
330
+				'help_tour'     => array(
331
+					'Event_Editor_Help_Tour',
332
+				),
333
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
334
+				'require_nonce' => false,
335
+			),
336
+			'edit'                   => array(
337
+				'nav'           => array(
338
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
339
+					'order'      => 5,
340
+					'persistent' => false,
341
+					'url'        => isset($this->_req_data['post'])
342
+						? EE_Admin_Page::add_query_args_and_nonce(
343
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
344
+							$this->_current_page_view_url
345
+						)
346
+						: $this->_admin_base_url,
347
+				),
348
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
349
+				'help_tabs'     => array(
350
+					'event_editor_help_tab'                            => array(
351
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
352
+						'filename' => 'event_editor',
353
+					),
354
+					'event_editor_title_richtexteditor_help_tab'       => array(
355
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
356
+						'filename' => 'event_editor_title_richtexteditor',
357
+					),
358
+					'event_editor_venue_details_help_tab'              => array(
359
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
360
+						'filename' => 'event_editor_venue_details',
361
+					),
362
+					'event_editor_event_datetimes_help_tab'            => array(
363
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
364
+						'filename' => 'event_editor_event_datetimes',
365
+					),
366
+					'event_editor_event_tickets_help_tab'              => array(
367
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
368
+						'filename' => 'event_editor_event_tickets',
369
+					),
370
+					'event_editor_event_registration_options_help_tab' => array(
371
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
372
+						'filename' => 'event_editor_event_registration_options',
373
+					),
374
+					'event_editor_tags_categories_help_tab'            => array(
375
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
376
+						'filename' => 'event_editor_tags_categories',
377
+					),
378
+					'event_editor_questions_registrants_help_tab'      => array(
379
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
380
+						'filename' => 'event_editor_questions_registrants',
381
+					),
382
+					'event_editor_save_new_event_help_tab'             => array(
383
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
384
+						'filename' => 'event_editor_save_new_event',
385
+					),
386
+					'event_editor_other_help_tab'                      => array(
387
+						'title'    => esc_html__('Event Other', 'event_espresso'),
388
+						'filename' => 'event_editor_other',
389
+					),
390
+				),
391
+				/*'help_tour' => array(
392 392
 					'Event_Edit_Help_Tour'
393 393
 				),*/
394
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
395
-                'require_nonce' => false,
396
-            ),
397
-            'default_event_settings' => array(
398
-                'nav'           => array(
399
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
400
-                    'order' => 40,
401
-                ),
402
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
403
-                'labels'        => array(
404
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
405
-                ),
406
-                'help_tabs'     => array(
407
-                    'default_settings_help_tab'        => array(
408
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
409
-                        'filename' => 'events_default_settings',
410
-                    ),
411
-                    'default_settings_status_help_tab' => array(
412
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
413
-                        'filename' => 'events_default_settings_status',
414
-                    ),
415
-                    'default_maximum_tickets_help_tab' => array(
416
-                        'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
417
-                        'filename' => 'events_default_settings_max_tickets',
418
-                    )
419
-                ),
420
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
421
-                'require_nonce' => false,
422
-            ),
423
-            //template settings
424
-            'template_settings'      => array(
425
-                'nav'           => array(
426
-                    'label' => esc_html__('Templates', 'event_espresso'),
427
-                    'order' => 30,
428
-                ),
429
-                'metaboxes'     => $this->_default_espresso_metaboxes,
430
-                'help_tabs'     => array(
431
-                    'general_settings_templates_help_tab' => array(
432
-                        'title'    => esc_html__('Templates', 'event_espresso'),
433
-                        'filename' => 'general_settings_templates',
434
-                    ),
435
-                ),
436
-                'help_tour'     => array('Templates_Help_Tour'),
437
-                'require_nonce' => false,
438
-            ),
439
-            //event category stuff
440
-            'add_category'           => array(
441
-                'nav'           => array(
442
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
443
-                    'order'      => 15,
444
-                    'persistent' => false,
445
-                ),
446
-                'help_tabs'     => array(
447
-                    'add_category_help_tab' => array(
448
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
449
-                        'filename' => 'events_add_category',
450
-                    ),
451
-                ),
452
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
453
-                'metaboxes'     => array('_publish_post_box'),
454
-                'require_nonce' => false,
455
-            ),
456
-            'edit_category'          => array(
457
-                'nav'           => array(
458
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
459
-                    'order'      => 15,
460
-                    'persistent' => false,
461
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
462
-                        ? add_query_arg(
463
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
464
-                            $this->_current_page_view_url
465
-                        )
466
-                        : $this->_admin_base_url,
467
-                ),
468
-                'help_tabs'     => array(
469
-                    'edit_category_help_tab' => array(
470
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
471
-                        'filename' => 'events_edit_category',
472
-                    ),
473
-                ),
474
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
475
-                'metaboxes'     => array('_publish_post_box'),
476
-                'require_nonce' => false,
477
-            ),
478
-            'category_list'          => array(
479
-                'nav'           => array(
480
-                    'label' => esc_html__('Categories', 'event_espresso'),
481
-                    'order' => 20,
482
-                ),
483
-                'list_table'    => 'Event_Categories_Admin_List_Table',
484
-                'help_tabs'     => array(
485
-                    'events_categories_help_tab'                       => array(
486
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
487
-                        'filename' => 'events_categories',
488
-                    ),
489
-                    'events_categories_table_column_headings_help_tab' => array(
490
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
491
-                        'filename' => 'events_categories_table_column_headings',
492
-                    ),
493
-                    'events_categories_view_help_tab'                  => array(
494
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
495
-                        'filename' => 'events_categories_views',
496
-                    ),
497
-                    'events_categories_other_help_tab'                 => array(
498
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
499
-                        'filename' => 'events_categories_other',
500
-                    ),
501
-                ),
502
-                'help_tour'     => array(
503
-                    'Event_Categories_Help_Tour',
504
-                ),
505
-                'metaboxes'     => $this->_default_espresso_metaboxes,
506
-                'require_nonce' => false,
507
-            ),
508
-        );
509
-    }
510
-
511
-
512
-    /**
513
-     * Used to register any global screen options if necessary for every route in this admin page group.
514
-     */
515
-    protected function _add_screen_options()
516
-    {
517
-    }
518
-
519
-
520
-    /**
521
-     * Implementing the screen options for the 'default' route.
522
-     */
523
-    protected function _add_screen_options_default()
524
-    {
525
-        $this->_per_page_screen_option();
526
-    }
527
-
528
-
529
-    /**
530
-     * Implementing screen options for the category list route.
531
-     */
532
-    protected function _add_screen_options_category_list()
533
-    {
534
-        $page_title = $this->_admin_page_title;
535
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
536
-        $this->_per_page_screen_option();
537
-        $this->_admin_page_title = $page_title;
538
-    }
539
-
540
-
541
-    /**
542
-     * Used to register any global feature pointers for the admin page group.
543
-     */
544
-    protected function _add_feature_pointers()
545
-    {
546
-    }
547
-
548
-
549
-    /**
550
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
551
-     */
552
-    public function load_scripts_styles()
553
-    {
554
-        wp_register_style(
555
-            'events-admin-css',
556
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
557
-            array(),
558
-            EVENT_ESPRESSO_VERSION
559
-        );
560
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
561
-        wp_enqueue_style('events-admin-css');
562
-        wp_enqueue_style('ee-cat-admin');
563
-        //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
564
-        //registers for all views
565
-        //scripts
566
-        wp_register_script(
567
-            'event_editor_js',
568
-            EVENTS_ASSETS_URL . 'event_editor.js',
569
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
570
-            EVENT_ESPRESSO_VERSION,
571
-            true
572
-        );
573
-    }
574
-
575
-
576
-
577
-    /**
578
-     * Enqueuing scripts and styles specific to this view
579
-     */
580
-    public function load_scripts_styles_create_new()
581
-    {
582
-        $this->load_scripts_styles_edit();
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     * Enqueuing scripts and styles specific to this view
589
-     */
590
-    public function load_scripts_styles_edit()
591
-    {
592
-        //styles
593
-        wp_enqueue_style('espresso-ui-theme');
594
-        wp_register_style(
595
-            'event-editor-css',
596
-            EVENTS_ASSETS_URL . 'event-editor.css',
597
-            array('ee-admin-css'),
598
-            EVENT_ESPRESSO_VERSION
599
-        );
600
-        wp_enqueue_style('event-editor-css');
601
-        //scripts
602
-        wp_register_script(
603
-            'event-datetime-metabox',
604
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
605
-            array('event_editor_js', 'ee-datepicker'),
606
-            EVENT_ESPRESSO_VERSION
607
-        );
608
-        wp_enqueue_script('event-datetime-metabox');
609
-    }
610
-
611
-
612
-    /**
613
-     * Populating the _views property for the category list table view.
614
-     */
615
-    protected function _set_list_table_views_category_list()
616
-    {
617
-        $this->_views = array(
618
-            'all' => array(
619
-                'slug'        => 'all',
620
-                'label'       => esc_html__('All', 'event_espresso'),
621
-                'count'       => 0,
622
-                'bulk_action' => array(
623
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
624
-                ),
625
-            ),
626
-        );
627
-    }
628
-
629
-
630
-    /**
631
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
632
-     */
633
-    public function admin_init()
634
-    {
635
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
636
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
637
-            'event_espresso'
638
-        );
639
-    }
640
-
641
-
642
-    /**
643
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page group.
644
-     */
645
-    public function admin_notices()
646
-    {
647
-    }
648
-
649
-
650
-    /**
651
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
652
-     * this admin page group.
653
-     */
654
-    public function admin_footer_scripts()
655
-    {
656
-    }
657
-
658
-
659
-
660
-    /**
661
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
662
-     * warning (via EE_Error::add_error());
663
-     *
664
-     * @param  EE_Event $event Event object
665
-     * @access public
666
-     * @return void
667
-     */
668
-    public function verify_event_edit($event = null)
669
-    {
670
-        // no event?
671
-        if (empty($event)) {
672
-            // set event
673
-            $event = $this->_cpt_model_obj;
674
-        }
675
-        // STILL no event?
676
-        if (! $event instanceof EE_Event) {
677
-            return;
678
-        }
679
-        $orig_status = $event->status();
680
-        // first check if event is active.
681
-        if (
682
-            $orig_status === EEM_Event::cancelled
683
-            || $orig_status === EEM_Event::postponed
684
-            || $event->is_expired()
685
-            || $event->is_inactive()
686
-        ) {
687
-            return;
688
-        }
689
-        //made it here so it IS active... next check that any of the tickets are sold.
690
-        if ($event->is_sold_out(true)) {
691
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
692
-                EE_Error::add_attention(
693
-                    sprintf(
694
-                        esc_html__(
695
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
696
-                            'event_espresso'
697
-                        ),
698
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
699
-                    )
700
-                );
701
-            }
702
-            return;
703
-        } else if ($orig_status === EEM_Event::sold_out) {
704
-            EE_Error::add_attention(
705
-                sprintf(
706
-                    esc_html__(
707
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
708
-                        'event_espresso'
709
-                    ),
710
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
711
-                )
712
-            );
713
-        }
714
-        //now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
715
-        if ( ! $event->tickets_on_sale()) {
716
-            return;
717
-        }
718
-        //made it here so show warning
719
-        $this->_edit_event_warning();
720
-    }
721
-
722
-
723
-
724
-    /**
725
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
726
-     * When needed, hook this into a EE_Error::add_error() notice.
727
-     *
728
-     * @access protected
729
-     * @return void
730
-     */
731
-    protected function _edit_event_warning()
732
-    {
733
-        // we don't want to add warnings during these requests
734
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
735
-            return;
736
-        }
737
-        EE_Error::add_attention(
738
-            esc_html__(
739
-                'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
740
-                'event_espresso'
741
-            )
742
-        );
743
-    }
744
-
745
-
746
-
747
-    /**
748
-     * When a user is creating a new event, notify them if they haven't set their timezone.
749
-     * Otherwise, do the normal logic
750
-     *
751
-     * @return string
752
-     * @throws \EE_Error
753
-     */
754
-    protected function _create_new_cpt_item()
755
-    {
756
-        $has_timezone_string = get_option('timezone_string');
757
-        //only nag them about setting their timezone if it's their first event, and they haven't already done it
758
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
759
-            EE_Error::add_attention(
760
-                sprintf(
761
-                    __(
762
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
763
-                        'event_espresso'
764
-                    ),
765
-                    '<br>',
766
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
767
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
768
-                    . '</select>',
769
-                    '<button class="button button-secondary timezone-submit">',
770
-                    '</button><span class="spinner"></span>'
771
-                ),
772
-                __FILE__,
773
-                __FUNCTION__,
774
-                __LINE__
775
-            );
776
-        }
777
-        return parent::_create_new_cpt_item();
778
-    }
779
-
780
-
781
-    /**
782
-     * Sets the _views property for the default route in this admin page group.
783
-     */
784
-    protected function _set_list_table_views_default()
785
-    {
786
-        $this->_views = array(
787
-            'all'   => array(
788
-                'slug'        => 'all',
789
-                'label'       => esc_html__('View All Events', 'event_espresso'),
790
-                'count'       => 0,
791
-                'bulk_action' => array(
792
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
793
-                ),
794
-            ),
795
-            'draft' => array(
796
-                'slug'        => 'draft',
797
-                'label'       => esc_html__('Draft', 'event_espresso'),
798
-                'count'       => 0,
799
-                'bulk_action' => array(
800
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
801
-                ),
802
-            ),
803
-        );
804
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
805
-            $this->_views['trash'] = array(
806
-                'slug'        => 'trash',
807
-                'label'       => esc_html__('Trash', 'event_espresso'),
808
-                'count'       => 0,
809
-                'bulk_action' => array(
810
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
811
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
812
-                ),
813
-            );
814
-        }
815
-    }
816
-
817
-
818
-
819
-    /**
820
-     * Provides the legend item array for the default list table view.
821
-     * @return array
822
-     */
823
-    protected function _event_legend_items()
824
-    {
825
-        $items = array(
826
-            'view_details'   => array(
827
-                'class' => 'dashicons dashicons-search',
828
-                'desc'  => esc_html__('View Event', 'event_espresso'),
829
-            ),
830
-            'edit_event'     => array(
831
-                'class' => 'ee-icon ee-icon-calendar-edit',
832
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
833
-            ),
834
-            'view_attendees' => array(
835
-                'class' => 'dashicons dashicons-groups',
836
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
837
-            ),
838
-        );
839
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
840
-        $statuses = array(
841
-            'sold_out_status'  => array(
842
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
843
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
844
-            ),
845
-            'active_status'    => array(
846
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
847
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
848
-            ),
849
-            'upcoming_status'  => array(
850
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
851
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
852
-            ),
853
-            'postponed_status' => array(
854
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
855
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
856
-            ),
857
-            'cancelled_status' => array(
858
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
859
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
860
-            ),
861
-            'expired_status'   => array(
862
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
863
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
864
-            ),
865
-            'inactive_status'  => array(
866
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
867
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
868
-            ),
869
-        );
870
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
871
-        return array_merge($items, $statuses);
872
-    }
873
-
874
-
875
-
876
-    /**
877
-     * @return EEM_Event
878
-     */
879
-    private function _event_model()
880
-    {
881
-        if ( ! $this->_event_model instanceof EEM_Event) {
882
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
883
-        }
884
-        return $this->_event_model;
885
-    }
886
-
887
-
888
-
889
-    /**
890
-     * Adds extra buttons to the WP CPT permalink field row.
891
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
892
-     *
893
-     * @param  string $return    the current html
894
-     * @param  int    $id        the post id for the page
895
-     * @param  string $new_title What the title is
896
-     * @param  string $new_slug  what the slug is
897
-     * @return string            The new html string for the permalink area
898
-     */
899
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
900
-    {
901
-        //make sure this is only when editing
902
-        if ( ! empty($id)) {
903
-            $post = get_post($id);
904
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
905
-                       . esc_html__('Shortcode', 'event_espresso')
906
-                       . '</a> ';
907
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
908
-                       . $post->ID
909
-                       . ']">';
910
-        }
911
-        return $return;
912
-    }
913
-
914
-
915
-
916
-    /**
917
-     * _events_overview_list_table
918
-     * This contains the logic for showing the events_overview list
919
-     *
920
-     * @access protected
921
-     * @return void
922
-     * @throws \EE_Error
923
-     */
924
-    protected function _events_overview_list_table()
925
-    {
926
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
927
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
928
-            ? (array)$this->_template_args['after_list_table']
929
-            : array();
930
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
931
-                                                                              . EEH_Template::get_button_or_link(
932
-                get_post_type_archive_link('espresso_events'),
933
-                esc_html__("View Event Archive Page", "event_espresso"),
934
-                'button'
935
-            );
936
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
937
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
938
-                'create_new',
939
-                'add',
940
-                array(),
941
-                'add-new-h2'
942
-            );
943
-        $this->display_admin_list_table_page_with_no_sidebar();
944
-    }
945
-
946
-
947
-
948
-    /**
949
-     * this allows for extra misc actions in the default WP publish box
950
-     *
951
-     * @return void
952
-     */
953
-    public function extra_misc_actions_publish_box()
954
-    {
955
-        $this->_generate_publish_box_extra_content();
956
-    }
957
-
958
-
959
-
960
-    /**
961
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
962
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
963
-     * data.
964
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
965
-     * ALSO very important.  When a post transitions from scheduled to published, the save_post action is fired but you
966
-     * will NOT have any _POST data containing any extra info you may have from other meta saves.  So MAKE sure that
967
-     * you handle this accordingly.
968
-     *
969
-     * @access protected
970
-     * @abstract
971
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
972
-     * @param  object $post    The post object of the cpt that was saved.
973
-     * @return void
974
-     */
975
-    protected function _insert_update_cpt_item($post_id, $post)
976
-    {
977
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
978
-            //get out we're not processing an event save.
979
-            return;
980
-        }
981
-        $event_values = array(
982
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
983
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
984
-            'EVT_additional_limit'            => min(
985
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
986
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
987
-            ),
988
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
989
-                ? $this->_req_data['EVT_default_registration_status']
990
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
991
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
992
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
993
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
994
-                ? $this->_req_data['timezone_string'] : null,
995
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
996
-                ? $this->_req_data['externalURL'] : null,
997
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
998
-                ? $this->_req_data['event_phone'] : null,
999
-        );
1000
-        //update event
1001
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1002
-        //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1003
-        $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
1004
-        $event = $this->_event_model()->get_one(array($get_one_where));
1005
-        //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1006
-        $event_update_callbacks = apply_filters(
1007
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1008
-            array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
1009
-        );
1010
-        $att_success = true;
1011
-        foreach ($event_update_callbacks as $e_callback) {
1012
-            $_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
1013
-            $att_success = ! $att_success ? $att_success
1014
-                : $_succ; //if ANY of these updates fail then we want the appropriate global error message
1015
-        }
1016
-        //any errors?
1017
-        if ($success && false === $att_success) {
1018
-            EE_Error::add_error(
1019
-                esc_html__(
1020
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1021
-                    'event_espresso'
1022
-                ),
1023
-                __FILE__,
1024
-                __FUNCTION__,
1025
-                __LINE__
1026
-            );
1027
-        } else if ($success === false) {
1028
-            EE_Error::add_error(
1029
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1030
-                __FILE__,
1031
-                __FUNCTION__,
1032
-                __LINE__
1033
-            );
1034
-        }
1035
-    }
1036
-
1037
-
1038
-
1039
-    /**
1040
-     * @see parent::restore_item()
1041
-     * @param int $post_id
1042
-     * @param int $revision_id
1043
-     */
1044
-    protected function _restore_cpt_item($post_id, $revision_id)
1045
-    {
1046
-        //copy existing event meta to new post
1047
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1048
-        if ($post_evt instanceof EE_Event) {
1049
-            //meta revision restore
1050
-            $post_evt->restore_revision($revision_id);
1051
-            //related objs restore
1052
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1053
-        }
1054
-    }
1055
-
1056
-
1057
-
1058
-    /**
1059
-     * Attach the venue to the Event
1060
-     *
1061
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1062
-     * @param  array     $data   The request data from the form
1063
-     * @return bool           Success or fail.
1064
-     */
1065
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1066
-    {
1067
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1068
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1069
-        $rows_affected = null;
1070
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1071
-        // very important.  If we don't have a venue name...
1072
-        // then we'll get out because not necessary to create empty venue
1073
-        if (empty($data['venue_title'])) {
1074
-            return false;
1075
-        }
1076
-        $venue_array = array(
1077
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1078
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1079
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1080
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1081
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1082
-                : null,
1083
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1084
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1085
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1086
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1087
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1088
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1089
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1090
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1091
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1092
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1093
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1094
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1095
-            'status'              => 'publish',
1096
-        );
1097
-        //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1098
-        if ( ! empty($venue_id)) {
1099
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1100
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1101
-            //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1102
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1103
-            return $rows_affected > 0 ? true : false;
1104
-        } else {
1105
-            //we insert the venue
1106
-            $venue_id = $venue_model->insert($venue_array);
1107
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1108
-            return ! empty($venue_id) ? true : false;
1109
-        }
1110
-        //when we have the ancestor come in it's already been handled by the revision save.
1111
-    }
1112
-
1113
-
1114
-
1115
-    /**
1116
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1117
-     *
1118
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1119
-     * @param  array    $data   The request data from the form
1120
-     * @return array
1121
-     */
1122
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1123
-    {
1124
-        $success = true;
1125
-        $saved_dtt = null;
1126
-        $saved_tickets = array();
1127
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1128
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1129
-            //trim all values to ensure any excess whitespace is removed.
1130
-            $dtt = array_map('trim', $dtt);
1131
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1132
-                : $dtt['DTT_EVT_start'];
1133
-            $datetime_values = array(
1134
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1135
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1136
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1137
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1138
-                'DTT_order'     => $row,
1139
-            );
1140
-            //if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1141
-            if ( ! empty($dtt['DTT_ID'])) {
1142
-                $DTM = EE_Registry::instance()
1143
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1144
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1145
-                $DTM->set_date_format($incoming_date_formats[0]);
1146
-                $DTM->set_time_format($incoming_date_formats[1]);
1147
-                foreach ($datetime_values as $field => $value) {
1148
-                    $DTM->set($field, $value);
1149
-                }
1150
-                //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1151
-                $saved_dtts[$DTM->ID()] = $DTM;
1152
-            } else {
1153
-                $DTM = EE_Registry::instance()->load_class(
1154
-                    'Datetime',
1155
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1156
-                    false,
1157
-                    false
1158
-                );
1159
-                foreach ($datetime_values as $field => $value) {
1160
-                    $DTM->set($field, $value);
1161
-                }
1162
-            }
1163
-            $DTM->save();
1164
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1165
-            //load DTT helper
1166
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1167
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1168
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1169
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1170
-                $DTT->save();
1171
-            }
1172
-            //now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1173
-            $saved_dtt = $DTT;
1174
-            $success = ! $success ? $success : $DTT;
1175
-            //if ANY of these updates fail then we want the appropriate global error message.
1176
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1177
-        }
1178
-        //no dtts get deleted so we don't do any of that logic here.
1179
-        //update tickets next
1180
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1181
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1182
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1183
-            $update_prices = false;
1184
-            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1185
-                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1186
-            // trim inputs to ensure any excess whitespace is removed.
1187
-            $tkt = array_map('trim', $tkt);
1188
-            if (empty($tkt['TKT_start_date'])) {
1189
-                //let's use now in the set timezone.
1190
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1191
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1192
-            }
1193
-            if (empty($tkt['TKT_end_date'])) {
1194
-                //use the start date of the first datetime
1195
-                $dtt = $evtobj->first_datetime();
1196
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1197
-                    $incoming_date_formats[0],
1198
-                    $incoming_date_formats[1]
1199
-                );
1200
-            }
1201
-            $TKT_values = array(
1202
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1203
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1204
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1205
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1206
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1207
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1208
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1209
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1210
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1211
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1212
-                'TKT_row'         => $row,
1213
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1214
-                'TKT_price'       => $ticket_price,
1215
-            );
1216
-            //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1217
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1218
-                $TKT_values['TKT_ID'] = 0;
1219
-                $TKT_values['TKT_is_default'] = 0;
1220
-                $TKT_values['TKT_price'] = $ticket_price;
1221
-                $update_prices = true;
1222
-            }
1223
-            //if we have a TKT_ID then we need to get that existing TKT_obj and update it
1224
-            //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1225
-            //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1226
-            if ( ! empty($tkt['TKT_ID'])) {
1227
-                $TKT = EE_Registry::instance()
1228
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1229
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1230
-                if ($TKT instanceof EE_Ticket) {
1231
-                    $ticket_sold = $TKT->count_related(
1232
-                        'Registration',
1233
-                        array(
1234
-                            array(
1235
-                                'STS_ID' => array(
1236
-                                    'NOT IN',
1237
-                                    array(EEM_Registration::status_id_incomplete),
1238
-                                ),
1239
-                            ),
1240
-                        )
1241
-                    ) > 0 ? true : false;
1242
-                    //let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1243
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1244
-                                      && ! $TKT->get(
1245
-                        'TKT_deleted'
1246
-                    ) ? true : false;
1247
-                    $TKT->set_date_format($incoming_date_formats[0]);
1248
-                    $TKT->set_time_format($incoming_date_formats[1]);
1249
-                    //set new values
1250
-                    foreach ($TKT_values as $field => $value) {
1251
-                        if ($field == 'TKT_qty') {
1252
-                            $TKT->set_qty($value);
1253
-                        } else {
1254
-                            $TKT->set($field, $value);
1255
-                        }
1256
-                    }
1257
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1258
-                    if ($create_new_TKT) {
1259
-                        //archive the old ticket first
1260
-                        $TKT->set('TKT_deleted', 1);
1261
-                        $TKT->save();
1262
-                        //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1263
-                        $saved_tickets[$TKT->ID()] = $TKT;
1264
-                        //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1265
-                        $TKT = clone $TKT;
1266
-                        $TKT->set('TKT_ID', 0);
1267
-                        $TKT->set('TKT_deleted', 0);
1268
-                        $TKT->set('TKT_price', $ticket_price);
1269
-                        $TKT->set('TKT_sold', 0);
1270
-                        //now we need to make sure that $new prices are created as well and attached to new ticket.
1271
-                        $update_prices = true;
1272
-                    }
1273
-                    //make sure price is set if it hasn't been already
1274
-                    $TKT->set('TKT_price', $ticket_price);
1275
-                }
1276
-            } else {
1277
-                //no TKT_id so a new TKT
1278
-                $TKT_values['TKT_price'] = $ticket_price;
1279
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1280
-                if ($TKT instanceof EE_Ticket) {
1281
-                    //need to reset values to properly account for the date formats
1282
-                    $TKT->set_date_format($incoming_date_formats[0]);
1283
-                    $TKT->set_time_format($incoming_date_formats[1]);
1284
-                    $TKT->set_timezone($evtobj->get_timezone());
1285
-                    //set new values
1286
-                    foreach ($TKT_values as $field => $value) {
1287
-                        if ($field == 'TKT_qty') {
1288
-                            $TKT->set_qty($value);
1289
-                        } else {
1290
-                            $TKT->set($field, $value);
1291
-                        }
1292
-                    }
1293
-                    $update_prices = true;
1294
-                }
1295
-            }
1296
-            // cap ticket qty by datetime reg limits
1297
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1298
-            //update ticket.
1299
-            $TKT->save();
1300
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1301
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1302
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1303
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1304
-                $TKT->save();
1305
-            }
1306
-            //initially let's add the ticket to the dtt
1307
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1308
-            $saved_tickets[$TKT->ID()] = $TKT;
1309
-            //add prices to ticket
1310
-            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1311
-        }
1312
-        //however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1313
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1314
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1315
-        foreach ($tickets_removed as $id) {
1316
-            $id = absint($id);
1317
-            //get the ticket for this id
1318
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1319
-            //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1320
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1321
-            foreach ($dtts as $dtt) {
1322
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1323
-            }
1324
-            //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1325
-            $tkt_to_remove->delete_related_permanently('Price');
1326
-            //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1327
-            $tkt_to_remove->delete_permanently();
1328
-        }
1329
-        return array($saved_dtt, $saved_tickets);
1330
-    }
1331
-
1332
-
1333
-
1334
-    /**
1335
-     * This attaches a list of given prices to a ticket.
1336
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1337
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1338
-     * price info and prices are automatically "archived" via the ticket.
1339
-     *
1340
-     * @access  private
1341
-     * @param array     $prices     Array of prices from the form.
1342
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1343
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1344
-     * @return  void
1345
-     */
1346
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1347
-    {
1348
-        foreach ($prices as $row => $prc) {
1349
-            $PRC_values = array(
1350
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1351
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1352
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1353
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1354
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1355
-                'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1356
-                'PRC_order'      => $row,
1357
-            );
1358
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1359
-                $PRC_values['PRC_ID'] = 0;
1360
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1361
-            } else {
1362
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1363
-                //update this price with new values
1364
-                foreach ($PRC_values as $field => $newprc) {
1365
-                    $PRC->set($field, $newprc);
1366
-                }
1367
-                $PRC->save();
1368
-            }
1369
-            $ticket->_add_relation_to($PRC, 'Price');
1370
-        }
1371
-    }
1372
-
1373
-
1374
-
1375
-    /**
1376
-     * Add in our autosave ajax handlers
1377
-     *
1378
-     */
1379
-    protected function _ee_autosave_create_new()
1380
-    {
1381
-    }
1382
-
1383
-
1384
-    /**
1385
-     * More autosave handlers.
1386
-     */
1387
-    protected function _ee_autosave_edit()
1388
-    {
1389
-        return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1390
-    }
1391
-
1392
-
1393
-
1394
-    /**
1395
-     *    _generate_publish_box_extra_content
1396
-     */
1397
-    private function _generate_publish_box_extra_content()
1398
-    {
1399
-        //load formatter helper
1400
-        //args for getting related registrations
1401
-        $approved_query_args = array(
1402
-            array(
1403
-                'REG_deleted' => 0,
1404
-                'STS_ID'      => EEM_Registration::status_id_approved,
1405
-            ),
1406
-        );
1407
-        $not_approved_query_args = array(
1408
-            array(
1409
-                'REG_deleted' => 0,
1410
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1411
-            ),
1412
-        );
1413
-        $pending_payment_query_args = array(
1414
-            array(
1415
-                'REG_deleted' => 0,
1416
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1417
-            ),
1418
-        );
1419
-        // publish box
1420
-        $publish_box_extra_args = array(
1421
-            'view_approved_reg_url'        => add_query_arg(
1422
-                array(
1423
-                    'action'      => 'default',
1424
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1425
-                    '_reg_status' => EEM_Registration::status_id_approved,
1426
-                ),
1427
-                REG_ADMIN_URL
1428
-            ),
1429
-            'view_not_approved_reg_url'    => add_query_arg(
1430
-                array(
1431
-                    'action'      => 'default',
1432
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1433
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1434
-                ),
1435
-                REG_ADMIN_URL
1436
-            ),
1437
-            'view_pending_payment_reg_url' => add_query_arg(
1438
-                array(
1439
-                    'action'      => 'default',
1440
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1441
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1442
-                ),
1443
-                REG_ADMIN_URL
1444
-            ),
1445
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1446
-                'Registration',
1447
-                $approved_query_args
1448
-            ),
1449
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1450
-                'Registration',
1451
-                $not_approved_query_args
1452
-            ),
1453
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1454
-                'Registration',
1455
-                $pending_payment_query_args
1456
-            ),
1457
-            'misc_pub_section_class'       => apply_filters(
1458
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1459
-                'misc-pub-section'
1460
-            ),
1461
-        );
1462
-        ob_start();
1463
-        do_action(
1464
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1465
-            $this->_cpt_model_obj
1466
-        );
1467
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1468
-        // load template
1469
-        EEH_Template::display_template(
1470
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1471
-            $publish_box_extra_args
1472
-        );
1473
-    }
1474
-
1475
-
1476
-
1477
-    /**
1478
-     * @return EE_Event
1479
-     */
1480
-    public function get_event_object()
1481
-    {
1482
-        return $this->_cpt_model_obj;
1483
-    }
1484
-
1485
-
1486
-
1487
-
1488
-    /** METABOXES * */
1489
-    /**
1490
-     * _register_event_editor_meta_boxes
1491
-     * add all metaboxes related to the event_editor
1492
-     *
1493
-     * @return void
1494
-     */
1495
-    protected function _register_event_editor_meta_boxes()
1496
-    {
1497
-        $this->verify_cpt_object();
1498
-        add_meta_box(
1499
-            'espresso_event_editor_tickets',
1500
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1501
-            array($this, 'ticket_metabox'),
1502
-            $this->page_slug,
1503
-            'normal',
1504
-            'high'
1505
-        );
1506
-        add_meta_box(
1507
-            'espresso_event_editor_event_options',
1508
-            esc_html__('Event Registration Options', 'event_espresso'),
1509
-            array($this, 'registration_options_meta_box'),
1510
-            $this->page_slug,
1511
-            'side',
1512
-            'default'
1513
-        );
1514
-        // NOTE: if you're looking for other metaboxes in here,
1515
-        // where a metabox has a related management page in the admin
1516
-        // you will find it setup in the related management page's "_Hooks" file.
1517
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1518
-    }
1519
-
1520
-
1521
-    /**
1522
-     * @throws DomainException
1523
-     * @throws EE_Error
1524
-     */
1525
-    public function ticket_metabox()
1526
-    {
1527
-        $existing_datetime_ids = $existing_ticket_ids = array();
1528
-        //defaults for template args
1529
-        $template_args = array(
1530
-            'existing_datetime_ids'    => '',
1531
-            'event_datetime_help_link' => '',
1532
-            'ticket_options_help_link' => '',
1533
-            'time'                     => null,
1534
-            'ticket_rows'              => '',
1535
-            'existing_ticket_ids'      => '',
1536
-            'total_ticket_rows'        => 1,
1537
-            'ticket_js_structure'      => '',
1538
-            'trash_icon'               => 'ee-lock-icon',
1539
-            'disabled'                 => '',
1540
-        );
1541
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1542
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1543
-        /**
1544
-         * 1. Start with retrieving Datetimes
1545
-         * 2. Fore each datetime get related tickets
1546
-         * 3. For each ticket get related prices
1547
-         */
1548
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1549
-        /** @type EE_Datetime $first_datetime */
1550
-        $first_datetime = reset($times);
1551
-        //do we get related tickets?
1552
-        if ($first_datetime instanceof EE_Datetime
1553
-            && $first_datetime->ID() !== 0
1554
-        ) {
1555
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1556
-            $template_args['time'] = $first_datetime;
1557
-            $related_tickets = $first_datetime->tickets(
1558
-                array(
1559
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1560
-                    'default_where_conditions' => 'none',
1561
-                )
1562
-            );
1563
-            if ( ! empty($related_tickets)) {
1564
-                $template_args['total_ticket_rows'] = count($related_tickets);
1565
-                $row = 0;
1566
-                foreach ($related_tickets as $ticket) {
1567
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1568
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1569
-                    $row++;
1570
-                }
1571
-            } else {
1572
-                $template_args['total_ticket_rows'] = 1;
1573
-                /** @type EE_Ticket $ticket */
1574
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1575
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1576
-            }
1577
-        } else {
1578
-            $template_args['time'] = $times[0];
1579
-            /** @type EE_Ticket $ticket */
1580
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1581
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1582
-            // NOTE: we're just sending the first default row
1583
-            // (decaf can't manage default tickets so this should be sufficient);
1584
-        }
1585
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1586
-            'event_editor_event_datetimes_help_tab'
1587
-        );
1588
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1589
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1590
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1591
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1592
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1593
-            true
1594
-        );
1595
-        $template = apply_filters(
1596
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1597
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1598
-        );
1599
-        EEH_Template::display_template($template, $template_args);
1600
-    }
1601
-
1602
-
1603
-
1604
-    /**
1605
-     * Setup an individual ticket form for the decaf event editor page
1606
-     *
1607
-     * @access private
1608
-     * @param  EE_Ticket $ticket   the ticket object
1609
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1610
-     * @param int        $row
1611
-     * @return string generated html for the ticket row.
1612
-     */
1613
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1614
-    {
1615
-        $template_args = array(
1616
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1617
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1618
-                : '',
1619
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1620
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1621
-            'TKT_name'            => $ticket->get('TKT_name'),
1622
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1623
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1624
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1625
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1626
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1627
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1628
-            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1629
-                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1630
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1631
-            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1632
-                : ' disabled=disabled',
1633
-        );
1634
-        $price = $ticket->ID() !== 0
1635
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1636
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1637
-        $price_args = array(
1638
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1639
-            'PRC_amount'            => $price->get('PRC_amount'),
1640
-            'PRT_ID'                => $price->get('PRT_ID'),
1641
-            'PRC_ID'                => $price->get('PRC_ID'),
1642
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1643
-        );
1644
-        //make sure we have default start and end dates if skeleton
1645
-        //handle rows that should NOT be empty
1646
-        if (empty($template_args['TKT_start_date'])) {
1647
-            //if empty then the start date will be now.
1648
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1649
-        }
1650
-        if (empty($template_args['TKT_end_date'])) {
1651
-            //get the earliest datetime (if present);
1652
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1653
-                ? $this->_cpt_model_obj->get_first_related(
1654
-                    'Datetime',
1655
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1656
-                )
1657
-                : null;
1658
-            if ( ! empty($earliest_dtt)) {
1659
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1660
-            } else {
1661
-                $template_args['TKT_end_date'] = date(
1662
-                    'Y-m-d h:i a',
1663
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1664
-                );
1665
-            }
1666
-        }
1667
-        $template_args = array_merge($template_args, $price_args);
1668
-        $template = apply_filters(
1669
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1670
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1671
-            $ticket
1672
-        );
1673
-        return EEH_Template::display_template($template, $template_args, true);
1674
-    }
1675
-
1676
-
1677
-    /**
1678
-     * @throws DomainException
1679
-     */
1680
-    public function registration_options_meta_box()
1681
-    {
1682
-        $yes_no_values = array(
1683
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1684
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1685
-        );
1686
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1687
-            array(
1688
-                EEM_Registration::status_id_cancelled,
1689
-                EEM_Registration::status_id_declined,
1690
-                EEM_Registration::status_id_incomplete,
1691
-            ),
1692
-            true
1693
-        );
1694
-        //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1695
-        $template_args['_event'] = $this->_cpt_model_obj;
1696
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1697
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1698
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1699
-            'default_reg_status',
1700
-            $default_reg_status_values,
1701
-            $this->_cpt_model_obj->default_registration_status()
1702
-        );
1703
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1704
-            'display_desc',
1705
-            $yes_no_values,
1706
-            $this->_cpt_model_obj->display_description()
1707
-        );
1708
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1709
-            'display_ticket_selector',
1710
-            $yes_no_values,
1711
-            $this->_cpt_model_obj->display_ticket_selector(),
1712
-            '',
1713
-            '',
1714
-            false
1715
-        );
1716
-        $template_args['additional_registration_options'] = apply_filters(
1717
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1718
-            '',
1719
-            $template_args,
1720
-            $yes_no_values,
1721
-            $default_reg_status_values
1722
-        );
1723
-        EEH_Template::display_template(
1724
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1725
-            $template_args
1726
-        );
1727
-    }
1728
-
1729
-
1730
-
1731
-    /**
1732
-     * _get_events()
1733
-     * This method simply returns all the events (for the given _view and paging)
1734
-     *
1735
-     * @access public
1736
-     * @param int  $per_page     count of items per page (20 default);
1737
-     * @param int  $current_page what is the current page being viewed.
1738
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1739
-     *                           If FALSE then we return an array of event objects
1740
-     *                           that match the given _view and paging parameters.
1741
-     * @return array an array of event objects.
1742
-     */
1743
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1744
-    {
1745
-        $EEME = $this->_event_model();
1746
-        $offset = ($current_page - 1) * $per_page;
1747
-        $limit = $count ? null : $offset . ',' . $per_page;
1748
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1749
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1750
-        if (isset($this->_req_data['month_range'])) {
1751
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1752
-            //simulate the FIRST day of the month, that fixes issues for months like February
1753
-            //where PHP doesn't know what to assume for date.
1754
-            //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1755
-            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1756
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1757
-        }
1758
-        $where = array();
1759
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1760
-        //determine what post_status our condition will have for the query.
1761
-        switch ($status) {
1762
-            case 'month' :
1763
-            case 'today' :
1764
-            case null :
1765
-            case 'all' :
1766
-                break;
1767
-            case 'draft' :
1768
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1769
-                break;
1770
-            default :
1771
-                $where['status'] = $status;
1772
-        }
1773
-        //categories?
1774
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1775
-            ? $this->_req_data['EVT_CAT'] : null;
1776
-        if ( ! empty ($category)) {
1777
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1778
-            $where['Term_Taxonomy.term_id'] = $category;
1779
-        }
1780
-        //date where conditions
1781
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1782
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1783
-            $DateTime = new DateTime(
1784
-                $year_r . '-' . $month_r . '-01 00:00:00',
1785
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1786
-            );
1787
-            $start = $DateTime->format(implode(' ', $start_formats));
1788
-            $end = $DateTime->setDate($year_r, $month_r, $DateTime
1789
-                ->format('t'))->setTime(23, 59, 59)
1790
-                            ->format(implode(' ', $start_formats));
1791
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1792
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1793
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1794
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1795
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1796
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1797
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1798
-            $now = date('Y-m-01');
1799
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1800
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1801
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1802
-                            ->setTime(23, 59, 59)
1803
-                            ->format(implode(' ', $start_formats));
1804
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1805
-        }
1806
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1807
-            $where['EVT_wp_user'] = get_current_user_id();
1808
-        } else {
1809
-            if ( ! isset($where['status'])) {
1810
-                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1811
-                    $where['OR'] = array(
1812
-                        'status*restrict_private' => array('!=', 'private'),
1813
-                        'AND'                     => array(
1814
-                            'status*inclusive' => array('=', 'private'),
1815
-                            'EVT_wp_user'      => get_current_user_id(),
1816
-                        ),
1817
-                    );
1818
-                }
1819
-            }
1820
-        }
1821
-        if (isset($this->_req_data['EVT_wp_user'])) {
1822
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1823
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1824
-            ) {
1825
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1826
-            }
1827
-        }
1828
-        //search query handling
1829
-        if (isset($this->_req_data['s'])) {
1830
-            $search_string = '%' . $this->_req_data['s'] . '%';
1831
-            $where['OR'] = array(
1832
-                'EVT_name'       => array('LIKE', $search_string),
1833
-                'EVT_desc'       => array('LIKE', $search_string),
1834
-                'EVT_short_desc' => array('LIKE', $search_string),
1835
-            );
1836
-        }
1837
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1838
-        $query_params = apply_filters(
1839
-            'FHEE__Events_Admin_Page__get_events__query_params',
1840
-            array(
1841
-                $where,
1842
-                'limit'    => $limit,
1843
-                'order_by' => $orderby,
1844
-                'order'    => $order,
1845
-                'group_by' => 'EVT_ID',
1846
-            ),
1847
-            $this->_req_data
1848
-        );
1849
-        //let's first check if we have special requests coming in.
1850
-        if (isset($this->_req_data['active_status'])) {
1851
-            switch ($this->_req_data['active_status']) {
1852
-                case 'upcoming' :
1853
-                    return $EEME->get_upcoming_events($query_params, $count);
1854
-                    break;
1855
-                case 'expired' :
1856
-                    return $EEME->get_expired_events($query_params, $count);
1857
-                    break;
1858
-                case 'active' :
1859
-                    return $EEME->get_active_events($query_params, $count);
1860
-                    break;
1861
-                case 'inactive' :
1862
-                    return $EEME->get_inactive_events($query_params, $count);
1863
-                    break;
1864
-            }
1865
-        }
1866
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1867
-        return $events;
1868
-    }
1869
-
1870
-
1871
-
1872
-    /**
1873
-     * handling for WordPress CPT actions (trash, restore, delete)
1874
-     *
1875
-     * @param string $post_id
1876
-     */
1877
-    public function trash_cpt_item($post_id)
1878
-    {
1879
-        $this->_req_data['EVT_ID'] = $post_id;
1880
-        $this->_trash_or_restore_event('trash', false);
1881
-    }
1882
-
1883
-
1884
-
1885
-    /**
1886
-     * @param string $post_id
1887
-     */
1888
-    public function restore_cpt_item($post_id)
1889
-    {
1890
-        $this->_req_data['EVT_ID'] = $post_id;
1891
-        $this->_trash_or_restore_event('draft', false);
1892
-    }
1893
-
1894
-
1895
-
1896
-    /**
1897
-     * @param string $post_id
1898
-     */
1899
-    public function delete_cpt_item($post_id)
1900
-    {
1901
-        $this->_req_data['EVT_ID'] = $post_id;
1902
-        $this->_delete_event(false);
1903
-    }
1904
-
1905
-
1906
-
1907
-    /**
1908
-     * _trash_or_restore_event
1909
-     *
1910
-     * @access protected
1911
-     * @param  string $event_status
1912
-     * @param bool    $redirect_after
1913
-     */
1914
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1915
-    {
1916
-        //determine the event id and set to array.
1917
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1918
-        // loop thru events
1919
-        if ($EVT_ID) {
1920
-            // clean status
1921
-            $event_status = sanitize_key($event_status);
1922
-            // grab status
1923
-            if ( ! empty($event_status)) {
1924
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1925
-            } else {
1926
-                $success = false;
1927
-                $msg = esc_html__(
1928
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1929
-                    'event_espresso'
1930
-                );
1931
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1932
-            }
1933
-        } else {
1934
-            $success = false;
1935
-            $msg = esc_html__(
1936
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1937
-                'event_espresso'
1938
-            );
1939
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1940
-        }
1941
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1942
-        if ($redirect_after) {
1943
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1944
-        }
1945
-    }
1946
-
1947
-
1948
-
1949
-    /**
1950
-     * _trash_or_restore_events
1951
-     *
1952
-     * @access protected
1953
-     * @param  string $event_status
1954
-     * @return void
1955
-     */
1956
-    protected function _trash_or_restore_events($event_status = 'trash')
1957
-    {
1958
-        // clean status
1959
-        $event_status = sanitize_key($event_status);
1960
-        // grab status
1961
-        if ( ! empty($event_status)) {
1962
-            $success = true;
1963
-            //determine the event id and set to array.
1964
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1965
-            // loop thru events
1966
-            foreach ($EVT_IDs as $EVT_ID) {
1967
-                if ($EVT_ID = absint($EVT_ID)) {
1968
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1969
-                    $success = $results !== false ? $success : false;
1970
-                } else {
1971
-                    $msg = sprintf(
1972
-                        esc_html__(
1973
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1974
-                            'event_espresso'
1975
-                        ),
1976
-                        $EVT_ID
1977
-                    );
1978
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1979
-                    $success = false;
1980
-                }
1981
-            }
1982
-        } else {
1983
-            $success = false;
1984
-            $msg = esc_html__(
1985
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1986
-                'event_espresso'
1987
-            );
1988
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1989
-        }
1990
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1991
-        $success = $success ? 2 : false;
1992
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1993
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1994
-    }
1995
-
1996
-
1997
-
1998
-    /**
1999
-     * _trash_or_restore_events
2000
-     *
2001
-     * @access  private
2002
-     * @param  int    $EVT_ID
2003
-     * @param  string $event_status
2004
-     * @return bool
2005
-     */
2006
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2007
-    {
2008
-        // grab event id
2009
-        if ( ! $EVT_ID) {
2010
-            $msg = esc_html__(
2011
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2012
-                'event_espresso'
2013
-            );
2014
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2015
-            return false;
2016
-        }
2017
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2018
-        // clean status
2019
-        $event_status = sanitize_key($event_status);
2020
-        // grab status
2021
-        if (empty($event_status)) {
2022
-            $msg = esc_html__(
2023
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2024
-                'event_espresso'
2025
-            );
2026
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2027
-            return false;
2028
-        }
2029
-        // was event trashed or restored ?
2030
-        switch ($event_status) {
2031
-            case 'draft' :
2032
-                $action = 'restored from the trash';
2033
-                $hook = 'AHEE_event_restored_from_trash';
2034
-                break;
2035
-            case 'trash' :
2036
-                $action = 'moved to the trash';
2037
-                $hook = 'AHEE_event_moved_to_trash';
2038
-                break;
2039
-            default :
2040
-                $action = 'updated';
2041
-                $hook = false;
2042
-        }
2043
-        //use class to change status
2044
-        $this->_cpt_model_obj->set_status($event_status);
2045
-        $success = $this->_cpt_model_obj->save();
2046
-        if ($success === false) {
2047
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2048
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2049
-            return false;
2050
-        }
2051
-        if ($hook) {
2052
-            do_action($hook);
2053
-        }
2054
-        return true;
2055
-    }
2056
-
2057
-
2058
-
2059
-    /**
2060
-     * _delete_event
2061
-     *
2062
-     * @access protected
2063
-     * @param bool $redirect_after
2064
-     */
2065
-    protected function _delete_event($redirect_after = true)
2066
-    {
2067
-        //determine the event id and set to array.
2068
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2069
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2070
-        // loop thru events
2071
-        if ($EVT_ID) {
2072
-            $success = $this->_permanently_delete_event($EVT_ID);
2073
-            // get list of events with no prices
2074
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2075
-            // remove this event from the list of events with no prices
2076
-            if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2077
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2078
-            }
2079
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2080
-        } else {
2081
-            $success = false;
2082
-            $msg = esc_html__(
2083
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2084
-                'event_espresso'
2085
-            );
2086
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2087
-        }
2088
-        if ($redirect_after) {
2089
-            $this->_redirect_after_action(
2090
-                $success,
2091
-                'Event',
2092
-                'deleted',
2093
-                array('action' => 'default', 'status' => 'trash')
2094
-            );
2095
-        }
2096
-    }
2097
-
2098
-
2099
-
2100
-    /**
2101
-     * _delete_events
2102
-     *
2103
-     * @access protected
2104
-     * @return void
2105
-     */
2106
-    protected function _delete_events()
2107
-    {
2108
-        $success = true;
2109
-        // get list of events with no prices
2110
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2111
-        //determine the event id and set to array.
2112
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2113
-        // loop thru events
2114
-        foreach ($EVT_IDs as $EVT_ID) {
2115
-            $EVT_ID = absint($EVT_ID);
2116
-            if ($EVT_ID) {
2117
-                $results = $this->_permanently_delete_event($EVT_ID);
2118
-                $success = $results !== false ? $success : false;
2119
-                // remove this event from the list of events with no prices
2120
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2121
-            } else {
2122
-                $success = false;
2123
-                $msg = esc_html__(
2124
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2125
-                    'event_espresso'
2126
-                );
2127
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2128
-            }
2129
-        }
2130
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2131
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2132
-        $success = $success ? 2 : false;
2133
-        $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2134
-    }
2135
-
2136
-
2137
-
2138
-    /**
2139
-     * _permanently_delete_event
2140
-     *
2141
-     * @access  private
2142
-     * @param  int $EVT_ID
2143
-     * @return bool
2144
-     */
2145
-    private function _permanently_delete_event($EVT_ID = 0)
2146
-    {
2147
-        // grab event id
2148
-        if ( ! $EVT_ID) {
2149
-            $msg = esc_html__(
2150
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2151
-                'event_espresso'
2152
-            );
2153
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2154
-            return false;
2155
-        }
2156
-        if (
2157
-            ! $this->_cpt_model_obj instanceof EE_Event
2158
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2159
-        ) {
2160
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2161
-        }
2162
-        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2163
-            return false;
2164
-        }
2165
-        //need to delete related tickets and prices first.
2166
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2167
-        foreach ($datetimes as $datetime) {
2168
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2169
-            $tickets = $datetime->get_many_related('Ticket');
2170
-            foreach ($tickets as $ticket) {
2171
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2172
-                $ticket->delete_related_permanently('Price');
2173
-                $ticket->delete_permanently();
2174
-            }
2175
-            $datetime->delete();
2176
-        }
2177
-        //what about related venues or terms?
2178
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2179
-        foreach ($venues as $venue) {
2180
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2181
-        }
2182
-        //any attached question groups?
2183
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2184
-        if ( ! empty($question_groups)) {
2185
-            foreach ($question_groups as $question_group) {
2186
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2187
-            }
2188
-        }
2189
-        //Message Template Groups
2190
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2191
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2192
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2193
-        foreach ($term_taxonomies as $term_taxonomy) {
2194
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2195
-        }
2196
-        $success = $this->_cpt_model_obj->delete_permanently();
2197
-        // did it all go as planned ?
2198
-        if ($success) {
2199
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2200
-            EE_Error::add_success($msg);
2201
-        } else {
2202
-            $msg = sprintf(
2203
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2204
-                $EVT_ID
2205
-            );
2206
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2207
-            return false;
2208
-        }
2209
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2210
-        return true;
2211
-    }
2212
-
2213
-
2214
-
2215
-    /**
2216
-     * get total number of events
2217
-     *
2218
-     * @access public
2219
-     * @return int
2220
-     */
2221
-    public function total_events()
2222
-    {
2223
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2224
-        return $count;
2225
-    }
2226
-
2227
-
2228
-
2229
-    /**
2230
-     * get total number of draft events
2231
-     *
2232
-     * @access public
2233
-     * @return int
2234
-     */
2235
-    public function total_events_draft()
2236
-    {
2237
-        $where = array(
2238
-            'status' => array('IN', array('draft', 'auto-draft')),
2239
-        );
2240
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2241
-        return $count;
2242
-    }
2243
-
2244
-
2245
-
2246
-    /**
2247
-     * get total number of trashed events
2248
-     *
2249
-     * @access public
2250
-     * @return int
2251
-     */
2252
-    public function total_trashed_events()
2253
-    {
2254
-        $where = array(
2255
-            'status' => 'trash',
2256
-        );
2257
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2258
-        return $count;
2259
-    }
2260
-
2261
-
2262
-    /**
2263
-     *    _default_event_settings
2264
-     *    This generates the Default Settings Tab
2265
-     *
2266
-     * @return void
2267
-     * @throws EE_Error
2268
-     */
2269
-    protected function _default_event_settings()
2270
-    {
2271
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2272
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2273
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2274
-        $this->display_admin_page_with_sidebar();
2275
-    }
2276
-
2277
-
2278
-    /**
2279
-     * Return the form for event settings.
2280
-     * @return EE_Form_Section_Proper
2281
-     */
2282
-    protected function _default_event_settings_form()
2283
-    {
2284
-        $registration_config = EE_Registry::instance()->CFG->registration;
2285
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2286
-        //exclude
2287
-            array(
2288
-                EEM_Registration::status_id_cancelled,
2289
-                EEM_Registration::status_id_declined,
2290
-                EEM_Registration::status_id_incomplete,
2291
-                EEM_Registration::status_id_wait_list,
2292
-            ),
2293
-            true
2294
-        );
2295
-        return new EE_Form_Section_Proper(
2296
-            array(
2297
-                'name' => 'update_default_event_settings',
2298
-                'html_id' => 'update_default_event_settings',
2299
-                'html_class' => 'form-table',
2300
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2301
-                'subsections' => apply_filters(
2302
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2303
-                    array(
2304
-                        'default_reg_status' => new EE_Select_Input(
2305
-                            $registration_stati_for_selection,
2306
-                            array(
2307
-                                'default' => isset($registration_config->default_STS_ID)
2308
-                                             && array_key_exists(
2309
-                                                $registration_config->default_STS_ID,
2310
-                                                $registration_stati_for_selection
2311
-                                             )
2312
-                                            ? sanitize_text_field($registration_config->default_STS_ID)
2313
-                                            : EEM_Registration::status_id_pending_payment,
2314
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2315
-                                                    . EEH_Template::get_help_tab_link(
2316
-                                                        'default_settings_status_help_tab'
2317
-                                                    ),
2318
-                                'html_help_text' => esc_html__(
2319
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2320
-                                    'event_espresso'
2321
-                                )
2322
-                            )
2323
-                        ),
2324
-                        'default_max_tickets' => new EE_Integer_Input(
2325
-                            array(
2326
-                                'default' => isset($registration_config->default_maximum_number_of_tickets)
2327
-                                    ? $registration_config->default_maximum_number_of_tickets
2328
-                                    : EEM_Event::get_default_additional_limit(),
2329
-                                'html_label_text' => esc_html__(
2330
-                                    'Default Maximum Tickets Allowed Per Order:',
2331
-                                    'event_espresso'
2332
-                                ) . EEH_Template::get_help_tab_link(
2333
-                                    'default_maximum_tickets_help_tab"'
2334
-                                    ),
2335
-                                'html_help_text' => esc_html__(
2336
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2337
-                                    'event_espresso'
2338
-                                )
2339
-                            )
2340
-                        )
2341
-                    )
2342
-                )
2343
-            )
2344
-        );
2345
-    }
2346
-
2347
-
2348
-    /**
2349
-     * _update_default_event_settings
2350
-     *
2351
-     * @access protected
2352
-     * @return void
2353
-     * @throws EE_Error
2354
-     */
2355
-    protected function _update_default_event_settings()
2356
-    {
2357
-        $registration_config = EE_Registry::instance()->CFG->registration;
2358
-        $form = $this->_default_event_settings_form();
2359
-        if ($form->was_submitted()) {
2360
-            $form->receive_form_submission();
2361
-            if ($form->is_valid()) {
2362
-                $valid_data = $form->valid_data();
2363
-                if (isset($valid_data['default_reg_status'])) {
2364
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2365
-                }
2366
-                if (isset($valid_data['default_max_tickets'])) {
2367
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2368
-                }
2369
-                //update because data was valid!
2370
-                EE_Registry::instance()->CFG->update_espresso_config();
2371
-                EE_Error::overwrite_success();
2372
-                EE_Error::add_success(
2373
-                    __('Default Event Settings were updated', 'event_espresso')
2374
-                );
2375
-            }
2376
-        }
2377
-        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2378
-    }
2379
-
2380
-
2381
-
2382
-    /*************        Templates        *************/
2383
-    protected function _template_settings()
2384
-    {
2385
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2386
-        $this->_template_args['preview_img'] = '<img src="'
2387
-                                               . EVENTS_ASSETS_URL
2388
-                                               . DS
2389
-                                               . 'images'
2390
-                                               . DS
2391
-                                               . 'caffeinated_template_features.jpg" alt="'
2392
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2393
-                                               . '" />';
2394
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2395
-                'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2396
-                'event_espresso'
2397
-            ) . '</strong>';
2398
-        $this->display_admin_caf_preview_page('template_settings_tab');
2399
-    }
2400
-
2401
-
2402
-    /** Event Category Stuff **/
2403
-    /**
2404
-     * set the _category property with the category object for the loaded page.
2405
-     *
2406
-     * @access private
2407
-     * @return void
2408
-     */
2409
-    private function _set_category_object()
2410
-    {
2411
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2412
-            return;
2413
-        } //already have the category object so get out.
2414
-        //set default category object
2415
-        $this->_set_empty_category_object();
2416
-        //only set if we've got an id
2417
-        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2418
-            return;
2419
-        }
2420
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2421
-        $term = get_term($category_id, 'espresso_event_categories');
2422
-        if ( ! empty($term)) {
2423
-            $this->_category->category_name = $term->name;
2424
-            $this->_category->category_identifier = $term->slug;
2425
-            $this->_category->category_desc = $term->description;
2426
-            $this->_category->id = $term->term_id;
2427
-            $this->_category->parent = $term->parent;
2428
-        }
2429
-    }
2430
-
2431
-
2432
-    /**
2433
-     * Clears out category properties.
2434
-     */
2435
-    private function _set_empty_category_object()
2436
-    {
2437
-        $this->_category = new stdClass();
2438
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2439
-        $this->_category->id = $this->_category->parent = 0;
2440
-    }
2441
-
2442
-
2443
-    /**
2444
-     * @throws EE_Error
2445
-     */
2446
-    protected function _category_list_table()
2447
-    {
2448
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2449
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2450
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2451
-                'add_category',
2452
-                'add_category',
2453
-                array(),
2454
-                'add-new-h2'
2455
-            );
2456
-        $this->display_admin_list_table_page_with_sidebar();
2457
-    }
2458
-
2459
-
2460
-
2461
-    /**
2462
-     * Output category details view.
2463
-     */
2464
-    protected function _category_details($view)
2465
-    {
2466
-        //load formatter helper
2467
-        //load field generator helper
2468
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2469
-        $this->_set_add_edit_form_tags($route);
2470
-        $this->_set_category_object();
2471
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2472
-        $delete_action = 'delete_category';
2473
-        //custom redirect
2474
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2475
-            array('action' => 'category_list'),
2476
-            $this->_admin_base_url
2477
-        );
2478
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2479
-        //take care of contents
2480
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2481
-        $this->display_admin_page_with_sidebar();
2482
-    }
2483
-
2484
-
2485
-
2486
-    /**
2487
-     * Output category details content.
2488
-     */
2489
-    protected function _category_details_content()
2490
-    {
2491
-        $editor_args['category_desc'] = array(
2492
-            'type'          => 'wp_editor',
2493
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2494
-            'class'         => 'my_editor_custom',
2495
-            'wpeditor_args' => array('media_buttons' => false),
2496
-        );
2497
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2498
-        $all_terms = get_terms(
2499
-            array('espresso_event_categories'),
2500
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2501
-        );
2502
-        //setup category select for term parents.
2503
-        $category_select_values[] = array(
2504
-            'text' => esc_html__('No Parent', 'event_espresso'),
2505
-            'id'   => 0,
2506
-        );
2507
-        foreach ($all_terms as $term) {
2508
-            $category_select_values[] = array(
2509
-                'text' => $term->name,
2510
-                'id'   => $term->term_id,
2511
-            );
2512
-        }
2513
-        $category_select = EEH_Form_Fields::select_input(
2514
-            'category_parent',
2515
-            $category_select_values,
2516
-            $this->_category->parent
2517
-        );
2518
-        $template_args = array(
2519
-            'category'                 => $this->_category,
2520
-            'category_select'          => $category_select,
2521
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2522
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2523
-            'disable'                  => '',
2524
-            'disabled_message'         => false,
2525
-        );
2526
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2527
-        return EEH_Template::display_template($template, $template_args, true);
2528
-    }
2529
-
2530
-
2531
-    /**
2532
-     * Handles deleting categories.
2533
-     */
2534
-    protected function _delete_categories()
2535
-    {
2536
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2537
-            : (array)$this->_req_data['category_id'];
2538
-        foreach ($cat_ids as $cat_id) {
2539
-            $this->_delete_category($cat_id);
2540
-        }
2541
-        //doesn't matter what page we're coming from... we're going to the same place after delete.
2542
-        $query_args = array(
2543
-            'action' => 'category_list',
2544
-        );
2545
-        $this->_redirect_after_action(0, '', '', $query_args);
2546
-    }
2547
-
2548
-
2549
-
2550
-    /**
2551
-     * Handles deleting specific category.
2552
-     * @param int $cat_id
2553
-     */
2554
-    protected function _delete_category($cat_id)
2555
-    {
2556
-        $cat_id = absint($cat_id);
2557
-        wp_delete_term($cat_id, 'espresso_event_categories');
2558
-    }
2559
-
2560
-
2561
-
2562
-    /**
2563
-     * Handles triggering the update or insertion of a new category.
2564
-     * @param bool $new_category  true means we're triggering the insert of a new category.
2565
-     */
2566
-    protected function _insert_or_update_category($new_category)
2567
-    {
2568
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2569
-        $success = 0; //we already have a success message so lets not send another.
2570
-        if ($cat_id) {
2571
-            $query_args = array(
2572
-                'action'     => 'edit_category',
2573
-                'EVT_CAT_ID' => $cat_id,
2574
-            );
2575
-        } else {
2576
-            $query_args = array('action' => 'add_category');
2577
-        }
2578
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2579
-    }
2580
-
2581
-
2582
-
2583
-    /**
2584
-     * Inserts or updates category
2585
-     * @param bool $update (true indicates we're updating a category).
2586
-     * @return bool|mixed|string
2587
-     */
2588
-    private function _insert_category($update = false)
2589
-    {
2590
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2591
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2592
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2593
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2594
-        if (empty($category_name)) {
2595
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2596
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2597
-            return false;
2598
-        }
2599
-        $term_args = array(
2600
-            'name'        => $category_name,
2601
-            'description' => $category_desc,
2602
-            'parent'      => $category_parent,
2603
-        );
2604
-        //was the category_identifier input disabled?
2605
-        if (isset($this->_req_data['category_identifier'])) {
2606
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2607
-        }
2608
-        $insert_ids = $update
2609
-            ? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2610
-            : wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2611
-        if ( ! is_array($insert_ids)) {
2612
-            $msg = esc_html__(
2613
-                'An error occurred and the category has not been saved to the database.',
2614
-                'event_espresso'
2615
-            );
2616
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2617
-        } else {
2618
-            $cat_id = $insert_ids['term_id'];
2619
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2620
-            EE_Error::add_success($msg);
2621
-        }
2622
-        return $cat_id;
2623
-    }
2624
-
2625
-
2626
-
2627
-    /**
2628
-     * Gets categories or count of categories matching the arguments in the request.
2629
-     * @param int  $per_page
2630
-     * @param int  $current_page
2631
-     * @param bool $count
2632
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2633
-     */
2634
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2635
-    {
2636
-        //testing term stuff
2637
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2638
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2639
-        $limit = ($current_page - 1) * $per_page;
2640
-        $where = array('taxonomy' => 'espresso_event_categories');
2641
-        if (isset($this->_req_data['s'])) {
2642
-            $sstr = '%' . $this->_req_data['s'] . '%';
2643
-            $where['OR'] = array(
2644
-                'Term.name'   => array('LIKE', $sstr),
2645
-                'description' => array('LIKE', $sstr),
2646
-            );
2647
-        }
2648
-        $query_params = array(
2649
-            $where,
2650
-            'order_by'   => array($orderby => $order),
2651
-            'limit'      => $limit . ',' . $per_page,
2652
-            'force_join' => array('Term'),
2653
-        );
2654
-        $categories = $count
2655
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2656
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2657
-        return $categories;
2658
-    }
2659
-
2660
-    /* end category stuff */
2661
-    /**************/
2662
-
2663
-
2664
-    /**
2665
-     * Callback for the `ee_save_timezone_setting` ajax action.
2666
-     * @throws EE_Error
2667
-     */
2668
-    public function save_timezonestring_setting()
2669
-    {
2670
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2671
-            ? $this->_req_data['timezone_selected']
2672
-            : '';
2673
-        if  (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2674
-        {
2675
-            EE_Error::add_error(
2676
-                esc_html('An invalid timezone string submitted.', 'event_espresso'),
2677
-                __FILE__, __FUNCTION__, __LINE__
2678
-            );
2679
-            $this->_template_args['error'] = true;
2680
-            $this->_return_json();
2681
-        }
2682
-
2683
-        update_option('timezone_string', $timezone_string);
2684
-        EE_Error::add_success(
2685
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2686
-        );
2687
-        $this->_template_args['success'] = true;
2688
-        $this->_return_json(true, array('action' => 'create_new'));
2689
-    }
394
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
395
+				'require_nonce' => false,
396
+			),
397
+			'default_event_settings' => array(
398
+				'nav'           => array(
399
+					'label' => esc_html__('Default Settings', 'event_espresso'),
400
+					'order' => 40,
401
+				),
402
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
403
+				'labels'        => array(
404
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
405
+				),
406
+				'help_tabs'     => array(
407
+					'default_settings_help_tab'        => array(
408
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
409
+						'filename' => 'events_default_settings',
410
+					),
411
+					'default_settings_status_help_tab' => array(
412
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
413
+						'filename' => 'events_default_settings_status',
414
+					),
415
+					'default_maximum_tickets_help_tab' => array(
416
+						'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
417
+						'filename' => 'events_default_settings_max_tickets',
418
+					)
419
+				),
420
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
421
+				'require_nonce' => false,
422
+			),
423
+			//template settings
424
+			'template_settings'      => array(
425
+				'nav'           => array(
426
+					'label' => esc_html__('Templates', 'event_espresso'),
427
+					'order' => 30,
428
+				),
429
+				'metaboxes'     => $this->_default_espresso_metaboxes,
430
+				'help_tabs'     => array(
431
+					'general_settings_templates_help_tab' => array(
432
+						'title'    => esc_html__('Templates', 'event_espresso'),
433
+						'filename' => 'general_settings_templates',
434
+					),
435
+				),
436
+				'help_tour'     => array('Templates_Help_Tour'),
437
+				'require_nonce' => false,
438
+			),
439
+			//event category stuff
440
+			'add_category'           => array(
441
+				'nav'           => array(
442
+					'label'      => esc_html__('Add Category', 'event_espresso'),
443
+					'order'      => 15,
444
+					'persistent' => false,
445
+				),
446
+				'help_tabs'     => array(
447
+					'add_category_help_tab' => array(
448
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
449
+						'filename' => 'events_add_category',
450
+					),
451
+				),
452
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
453
+				'metaboxes'     => array('_publish_post_box'),
454
+				'require_nonce' => false,
455
+			),
456
+			'edit_category'          => array(
457
+				'nav'           => array(
458
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
459
+					'order'      => 15,
460
+					'persistent' => false,
461
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
462
+						? add_query_arg(
463
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
464
+							$this->_current_page_view_url
465
+						)
466
+						: $this->_admin_base_url,
467
+				),
468
+				'help_tabs'     => array(
469
+					'edit_category_help_tab' => array(
470
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
471
+						'filename' => 'events_edit_category',
472
+					),
473
+				),
474
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
475
+				'metaboxes'     => array('_publish_post_box'),
476
+				'require_nonce' => false,
477
+			),
478
+			'category_list'          => array(
479
+				'nav'           => array(
480
+					'label' => esc_html__('Categories', 'event_espresso'),
481
+					'order' => 20,
482
+				),
483
+				'list_table'    => 'Event_Categories_Admin_List_Table',
484
+				'help_tabs'     => array(
485
+					'events_categories_help_tab'                       => array(
486
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
487
+						'filename' => 'events_categories',
488
+					),
489
+					'events_categories_table_column_headings_help_tab' => array(
490
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
491
+						'filename' => 'events_categories_table_column_headings',
492
+					),
493
+					'events_categories_view_help_tab'                  => array(
494
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
495
+						'filename' => 'events_categories_views',
496
+					),
497
+					'events_categories_other_help_tab'                 => array(
498
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
499
+						'filename' => 'events_categories_other',
500
+					),
501
+				),
502
+				'help_tour'     => array(
503
+					'Event_Categories_Help_Tour',
504
+				),
505
+				'metaboxes'     => $this->_default_espresso_metaboxes,
506
+				'require_nonce' => false,
507
+			),
508
+		);
509
+	}
510
+
511
+
512
+	/**
513
+	 * Used to register any global screen options if necessary for every route in this admin page group.
514
+	 */
515
+	protected function _add_screen_options()
516
+	{
517
+	}
518
+
519
+
520
+	/**
521
+	 * Implementing the screen options for the 'default' route.
522
+	 */
523
+	protected function _add_screen_options_default()
524
+	{
525
+		$this->_per_page_screen_option();
526
+	}
527
+
528
+
529
+	/**
530
+	 * Implementing screen options for the category list route.
531
+	 */
532
+	protected function _add_screen_options_category_list()
533
+	{
534
+		$page_title = $this->_admin_page_title;
535
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
536
+		$this->_per_page_screen_option();
537
+		$this->_admin_page_title = $page_title;
538
+	}
539
+
540
+
541
+	/**
542
+	 * Used to register any global feature pointers for the admin page group.
543
+	 */
544
+	protected function _add_feature_pointers()
545
+	{
546
+	}
547
+
548
+
549
+	/**
550
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
551
+	 */
552
+	public function load_scripts_styles()
553
+	{
554
+		wp_register_style(
555
+			'events-admin-css',
556
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
557
+			array(),
558
+			EVENT_ESPRESSO_VERSION
559
+		);
560
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
561
+		wp_enqueue_style('events-admin-css');
562
+		wp_enqueue_style('ee-cat-admin');
563
+		//todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
564
+		//registers for all views
565
+		//scripts
566
+		wp_register_script(
567
+			'event_editor_js',
568
+			EVENTS_ASSETS_URL . 'event_editor.js',
569
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
570
+			EVENT_ESPRESSO_VERSION,
571
+			true
572
+		);
573
+	}
574
+
575
+
576
+
577
+	/**
578
+	 * Enqueuing scripts and styles specific to this view
579
+	 */
580
+	public function load_scripts_styles_create_new()
581
+	{
582
+		$this->load_scripts_styles_edit();
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 * Enqueuing scripts and styles specific to this view
589
+	 */
590
+	public function load_scripts_styles_edit()
591
+	{
592
+		//styles
593
+		wp_enqueue_style('espresso-ui-theme');
594
+		wp_register_style(
595
+			'event-editor-css',
596
+			EVENTS_ASSETS_URL . 'event-editor.css',
597
+			array('ee-admin-css'),
598
+			EVENT_ESPRESSO_VERSION
599
+		);
600
+		wp_enqueue_style('event-editor-css');
601
+		//scripts
602
+		wp_register_script(
603
+			'event-datetime-metabox',
604
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
605
+			array('event_editor_js', 'ee-datepicker'),
606
+			EVENT_ESPRESSO_VERSION
607
+		);
608
+		wp_enqueue_script('event-datetime-metabox');
609
+	}
610
+
611
+
612
+	/**
613
+	 * Populating the _views property for the category list table view.
614
+	 */
615
+	protected function _set_list_table_views_category_list()
616
+	{
617
+		$this->_views = array(
618
+			'all' => array(
619
+				'slug'        => 'all',
620
+				'label'       => esc_html__('All', 'event_espresso'),
621
+				'count'       => 0,
622
+				'bulk_action' => array(
623
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
624
+				),
625
+			),
626
+		);
627
+	}
628
+
629
+
630
+	/**
631
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
632
+	 */
633
+	public function admin_init()
634
+	{
635
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
636
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
637
+			'event_espresso'
638
+		);
639
+	}
640
+
641
+
642
+	/**
643
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page group.
644
+	 */
645
+	public function admin_notices()
646
+	{
647
+	}
648
+
649
+
650
+	/**
651
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
652
+	 * this admin page group.
653
+	 */
654
+	public function admin_footer_scripts()
655
+	{
656
+	}
657
+
658
+
659
+
660
+	/**
661
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
662
+	 * warning (via EE_Error::add_error());
663
+	 *
664
+	 * @param  EE_Event $event Event object
665
+	 * @access public
666
+	 * @return void
667
+	 */
668
+	public function verify_event_edit($event = null)
669
+	{
670
+		// no event?
671
+		if (empty($event)) {
672
+			// set event
673
+			$event = $this->_cpt_model_obj;
674
+		}
675
+		// STILL no event?
676
+		if (! $event instanceof EE_Event) {
677
+			return;
678
+		}
679
+		$orig_status = $event->status();
680
+		// first check if event is active.
681
+		if (
682
+			$orig_status === EEM_Event::cancelled
683
+			|| $orig_status === EEM_Event::postponed
684
+			|| $event->is_expired()
685
+			|| $event->is_inactive()
686
+		) {
687
+			return;
688
+		}
689
+		//made it here so it IS active... next check that any of the tickets are sold.
690
+		if ($event->is_sold_out(true)) {
691
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
692
+				EE_Error::add_attention(
693
+					sprintf(
694
+						esc_html__(
695
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
696
+							'event_espresso'
697
+						),
698
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
699
+					)
700
+				);
701
+			}
702
+			return;
703
+		} else if ($orig_status === EEM_Event::sold_out) {
704
+			EE_Error::add_attention(
705
+				sprintf(
706
+					esc_html__(
707
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
708
+						'event_espresso'
709
+					),
710
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
711
+				)
712
+			);
713
+		}
714
+		//now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
715
+		if ( ! $event->tickets_on_sale()) {
716
+			return;
717
+		}
718
+		//made it here so show warning
719
+		$this->_edit_event_warning();
720
+	}
721
+
722
+
723
+
724
+	/**
725
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
726
+	 * When needed, hook this into a EE_Error::add_error() notice.
727
+	 *
728
+	 * @access protected
729
+	 * @return void
730
+	 */
731
+	protected function _edit_event_warning()
732
+	{
733
+		// we don't want to add warnings during these requests
734
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
735
+			return;
736
+		}
737
+		EE_Error::add_attention(
738
+			esc_html__(
739
+				'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
740
+				'event_espresso'
741
+			)
742
+		);
743
+	}
744
+
745
+
746
+
747
+	/**
748
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
749
+	 * Otherwise, do the normal logic
750
+	 *
751
+	 * @return string
752
+	 * @throws \EE_Error
753
+	 */
754
+	protected function _create_new_cpt_item()
755
+	{
756
+		$has_timezone_string = get_option('timezone_string');
757
+		//only nag them about setting their timezone if it's their first event, and they haven't already done it
758
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
759
+			EE_Error::add_attention(
760
+				sprintf(
761
+					__(
762
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
763
+						'event_espresso'
764
+					),
765
+					'<br>',
766
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
767
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
768
+					. '</select>',
769
+					'<button class="button button-secondary timezone-submit">',
770
+					'</button><span class="spinner"></span>'
771
+				),
772
+				__FILE__,
773
+				__FUNCTION__,
774
+				__LINE__
775
+			);
776
+		}
777
+		return parent::_create_new_cpt_item();
778
+	}
779
+
780
+
781
+	/**
782
+	 * Sets the _views property for the default route in this admin page group.
783
+	 */
784
+	protected function _set_list_table_views_default()
785
+	{
786
+		$this->_views = array(
787
+			'all'   => array(
788
+				'slug'        => 'all',
789
+				'label'       => esc_html__('View All Events', 'event_espresso'),
790
+				'count'       => 0,
791
+				'bulk_action' => array(
792
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
793
+				),
794
+			),
795
+			'draft' => array(
796
+				'slug'        => 'draft',
797
+				'label'       => esc_html__('Draft', 'event_espresso'),
798
+				'count'       => 0,
799
+				'bulk_action' => array(
800
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
801
+				),
802
+			),
803
+		);
804
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
805
+			$this->_views['trash'] = array(
806
+				'slug'        => 'trash',
807
+				'label'       => esc_html__('Trash', 'event_espresso'),
808
+				'count'       => 0,
809
+				'bulk_action' => array(
810
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
811
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
812
+				),
813
+			);
814
+		}
815
+	}
816
+
817
+
818
+
819
+	/**
820
+	 * Provides the legend item array for the default list table view.
821
+	 * @return array
822
+	 */
823
+	protected function _event_legend_items()
824
+	{
825
+		$items = array(
826
+			'view_details'   => array(
827
+				'class' => 'dashicons dashicons-search',
828
+				'desc'  => esc_html__('View Event', 'event_espresso'),
829
+			),
830
+			'edit_event'     => array(
831
+				'class' => 'ee-icon ee-icon-calendar-edit',
832
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
833
+			),
834
+			'view_attendees' => array(
835
+				'class' => 'dashicons dashicons-groups',
836
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
837
+			),
838
+		);
839
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
840
+		$statuses = array(
841
+			'sold_out_status'  => array(
842
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
843
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
844
+			),
845
+			'active_status'    => array(
846
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
847
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
848
+			),
849
+			'upcoming_status'  => array(
850
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
851
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
852
+			),
853
+			'postponed_status' => array(
854
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
855
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
856
+			),
857
+			'cancelled_status' => array(
858
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
859
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
860
+			),
861
+			'expired_status'   => array(
862
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
863
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
864
+			),
865
+			'inactive_status'  => array(
866
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
867
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
868
+			),
869
+		);
870
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
871
+		return array_merge($items, $statuses);
872
+	}
873
+
874
+
875
+
876
+	/**
877
+	 * @return EEM_Event
878
+	 */
879
+	private function _event_model()
880
+	{
881
+		if ( ! $this->_event_model instanceof EEM_Event) {
882
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
883
+		}
884
+		return $this->_event_model;
885
+	}
886
+
887
+
888
+
889
+	/**
890
+	 * Adds extra buttons to the WP CPT permalink field row.
891
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
892
+	 *
893
+	 * @param  string $return    the current html
894
+	 * @param  int    $id        the post id for the page
895
+	 * @param  string $new_title What the title is
896
+	 * @param  string $new_slug  what the slug is
897
+	 * @return string            The new html string for the permalink area
898
+	 */
899
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
900
+	{
901
+		//make sure this is only when editing
902
+		if ( ! empty($id)) {
903
+			$post = get_post($id);
904
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
905
+					   . esc_html__('Shortcode', 'event_espresso')
906
+					   . '</a> ';
907
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
908
+					   . $post->ID
909
+					   . ']">';
910
+		}
911
+		return $return;
912
+	}
913
+
914
+
915
+
916
+	/**
917
+	 * _events_overview_list_table
918
+	 * This contains the logic for showing the events_overview list
919
+	 *
920
+	 * @access protected
921
+	 * @return void
922
+	 * @throws \EE_Error
923
+	 */
924
+	protected function _events_overview_list_table()
925
+	{
926
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
927
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
928
+			? (array)$this->_template_args['after_list_table']
929
+			: array();
930
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
931
+																			  . EEH_Template::get_button_or_link(
932
+				get_post_type_archive_link('espresso_events'),
933
+				esc_html__("View Event Archive Page", "event_espresso"),
934
+				'button'
935
+			);
936
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
937
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
938
+				'create_new',
939
+				'add',
940
+				array(),
941
+				'add-new-h2'
942
+			);
943
+		$this->display_admin_list_table_page_with_no_sidebar();
944
+	}
945
+
946
+
947
+
948
+	/**
949
+	 * this allows for extra misc actions in the default WP publish box
950
+	 *
951
+	 * @return void
952
+	 */
953
+	public function extra_misc_actions_publish_box()
954
+	{
955
+		$this->_generate_publish_box_extra_content();
956
+	}
957
+
958
+
959
+
960
+	/**
961
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
962
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
963
+	 * data.
964
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
965
+	 * ALSO very important.  When a post transitions from scheduled to published, the save_post action is fired but you
966
+	 * will NOT have any _POST data containing any extra info you may have from other meta saves.  So MAKE sure that
967
+	 * you handle this accordingly.
968
+	 *
969
+	 * @access protected
970
+	 * @abstract
971
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
972
+	 * @param  object $post    The post object of the cpt that was saved.
973
+	 * @return void
974
+	 */
975
+	protected function _insert_update_cpt_item($post_id, $post)
976
+	{
977
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
978
+			//get out we're not processing an event save.
979
+			return;
980
+		}
981
+		$event_values = array(
982
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
983
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
984
+			'EVT_additional_limit'            => min(
985
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
986
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
987
+			),
988
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
989
+				? $this->_req_data['EVT_default_registration_status']
990
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
991
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
992
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
993
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
994
+				? $this->_req_data['timezone_string'] : null,
995
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
996
+				? $this->_req_data['externalURL'] : null,
997
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
998
+				? $this->_req_data['event_phone'] : null,
999
+		);
1000
+		//update event
1001
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1002
+		//get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1003
+		$get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
1004
+		$event = $this->_event_model()->get_one(array($get_one_where));
1005
+		//the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1006
+		$event_update_callbacks = apply_filters(
1007
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1008
+			array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
1009
+		);
1010
+		$att_success = true;
1011
+		foreach ($event_update_callbacks as $e_callback) {
1012
+			$_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
1013
+			$att_success = ! $att_success ? $att_success
1014
+				: $_succ; //if ANY of these updates fail then we want the appropriate global error message
1015
+		}
1016
+		//any errors?
1017
+		if ($success && false === $att_success) {
1018
+			EE_Error::add_error(
1019
+				esc_html__(
1020
+					'Event Details saved successfully but something went wrong with saving attachments.',
1021
+					'event_espresso'
1022
+				),
1023
+				__FILE__,
1024
+				__FUNCTION__,
1025
+				__LINE__
1026
+			);
1027
+		} else if ($success === false) {
1028
+			EE_Error::add_error(
1029
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1030
+				__FILE__,
1031
+				__FUNCTION__,
1032
+				__LINE__
1033
+			);
1034
+		}
1035
+	}
1036
+
1037
+
1038
+
1039
+	/**
1040
+	 * @see parent::restore_item()
1041
+	 * @param int $post_id
1042
+	 * @param int $revision_id
1043
+	 */
1044
+	protected function _restore_cpt_item($post_id, $revision_id)
1045
+	{
1046
+		//copy existing event meta to new post
1047
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1048
+		if ($post_evt instanceof EE_Event) {
1049
+			//meta revision restore
1050
+			$post_evt->restore_revision($revision_id);
1051
+			//related objs restore
1052
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1053
+		}
1054
+	}
1055
+
1056
+
1057
+
1058
+	/**
1059
+	 * Attach the venue to the Event
1060
+	 *
1061
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1062
+	 * @param  array     $data   The request data from the form
1063
+	 * @return bool           Success or fail.
1064
+	 */
1065
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1066
+	{
1067
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1068
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1069
+		$rows_affected = null;
1070
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1071
+		// very important.  If we don't have a venue name...
1072
+		// then we'll get out because not necessary to create empty venue
1073
+		if (empty($data['venue_title'])) {
1074
+			return false;
1075
+		}
1076
+		$venue_array = array(
1077
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1078
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1079
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1080
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1081
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1082
+				: null,
1083
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1084
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1085
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1086
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1087
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1088
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1089
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1090
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1091
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1092
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1093
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1094
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1095
+			'status'              => 'publish',
1096
+		);
1097
+		//if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1098
+		if ( ! empty($venue_id)) {
1099
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1100
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1101
+			//we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1102
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1103
+			return $rows_affected > 0 ? true : false;
1104
+		} else {
1105
+			//we insert the venue
1106
+			$venue_id = $venue_model->insert($venue_array);
1107
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1108
+			return ! empty($venue_id) ? true : false;
1109
+		}
1110
+		//when we have the ancestor come in it's already been handled by the revision save.
1111
+	}
1112
+
1113
+
1114
+
1115
+	/**
1116
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1117
+	 *
1118
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1119
+	 * @param  array    $data   The request data from the form
1120
+	 * @return array
1121
+	 */
1122
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1123
+	{
1124
+		$success = true;
1125
+		$saved_dtt = null;
1126
+		$saved_tickets = array();
1127
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1128
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1129
+			//trim all values to ensure any excess whitespace is removed.
1130
+			$dtt = array_map('trim', $dtt);
1131
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1132
+				: $dtt['DTT_EVT_start'];
1133
+			$datetime_values = array(
1134
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1135
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1136
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1137
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1138
+				'DTT_order'     => $row,
1139
+			);
1140
+			//if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1141
+			if ( ! empty($dtt['DTT_ID'])) {
1142
+				$DTM = EE_Registry::instance()
1143
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1144
+								  ->get_one_by_ID($dtt['DTT_ID']);
1145
+				$DTM->set_date_format($incoming_date_formats[0]);
1146
+				$DTM->set_time_format($incoming_date_formats[1]);
1147
+				foreach ($datetime_values as $field => $value) {
1148
+					$DTM->set($field, $value);
1149
+				}
1150
+				//make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1151
+				$saved_dtts[$DTM->ID()] = $DTM;
1152
+			} else {
1153
+				$DTM = EE_Registry::instance()->load_class(
1154
+					'Datetime',
1155
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1156
+					false,
1157
+					false
1158
+				);
1159
+				foreach ($datetime_values as $field => $value) {
1160
+					$DTM->set($field, $value);
1161
+				}
1162
+			}
1163
+			$DTM->save();
1164
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1165
+			//load DTT helper
1166
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1167
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1168
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1169
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1170
+				$DTT->save();
1171
+			}
1172
+			//now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1173
+			$saved_dtt = $DTT;
1174
+			$success = ! $success ? $success : $DTT;
1175
+			//if ANY of these updates fail then we want the appropriate global error message.
1176
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1177
+		}
1178
+		//no dtts get deleted so we don't do any of that logic here.
1179
+		//update tickets next
1180
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1181
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1182
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1183
+			$update_prices = false;
1184
+			$ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1185
+				? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1186
+			// trim inputs to ensure any excess whitespace is removed.
1187
+			$tkt = array_map('trim', $tkt);
1188
+			if (empty($tkt['TKT_start_date'])) {
1189
+				//let's use now in the set timezone.
1190
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1191
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1192
+			}
1193
+			if (empty($tkt['TKT_end_date'])) {
1194
+				//use the start date of the first datetime
1195
+				$dtt = $evtobj->first_datetime();
1196
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1197
+					$incoming_date_formats[0],
1198
+					$incoming_date_formats[1]
1199
+				);
1200
+			}
1201
+			$TKT_values = array(
1202
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1203
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1204
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1205
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1206
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1207
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1208
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1209
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1210
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1211
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1212
+				'TKT_row'         => $row,
1213
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1214
+				'TKT_price'       => $ticket_price,
1215
+			);
1216
+			//if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1217
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1218
+				$TKT_values['TKT_ID'] = 0;
1219
+				$TKT_values['TKT_is_default'] = 0;
1220
+				$TKT_values['TKT_price'] = $ticket_price;
1221
+				$update_prices = true;
1222
+			}
1223
+			//if we have a TKT_ID then we need to get that existing TKT_obj and update it
1224
+			//we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1225
+			//keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1226
+			if ( ! empty($tkt['TKT_ID'])) {
1227
+				$TKT = EE_Registry::instance()
1228
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1229
+								  ->get_one_by_ID($tkt['TKT_ID']);
1230
+				if ($TKT instanceof EE_Ticket) {
1231
+					$ticket_sold = $TKT->count_related(
1232
+						'Registration',
1233
+						array(
1234
+							array(
1235
+								'STS_ID' => array(
1236
+									'NOT IN',
1237
+									array(EEM_Registration::status_id_incomplete),
1238
+								),
1239
+							),
1240
+						)
1241
+					) > 0 ? true : false;
1242
+					//let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1243
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1244
+									  && ! $TKT->get(
1245
+						'TKT_deleted'
1246
+					) ? true : false;
1247
+					$TKT->set_date_format($incoming_date_formats[0]);
1248
+					$TKT->set_time_format($incoming_date_formats[1]);
1249
+					//set new values
1250
+					foreach ($TKT_values as $field => $value) {
1251
+						if ($field == 'TKT_qty') {
1252
+							$TKT->set_qty($value);
1253
+						} else {
1254
+							$TKT->set($field, $value);
1255
+						}
1256
+					}
1257
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1258
+					if ($create_new_TKT) {
1259
+						//archive the old ticket first
1260
+						$TKT->set('TKT_deleted', 1);
1261
+						$TKT->save();
1262
+						//make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1263
+						$saved_tickets[$TKT->ID()] = $TKT;
1264
+						//create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1265
+						$TKT = clone $TKT;
1266
+						$TKT->set('TKT_ID', 0);
1267
+						$TKT->set('TKT_deleted', 0);
1268
+						$TKT->set('TKT_price', $ticket_price);
1269
+						$TKT->set('TKT_sold', 0);
1270
+						//now we need to make sure that $new prices are created as well and attached to new ticket.
1271
+						$update_prices = true;
1272
+					}
1273
+					//make sure price is set if it hasn't been already
1274
+					$TKT->set('TKT_price', $ticket_price);
1275
+				}
1276
+			} else {
1277
+				//no TKT_id so a new TKT
1278
+				$TKT_values['TKT_price'] = $ticket_price;
1279
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1280
+				if ($TKT instanceof EE_Ticket) {
1281
+					//need to reset values to properly account for the date formats
1282
+					$TKT->set_date_format($incoming_date_formats[0]);
1283
+					$TKT->set_time_format($incoming_date_formats[1]);
1284
+					$TKT->set_timezone($evtobj->get_timezone());
1285
+					//set new values
1286
+					foreach ($TKT_values as $field => $value) {
1287
+						if ($field == 'TKT_qty') {
1288
+							$TKT->set_qty($value);
1289
+						} else {
1290
+							$TKT->set($field, $value);
1291
+						}
1292
+					}
1293
+					$update_prices = true;
1294
+				}
1295
+			}
1296
+			// cap ticket qty by datetime reg limits
1297
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1298
+			//update ticket.
1299
+			$TKT->save();
1300
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1301
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1302
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1303
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1304
+				$TKT->save();
1305
+			}
1306
+			//initially let's add the ticket to the dtt
1307
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1308
+			$saved_tickets[$TKT->ID()] = $TKT;
1309
+			//add prices to ticket
1310
+			$this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1311
+		}
1312
+		//however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1313
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1314
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1315
+		foreach ($tickets_removed as $id) {
1316
+			$id = absint($id);
1317
+			//get the ticket for this id
1318
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1319
+			//need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1320
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1321
+			foreach ($dtts as $dtt) {
1322
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1323
+			}
1324
+			//need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1325
+			$tkt_to_remove->delete_related_permanently('Price');
1326
+			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1327
+			$tkt_to_remove->delete_permanently();
1328
+		}
1329
+		return array($saved_dtt, $saved_tickets);
1330
+	}
1331
+
1332
+
1333
+
1334
+	/**
1335
+	 * This attaches a list of given prices to a ticket.
1336
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1337
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1338
+	 * price info and prices are automatically "archived" via the ticket.
1339
+	 *
1340
+	 * @access  private
1341
+	 * @param array     $prices     Array of prices from the form.
1342
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1343
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1344
+	 * @return  void
1345
+	 */
1346
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1347
+	{
1348
+		foreach ($prices as $row => $prc) {
1349
+			$PRC_values = array(
1350
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1351
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1352
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1353
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1354
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1355
+				'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1356
+				'PRC_order'      => $row,
1357
+			);
1358
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1359
+				$PRC_values['PRC_ID'] = 0;
1360
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1361
+			} else {
1362
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1363
+				//update this price with new values
1364
+				foreach ($PRC_values as $field => $newprc) {
1365
+					$PRC->set($field, $newprc);
1366
+				}
1367
+				$PRC->save();
1368
+			}
1369
+			$ticket->_add_relation_to($PRC, 'Price');
1370
+		}
1371
+	}
1372
+
1373
+
1374
+
1375
+	/**
1376
+	 * Add in our autosave ajax handlers
1377
+	 *
1378
+	 */
1379
+	protected function _ee_autosave_create_new()
1380
+	{
1381
+	}
1382
+
1383
+
1384
+	/**
1385
+	 * More autosave handlers.
1386
+	 */
1387
+	protected function _ee_autosave_edit()
1388
+	{
1389
+		return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1390
+	}
1391
+
1392
+
1393
+
1394
+	/**
1395
+	 *    _generate_publish_box_extra_content
1396
+	 */
1397
+	private function _generate_publish_box_extra_content()
1398
+	{
1399
+		//load formatter helper
1400
+		//args for getting related registrations
1401
+		$approved_query_args = array(
1402
+			array(
1403
+				'REG_deleted' => 0,
1404
+				'STS_ID'      => EEM_Registration::status_id_approved,
1405
+			),
1406
+		);
1407
+		$not_approved_query_args = array(
1408
+			array(
1409
+				'REG_deleted' => 0,
1410
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1411
+			),
1412
+		);
1413
+		$pending_payment_query_args = array(
1414
+			array(
1415
+				'REG_deleted' => 0,
1416
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1417
+			),
1418
+		);
1419
+		// publish box
1420
+		$publish_box_extra_args = array(
1421
+			'view_approved_reg_url'        => add_query_arg(
1422
+				array(
1423
+					'action'      => 'default',
1424
+					'event_id'    => $this->_cpt_model_obj->ID(),
1425
+					'_reg_status' => EEM_Registration::status_id_approved,
1426
+				),
1427
+				REG_ADMIN_URL
1428
+			),
1429
+			'view_not_approved_reg_url'    => add_query_arg(
1430
+				array(
1431
+					'action'      => 'default',
1432
+					'event_id'    => $this->_cpt_model_obj->ID(),
1433
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1434
+				),
1435
+				REG_ADMIN_URL
1436
+			),
1437
+			'view_pending_payment_reg_url' => add_query_arg(
1438
+				array(
1439
+					'action'      => 'default',
1440
+					'event_id'    => $this->_cpt_model_obj->ID(),
1441
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1442
+				),
1443
+				REG_ADMIN_URL
1444
+			),
1445
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1446
+				'Registration',
1447
+				$approved_query_args
1448
+			),
1449
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1450
+				'Registration',
1451
+				$not_approved_query_args
1452
+			),
1453
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1454
+				'Registration',
1455
+				$pending_payment_query_args
1456
+			),
1457
+			'misc_pub_section_class'       => apply_filters(
1458
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1459
+				'misc-pub-section'
1460
+			),
1461
+		);
1462
+		ob_start();
1463
+		do_action(
1464
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1465
+			$this->_cpt_model_obj
1466
+		);
1467
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1468
+		// load template
1469
+		EEH_Template::display_template(
1470
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1471
+			$publish_box_extra_args
1472
+		);
1473
+	}
1474
+
1475
+
1476
+
1477
+	/**
1478
+	 * @return EE_Event
1479
+	 */
1480
+	public function get_event_object()
1481
+	{
1482
+		return $this->_cpt_model_obj;
1483
+	}
1484
+
1485
+
1486
+
1487
+
1488
+	/** METABOXES * */
1489
+	/**
1490
+	 * _register_event_editor_meta_boxes
1491
+	 * add all metaboxes related to the event_editor
1492
+	 *
1493
+	 * @return void
1494
+	 */
1495
+	protected function _register_event_editor_meta_boxes()
1496
+	{
1497
+		$this->verify_cpt_object();
1498
+		add_meta_box(
1499
+			'espresso_event_editor_tickets',
1500
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1501
+			array($this, 'ticket_metabox'),
1502
+			$this->page_slug,
1503
+			'normal',
1504
+			'high'
1505
+		);
1506
+		add_meta_box(
1507
+			'espresso_event_editor_event_options',
1508
+			esc_html__('Event Registration Options', 'event_espresso'),
1509
+			array($this, 'registration_options_meta_box'),
1510
+			$this->page_slug,
1511
+			'side',
1512
+			'default'
1513
+		);
1514
+		// NOTE: if you're looking for other metaboxes in here,
1515
+		// where a metabox has a related management page in the admin
1516
+		// you will find it setup in the related management page's "_Hooks" file.
1517
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1518
+	}
1519
+
1520
+
1521
+	/**
1522
+	 * @throws DomainException
1523
+	 * @throws EE_Error
1524
+	 */
1525
+	public function ticket_metabox()
1526
+	{
1527
+		$existing_datetime_ids = $existing_ticket_ids = array();
1528
+		//defaults for template args
1529
+		$template_args = array(
1530
+			'existing_datetime_ids'    => '',
1531
+			'event_datetime_help_link' => '',
1532
+			'ticket_options_help_link' => '',
1533
+			'time'                     => null,
1534
+			'ticket_rows'              => '',
1535
+			'existing_ticket_ids'      => '',
1536
+			'total_ticket_rows'        => 1,
1537
+			'ticket_js_structure'      => '',
1538
+			'trash_icon'               => 'ee-lock-icon',
1539
+			'disabled'                 => '',
1540
+		);
1541
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1542
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1543
+		/**
1544
+		 * 1. Start with retrieving Datetimes
1545
+		 * 2. Fore each datetime get related tickets
1546
+		 * 3. For each ticket get related prices
1547
+		 */
1548
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1549
+		/** @type EE_Datetime $first_datetime */
1550
+		$first_datetime = reset($times);
1551
+		//do we get related tickets?
1552
+		if ($first_datetime instanceof EE_Datetime
1553
+			&& $first_datetime->ID() !== 0
1554
+		) {
1555
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1556
+			$template_args['time'] = $first_datetime;
1557
+			$related_tickets = $first_datetime->tickets(
1558
+				array(
1559
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1560
+					'default_where_conditions' => 'none',
1561
+				)
1562
+			);
1563
+			if ( ! empty($related_tickets)) {
1564
+				$template_args['total_ticket_rows'] = count($related_tickets);
1565
+				$row = 0;
1566
+				foreach ($related_tickets as $ticket) {
1567
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1568
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1569
+					$row++;
1570
+				}
1571
+			} else {
1572
+				$template_args['total_ticket_rows'] = 1;
1573
+				/** @type EE_Ticket $ticket */
1574
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1575
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1576
+			}
1577
+		} else {
1578
+			$template_args['time'] = $times[0];
1579
+			/** @type EE_Ticket $ticket */
1580
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1581
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1582
+			// NOTE: we're just sending the first default row
1583
+			// (decaf can't manage default tickets so this should be sufficient);
1584
+		}
1585
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1586
+			'event_editor_event_datetimes_help_tab'
1587
+		);
1588
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1589
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1590
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1591
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1592
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1593
+			true
1594
+		);
1595
+		$template = apply_filters(
1596
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1597
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1598
+		);
1599
+		EEH_Template::display_template($template, $template_args);
1600
+	}
1601
+
1602
+
1603
+
1604
+	/**
1605
+	 * Setup an individual ticket form for the decaf event editor page
1606
+	 *
1607
+	 * @access private
1608
+	 * @param  EE_Ticket $ticket   the ticket object
1609
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1610
+	 * @param int        $row
1611
+	 * @return string generated html for the ticket row.
1612
+	 */
1613
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1614
+	{
1615
+		$template_args = array(
1616
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1617
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1618
+				: '',
1619
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1620
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1621
+			'TKT_name'            => $ticket->get('TKT_name'),
1622
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1623
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1624
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1625
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1626
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1627
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1628
+			'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1629
+									 && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1630
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1631
+			'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1632
+				: ' disabled=disabled',
1633
+		);
1634
+		$price = $ticket->ID() !== 0
1635
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1636
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1637
+		$price_args = array(
1638
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1639
+			'PRC_amount'            => $price->get('PRC_amount'),
1640
+			'PRT_ID'                => $price->get('PRT_ID'),
1641
+			'PRC_ID'                => $price->get('PRC_ID'),
1642
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1643
+		);
1644
+		//make sure we have default start and end dates if skeleton
1645
+		//handle rows that should NOT be empty
1646
+		if (empty($template_args['TKT_start_date'])) {
1647
+			//if empty then the start date will be now.
1648
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1649
+		}
1650
+		if (empty($template_args['TKT_end_date'])) {
1651
+			//get the earliest datetime (if present);
1652
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1653
+				? $this->_cpt_model_obj->get_first_related(
1654
+					'Datetime',
1655
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1656
+				)
1657
+				: null;
1658
+			if ( ! empty($earliest_dtt)) {
1659
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1660
+			} else {
1661
+				$template_args['TKT_end_date'] = date(
1662
+					'Y-m-d h:i a',
1663
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1664
+				);
1665
+			}
1666
+		}
1667
+		$template_args = array_merge($template_args, $price_args);
1668
+		$template = apply_filters(
1669
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1670
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1671
+			$ticket
1672
+		);
1673
+		return EEH_Template::display_template($template, $template_args, true);
1674
+	}
1675
+
1676
+
1677
+	/**
1678
+	 * @throws DomainException
1679
+	 */
1680
+	public function registration_options_meta_box()
1681
+	{
1682
+		$yes_no_values = array(
1683
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1684
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1685
+		);
1686
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1687
+			array(
1688
+				EEM_Registration::status_id_cancelled,
1689
+				EEM_Registration::status_id_declined,
1690
+				EEM_Registration::status_id_incomplete,
1691
+			),
1692
+			true
1693
+		);
1694
+		//$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1695
+		$template_args['_event'] = $this->_cpt_model_obj;
1696
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1697
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1698
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1699
+			'default_reg_status',
1700
+			$default_reg_status_values,
1701
+			$this->_cpt_model_obj->default_registration_status()
1702
+		);
1703
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1704
+			'display_desc',
1705
+			$yes_no_values,
1706
+			$this->_cpt_model_obj->display_description()
1707
+		);
1708
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1709
+			'display_ticket_selector',
1710
+			$yes_no_values,
1711
+			$this->_cpt_model_obj->display_ticket_selector(),
1712
+			'',
1713
+			'',
1714
+			false
1715
+		);
1716
+		$template_args['additional_registration_options'] = apply_filters(
1717
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1718
+			'',
1719
+			$template_args,
1720
+			$yes_no_values,
1721
+			$default_reg_status_values
1722
+		);
1723
+		EEH_Template::display_template(
1724
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1725
+			$template_args
1726
+		);
1727
+	}
1728
+
1729
+
1730
+
1731
+	/**
1732
+	 * _get_events()
1733
+	 * This method simply returns all the events (for the given _view and paging)
1734
+	 *
1735
+	 * @access public
1736
+	 * @param int  $per_page     count of items per page (20 default);
1737
+	 * @param int  $current_page what is the current page being viewed.
1738
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1739
+	 *                           If FALSE then we return an array of event objects
1740
+	 *                           that match the given _view and paging parameters.
1741
+	 * @return array an array of event objects.
1742
+	 */
1743
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1744
+	{
1745
+		$EEME = $this->_event_model();
1746
+		$offset = ($current_page - 1) * $per_page;
1747
+		$limit = $count ? null : $offset . ',' . $per_page;
1748
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1749
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1750
+		if (isset($this->_req_data['month_range'])) {
1751
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1752
+			//simulate the FIRST day of the month, that fixes issues for months like February
1753
+			//where PHP doesn't know what to assume for date.
1754
+			//@see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1755
+			$month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1756
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1757
+		}
1758
+		$where = array();
1759
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1760
+		//determine what post_status our condition will have for the query.
1761
+		switch ($status) {
1762
+			case 'month' :
1763
+			case 'today' :
1764
+			case null :
1765
+			case 'all' :
1766
+				break;
1767
+			case 'draft' :
1768
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1769
+				break;
1770
+			default :
1771
+				$where['status'] = $status;
1772
+		}
1773
+		//categories?
1774
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1775
+			? $this->_req_data['EVT_CAT'] : null;
1776
+		if ( ! empty ($category)) {
1777
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1778
+			$where['Term_Taxonomy.term_id'] = $category;
1779
+		}
1780
+		//date where conditions
1781
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1782
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1783
+			$DateTime = new DateTime(
1784
+				$year_r . '-' . $month_r . '-01 00:00:00',
1785
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1786
+			);
1787
+			$start = $DateTime->format(implode(' ', $start_formats));
1788
+			$end = $DateTime->setDate($year_r, $month_r, $DateTime
1789
+				->format('t'))->setTime(23, 59, 59)
1790
+							->format(implode(' ', $start_formats));
1791
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1792
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1793
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1794
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1795
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1796
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1797
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1798
+			$now = date('Y-m-01');
1799
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1800
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1801
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1802
+							->setTime(23, 59, 59)
1803
+							->format(implode(' ', $start_formats));
1804
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1805
+		}
1806
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1807
+			$where['EVT_wp_user'] = get_current_user_id();
1808
+		} else {
1809
+			if ( ! isset($where['status'])) {
1810
+				if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1811
+					$where['OR'] = array(
1812
+						'status*restrict_private' => array('!=', 'private'),
1813
+						'AND'                     => array(
1814
+							'status*inclusive' => array('=', 'private'),
1815
+							'EVT_wp_user'      => get_current_user_id(),
1816
+						),
1817
+					);
1818
+				}
1819
+			}
1820
+		}
1821
+		if (isset($this->_req_data['EVT_wp_user'])) {
1822
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1823
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1824
+			) {
1825
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1826
+			}
1827
+		}
1828
+		//search query handling
1829
+		if (isset($this->_req_data['s'])) {
1830
+			$search_string = '%' . $this->_req_data['s'] . '%';
1831
+			$where['OR'] = array(
1832
+				'EVT_name'       => array('LIKE', $search_string),
1833
+				'EVT_desc'       => array('LIKE', $search_string),
1834
+				'EVT_short_desc' => array('LIKE', $search_string),
1835
+			);
1836
+		}
1837
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1838
+		$query_params = apply_filters(
1839
+			'FHEE__Events_Admin_Page__get_events__query_params',
1840
+			array(
1841
+				$where,
1842
+				'limit'    => $limit,
1843
+				'order_by' => $orderby,
1844
+				'order'    => $order,
1845
+				'group_by' => 'EVT_ID',
1846
+			),
1847
+			$this->_req_data
1848
+		);
1849
+		//let's first check if we have special requests coming in.
1850
+		if (isset($this->_req_data['active_status'])) {
1851
+			switch ($this->_req_data['active_status']) {
1852
+				case 'upcoming' :
1853
+					return $EEME->get_upcoming_events($query_params, $count);
1854
+					break;
1855
+				case 'expired' :
1856
+					return $EEME->get_expired_events($query_params, $count);
1857
+					break;
1858
+				case 'active' :
1859
+					return $EEME->get_active_events($query_params, $count);
1860
+					break;
1861
+				case 'inactive' :
1862
+					return $EEME->get_inactive_events($query_params, $count);
1863
+					break;
1864
+			}
1865
+		}
1866
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1867
+		return $events;
1868
+	}
1869
+
1870
+
1871
+
1872
+	/**
1873
+	 * handling for WordPress CPT actions (trash, restore, delete)
1874
+	 *
1875
+	 * @param string $post_id
1876
+	 */
1877
+	public function trash_cpt_item($post_id)
1878
+	{
1879
+		$this->_req_data['EVT_ID'] = $post_id;
1880
+		$this->_trash_or_restore_event('trash', false);
1881
+	}
1882
+
1883
+
1884
+
1885
+	/**
1886
+	 * @param string $post_id
1887
+	 */
1888
+	public function restore_cpt_item($post_id)
1889
+	{
1890
+		$this->_req_data['EVT_ID'] = $post_id;
1891
+		$this->_trash_or_restore_event('draft', false);
1892
+	}
1893
+
1894
+
1895
+
1896
+	/**
1897
+	 * @param string $post_id
1898
+	 */
1899
+	public function delete_cpt_item($post_id)
1900
+	{
1901
+		$this->_req_data['EVT_ID'] = $post_id;
1902
+		$this->_delete_event(false);
1903
+	}
1904
+
1905
+
1906
+
1907
+	/**
1908
+	 * _trash_or_restore_event
1909
+	 *
1910
+	 * @access protected
1911
+	 * @param  string $event_status
1912
+	 * @param bool    $redirect_after
1913
+	 */
1914
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1915
+	{
1916
+		//determine the event id and set to array.
1917
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1918
+		// loop thru events
1919
+		if ($EVT_ID) {
1920
+			// clean status
1921
+			$event_status = sanitize_key($event_status);
1922
+			// grab status
1923
+			if ( ! empty($event_status)) {
1924
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1925
+			} else {
1926
+				$success = false;
1927
+				$msg = esc_html__(
1928
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1929
+					'event_espresso'
1930
+				);
1931
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1932
+			}
1933
+		} else {
1934
+			$success = false;
1935
+			$msg = esc_html__(
1936
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1937
+				'event_espresso'
1938
+			);
1939
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1940
+		}
1941
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1942
+		if ($redirect_after) {
1943
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1944
+		}
1945
+	}
1946
+
1947
+
1948
+
1949
+	/**
1950
+	 * _trash_or_restore_events
1951
+	 *
1952
+	 * @access protected
1953
+	 * @param  string $event_status
1954
+	 * @return void
1955
+	 */
1956
+	protected function _trash_or_restore_events($event_status = 'trash')
1957
+	{
1958
+		// clean status
1959
+		$event_status = sanitize_key($event_status);
1960
+		// grab status
1961
+		if ( ! empty($event_status)) {
1962
+			$success = true;
1963
+			//determine the event id and set to array.
1964
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1965
+			// loop thru events
1966
+			foreach ($EVT_IDs as $EVT_ID) {
1967
+				if ($EVT_ID = absint($EVT_ID)) {
1968
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1969
+					$success = $results !== false ? $success : false;
1970
+				} else {
1971
+					$msg = sprintf(
1972
+						esc_html__(
1973
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1974
+							'event_espresso'
1975
+						),
1976
+						$EVT_ID
1977
+					);
1978
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1979
+					$success = false;
1980
+				}
1981
+			}
1982
+		} else {
1983
+			$success = false;
1984
+			$msg = esc_html__(
1985
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1986
+				'event_espresso'
1987
+			);
1988
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1989
+		}
1990
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1991
+		$success = $success ? 2 : false;
1992
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1993
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1994
+	}
1995
+
1996
+
1997
+
1998
+	/**
1999
+	 * _trash_or_restore_events
2000
+	 *
2001
+	 * @access  private
2002
+	 * @param  int    $EVT_ID
2003
+	 * @param  string $event_status
2004
+	 * @return bool
2005
+	 */
2006
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2007
+	{
2008
+		// grab event id
2009
+		if ( ! $EVT_ID) {
2010
+			$msg = esc_html__(
2011
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2012
+				'event_espresso'
2013
+			);
2014
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2015
+			return false;
2016
+		}
2017
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2018
+		// clean status
2019
+		$event_status = sanitize_key($event_status);
2020
+		// grab status
2021
+		if (empty($event_status)) {
2022
+			$msg = esc_html__(
2023
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2024
+				'event_espresso'
2025
+			);
2026
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2027
+			return false;
2028
+		}
2029
+		// was event trashed or restored ?
2030
+		switch ($event_status) {
2031
+			case 'draft' :
2032
+				$action = 'restored from the trash';
2033
+				$hook = 'AHEE_event_restored_from_trash';
2034
+				break;
2035
+			case 'trash' :
2036
+				$action = 'moved to the trash';
2037
+				$hook = 'AHEE_event_moved_to_trash';
2038
+				break;
2039
+			default :
2040
+				$action = 'updated';
2041
+				$hook = false;
2042
+		}
2043
+		//use class to change status
2044
+		$this->_cpt_model_obj->set_status($event_status);
2045
+		$success = $this->_cpt_model_obj->save();
2046
+		if ($success === false) {
2047
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2048
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2049
+			return false;
2050
+		}
2051
+		if ($hook) {
2052
+			do_action($hook);
2053
+		}
2054
+		return true;
2055
+	}
2056
+
2057
+
2058
+
2059
+	/**
2060
+	 * _delete_event
2061
+	 *
2062
+	 * @access protected
2063
+	 * @param bool $redirect_after
2064
+	 */
2065
+	protected function _delete_event($redirect_after = true)
2066
+	{
2067
+		//determine the event id and set to array.
2068
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2069
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2070
+		// loop thru events
2071
+		if ($EVT_ID) {
2072
+			$success = $this->_permanently_delete_event($EVT_ID);
2073
+			// get list of events with no prices
2074
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2075
+			// remove this event from the list of events with no prices
2076
+			if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2077
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2078
+			}
2079
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2080
+		} else {
2081
+			$success = false;
2082
+			$msg = esc_html__(
2083
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2084
+				'event_espresso'
2085
+			);
2086
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2087
+		}
2088
+		if ($redirect_after) {
2089
+			$this->_redirect_after_action(
2090
+				$success,
2091
+				'Event',
2092
+				'deleted',
2093
+				array('action' => 'default', 'status' => 'trash')
2094
+			);
2095
+		}
2096
+	}
2097
+
2098
+
2099
+
2100
+	/**
2101
+	 * _delete_events
2102
+	 *
2103
+	 * @access protected
2104
+	 * @return void
2105
+	 */
2106
+	protected function _delete_events()
2107
+	{
2108
+		$success = true;
2109
+		// get list of events with no prices
2110
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2111
+		//determine the event id and set to array.
2112
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2113
+		// loop thru events
2114
+		foreach ($EVT_IDs as $EVT_ID) {
2115
+			$EVT_ID = absint($EVT_ID);
2116
+			if ($EVT_ID) {
2117
+				$results = $this->_permanently_delete_event($EVT_ID);
2118
+				$success = $results !== false ? $success : false;
2119
+				// remove this event from the list of events with no prices
2120
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2121
+			} else {
2122
+				$success = false;
2123
+				$msg = esc_html__(
2124
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2125
+					'event_espresso'
2126
+				);
2127
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2128
+			}
2129
+		}
2130
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2131
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2132
+		$success = $success ? 2 : false;
2133
+		$this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2134
+	}
2135
+
2136
+
2137
+
2138
+	/**
2139
+	 * _permanently_delete_event
2140
+	 *
2141
+	 * @access  private
2142
+	 * @param  int $EVT_ID
2143
+	 * @return bool
2144
+	 */
2145
+	private function _permanently_delete_event($EVT_ID = 0)
2146
+	{
2147
+		// grab event id
2148
+		if ( ! $EVT_ID) {
2149
+			$msg = esc_html__(
2150
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2151
+				'event_espresso'
2152
+			);
2153
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2154
+			return false;
2155
+		}
2156
+		if (
2157
+			! $this->_cpt_model_obj instanceof EE_Event
2158
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2159
+		) {
2160
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2161
+		}
2162
+		if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2163
+			return false;
2164
+		}
2165
+		//need to delete related tickets and prices first.
2166
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2167
+		foreach ($datetimes as $datetime) {
2168
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2169
+			$tickets = $datetime->get_many_related('Ticket');
2170
+			foreach ($tickets as $ticket) {
2171
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2172
+				$ticket->delete_related_permanently('Price');
2173
+				$ticket->delete_permanently();
2174
+			}
2175
+			$datetime->delete();
2176
+		}
2177
+		//what about related venues or terms?
2178
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2179
+		foreach ($venues as $venue) {
2180
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2181
+		}
2182
+		//any attached question groups?
2183
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2184
+		if ( ! empty($question_groups)) {
2185
+			foreach ($question_groups as $question_group) {
2186
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2187
+			}
2188
+		}
2189
+		//Message Template Groups
2190
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2191
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2192
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2193
+		foreach ($term_taxonomies as $term_taxonomy) {
2194
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2195
+		}
2196
+		$success = $this->_cpt_model_obj->delete_permanently();
2197
+		// did it all go as planned ?
2198
+		if ($success) {
2199
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2200
+			EE_Error::add_success($msg);
2201
+		} else {
2202
+			$msg = sprintf(
2203
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2204
+				$EVT_ID
2205
+			);
2206
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2207
+			return false;
2208
+		}
2209
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2210
+		return true;
2211
+	}
2212
+
2213
+
2214
+
2215
+	/**
2216
+	 * get total number of events
2217
+	 *
2218
+	 * @access public
2219
+	 * @return int
2220
+	 */
2221
+	public function total_events()
2222
+	{
2223
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2224
+		return $count;
2225
+	}
2226
+
2227
+
2228
+
2229
+	/**
2230
+	 * get total number of draft events
2231
+	 *
2232
+	 * @access public
2233
+	 * @return int
2234
+	 */
2235
+	public function total_events_draft()
2236
+	{
2237
+		$where = array(
2238
+			'status' => array('IN', array('draft', 'auto-draft')),
2239
+		);
2240
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2241
+		return $count;
2242
+	}
2243
+
2244
+
2245
+
2246
+	/**
2247
+	 * get total number of trashed events
2248
+	 *
2249
+	 * @access public
2250
+	 * @return int
2251
+	 */
2252
+	public function total_trashed_events()
2253
+	{
2254
+		$where = array(
2255
+			'status' => 'trash',
2256
+		);
2257
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2258
+		return $count;
2259
+	}
2260
+
2261
+
2262
+	/**
2263
+	 *    _default_event_settings
2264
+	 *    This generates the Default Settings Tab
2265
+	 *
2266
+	 * @return void
2267
+	 * @throws EE_Error
2268
+	 */
2269
+	protected function _default_event_settings()
2270
+	{
2271
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2272
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2273
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2274
+		$this->display_admin_page_with_sidebar();
2275
+	}
2276
+
2277
+
2278
+	/**
2279
+	 * Return the form for event settings.
2280
+	 * @return EE_Form_Section_Proper
2281
+	 */
2282
+	protected function _default_event_settings_form()
2283
+	{
2284
+		$registration_config = EE_Registry::instance()->CFG->registration;
2285
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2286
+		//exclude
2287
+			array(
2288
+				EEM_Registration::status_id_cancelled,
2289
+				EEM_Registration::status_id_declined,
2290
+				EEM_Registration::status_id_incomplete,
2291
+				EEM_Registration::status_id_wait_list,
2292
+			),
2293
+			true
2294
+		);
2295
+		return new EE_Form_Section_Proper(
2296
+			array(
2297
+				'name' => 'update_default_event_settings',
2298
+				'html_id' => 'update_default_event_settings',
2299
+				'html_class' => 'form-table',
2300
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2301
+				'subsections' => apply_filters(
2302
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2303
+					array(
2304
+						'default_reg_status' => new EE_Select_Input(
2305
+							$registration_stati_for_selection,
2306
+							array(
2307
+								'default' => isset($registration_config->default_STS_ID)
2308
+											 && array_key_exists(
2309
+												$registration_config->default_STS_ID,
2310
+												$registration_stati_for_selection
2311
+											 )
2312
+											? sanitize_text_field($registration_config->default_STS_ID)
2313
+											: EEM_Registration::status_id_pending_payment,
2314
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2315
+													. EEH_Template::get_help_tab_link(
2316
+														'default_settings_status_help_tab'
2317
+													),
2318
+								'html_help_text' => esc_html__(
2319
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2320
+									'event_espresso'
2321
+								)
2322
+							)
2323
+						),
2324
+						'default_max_tickets' => new EE_Integer_Input(
2325
+							array(
2326
+								'default' => isset($registration_config->default_maximum_number_of_tickets)
2327
+									? $registration_config->default_maximum_number_of_tickets
2328
+									: EEM_Event::get_default_additional_limit(),
2329
+								'html_label_text' => esc_html__(
2330
+									'Default Maximum Tickets Allowed Per Order:',
2331
+									'event_espresso'
2332
+								) . EEH_Template::get_help_tab_link(
2333
+									'default_maximum_tickets_help_tab"'
2334
+									),
2335
+								'html_help_text' => esc_html__(
2336
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2337
+									'event_espresso'
2338
+								)
2339
+							)
2340
+						)
2341
+					)
2342
+				)
2343
+			)
2344
+		);
2345
+	}
2346
+
2347
+
2348
+	/**
2349
+	 * _update_default_event_settings
2350
+	 *
2351
+	 * @access protected
2352
+	 * @return void
2353
+	 * @throws EE_Error
2354
+	 */
2355
+	protected function _update_default_event_settings()
2356
+	{
2357
+		$registration_config = EE_Registry::instance()->CFG->registration;
2358
+		$form = $this->_default_event_settings_form();
2359
+		if ($form->was_submitted()) {
2360
+			$form->receive_form_submission();
2361
+			if ($form->is_valid()) {
2362
+				$valid_data = $form->valid_data();
2363
+				if (isset($valid_data['default_reg_status'])) {
2364
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2365
+				}
2366
+				if (isset($valid_data['default_max_tickets'])) {
2367
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2368
+				}
2369
+				//update because data was valid!
2370
+				EE_Registry::instance()->CFG->update_espresso_config();
2371
+				EE_Error::overwrite_success();
2372
+				EE_Error::add_success(
2373
+					__('Default Event Settings were updated', 'event_espresso')
2374
+				);
2375
+			}
2376
+		}
2377
+		$this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2378
+	}
2379
+
2380
+
2381
+
2382
+	/*************        Templates        *************/
2383
+	protected function _template_settings()
2384
+	{
2385
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2386
+		$this->_template_args['preview_img'] = '<img src="'
2387
+											   . EVENTS_ASSETS_URL
2388
+											   . DS
2389
+											   . 'images'
2390
+											   . DS
2391
+											   . 'caffeinated_template_features.jpg" alt="'
2392
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2393
+											   . '" />';
2394
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__(
2395
+				'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2396
+				'event_espresso'
2397
+			) . '</strong>';
2398
+		$this->display_admin_caf_preview_page('template_settings_tab');
2399
+	}
2400
+
2401
+
2402
+	/** Event Category Stuff **/
2403
+	/**
2404
+	 * set the _category property with the category object for the loaded page.
2405
+	 *
2406
+	 * @access private
2407
+	 * @return void
2408
+	 */
2409
+	private function _set_category_object()
2410
+	{
2411
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2412
+			return;
2413
+		} //already have the category object so get out.
2414
+		//set default category object
2415
+		$this->_set_empty_category_object();
2416
+		//only set if we've got an id
2417
+		if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2418
+			return;
2419
+		}
2420
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2421
+		$term = get_term($category_id, 'espresso_event_categories');
2422
+		if ( ! empty($term)) {
2423
+			$this->_category->category_name = $term->name;
2424
+			$this->_category->category_identifier = $term->slug;
2425
+			$this->_category->category_desc = $term->description;
2426
+			$this->_category->id = $term->term_id;
2427
+			$this->_category->parent = $term->parent;
2428
+		}
2429
+	}
2430
+
2431
+
2432
+	/**
2433
+	 * Clears out category properties.
2434
+	 */
2435
+	private function _set_empty_category_object()
2436
+	{
2437
+		$this->_category = new stdClass();
2438
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2439
+		$this->_category->id = $this->_category->parent = 0;
2440
+	}
2441
+
2442
+
2443
+	/**
2444
+	 * @throws EE_Error
2445
+	 */
2446
+	protected function _category_list_table()
2447
+	{
2448
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2449
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2450
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2451
+				'add_category',
2452
+				'add_category',
2453
+				array(),
2454
+				'add-new-h2'
2455
+			);
2456
+		$this->display_admin_list_table_page_with_sidebar();
2457
+	}
2458
+
2459
+
2460
+
2461
+	/**
2462
+	 * Output category details view.
2463
+	 */
2464
+	protected function _category_details($view)
2465
+	{
2466
+		//load formatter helper
2467
+		//load field generator helper
2468
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2469
+		$this->_set_add_edit_form_tags($route);
2470
+		$this->_set_category_object();
2471
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2472
+		$delete_action = 'delete_category';
2473
+		//custom redirect
2474
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2475
+			array('action' => 'category_list'),
2476
+			$this->_admin_base_url
2477
+		);
2478
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2479
+		//take care of contents
2480
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2481
+		$this->display_admin_page_with_sidebar();
2482
+	}
2483
+
2484
+
2485
+
2486
+	/**
2487
+	 * Output category details content.
2488
+	 */
2489
+	protected function _category_details_content()
2490
+	{
2491
+		$editor_args['category_desc'] = array(
2492
+			'type'          => 'wp_editor',
2493
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2494
+			'class'         => 'my_editor_custom',
2495
+			'wpeditor_args' => array('media_buttons' => false),
2496
+		);
2497
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2498
+		$all_terms = get_terms(
2499
+			array('espresso_event_categories'),
2500
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2501
+		);
2502
+		//setup category select for term parents.
2503
+		$category_select_values[] = array(
2504
+			'text' => esc_html__('No Parent', 'event_espresso'),
2505
+			'id'   => 0,
2506
+		);
2507
+		foreach ($all_terms as $term) {
2508
+			$category_select_values[] = array(
2509
+				'text' => $term->name,
2510
+				'id'   => $term->term_id,
2511
+			);
2512
+		}
2513
+		$category_select = EEH_Form_Fields::select_input(
2514
+			'category_parent',
2515
+			$category_select_values,
2516
+			$this->_category->parent
2517
+		);
2518
+		$template_args = array(
2519
+			'category'                 => $this->_category,
2520
+			'category_select'          => $category_select,
2521
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2522
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2523
+			'disable'                  => '',
2524
+			'disabled_message'         => false,
2525
+		);
2526
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2527
+		return EEH_Template::display_template($template, $template_args, true);
2528
+	}
2529
+
2530
+
2531
+	/**
2532
+	 * Handles deleting categories.
2533
+	 */
2534
+	protected function _delete_categories()
2535
+	{
2536
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2537
+			: (array)$this->_req_data['category_id'];
2538
+		foreach ($cat_ids as $cat_id) {
2539
+			$this->_delete_category($cat_id);
2540
+		}
2541
+		//doesn't matter what page we're coming from... we're going to the same place after delete.
2542
+		$query_args = array(
2543
+			'action' => 'category_list',
2544
+		);
2545
+		$this->_redirect_after_action(0, '', '', $query_args);
2546
+	}
2547
+
2548
+
2549
+
2550
+	/**
2551
+	 * Handles deleting specific category.
2552
+	 * @param int $cat_id
2553
+	 */
2554
+	protected function _delete_category($cat_id)
2555
+	{
2556
+		$cat_id = absint($cat_id);
2557
+		wp_delete_term($cat_id, 'espresso_event_categories');
2558
+	}
2559
+
2560
+
2561
+
2562
+	/**
2563
+	 * Handles triggering the update or insertion of a new category.
2564
+	 * @param bool $new_category  true means we're triggering the insert of a new category.
2565
+	 */
2566
+	protected function _insert_or_update_category($new_category)
2567
+	{
2568
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2569
+		$success = 0; //we already have a success message so lets not send another.
2570
+		if ($cat_id) {
2571
+			$query_args = array(
2572
+				'action'     => 'edit_category',
2573
+				'EVT_CAT_ID' => $cat_id,
2574
+			);
2575
+		} else {
2576
+			$query_args = array('action' => 'add_category');
2577
+		}
2578
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2579
+	}
2580
+
2581
+
2582
+
2583
+	/**
2584
+	 * Inserts or updates category
2585
+	 * @param bool $update (true indicates we're updating a category).
2586
+	 * @return bool|mixed|string
2587
+	 */
2588
+	private function _insert_category($update = false)
2589
+	{
2590
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2591
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2592
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2593
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2594
+		if (empty($category_name)) {
2595
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2596
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2597
+			return false;
2598
+		}
2599
+		$term_args = array(
2600
+			'name'        => $category_name,
2601
+			'description' => $category_desc,
2602
+			'parent'      => $category_parent,
2603
+		);
2604
+		//was the category_identifier input disabled?
2605
+		if (isset($this->_req_data['category_identifier'])) {
2606
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2607
+		}
2608
+		$insert_ids = $update
2609
+			? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2610
+			: wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2611
+		if ( ! is_array($insert_ids)) {
2612
+			$msg = esc_html__(
2613
+				'An error occurred and the category has not been saved to the database.',
2614
+				'event_espresso'
2615
+			);
2616
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2617
+		} else {
2618
+			$cat_id = $insert_ids['term_id'];
2619
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2620
+			EE_Error::add_success($msg);
2621
+		}
2622
+		return $cat_id;
2623
+	}
2624
+
2625
+
2626
+
2627
+	/**
2628
+	 * Gets categories or count of categories matching the arguments in the request.
2629
+	 * @param int  $per_page
2630
+	 * @param int  $current_page
2631
+	 * @param bool $count
2632
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2633
+	 */
2634
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2635
+	{
2636
+		//testing term stuff
2637
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2638
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2639
+		$limit = ($current_page - 1) * $per_page;
2640
+		$where = array('taxonomy' => 'espresso_event_categories');
2641
+		if (isset($this->_req_data['s'])) {
2642
+			$sstr = '%' . $this->_req_data['s'] . '%';
2643
+			$where['OR'] = array(
2644
+				'Term.name'   => array('LIKE', $sstr),
2645
+				'description' => array('LIKE', $sstr),
2646
+			);
2647
+		}
2648
+		$query_params = array(
2649
+			$where,
2650
+			'order_by'   => array($orderby => $order),
2651
+			'limit'      => $limit . ',' . $per_page,
2652
+			'force_join' => array('Term'),
2653
+		);
2654
+		$categories = $count
2655
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2656
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2657
+		return $categories;
2658
+	}
2659
+
2660
+	/* end category stuff */
2661
+	/**************/
2662
+
2663
+
2664
+	/**
2665
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2666
+	 * @throws EE_Error
2667
+	 */
2668
+	public function save_timezonestring_setting()
2669
+	{
2670
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2671
+			? $this->_req_data['timezone_selected']
2672
+			: '';
2673
+		if  (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2674
+		{
2675
+			EE_Error::add_error(
2676
+				esc_html('An invalid timezone string submitted.', 'event_espresso'),
2677
+				__FILE__, __FUNCTION__, __LINE__
2678
+			);
2679
+			$this->_template_args['error'] = true;
2680
+			$this->_return_json();
2681
+		}
2682
+
2683
+		update_option('timezone_string', $timezone_string);
2684
+		EE_Error::add_success(
2685
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2686
+		);
2687
+		$this->_template_args['success'] = true;
2688
+		$this->_return_json(true, array('action' => 'create_new'));
2689
+	}
2690 2690
 }
2691 2691
 //end class Events_Admin_Page
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -553,11 +553,11 @@  discard block
 block discarded – undo
553 553
     {
554 554
         wp_register_style(
555 555
             'events-admin-css',
556
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
556
+            EVENTS_ASSETS_URL.'events-admin-page.css',
557 557
             array(),
558 558
             EVENT_ESPRESSO_VERSION
559 559
         );
560
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
560
+        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
561 561
         wp_enqueue_style('events-admin-css');
562 562
         wp_enqueue_style('ee-cat-admin');
563 563
         //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
         //scripts
566 566
         wp_register_script(
567 567
             'event_editor_js',
568
-            EVENTS_ASSETS_URL . 'event_editor.js',
568
+            EVENTS_ASSETS_URL.'event_editor.js',
569 569
             array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
570 570
             EVENT_ESPRESSO_VERSION,
571 571
             true
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
         wp_enqueue_style('espresso-ui-theme');
594 594
         wp_register_style(
595 595
             'event-editor-css',
596
-            EVENTS_ASSETS_URL . 'event-editor.css',
596
+            EVENTS_ASSETS_URL.'event-editor.css',
597 597
             array('ee-admin-css'),
598 598
             EVENT_ESPRESSO_VERSION
599 599
         );
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
         //scripts
602 602
         wp_register_script(
603 603
             'event-datetime-metabox',
604
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
604
+            EVENTS_ASSETS_URL.'event-datetime-metabox.js',
605 605
             array('event_editor_js', 'ee-datepicker'),
606 606
             EVENT_ESPRESSO_VERSION
607 607
         );
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
             $event = $this->_cpt_model_obj;
674 674
         }
675 675
         // STILL no event?
676
-        if (! $event instanceof EE_Event) {
676
+        if ( ! $event instanceof EE_Event) {
677 677
             return;
678 678
         }
679 679
         $orig_status = $event->status();
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
     {
756 756
         $has_timezone_string = get_option('timezone_string');
757 757
         //only nag them about setting their timezone if it's their first event, and they haven't already done it
758
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
758
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
759 759
             EE_Error::add_attention(
760 760
                 sprintf(
761 761
                     __(
@@ -839,31 +839,31 @@  discard block
 block discarded – undo
839 839
         $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
840 840
         $statuses = array(
841 841
             'sold_out_status'  => array(
842
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
842
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
843 843
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
844 844
             ),
845 845
             'active_status'    => array(
846
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
846
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
847 847
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
848 848
             ),
849 849
             'upcoming_status'  => array(
850
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
850
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
851 851
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
852 852
             ),
853 853
             'postponed_status' => array(
854
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
854
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
855 855
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
856 856
             ),
857 857
             'cancelled_status' => array(
858
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
858
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
859 859
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
860 860
             ),
861 861
             'expired_status'   => array(
862
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
862
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
863 863
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
864 864
             ),
865 865
             'inactive_status'  => array(
866
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
866
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
867 867
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
868 868
             ),
869 869
         );
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
     {
926 926
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
927 927
         $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
928
-            ? (array)$this->_template_args['after_list_table']
928
+            ? (array) $this->_template_args['after_list_table']
929 929
             : array();
930 930
         $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
931 931
                                                                               . EEH_Template::get_button_or_link(
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
                 'button'
935 935
             );
936 936
         $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
937
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
937
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
938 938
                 'create_new',
939 939
                 'add',
940 940
                 array(),
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
      */
1065 1065
     protected function _default_venue_update(\EE_Event $evtobj, $data)
1066 1066
     {
1067
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1067
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1068 1068
         $venue_model = EE_Registry::instance()->load_model('Venue');
1069 1069
         $rows_affected = null;
1070 1070
         $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
             if (empty($tkt['TKT_start_date'])) {
1189 1189
                 //let's use now in the set timezone.
1190 1190
                 $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1191
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1191
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1192 1192
             }
1193 1193
             if (empty($tkt['TKT_end_date'])) {
1194 1194
                 //use the start date of the first datetime
@@ -1467,7 +1467,7 @@  discard block
 block discarded – undo
1467 1467
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1468 1468
         // load template
1469 1469
         EEH_Template::display_template(
1470
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1470
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1471 1471
             $publish_box_extra_args
1472 1472
         );
1473 1473
     }
@@ -1594,7 +1594,7 @@  discard block
 block discarded – undo
1594 1594
         );
1595 1595
         $template = apply_filters(
1596 1596
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1597
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1597
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1598 1598
         );
1599 1599
         EEH_Template::display_template($template, $template_args);
1600 1600
     }
@@ -1613,7 +1613,7 @@  discard block
 block discarded – undo
1613 1613
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1614 1614
     {
1615 1615
         $template_args = array(
1616
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1616
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1617 1617
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1618 1618
                 : '',
1619 1619
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1667,7 +1667,7 @@  discard block
 block discarded – undo
1667 1667
         $template_args = array_merge($template_args, $price_args);
1668 1668
         $template = apply_filters(
1669 1669
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1670
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1670
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1671 1671
             $ticket
1672 1672
         );
1673 1673
         return EEH_Template::display_template($template, $template_args, true);
@@ -1721,7 +1721,7 @@  discard block
 block discarded – undo
1721 1721
             $default_reg_status_values
1722 1722
         );
1723 1723
         EEH_Template::display_template(
1724
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1724
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1725 1725
             $template_args
1726 1726
         );
1727 1727
     }
@@ -1744,7 +1744,7 @@  discard block
 block discarded – undo
1744 1744
     {
1745 1745
         $EEME = $this->_event_model();
1746 1746
         $offset = ($current_page - 1) * $per_page;
1747
-        $limit = $count ? null : $offset . ',' . $per_page;
1747
+        $limit = $count ? null : $offset.','.$per_page;
1748 1748
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1749 1749
         $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1750 1750
         if (isset($this->_req_data['month_range'])) {
@@ -1781,7 +1781,7 @@  discard block
 block discarded – undo
1781 1781
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1782 1782
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1783 1783
             $DateTime = new DateTime(
1784
-                $year_r . '-' . $month_r . '-01 00:00:00',
1784
+                $year_r.'-'.$month_r.'-01 00:00:00',
1785 1785
                 new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1786 1786
             );
1787 1787
             $start = $DateTime->format(implode(' ', $start_formats));
@@ -1827,7 +1827,7 @@  discard block
 block discarded – undo
1827 1827
         }
1828 1828
         //search query handling
1829 1829
         if (isset($this->_req_data['s'])) {
1830
-            $search_string = '%' . $this->_req_data['s'] . '%';
1830
+            $search_string = '%'.$this->_req_data['s'].'%';
1831 1831
             $where['OR'] = array(
1832 1832
                 'EVT_name'       => array('LIKE', $search_string),
1833 1833
                 'EVT_desc'       => array('LIKE', $search_string),
@@ -1961,7 +1961,7 @@  discard block
 block discarded – undo
1961 1961
         if ( ! empty($event_status)) {
1962 1962
             $success = true;
1963 1963
             //determine the event id and set to array.
1964
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1964
+            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1965 1965
             // loop thru events
1966 1966
             foreach ($EVT_IDs as $EVT_ID) {
1967 1967
                 if ($EVT_ID = absint($EVT_ID)) {
@@ -2109,7 +2109,7 @@  discard block
 block discarded – undo
2109 2109
         // get list of events with no prices
2110 2110
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2111 2111
         //determine the event id and set to array.
2112
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2112
+        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
2113 2113
         // loop thru events
2114 2114
         foreach ($EVT_IDs as $EVT_ID) {
2115 2115
             $EVT_ID = absint($EVT_ID);
@@ -2329,7 +2329,7 @@  discard block
 block discarded – undo
2329 2329
                                 'html_label_text' => esc_html__(
2330 2330
                                     'Default Maximum Tickets Allowed Per Order:',
2331 2331
                                     'event_espresso'
2332
-                                ) . EEH_Template::get_help_tab_link(
2332
+                                ).EEH_Template::get_help_tab_link(
2333 2333
                                     'default_maximum_tickets_help_tab"'
2334 2334
                                     ),
2335 2335
                                 'html_help_text' => esc_html__(
@@ -2391,10 +2391,10 @@  discard block
 block discarded – undo
2391 2391
                                                . 'caffeinated_template_features.jpg" alt="'
2392 2392
                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2393 2393
                                                . '" />';
2394
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2394
+        $this->_template_args['preview_text'] = '<strong>'.esc_html__(
2395 2395
                 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2396 2396
                 'event_espresso'
2397
-            ) . '</strong>';
2397
+            ).'</strong>';
2398 2398
         $this->display_admin_caf_preview_page('template_settings_tab');
2399 2399
     }
2400 2400
 
@@ -2447,7 +2447,7 @@  discard block
 block discarded – undo
2447 2447
     {
2448 2448
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2449 2449
         $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2450
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2450
+        $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
2451 2451
                 'add_category',
2452 2452
                 'add_category',
2453 2453
                 array(),
@@ -2523,7 +2523,7 @@  discard block
 block discarded – undo
2523 2523
             'disable'                  => '',
2524 2524
             'disabled_message'         => false,
2525 2525
         );
2526
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2526
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2527 2527
         return EEH_Template::display_template($template, $template_args, true);
2528 2528
     }
2529 2529
 
@@ -2533,8 +2533,8 @@  discard block
 block discarded – undo
2533 2533
      */
2534 2534
     protected function _delete_categories()
2535 2535
     {
2536
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2537
-            : (array)$this->_req_data['category_id'];
2536
+        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2537
+            : (array) $this->_req_data['category_id'];
2538 2538
         foreach ($cat_ids as $cat_id) {
2539 2539
             $this->_delete_category($cat_id);
2540 2540
         }
@@ -2639,7 +2639,7 @@  discard block
 block discarded – undo
2639 2639
         $limit = ($current_page - 1) * $per_page;
2640 2640
         $where = array('taxonomy' => 'espresso_event_categories');
2641 2641
         if (isset($this->_req_data['s'])) {
2642
-            $sstr = '%' . $this->_req_data['s'] . '%';
2642
+            $sstr = '%'.$this->_req_data['s'].'%';
2643 2643
             $where['OR'] = array(
2644 2644
                 'Term.name'   => array('LIKE', $sstr),
2645 2645
                 'description' => array('LIKE', $sstr),
@@ -2648,7 +2648,7 @@  discard block
 block discarded – undo
2648 2648
         $query_params = array(
2649 2649
             $where,
2650 2650
             'order_by'   => array($orderby => $order),
2651
-            'limit'      => $limit . ',' . $per_page,
2651
+            'limit'      => $limit.','.$per_page,
2652 2652
             'force_join' => array('Term'),
2653 2653
         );
2654 2654
         $categories = $count
@@ -2670,7 +2670,7 @@  discard block
 block discarded – undo
2670 2670
         $timezone_string = isset($this->_req_data['timezone_selected'])
2671 2671
             ? $this->_req_data['timezone_selected']
2672 2672
             : '';
2673
-        if  (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2673
+        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false))
2674 2674
         {
2675 2675
             EE_Error::add_error(
2676 2676
                 esc_html('An invalid timezone string submitted.', 'event_espresso'),
Please login to merge, or discard this patch.