Completed
Branch db-repair-tool (5be9a7)
by
unknown
13:43 queued 07:31
created
modules/batch/templates/batch_wrapper.template.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,5 +4,5 @@
 block discarded – undo
4 4
 if( $batch_request_type == EED_Batch::batch_job ) {
5 5
 	require( 'batch_runner.template.php' );
6 6
 } elseif( $batch_request_type == EED_Batch::batch_file_job ) {
7
-    require( 'batch_file_runner.template.php' );
7
+	require( 'batch_file_runner.template.php' );
8 8
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 //just makes the template conditional on the batch request type
3 3
 $batch_request_type = EED_Batch::instance()->batch_request_type();
4
-if( $batch_request_type == EED_Batch::batch_job ) {
5
-	require( 'batch_runner.template.php' );
6
-} elseif( $batch_request_type == EED_Batch::batch_file_job ) {
7
-    require( 'batch_file_runner.template.php' );
4
+if ($batch_request_type == EED_Batch::batch_job) {
5
+	require('batch_runner.template.php');
6
+} elseif ($batch_request_type == EED_Batch::batch_file_job) {
7
+    require('batch_file_runner.template.php');
8 8
 }
Please login to merge, or discard this patch.
modules/batch/templates/batch_frontend_wrapper.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2 2
 //wraps the template in the typical wordpress header and footer
3 3
 get_header();
4
-require( 'batch_wrapper.template.php');
4
+require('batch_wrapper.template.php');
5 5
 get_footer();
Please login to merge, or discard this patch.
modules/batch/templates/batch_runner.template.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 <div class="ee-batch-runner__wrapper ee-admin-container">
6 6
 	<div class="padding">
7
-		<h1><?php esc_html_e( 'Running Batch Job...', 'event_espresso' );?></h1>
7
+		<h1><?php esc_html_e('Running Batch Job...', 'event_espresso'); ?></h1>
8 8
 		<div class="progress-bar-wrapper">
9 9
 			<div id='batch-progress' class='progress-responsive'></div>
10 10
 			<label><?php esc_html_e('progress', 'event_espresso'); ?></label>
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2907 added lines, -2907 removed lines patch added patch discarded remove patch
@@ -16,2914 +16,2914 @@
 block discarded – undo
16 16
  */
17 17
 class Events_Admin_Page extends EE_Admin_Page_CPT
18 18
 {
19
-    /**
20
-     * This will hold the event object for event_details screen.
19
+	/**
20
+	 * This will hold the event object for event_details screen.
21
+	 *
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
+	 * @var EE_Event
45
+	 */
46
+	protected $_cpt_model_obj = false;
47
+
48
+
49
+	/**
50
+	 * @var NodeGroupDao
51
+	 */
52
+	protected $model_obj_node_group_persister;
53
+
54
+	/**
55
+	 * @var AdvancedEditorAdminFormSection
56
+	 */
57
+	protected $advanced_editor_admin_form;
58
+
59
+
60
+	/**
61
+	 * Initialize page props for this admin page group.
62
+	 */
63
+	protected function _init_page_props()
64
+	{
65
+		$this->page_slug        = EVENTS_PG_SLUG;
66
+		$this->page_label       = EVENTS_LABEL;
67
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
68
+		$this->_admin_base_path = EVENTS_ADMIN;
69
+		$this->_cpt_model_names = [
70
+			'create_new' => 'EEM_Event',
71
+			'edit'       => 'EEM_Event',
72
+		];
73
+		$this->_cpt_edit_routes = [
74
+			'espresso_events' => 'edit',
75
+		];
76
+		add_action(
77
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
78
+			[$this, 'verify_event_edit'],
79
+			10,
80
+			2
81
+		);
82
+	}
83
+
84
+
85
+	/**
86
+	 * Sets the ajax hooks used for this admin page group.
87
+	 */
88
+	protected function _ajax_hooks()
89
+	{
90
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Sets the page properties for this admin page group.
96
+	 */
97
+	protected function _define_page_props()
98
+	{
99
+		$this->_admin_page_title = EVENTS_LABEL;
100
+		$this->_labels           = [
101
+			'buttons'      => [
102
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
103
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
104
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
105
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
106
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
107
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
108
+			],
109
+			'editor_title' => [
110
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
111
+			],
112
+			'publishbox'   => [
113
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
114
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
115
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
116
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
117
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
118
+			],
119
+		];
120
+	}
121
+
122
+
123
+	/**
124
+	 * Sets the page routes property for this admin page group.
125
+	 */
126
+	protected function _set_page_routes()
127
+	{
128
+		// load formatter helper
129
+		// load field generator helper
130
+		// is there a evt_id in the request?
131
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
132
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
133
+
134
+		$this->_page_routes = [
135
+			'default'                       => [
136
+				'func'       => '_events_overview_list_table',
137
+				'capability' => 'ee_read_events',
138
+			],
139
+			'create_new'                    => [
140
+				'func'       => '_create_new_cpt_item',
141
+				'capability' => 'ee_edit_events',
142
+			],
143
+			'edit'                          => [
144
+				'func'       => '_edit_cpt_item',
145
+				'capability' => 'ee_edit_event',
146
+				'obj_id'     => $EVT_ID,
147
+			],
148
+			'copy_event'                    => [
149
+				'func'       => '_copy_events',
150
+				'capability' => 'ee_edit_event',
151
+				'obj_id'     => $EVT_ID,
152
+				'noheader'   => true,
153
+			],
154
+			'trash_event'                   => [
155
+				'func'       => '_trash_or_restore_event',
156
+				'args'       => ['event_status' => 'trash'],
157
+				'capability' => 'ee_delete_event',
158
+				'obj_id'     => $EVT_ID,
159
+				'noheader'   => true,
160
+			],
161
+			'trash_events'                  => [
162
+				'func'       => '_trash_or_restore_events',
163
+				'args'       => ['event_status' => 'trash'],
164
+				'capability' => 'ee_delete_events',
165
+				'noheader'   => true,
166
+			],
167
+			'restore_event'                 => [
168
+				'func'       => '_trash_or_restore_event',
169
+				'args'       => ['event_status' => 'draft'],
170
+				'capability' => 'ee_delete_event',
171
+				'obj_id'     => $EVT_ID,
172
+				'noheader'   => true,
173
+			],
174
+			'restore_events'                => [
175
+				'func'       => '_trash_or_restore_events',
176
+				'args'       => ['event_status' => 'draft'],
177
+				'capability' => 'ee_delete_events',
178
+				'noheader'   => true,
179
+			],
180
+			'delete_event'                  => [
181
+				'func'       => '_delete_event',
182
+				'capability' => 'ee_delete_event',
183
+				'obj_id'     => $EVT_ID,
184
+				'noheader'   => true,
185
+			],
186
+			'delete_events'                 => [
187
+				'func'       => '_delete_events',
188
+				'capability' => 'ee_delete_events',
189
+				'noheader'   => true,
190
+			],
191
+			'view_report'                   => [
192
+				'func'       => '_view_report',
193
+				'capability' => 'ee_edit_events',
194
+			],
195
+			'default_event_settings'        => [
196
+				'func'       => '_default_event_settings',
197
+				'capability' => 'manage_options',
198
+			],
199
+			'update_default_event_settings' => [
200
+				'func'       => '_update_default_event_settings',
201
+				'capability' => 'manage_options',
202
+				'noheader'   => true,
203
+			],
204
+			'template_settings'             => [
205
+				'func'       => '_template_settings',
206
+				'capability' => 'manage_options',
207
+			],
208
+			// event category tab related
209
+			'add_category'                  => [
210
+				'func'       => '_category_details',
211
+				'capability' => 'ee_edit_event_category',
212
+				'args'       => ['add'],
213
+			],
214
+			'edit_category'                 => [
215
+				'func'       => '_category_details',
216
+				'capability' => 'ee_edit_event_category',
217
+				'args'       => ['edit'],
218
+			],
219
+			'delete_categories'             => [
220
+				'func'       => '_delete_categories',
221
+				'capability' => 'ee_delete_event_category',
222
+				'noheader'   => true,
223
+			],
224
+			'delete_category'               => [
225
+				'func'       => '_delete_categories',
226
+				'capability' => 'ee_delete_event_category',
227
+				'noheader'   => true,
228
+			],
229
+			'insert_category'               => [
230
+				'func'       => '_insert_or_update_category',
231
+				'args'       => ['new_category' => true],
232
+				'capability' => 'ee_edit_event_category',
233
+				'noheader'   => true,
234
+			],
235
+			'update_category'               => [
236
+				'func'       => '_insert_or_update_category',
237
+				'args'       => ['new_category' => false],
238
+				'capability' => 'ee_edit_event_category',
239
+				'noheader'   => true,
240
+			],
241
+			'category_list'                 => [
242
+				'func'       => '_category_list_table',
243
+				'capability' => 'ee_manage_event_categories',
244
+			],
245
+			'preview_deletion'              => [
246
+				'func'       => 'previewDeletion',
247
+				'capability' => 'ee_delete_events',
248
+			],
249
+			'confirm_deletion'              => [
250
+				'func'       => 'confirmDeletion',
251
+				'capability' => 'ee_delete_events',
252
+				'noheader'   => true,
253
+			],
254
+		];
255
+	}
256
+
257
+
258
+	/**
259
+	 * Set the _page_config property for this admin page group.
260
+	 */
261
+	protected function _set_page_config()
262
+	{
263
+		$post_id            = $this->request->getRequestParam('post', 0, 'int');
264
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
265
+		$this->_page_config = [
266
+			'default'                => [
267
+				'nav'           => [
268
+					'label' => esc_html__('Overview', 'event_espresso'),
269
+					'order' => 10,
270
+				],
271
+				'list_table'    => 'Events_Admin_List_Table',
272
+				'help_tabs'     => [
273
+					'events_overview_help_tab'                       => [
274
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
275
+						'filename' => 'events_overview',
276
+					],
277
+					'events_overview_table_column_headings_help_tab' => [
278
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
279
+						'filename' => 'events_overview_table_column_headings',
280
+					],
281
+					'events_overview_filters_help_tab'               => [
282
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
283
+						'filename' => 'events_overview_filters',
284
+					],
285
+					'events_overview_view_help_tab'                  => [
286
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
287
+						'filename' => 'events_overview_views',
288
+					],
289
+					'events_overview_other_help_tab'                 => [
290
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
291
+						'filename' => 'events_overview_other',
292
+					],
293
+				],
294
+				'require_nonce' => false,
295
+			],
296
+			'create_new'             => [
297
+				'nav'           => [
298
+					'label'      => esc_html__('Add New Event', 'event_espresso'),
299
+					'order'      => 5,
300
+					'persistent' => false,
301
+				],
302
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
303
+				'help_tabs'     => [
304
+					'event_editor_help_tab'                            => [
305
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
306
+						'filename' => 'event_editor',
307
+					],
308
+					'event_editor_title_richtexteditor_help_tab'       => [
309
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
310
+						'filename' => 'event_editor_title_richtexteditor',
311
+					],
312
+					'event_editor_venue_details_help_tab'              => [
313
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
314
+						'filename' => 'event_editor_venue_details',
315
+					],
316
+					'event_editor_event_datetimes_help_tab'            => [
317
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
318
+						'filename' => 'event_editor_event_datetimes',
319
+					],
320
+					'event_editor_event_tickets_help_tab'              => [
321
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
322
+						'filename' => 'event_editor_event_tickets',
323
+					],
324
+					'event_editor_event_registration_options_help_tab' => [
325
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
326
+						'filename' => 'event_editor_event_registration_options',
327
+					],
328
+					'event_editor_tags_categories_help_tab'            => [
329
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
330
+						'filename' => 'event_editor_tags_categories',
331
+					],
332
+					'event_editor_questions_registrants_help_tab'      => [
333
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
334
+						'filename' => 'event_editor_questions_registrants',
335
+					],
336
+					'event_editor_save_new_event_help_tab'             => [
337
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
338
+						'filename' => 'event_editor_save_new_event',
339
+					],
340
+					'event_editor_other_help_tab'                      => [
341
+						'title'    => esc_html__('Event Other', 'event_espresso'),
342
+						'filename' => 'event_editor_other',
343
+					],
344
+				],
345
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
346
+				'require_nonce' => false,
347
+			],
348
+			'edit'                   => [
349
+				'nav'           => [
350
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
351
+					'order'      => 5,
352
+					'persistent' => false,
353
+					'url'        => $post_id
354
+						? EE_Admin_Page::add_query_args_and_nonce(
355
+							['post' => $post_id, 'action' => 'edit'],
356
+							$this->_current_page_view_url
357
+						)
358
+						: $this->_admin_base_url,
359
+				],
360
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
361
+				'help_tabs'     => [
362
+					'event_editor_help_tab'                            => [
363
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
364
+						'filename' => 'event_editor',
365
+					],
366
+					'event_editor_title_richtexteditor_help_tab'       => [
367
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
368
+						'filename' => 'event_editor_title_richtexteditor',
369
+					],
370
+					'event_editor_venue_details_help_tab'              => [
371
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
372
+						'filename' => 'event_editor_venue_details',
373
+					],
374
+					'event_editor_event_datetimes_help_tab'            => [
375
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
376
+						'filename' => 'event_editor_event_datetimes',
377
+					],
378
+					'event_editor_event_tickets_help_tab'              => [
379
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
380
+						'filename' => 'event_editor_event_tickets',
381
+					],
382
+					'event_editor_event_registration_options_help_tab' => [
383
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
384
+						'filename' => 'event_editor_event_registration_options',
385
+					],
386
+					'event_editor_tags_categories_help_tab'            => [
387
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
388
+						'filename' => 'event_editor_tags_categories',
389
+					],
390
+					'event_editor_questions_registrants_help_tab'      => [
391
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
392
+						'filename' => 'event_editor_questions_registrants',
393
+					],
394
+					'event_editor_save_new_event_help_tab'             => [
395
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
396
+						'filename' => 'event_editor_save_new_event',
397
+					],
398
+					'event_editor_other_help_tab'                      => [
399
+						'title'    => esc_html__('Event Other', 'event_espresso'),
400
+						'filename' => 'event_editor_other',
401
+					],
402
+				],
403
+				'require_nonce' => false,
404
+			],
405
+			'default_event_settings' => [
406
+				'nav'           => [
407
+					'label' => esc_html__('Default Settings', 'event_espresso'),
408
+					'order' => 40,
409
+				],
410
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
411
+				'labels'        => [
412
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
413
+				],
414
+				'help_tabs'     => [
415
+					'default_settings_help_tab'        => [
416
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
417
+						'filename' => 'events_default_settings',
418
+					],
419
+					'default_settings_status_help_tab' => [
420
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
421
+						'filename' => 'events_default_settings_status',
422
+					],
423
+					'default_maximum_tickets_help_tab' => [
424
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
425
+						'filename' => 'events_default_settings_max_tickets',
426
+					],
427
+				],
428
+				'require_nonce' => false,
429
+			],
430
+			// template settings
431
+			'template_settings'      => [
432
+				'nav'           => [
433
+					'label' => esc_html__('Templates', 'event_espresso'),
434
+					'order' => 30,
435
+				],
436
+				'metaboxes'     => $this->_default_espresso_metaboxes,
437
+				'help_tabs'     => [
438
+					'general_settings_templates_help_tab' => [
439
+						'title'    => esc_html__('Templates', 'event_espresso'),
440
+						'filename' => 'general_settings_templates',
441
+					],
442
+				],
443
+				'require_nonce' => false,
444
+			],
445
+			// event category stuff
446
+			'add_category'           => [
447
+				'nav'           => [
448
+					'label'      => esc_html__('Add Category', 'event_espresso'),
449
+					'order'      => 15,
450
+					'persistent' => false,
451
+				],
452
+				'help_tabs'     => [
453
+					'add_category_help_tab' => [
454
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
455
+						'filename' => 'events_add_category',
456
+					],
457
+				],
458
+				'metaboxes'     => ['_publish_post_box'],
459
+				'require_nonce' => false,
460
+			],
461
+			'edit_category'          => [
462
+				'nav'           => [
463
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
464
+					'order'      => 15,
465
+					'persistent' => false,
466
+					'url'        => $EVT_CAT_ID
467
+						? add_query_arg(
468
+							['EVT_CAT_ID' => $EVT_CAT_ID],
469
+							$this->_current_page_view_url
470
+						)
471
+						: $this->_admin_base_url,
472
+				],
473
+				'help_tabs'     => [
474
+					'edit_category_help_tab' => [
475
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
476
+						'filename' => 'events_edit_category',
477
+					],
478
+				],
479
+				'metaboxes'     => ['_publish_post_box'],
480
+				'require_nonce' => false,
481
+			],
482
+			'category_list'          => [
483
+				'nav'           => [
484
+					'label' => esc_html__('Categories', 'event_espresso'),
485
+					'order' => 20,
486
+				],
487
+				'list_table'    => 'Event_Categories_Admin_List_Table',
488
+				'help_tabs'     => [
489
+					'events_categories_help_tab'                       => [
490
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
491
+						'filename' => 'events_categories',
492
+					],
493
+					'events_categories_table_column_headings_help_tab' => [
494
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
495
+						'filename' => 'events_categories_table_column_headings',
496
+					],
497
+					'events_categories_view_help_tab'                  => [
498
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
499
+						'filename' => 'events_categories_views',
500
+					],
501
+					'events_categories_other_help_tab'                 => [
502
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
503
+						'filename' => 'events_categories_other',
504
+					],
505
+				],
506
+				'metaboxes'     => $this->_default_espresso_metaboxes,
507
+				'require_nonce' => false,
508
+			],
509
+			'preview_deletion'       => [
510
+				'nav'           => [
511
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
512
+					'order'      => 15,
513
+					'persistent' => false,
514
+					'url'        => '',
515
+				],
516
+				'require_nonce' => false,
517
+			],
518
+		];
519
+	}
520
+
521
+
522
+	/**
523
+	 * Used to register any global screen options if necessary for every route in this admin page group.
524
+	 */
525
+	protected function _add_screen_options()
526
+	{
527
+	}
528
+
529
+
530
+	/**
531
+	 * Implementing the screen options for the 'default' route.
532
+	 *
533
+	 * @throws InvalidArgumentException
534
+	 * @throws InvalidDataTypeException
535
+	 * @throws InvalidInterfaceException
536
+	 */
537
+	protected function _add_screen_options_default()
538
+	{
539
+		$this->_per_page_screen_option();
540
+	}
541
+
542
+
543
+	/**
544
+	 * Implementing screen options for the category list route.
545
+	 *
546
+	 * @throws InvalidArgumentException
547
+	 * @throws InvalidDataTypeException
548
+	 * @throws InvalidInterfaceException
549
+	 */
550
+	protected function _add_screen_options_category_list()
551
+	{
552
+		$page_title              = $this->_admin_page_title;
553
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
554
+		$this->_per_page_screen_option();
555
+		$this->_admin_page_title = $page_title;
556
+	}
557
+
558
+
559
+	/**
560
+	 * Used to register any global feature pointers for the admin page group.
561
+	 */
562
+	protected function _add_feature_pointers()
563
+	{
564
+	}
565
+
566
+
567
+	/**
568
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
569
+	 */
570
+	public function load_scripts_styles()
571
+	{
572
+		wp_register_style(
573
+			'events-admin-css',
574
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
575
+			[],
576
+			EVENT_ESPRESSO_VERSION
577
+		);
578
+		wp_register_style(
579
+			'ee-cat-admin',
580
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
581
+			[],
582
+			EVENT_ESPRESSO_VERSION
583
+		);
584
+		wp_enqueue_style('events-admin-css');
585
+		wp_enqueue_style('ee-cat-admin');
586
+		// scripts
587
+		wp_register_script(
588
+			'event_editor_js',
589
+			EVENTS_ASSETS_URL . 'event_editor.js',
590
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
591
+			EVENT_ESPRESSO_VERSION,
592
+			true
593
+		);
594
+	}
595
+
596
+
597
+	/**
598
+	 * Enqueuing scripts and styles specific to this view
599
+	 */
600
+	public function load_scripts_styles_create_new()
601
+	{
602
+		$this->load_scripts_styles_edit();
603
+	}
604
+
605
+
606
+	/**
607
+	 * Enqueuing scripts and styles specific to this view
608
+	 */
609
+	public function load_scripts_styles_edit()
610
+	{
611
+		// styles
612
+		wp_enqueue_style('espresso-ui-theme');
613
+		wp_register_style(
614
+			'event-editor-css',
615
+			EVENTS_ASSETS_URL . 'event-editor.css',
616
+			['ee-admin-css'],
617
+			EVENT_ESPRESSO_VERSION
618
+		);
619
+		wp_enqueue_style('event-editor-css');
620
+		// scripts
621
+		if (! $this->admin_config->useAdvancedEditor()) {
622
+			wp_register_script(
623
+				'event-datetime-metabox',
624
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
625
+				['event_editor_js', 'ee-datepicker'],
626
+				EVENT_ESPRESSO_VERSION
627
+			);
628
+			wp_enqueue_script('event-datetime-metabox');
629
+		}
630
+	}
631
+
632
+
633
+	/**
634
+	 * Populating the _views property for the category list table view.
635
+	 */
636
+	protected function _set_list_table_views_category_list()
637
+	{
638
+		$this->_views = [
639
+			'all' => [
640
+				'slug'        => 'all',
641
+				'label'       => esc_html__('All', 'event_espresso'),
642
+				'count'       => 0,
643
+				'bulk_action' => [
644
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
645
+				],
646
+			],
647
+		];
648
+	}
649
+
650
+
651
+	/**
652
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
653
+	 */
654
+	public function admin_init()
655
+	{
656
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
657
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
658
+			'event_espresso'
659
+		);
660
+	}
661
+
662
+
663
+	/**
664
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
665
+	 * group.
666
+	 */
667
+	public function admin_notices()
668
+	{
669
+	}
670
+
671
+
672
+	/**
673
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
674
+	 * this admin page group.
675
+	 */
676
+	public function admin_footer_scripts()
677
+	{
678
+	}
679
+
680
+
681
+	/**
682
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
683
+	 * warning (via EE_Error::add_error());
684
+	 *
685
+	 * @param EE_Event $event Event object
686
+	 * @param string   $req_type
687
+	 * @return void
688
+	 * @throws EE_Error
689
+	 * @throws ReflectionException
690
+	 */
691
+	public function verify_event_edit($event = null, $req_type = '')
692
+	{
693
+		// don't need to do this when processing
694
+		if (! empty($req_type)) {
695
+			return;
696
+		}
697
+		// no event?
698
+		if (! $event instanceof EE_Event) {
699
+			$event = $this->_cpt_model_obj;
700
+		}
701
+		// STILL no event?
702
+		if (! $event instanceof EE_Event) {
703
+			return;
704
+		}
705
+		$orig_status = $event->status();
706
+		// first check if event is active.
707
+		if (
708
+			$orig_status === EEM_Event::cancelled
709
+			|| $orig_status === EEM_Event::postponed
710
+			|| $event->is_expired()
711
+			|| $event->is_inactive()
712
+		) {
713
+			return;
714
+		}
715
+		// made it here so it IS active... next check that any of the tickets are sold.
716
+		if ($event->is_sold_out(true)) {
717
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
718
+				EE_Error::add_attention(
719
+					sprintf(
720
+						esc_html__(
721
+							'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.',
722
+							'event_espresso'
723
+						),
724
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
725
+					)
726
+				);
727
+			}
728
+			return;
729
+		}
730
+		if ($orig_status === EEM_Event::sold_out) {
731
+			EE_Error::add_attention(
732
+				sprintf(
733
+					esc_html__(
734
+						'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.',
735
+						'event_espresso'
736
+					),
737
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
738
+				)
739
+			);
740
+		}
741
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
742
+		if (! $event->tickets_on_sale()) {
743
+			return;
744
+		}
745
+		// made it here so show warning
746
+		$this->_edit_event_warning();
747
+	}
748
+
749
+
750
+	/**
751
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
752
+	 * When needed, hook this into a EE_Error::add_error() notice.
753
+	 *
754
+	 * @access protected
755
+	 * @return void
756
+	 */
757
+	protected function _edit_event_warning()
758
+	{
759
+		// we don't want to add warnings during these requests
760
+		if ($this->request->getRequestParam('action') === 'editpost') {
761
+			return;
762
+		}
763
+		EE_Error::add_attention(
764
+			sprintf(
765
+				esc_html__(
766
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
767
+					'event_espresso'
768
+				),
769
+				'<a class="espresso-help-tab-lnk ee-help-tab-link">',
770
+				'</a>'
771
+			)
772
+		);
773
+	}
774
+
775
+
776
+	/**
777
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
778
+	 * Otherwise, do the normal logic
779
+	 *
780
+	 * @return void
781
+	 * @throws EE_Error
782
+	 * @throws InvalidArgumentException
783
+	 * @throws InvalidDataTypeException
784
+	 * @throws InvalidInterfaceException
785
+	 */
786
+	protected function _create_new_cpt_item()
787
+	{
788
+		$has_timezone_string = get_option('timezone_string');
789
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
790
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
791
+			EE_Error::add_attention(
792
+				sprintf(
793
+					esc_html__(
794
+						'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',
795
+						'event_espresso'
796
+					),
797
+					'<br>',
798
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
799
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
800
+					. '</select>',
801
+					'<button class="button button--secondary timezone-submit">',
802
+					'</button><span class="spinner"></span>'
803
+				),
804
+				__FILE__,
805
+				__FUNCTION__,
806
+				__LINE__
807
+			);
808
+		}
809
+		parent::_create_new_cpt_item();
810
+	}
811
+
812
+
813
+	/**
814
+	 * Sets the _views property for the default route in this admin page group.
815
+	 */
816
+	protected function _set_list_table_views_default()
817
+	{
818
+		$this->_views = [
819
+			'all'   => [
820
+				'slug'        => 'all',
821
+				'label'       => esc_html__('View All Events', 'event_espresso'),
822
+				'count'       => 0,
823
+				'bulk_action' => [
824
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
825
+				],
826
+			],
827
+			'draft' => [
828
+				'slug'        => 'draft',
829
+				'label'       => esc_html__('Draft', 'event_espresso'),
830
+				'count'       => 0,
831
+				'bulk_action' => [
832
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
833
+				],
834
+			],
835
+		];
836
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
837
+			$this->_views['trash'] = [
838
+				'slug'        => 'trash',
839
+				'label'       => esc_html__('Trash', 'event_espresso'),
840
+				'count'       => 0,
841
+				'bulk_action' => [
842
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
843
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
844
+				],
845
+			];
846
+		}
847
+	}
848
+
849
+
850
+	/**
851
+	 * Provides the legend item array for the default list table view.
852
+	 *
853
+	 * @return array
854
+	 * @throws EE_Error
855
+	 * @throws EE_Error
856
+	 */
857
+	protected function _event_legend_items()
858
+	{
859
+		$items    = [
860
+			'view_details'   => [
861
+				'class' => 'dashicons dashicons-visibility',
862
+				'desc'  => esc_html__('View Event', 'event_espresso'),
863
+			],
864
+			'edit_event'     => [
865
+				'class' => 'dashicons dashicons-calendar-alt',
866
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
867
+			],
868
+			'view_attendees' => [
869
+				'class' => 'dashicons dashicons-groups',
870
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
871
+			],
872
+		];
873
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
874
+		$statuses = [
875
+			'sold_out_status'  => [
876
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
877
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
878
+			],
879
+			'active_status'    => [
880
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
881
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
882
+			],
883
+			'upcoming_status'  => [
884
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
885
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
886
+			],
887
+			'postponed_status' => [
888
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
889
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
890
+			],
891
+			'cancelled_status' => [
892
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
893
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
894
+			],
895
+			'expired_status'   => [
896
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
897
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
898
+			],
899
+			'inactive_status'  => [
900
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
901
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
902
+			],
903
+		];
904
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
905
+		return array_merge($items, $statuses);
906
+	}
907
+
908
+
909
+	/**
910
+	 * @return EEM_Event
911
+	 * @throws EE_Error
912
+	 * @throws InvalidArgumentException
913
+	 * @throws InvalidDataTypeException
914
+	 * @throws InvalidInterfaceException
915
+	 * @throws ReflectionException
916
+	 */
917
+	private function _event_model()
918
+	{
919
+		if (! $this->_event_model instanceof EEM_Event) {
920
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
921
+		}
922
+		return $this->_event_model;
923
+	}
924
+
925
+
926
+	/**
927
+	 * Adds extra buttons to the WP CPT permalink field row.
928
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
929
+	 *
930
+	 * @param string $return    the current html
931
+	 * @param int    $id        the post id for the page
932
+	 * @param string $new_title What the title is
933
+	 * @param string $new_slug  what the slug is
934
+	 * @return string            The new html string for the permalink area
935
+	 */
936
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
937
+	{
938
+		// make sure this is only when editing
939
+		if (! empty($id)) {
940
+			$post = get_post($id);
941
+			$return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
942
+					   . esc_html__('Shortcode', 'event_espresso')
943
+					   . '</a> ';
944
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
945
+					   . $post->ID
946
+					   . ']">';
947
+		}
948
+		return $return;
949
+	}
950
+
951
+
952
+	/**
953
+	 * _events_overview_list_table
954
+	 * This contains the logic for showing the events_overview list
955
+	 *
956
+	 * @access protected
957
+	 * @return void
958
+	 * @throws DomainException
959
+	 * @throws EE_Error
960
+	 * @throws InvalidArgumentException
961
+	 * @throws InvalidDataTypeException
962
+	 * @throws InvalidInterfaceException
963
+	 */
964
+	protected function _events_overview_list_table()
965
+	{
966
+		$after_list_table                           = [];
967
+		$links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
968
+		$links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
969
+		$links_html .= EEH_HTML::div(
970
+			EEH_Template::get_button_or_link(
971
+				get_post_type_archive_link('espresso_events'),
972
+				esc_html__('View Event Archive Page', 'event_espresso'),
973
+				'button button--small button--secondary'
974
+			),
975
+			'',
976
+			'ee-admin-button-row ee-admin-button-row--align-start'
977
+		);
978
+		$links_html .= EEH_HTML::divx();
979
+
980
+		$after_list_table['view_event_list_button'] = $links_html;
981
+
982
+		$after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
983
+		$this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
984
+			'create_new',
985
+			'add',
986
+			[],
987
+			'add-new-h2'
988
+		);
989
+
990
+		$this->_template_args['after_list_table']   = array_merge(
991
+			(array) $this->_template_args['after_list_table'],
992
+			$after_list_table
993
+		);
994
+		$this->display_admin_list_table_page_with_no_sidebar();
995
+	}
996
+
997
+
998
+	/**
999
+	 * this allows for extra misc actions in the default WP publish box
1000
+	 *
1001
+	 * @return void
1002
+	 * @throws DomainException
1003
+	 * @throws EE_Error
1004
+	 * @throws InvalidArgumentException
1005
+	 * @throws InvalidDataTypeException
1006
+	 * @throws InvalidInterfaceException
1007
+	 * @throws ReflectionException
1008
+	 */
1009
+	public function extra_misc_actions_publish_box()
1010
+	{
1011
+		$this->_generate_publish_box_extra_content();
1012
+	}
1013
+
1014
+
1015
+	/**
1016
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1017
+	 * saved.
1018
+	 * Typically you would use this to save any additional data.
1019
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1020
+	 * ALSO very important.  When a post transitions from scheduled to published,
1021
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1022
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1023
+	 *
1024
+	 * @access protected
1025
+	 * @abstract
1026
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1027
+	 * @param WP_Post $post    The post object of the cpt that was saved.
1028
+	 * @return void
1029
+	 * @throws EE_Error
1030
+	 * @throws InvalidArgumentException
1031
+	 * @throws InvalidDataTypeException
1032
+	 * @throws InvalidInterfaceException
1033
+	 * @throws ReflectionException
1034
+	 */
1035
+	protected function _insert_update_cpt_item($post_id, $post)
1036
+	{
1037
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1038
+			// get out we're not processing an event save.
1039
+			return;
1040
+		}
1041
+		$event_values = [
1042
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1043
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1044
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1045
+		];
1046
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1047
+		if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1048
+			$event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1049
+				'display_ticket_selector',
1050
+				false,
1051
+				'bool'
1052
+			);
1053
+			$event_values['EVT_additional_limit']            = min(
1054
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1055
+				$this->request->getRequestParam('additional_limit', null, 'int')
1056
+			);
1057
+			$event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1058
+				'EVT_default_registration_status',
1059
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1060
+			);
1061
+
1062
+			$event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1063
+			$event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1064
+			$event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1065
+		}
1066
+		// update event
1067
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1068
+		// get event_object for other metaboxes...
1069
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1070
+		// i have to setup where conditions to override the filters in the model
1071
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1072
+		$event = $this->_event_model()->get_one(
1073
+			[
1074
+				[
1075
+					$this->_event_model()->primary_key_name() => $post_id,
1076
+					'OR'                                      => [
1077
+						'status'   => $post->post_status,
1078
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1079
+						// but the returned object here has a status of "publish", so use the original post status as well
1080
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1081
+					],
1082
+				],
1083
+			]
1084
+		);
1085
+
1086
+		// the following are default callbacks for event attachment updates
1087
+		// that can be overridden by caffeinated functionality and/or addons.
1088
+		$event_update_callbacks = [];
1089
+		if (! $this->admin_config->useAdvancedEditor()) {
1090
+			$event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1091
+			$event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1092
+		}
1093
+		$event_update_callbacks = apply_filters(
1094
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1095
+			$event_update_callbacks
1096
+		);
1097
+
1098
+		$att_success = true;
1099
+		foreach ($event_update_callbacks as $e_callback) {
1100
+			$_success = is_callable($e_callback)
1101
+				? $e_callback($event, $this->request->requestParams())
1102
+				: false;
1103
+			// if ANY of these updates fail then we want the appropriate global error message
1104
+			$att_success = $_success !== false ? $att_success : false;
1105
+		}
1106
+		// any errors?
1107
+		if ($success && $att_success === false) {
1108
+			EE_Error::add_error(
1109
+				esc_html__(
1110
+					'Event Details saved successfully but something went wrong with saving attachments.',
1111
+					'event_espresso'
1112
+				),
1113
+				__FILE__,
1114
+				__FUNCTION__,
1115
+				__LINE__
1116
+			);
1117
+		} elseif ($success === false) {
1118
+			EE_Error::add_error(
1119
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1120
+				__FILE__,
1121
+				__FUNCTION__,
1122
+				__LINE__
1123
+			);
1124
+		}
1125
+	}
1126
+
1127
+
1128
+	/**
1129
+	 * @param int $post_id
1130
+	 * @param int $revision_id
1131
+	 * @throws EE_Error
1132
+	 * @throws EE_Error
1133
+	 * @throws ReflectionException
1134
+	 * @see parent::restore_item()
1135
+	 */
1136
+	protected function _restore_cpt_item($post_id, $revision_id)
1137
+	{
1138
+		// copy existing event meta to new post
1139
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1140
+		if ($post_evt instanceof EE_Event) {
1141
+			// meta revision restore
1142
+			$post_evt->restore_revision($revision_id);
1143
+			// related objs restore
1144
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1145
+		}
1146
+	}
1147
+
1148
+
1149
+	/**
1150
+	 * Attach the venue to the Event
1151
+	 *
1152
+	 * @param EE_Event $event Event Object to add the venue to
1153
+	 * @param array    $data  The request data from the form
1154
+	 * @return bool           Success or fail.
1155
+	 * @throws EE_Error
1156
+	 * @throws ReflectionException
1157
+	 */
1158
+	protected function _default_venue_update(EE_Event $event, $data)
1159
+	{
1160
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1161
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1162
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1163
+		// very important.  If we don't have a venue name...
1164
+		// then we'll get out because not necessary to create empty venue
1165
+		if (empty($data['venue_title'])) {
1166
+			return false;
1167
+		}
1168
+		$venue_array = [
1169
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1170
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1171
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1172
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1173
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1174
+				? $data['venue_short_description']
1175
+				: null,
1176
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1177
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1178
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1179
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1180
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1181
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1182
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1183
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1184
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1185
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1186
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1187
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1188
+			'status'              => 'publish',
1189
+		];
1190
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1191
+		if (! empty($venue_id)) {
1192
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1193
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1194
+			// we've gotta make sure that the venue is always attached to a revision..
1195
+			// add_relation_to should take care of making sure that the relation is already present.
1196
+			$event->_add_relation_to($venue_id, 'Venue');
1197
+			return $rows_affected > 0;
1198
+		}
1199
+		// we insert the venue
1200
+		$venue_id = $venue_model->insert($venue_array);
1201
+		$event->_add_relation_to($venue_id, 'Venue');
1202
+		return ! empty($venue_id);
1203
+		// when we have the ancestor come in it's already been handled by the revision save.
1204
+	}
1205
+
1206
+
1207
+	/**
1208
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1209
+	 *
1210
+	 * @param EE_Event $event The Event object we're attaching data to
1211
+	 * @param array    $data  The request data from the form
1212
+	 * @return array
1213
+	 * @throws EE_Error
1214
+	 * @throws ReflectionException
1215
+	 * @throws Exception
1216
+	 */
1217
+	protected function _default_tickets_update(EE_Event $event, $data)
1218
+	{
1219
+		if ($this->admin_config->useAdvancedEditor()) {
1220
+			return [];
1221
+		}
1222
+		$datetime       = null;
1223
+		$saved_tickets  = [];
1224
+		$event_timezone = $event->get_timezone();
1225
+		$date_formats   = ['Y-m-d', 'h:i a'];
1226
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1227
+			// trim all values to ensure any excess whitespace is removed.
1228
+			$datetime_data                = array_map('trim', $datetime_data);
1229
+			$datetime_data['DTT_EVT_end'] =
1230
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1231
+					? $datetime_data['DTT_EVT_end']
1232
+					: $datetime_data['DTT_EVT_start'];
1233
+			$datetime_values              = [
1234
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1235
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1236
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1237
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1238
+				'DTT_order'     => $row,
1239
+			];
1240
+			// if we have an id then let's get existing object first and then set the new values.
1241
+			//  Otherwise we instantiate a new object for save.
1242
+			if (! empty($datetime_data['DTT_ID'])) {
1243
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1244
+				if (! $datetime instanceof EE_Datetime) {
1245
+					throw new RuntimeException(
1246
+						sprintf(
1247
+							esc_html__(
1248
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1249
+								'event_espresso'
1250
+							),
1251
+							$datetime_data['DTT_ID']
1252
+						)
1253
+					);
1254
+				}
1255
+				$datetime->set_date_format($date_formats[0]);
1256
+				$datetime->set_time_format($date_formats[1]);
1257
+				foreach ($datetime_values as $field => $value) {
1258
+					$datetime->set($field, $value);
1259
+				}
1260
+			} else {
1261
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1262
+			}
1263
+			if (! $datetime instanceof EE_Datetime) {
1264
+				throw new RuntimeException(
1265
+					sprintf(
1266
+						esc_html__(
1267
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1268
+							'event_espresso'
1269
+						),
1270
+						print_r($datetime_values, true)
1271
+					)
1272
+				);
1273
+			}
1274
+			// before going any further make sure our dates are setup correctly
1275
+			// so that the end date is always equal or greater than the start date.
1276
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1277
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1278
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1279
+			}
1280
+			$datetime->save();
1281
+			$event->_add_relation_to($datetime, 'Datetime');
1282
+		}
1283
+		// no datetimes get deleted so we don't do any of that logic here.
1284
+		// update tickets next
1285
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1286
+
1287
+		// set up some default start and end dates in case those are not present in the incoming data
1288
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1289
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1290
+		// use the start date of the first datetime for the end date
1291
+		$first_datetime   = $event->first_datetime();
1292
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1293
+
1294
+		// now process the incoming data
1295
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1296
+			$update_prices = false;
1297
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1298
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1299
+				: 0;
1300
+			// trim inputs to ensure any excess whitespace is removed.
1301
+			$ticket_data   = array_map('trim', $ticket_data);
1302
+			$ticket_values = [
1303
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1304
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1305
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1306
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1307
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1308
+					? $ticket_data['TKT_start_date']
1309
+					: $default_start_date,
1310
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1311
+					? $ticket_data['TKT_end_date']
1312
+					: $default_end_date,
1313
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1314
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1315
+					? $ticket_data['TKT_qty']
1316
+					: EE_INF,
1317
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1318
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1319
+					? $ticket_data['TKT_uses']
1320
+					: EE_INF,
1321
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1322
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1323
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1324
+				'TKT_price'       => $ticket_price,
1325
+				'TKT_row'         => $row,
1326
+			];
1327
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1328
+			// which means in turn that the prices will become new prices as well.
1329
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1330
+				$ticket_values['TKT_ID']         = 0;
1331
+				$ticket_values['TKT_is_default'] = 0;
1332
+				$update_prices                   = true;
1333
+			}
1334
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1335
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1336
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1337
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1338
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1339
+			if (! empty($ticket_data['TKT_ID'])) {
1340
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1341
+				if (! $existing_ticket instanceof EE_Ticket) {
1342
+					throw new RuntimeException(
1343
+						sprintf(
1344
+							esc_html__(
1345
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1346
+								'event_espresso'
1347
+							),
1348
+							$ticket_data['TKT_ID']
1349
+						)
1350
+					);
1351
+				}
1352
+				$ticket_sold = $existing_ticket->count_related(
1353
+					'Registration',
1354
+					[
1355
+							[
1356
+								'STS_ID' => [
1357
+									'NOT IN',
1358
+									[EEM_Registration::status_id_incomplete],
1359
+								],
1360
+							],
1361
+						]
1362
+				) > 0;
1363
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1364
+				// if they are different then we create a new ticket (if $ticket_sold)
1365
+				// if they aren't different then we go ahead and modify existing ticket.
1366
+				$create_new_ticket = $ticket_sold
1367
+									 && $ticket_price !== $existing_ticket->price()
1368
+									 && ! $existing_ticket->deleted();
1369
+				$existing_ticket->set_date_format($date_formats[0]);
1370
+				$existing_ticket->set_time_format($date_formats[1]);
1371
+				// set new values
1372
+				foreach ($ticket_values as $field => $value) {
1373
+					if ($field == 'TKT_qty') {
1374
+						$existing_ticket->set_qty($value);
1375
+					} elseif ($field == 'TKT_price') {
1376
+						$existing_ticket->set('TKT_price', $ticket_price);
1377
+					} else {
1378
+						$existing_ticket->set($field, $value);
1379
+					}
1380
+				}
1381
+				$ticket = $existing_ticket;
1382
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1383
+				//  Otherwise we have to create a new ticket.
1384
+				if ($create_new_ticket) {
1385
+					// archive the old ticket first
1386
+					$existing_ticket->set('TKT_deleted', 1);
1387
+					$existing_ticket->save();
1388
+					// make sure this ticket is still recorded in our $saved_tickets
1389
+					// so we don't run it through the regular trash routine.
1390
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1391
+					// create new ticket that's a copy of the existing except,
1392
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1393
+					$new_ticket = clone $existing_ticket;
1394
+					$new_ticket->set('TKT_ID', 0);
1395
+					$new_ticket->set('TKT_deleted', 0);
1396
+					$new_ticket->set('TKT_sold', 0);
1397
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1398
+					$update_prices = true;
1399
+					$ticket        = $new_ticket;
1400
+				}
1401
+			} else {
1402
+				// no TKT_id so a new ticket
1403
+				$ticket_values['TKT_price'] = $ticket_price;
1404
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1405
+				$update_prices              = true;
1406
+			}
1407
+			if (! $ticket instanceof EE_Ticket) {
1408
+				throw new RuntimeException(
1409
+					sprintf(
1410
+						esc_html__(
1411
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1412
+							'event_espresso'
1413
+						),
1414
+						print_r($ticket_values, true)
1415
+					)
1416
+				);
1417
+			}
1418
+			// cap ticket qty by datetime reg limits
1419
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1420
+			// update ticket.
1421
+			$ticket->save();
1422
+			// before going any further make sure our dates are setup correctly
1423
+			// so that the end date is always equal or greater than the start date.
1424
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1425
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1426
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1427
+				$ticket->save();
1428
+			}
1429
+			// initially let's add the ticket to the datetime
1430
+			$datetime->_add_relation_to($ticket, 'Ticket');
1431
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1432
+			// add prices to ticket
1433
+			$prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1434
+				? $data['edit_prices'][ $row ]
1435
+				: [];
1436
+			$this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1437
+		}
1438
+		// however now we need to handle permanently deleting tickets via the ui.
1439
+		// Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1440
+		// However, it does allow for deleting tickets that have no tickets sold,
1441
+		// in which case we want to get rid of permanently because there is no need to save in db.
1442
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1443
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1444
+		foreach ($tickets_removed as $id) {
1445
+			$id = absint($id);
1446
+			// get the ticket for this id
1447
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1448
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1449
+				continue;
1450
+			}
1451
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1452
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1453
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1454
+			foreach ($related_datetimes as $related_datetime) {
1455
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1456
+			}
1457
+			// need to do the same for prices (except these prices can also be deleted because again,
1458
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1459
+			$ticket_to_remove->delete_related_permanently('Price');
1460
+			// finally let's delete this ticket
1461
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1462
+			$ticket_to_remove->delete_permanently();
1463
+		}
1464
+		return [$datetime, $saved_tickets];
1465
+	}
1466
+
1467
+
1468
+	/**
1469
+	 * This attaches a list of given prices to a ticket.
1470
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1471
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1472
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1473
+	 *
1474
+	 * @access  private
1475
+	 * @param array     $prices_data Array of prices from the form.
1476
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1477
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1478
+	 * @return  void
1479
+	 * @throws EE_Error
1480
+	 * @throws ReflectionException
1481
+	 */
1482
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1483
+	{
1484
+		$timezone = $ticket->get_timezone();
1485
+		foreach ($prices_data as $row => $price_data) {
1486
+			$price_values = [
1487
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1488
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1489
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1490
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1491
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1492
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1493
+				'PRC_order'      => $row,
1494
+			];
1495
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1496
+				$price_values['PRC_ID'] = 0;
1497
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1498
+			} else {
1499
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1500
+				// update this price with new values
1501
+				foreach ($price_values as $field => $new_price) {
1502
+					$price->set($field, $new_price);
1503
+				}
1504
+			}
1505
+			if (! $price instanceof EE_Price) {
1506
+				throw new RuntimeException(
1507
+					sprintf(
1508
+						esc_html__(
1509
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1510
+							'event_espresso'
1511
+						),
1512
+						print_r($price_values, true)
1513
+					)
1514
+				);
1515
+			}
1516
+			$price->save();
1517
+			$ticket->_add_relation_to($price, 'Price');
1518
+		}
1519
+	}
1520
+
1521
+
1522
+	/**
1523
+	 * Add in our autosave ajax handlers
1524
+	 *
1525
+	 */
1526
+	protected function _ee_autosave_create_new()
1527
+	{
1528
+	}
1529
+
1530
+
1531
+	/**
1532
+	 * More autosave handlers.
1533
+	 */
1534
+	protected function _ee_autosave_edit()
1535
+	{
1536
+	}
1537
+
1538
+
1539
+	/**
1540
+	 * @throws EE_Error
1541
+	 * @throws ReflectionException
1542
+	 */
1543
+	private function _generate_publish_box_extra_content()
1544
+	{
1545
+		// load formatter helper
1546
+		// args for getting related registrations
1547
+		$approved_query_args        = [
1548
+			[
1549
+				'REG_deleted' => 0,
1550
+				'STS_ID'      => EEM_Registration::status_id_approved,
1551
+			],
1552
+		];
1553
+		$not_approved_query_args    = [
1554
+			[
1555
+				'REG_deleted' => 0,
1556
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1557
+			],
1558
+		];
1559
+		$pending_payment_query_args = [
1560
+			[
1561
+				'REG_deleted' => 0,
1562
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1563
+			],
1564
+		];
1565
+		// publish box
1566
+		$publish_box_extra_args = [
1567
+			'view_approved_reg_url'        => add_query_arg(
1568
+				[
1569
+					'action'      => 'default',
1570
+					'event_id'    => $this->_cpt_model_obj->ID(),
1571
+					'_reg_status' => EEM_Registration::status_id_approved,
1572
+				],
1573
+				REG_ADMIN_URL
1574
+			),
1575
+			'view_not_approved_reg_url'    => add_query_arg(
1576
+				[
1577
+					'action'      => 'default',
1578
+					'event_id'    => $this->_cpt_model_obj->ID(),
1579
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1580
+				],
1581
+				REG_ADMIN_URL
1582
+			),
1583
+			'view_pending_payment_reg_url' => add_query_arg(
1584
+				[
1585
+					'action'      => 'default',
1586
+					'event_id'    => $this->_cpt_model_obj->ID(),
1587
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1588
+				],
1589
+				REG_ADMIN_URL
1590
+			),
1591
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1592
+				'Registration',
1593
+				$approved_query_args
1594
+			),
1595
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1596
+				'Registration',
1597
+				$not_approved_query_args
1598
+			),
1599
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1600
+				'Registration',
1601
+				$pending_payment_query_args
1602
+			),
1603
+			'misc_pub_section_class'       => apply_filters(
1604
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1605
+				'misc-pub-section'
1606
+			),
1607
+		];
1608
+		ob_start();
1609
+		do_action(
1610
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1611
+			$this->_cpt_model_obj
1612
+		);
1613
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1614
+		// load template
1615
+		EEH_Template::display_template(
1616
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1617
+			$publish_box_extra_args
1618
+		);
1619
+	}
1620
+
1621
+
1622
+	/**
1623
+	 * @return EE_Event
1624
+	 */
1625
+	public function get_event_object()
1626
+	{
1627
+		return $this->_cpt_model_obj;
1628
+	}
1629
+
1630
+
1631
+
1632
+
1633
+	/** METABOXES * */
1634
+	/**
1635
+	 * _register_event_editor_meta_boxes
1636
+	 * add all metaboxes related to the event_editor
1637
+	 *
1638
+	 * @return void
1639
+	 * @throws EE_Error
1640
+	 * @throws ReflectionException
1641
+	 */
1642
+	protected function _register_event_editor_meta_boxes()
1643
+	{
1644
+		$this->verify_cpt_object();
1645
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1646
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1647
+		if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1648
+			$this->addMetaBox(
1649
+				'espresso_event_editor_event_options',
1650
+				esc_html__('Event Registration Options', 'event_espresso'),
1651
+				[$this, 'registration_options_meta_box'],
1652
+				$this->page_slug,
1653
+				'side'
1654
+			);
1655
+		}
1656
+		if (! $use_advanced_editor) {
1657
+			$this->addMetaBox(
1658
+				'espresso_event_editor_tickets',
1659
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1660
+				[$this, 'ticket_metabox'],
1661
+				$this->page_slug,
1662
+				'normal',
1663
+				'high'
1664
+			);
1665
+		} elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1666
+			add_action(
1667
+				'add_meta_boxes_espresso_events',
1668
+				function () {
1669
+					global $current_screen;
1670
+					remove_meta_box('authordiv', $current_screen, 'normal');
1671
+				},
1672
+				99
1673
+			);
1674
+		}
1675
+		// NOTE: if you're looking for other metaboxes in here,
1676
+		// where a metabox has a related management page in the admin
1677
+		// you will find it setup in the related management page's "_Hooks" file.
1678
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1679
+	}
1680
+
1681
+
1682
+	/**
1683
+	 * @throws DomainException
1684
+	 * @throws EE_Error
1685
+	 * @throws ReflectionException
1686
+	 */
1687
+	public function ticket_metabox()
1688
+	{
1689
+		$existing_datetime_ids = $existing_ticket_ids = [];
1690
+		// defaults for template args
1691
+		$template_args = [
1692
+			'existing_datetime_ids'    => '',
1693
+			'event_datetime_help_link' => '',
1694
+			'ticket_options_help_link' => '',
1695
+			'time'                     => null,
1696
+			'ticket_rows'              => '',
1697
+			'existing_ticket_ids'      => '',
1698
+			'total_ticket_rows'        => 1,
1699
+			'ticket_js_structure'      => '',
1700
+			'trash_icon'               => 'dashicons dashicons-lock',
1701
+			'disabled'                 => '',
1702
+		];
1703
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1704
+		/**
1705
+		 * 1. Start with retrieving Datetimes
1706
+		 * 2. Fore each datetime get related tickets
1707
+		 * 3. For each ticket get related prices
1708
+		 */
1709
+		/** @var EEM_Datetime $datetime_model */
1710
+		$datetime_model = EE_Registry::instance()->load_model('Datetime');
1711
+		/** @var EEM_Ticket $datetime_model */
1712
+		$ticket_model = EE_Registry::instance()->load_model('Ticket');
1713
+		$times        = $datetime_model->get_all_event_dates($event_id);
1714
+		/** @type EE_Datetime $first_datetime */
1715
+		$first_datetime = reset($times);
1716
+		// do we get related tickets?
1717
+		if (
1718
+			$first_datetime instanceof EE_Datetime
1719
+			&& $first_datetime->ID() !== 0
1720
+		) {
1721
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1722
+			$template_args['time']   = $first_datetime;
1723
+			$related_tickets         = $first_datetime->tickets(
1724
+				[
1725
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1726
+					'default_where_conditions' => 'none',
1727
+				]
1728
+			);
1729
+			if (! empty($related_tickets)) {
1730
+				$template_args['total_ticket_rows'] = count($related_tickets);
1731
+				$row                                = 0;
1732
+				foreach ($related_tickets as $ticket) {
1733
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1734
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1735
+					$row++;
1736
+				}
1737
+			} else {
1738
+				$template_args['total_ticket_rows'] = 1;
1739
+				/** @type EE_Ticket $ticket */
1740
+				$ticket                       = $ticket_model->create_default_object();
1741
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1742
+			}
1743
+		} else {
1744
+			$template_args['time'] = $times[0];
1745
+			/** @type EE_Ticket[] $tickets */
1746
+			$tickets                      = $ticket_model->get_all_default_tickets();
1747
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1748
+			// NOTE: we're just sending the first default row
1749
+			// (decaf can't manage default tickets so this should be sufficient);
1750
+		}
1751
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1752
+			'event_editor_event_datetimes_help_tab'
1753
+		);
1754
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1755
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1756
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1757
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1758
+			$ticket_model->create_default_object(),
1759
+			true
1760
+		);
1761
+		$template                                  = apply_filters(
1762
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1763
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1764
+		);
1765
+		EEH_Template::display_template($template, $template_args);
1766
+	}
1767
+
1768
+
1769
+	/**
1770
+	 * Setup an individual ticket form for the decaf event editor page
1771
+	 *
1772
+	 * @access private
1773
+	 * @param EE_Ticket $ticket   the ticket object
1774
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1775
+	 * @param int       $row
1776
+	 * @return string generated html for the ticket row.
1777
+	 * @throws EE_Error
1778
+	 * @throws ReflectionException
1779
+	 */
1780
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1781
+	{
1782
+		$template_args = [
1783
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1784
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1785
+				: '',
1786
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1787
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1788
+			'TKT_name'            => $ticket->get('TKT_name'),
1789
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1790
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1791
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1792
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1793
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1794
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1795
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1796
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1797
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1798
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1799
+				: ' disabled=disabled',
1800
+		];
1801
+		$price         = $ticket->ID() !== 0
1802
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1803
+			: null;
1804
+		$price         = $price instanceof EE_Price
1805
+			? $price
1806
+			: EEM_Price::instance()->create_default_object();
1807
+		$price_args    = [
1808
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1809
+			'PRC_amount'            => $price->get('PRC_amount'),
1810
+			'PRT_ID'                => $price->get('PRT_ID'),
1811
+			'PRC_ID'                => $price->get('PRC_ID'),
1812
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1813
+		];
1814
+		// make sure we have default start and end dates if skeleton
1815
+		// handle rows that should NOT be empty
1816
+		if (empty($template_args['TKT_start_date'])) {
1817
+			// if empty then the start date will be now.
1818
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1819
+		}
1820
+		if (empty($template_args['TKT_end_date'])) {
1821
+			// get the earliest datetime (if present);
1822
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1823
+				? $this->_cpt_model_obj->get_first_related(
1824
+					'Datetime',
1825
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1826
+				)
1827
+				: null;
1828
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1829
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1830
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1831
+		}
1832
+		$template_args = array_merge($template_args, $price_args);
1833
+		$template      = apply_filters(
1834
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1835
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1836
+			$ticket
1837
+		);
1838
+		return EEH_Template::display_template($template, $template_args, true);
1839
+	}
1840
+
1841
+
1842
+	/**
1843
+	 * @throws EE_Error
1844
+	 * @throws ReflectionException
1845
+	 */
1846
+	public function registration_options_meta_box()
1847
+	{
1848
+		$yes_no_values             = [
1849
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1850
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1851
+		];
1852
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1853
+			[
1854
+				EEM_Registration::status_id_cancelled,
1855
+				EEM_Registration::status_id_declined,
1856
+				EEM_Registration::status_id_incomplete,
1857
+			],
1858
+			true
1859
+		);
1860
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1861
+		$template_args['_event']                          = $this->_cpt_model_obj;
1862
+		$template_args['event']                           = $this->_cpt_model_obj;
1863
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1864
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1865
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1866
+			'default_reg_status',
1867
+			$default_reg_status_values,
1868
+			$this->_cpt_model_obj->default_registration_status()
1869
+		);
1870
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1871
+			'display_desc',
1872
+			$yes_no_values,
1873
+			$this->_cpt_model_obj->display_description()
1874
+		);
1875
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1876
+			'display_ticket_selector',
1877
+			$yes_no_values,
1878
+			$this->_cpt_model_obj->display_ticket_selector(),
1879
+			'',
1880
+			'',
1881
+			false
1882
+		);
1883
+		$template_args['additional_registration_options'] = apply_filters(
1884
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1885
+			'',
1886
+			$template_args,
1887
+			$yes_no_values,
1888
+			$default_reg_status_values
1889
+		);
1890
+		EEH_Template::display_template(
1891
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1892
+			$template_args
1893
+		);
1894
+	}
1895
+
1896
+
1897
+	/**
1898
+	 * _get_events()
1899
+	 * This method simply returns all the events (for the given _view and paging)
1900
+	 *
1901
+	 * @access public
1902
+	 * @param int  $per_page     count of items per page (20 default);
1903
+	 * @param int  $current_page what is the current page being viewed.
1904
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1905
+	 *                           If FALSE then we return an array of event objects
1906
+	 *                           that match the given _view and paging parameters.
1907
+	 * @return array|int         an array of event objects or a count of them.
1908
+	 * @throws Exception
1909
+	 */
1910
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1911
+	{
1912
+		$EEM_Event   = $this->_event_model();
1913
+		$offset      = ($current_page - 1) * $per_page;
1914
+		$limit       = $count ? null : $offset . ',' . $per_page;
1915
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1916
+		$order       = $this->request->getRequestParam('order', 'DESC');
1917
+		$month_range = $this->request->getRequestParam('month_range');
1918
+		if ($month_range) {
1919
+			$pieces = explode(' ', $month_range, 3);
1920
+			// simulate the FIRST day of the month, that fixes issues for months like February
1921
+			// where PHP doesn't know what to assume for date.
1922
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1923
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1924
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1925
+		}
1926
+		$where  = [];
1927
+		$status = $this->request->getRequestParam('status');
1928
+		// determine what post_status our condition will have for the query.
1929
+		switch ($status) {
1930
+			case 'month':
1931
+			case 'today':
1932
+			case null:
1933
+			case 'all':
1934
+				break;
1935
+			case 'draft':
1936
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1937
+				break;
1938
+			default:
1939
+				$where['status'] = $status;
1940
+		}
1941
+		// categories? The default for all categories is -1
1942
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1943
+		if ($category !== -1) {
1944
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1945
+			$where['Term_Taxonomy.term_id']  = $category;
1946
+		}
1947
+		// date where conditions
1948
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1949
+		if ($month_range) {
1950
+			$DateTime = new DateTime(
1951
+				$year_r . '-' . $month_r . '-01 00:00:00',
1952
+				new DateTimeZone('UTC')
1953
+			);
1954
+			$start    = $DateTime->getTimestamp();
1955
+			// set the datetime to be the end of the month
1956
+			$DateTime->setDate(
1957
+				$year_r,
1958
+				$month_r,
1959
+				$DateTime->format('t')
1960
+			)->setTime(23, 59, 59);
1961
+			$end                             = $DateTime->getTimestamp();
1962
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1963
+		} elseif ($status === 'today') {
1964
+			$DateTime                        =
1965
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1966
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1967
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1968
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1969
+		} elseif ($status === 'month') {
1970
+			$now                             = date('Y-m-01');
1971
+			$DateTime                        =
1972
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1973
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1974
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1975
+														->setTime(23, 59, 59)
1976
+														->format(implode(' ', $start_formats));
1977
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1978
+		}
1979
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1980
+			$where['EVT_wp_user'] = get_current_user_id();
1981
+		} else {
1982
+			if (! isset($where['status'])) {
1983
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1984
+					$where['OR'] = [
1985
+						'status*restrict_private' => ['!=', 'private'],
1986
+						'AND'                     => [
1987
+							'status*inclusive' => ['=', 'private'],
1988
+							'EVT_wp_user'      => get_current_user_id(),
1989
+						],
1990
+					];
1991
+				}
1992
+			}
1993
+		}
1994
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1995
+		if (
1996
+			$wp_user
1997
+			&& $wp_user !== get_current_user_id()
1998
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1999
+		) {
2000
+			$where['EVT_wp_user'] = $wp_user;
2001
+		}
2002
+		// search query handling
2003
+		$search_term = $this->request->getRequestParam('s');
2004
+		if ($search_term) {
2005
+			$search_term = '%' . $search_term . '%';
2006
+			$where['OR'] = [
2007
+				'EVT_name'       => ['LIKE', $search_term],
2008
+				'EVT_desc'       => ['LIKE', $search_term],
2009
+				'EVT_short_desc' => ['LIKE', $search_term],
2010
+			];
2011
+		}
2012
+		// filter events by venue.
2013
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
2014
+		if ($venue) {
2015
+			$where['Venue.VNU_ID'] = $venue;
2016
+		}
2017
+		$request_params = $this->request->requestParams();
2018
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2019
+		$query_params   = apply_filters(
2020
+			'FHEE__Events_Admin_Page__get_events__query_params',
2021
+			[
2022
+				$where,
2023
+				'limit'    => $limit,
2024
+				'order_by' => $orderby,
2025
+				'order'    => $order,
2026
+				'group_by' => 'EVT_ID',
2027
+			],
2028
+			$request_params
2029
+		);
2030
+
2031
+		// let's first check if we have special requests coming in.
2032
+		$active_status = $this->request->getRequestParam('active_status');
2033
+		if ($active_status) {
2034
+			switch ($active_status) {
2035
+				case 'upcoming':
2036
+					return $EEM_Event->get_upcoming_events($query_params, $count);
2037
+				case 'expired':
2038
+					return $EEM_Event->get_expired_events($query_params, $count);
2039
+				case 'active':
2040
+					return $EEM_Event->get_active_events($query_params, $count);
2041
+				case 'inactive':
2042
+					return $EEM_Event->get_inactive_events($query_params, $count);
2043
+			}
2044
+		}
2045
+
2046
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2047
+	}
2048
+
2049
+
2050
+	/**
2051
+	 * handling for WordPress CPT actions (trash, restore, delete)
2052
+	 *
2053
+	 * @param string $post_id
2054
+	 * @throws EE_Error
2055
+	 * @throws ReflectionException
2056
+	 */
2057
+	public function trash_cpt_item($post_id)
2058
+	{
2059
+		$this->request->setRequestParam('EVT_ID', $post_id);
2060
+		$this->_trash_or_restore_event('trash', false);
2061
+	}
2062
+
2063
+
2064
+	/**
2065
+	 * @param string $post_id
2066
+	 * @throws EE_Error
2067
+	 * @throws ReflectionException
2068
+	 */
2069
+	public function restore_cpt_item($post_id)
2070
+	{
2071
+		$this->request->setRequestParam('EVT_ID', $post_id);
2072
+		$this->_trash_or_restore_event('draft', false);
2073
+	}
2074
+
2075
+
2076
+	/**
2077
+	 * @param string $post_id
2078
+	 * @throws EE_Error
2079
+	 * @throws EE_Error
2080
+	 */
2081
+	public function delete_cpt_item($post_id)
2082
+	{
2083
+		throw new EE_Error(
2084
+			esc_html__(
2085
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2086
+				'event_espresso'
2087
+			)
2088
+		);
2089
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2090
+		// $this->_delete_event();
2091
+	}
2092
+
2093
+
2094
+	/**
2095
+	 * _trash_or_restore_event
2096
+	 *
2097
+	 * @access protected
2098
+	 * @param string $event_status
2099
+	 * @param bool   $redirect_after
2100
+	 * @throws EE_Error
2101
+	 * @throws EE_Error
2102
+	 * @throws ReflectionException
2103
+	 */
2104
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2105
+	{
2106
+		// determine the event id and set to array.
2107
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2108
+		// loop thru events
2109
+		if ($EVT_ID) {
2110
+			// clean status
2111
+			$event_status = sanitize_key($event_status);
2112
+			// grab status
2113
+			if (! empty($event_status)) {
2114
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2115
+			} else {
2116
+				$success = false;
2117
+				$msg     = esc_html__(
2118
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2119
+					'event_espresso'
2120
+				);
2121
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2122
+			}
2123
+		} else {
2124
+			$success = false;
2125
+			$msg     = esc_html__(
2126
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2127
+				'event_espresso'
2128
+			);
2129
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2130
+		}
2131
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2132
+		if ($redirect_after) {
2133
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2134
+		}
2135
+	}
2136
+
2137
+
2138
+	/**
2139
+	 * _trash_or_restore_events
2140
+	 *
2141
+	 * @access protected
2142
+	 * @param string $event_status
2143
+	 * @return void
2144
+	 * @throws EE_Error
2145
+	 * @throws EE_Error
2146
+	 * @throws ReflectionException
2147
+	 */
2148
+	protected function _trash_or_restore_events($event_status = 'trash')
2149
+	{
2150
+		// clean status
2151
+		$event_status = sanitize_key($event_status);
2152
+		// grab status
2153
+		if (! empty($event_status)) {
2154
+			$success = true;
2155
+			// determine the event id and set to array.
2156
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2157
+			// loop thru events
2158
+			foreach ($EVT_IDs as $EVT_ID) {
2159
+				if ($EVT_ID = absint($EVT_ID)) {
2160
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2161
+					$success = $results !== false ? $success : false;
2162
+				} else {
2163
+					$msg = sprintf(
2164
+						esc_html__(
2165
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2166
+							'event_espresso'
2167
+						),
2168
+						$EVT_ID
2169
+					);
2170
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
+					$success = false;
2172
+				}
2173
+			}
2174
+		} else {
2175
+			$success = false;
2176
+			$msg     = esc_html__(
2177
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2178
+				'event_espresso'
2179
+			);
2180
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2181
+		}
2182
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2183
+		$success = $success ? 2 : false;
2184
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2185
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2186
+	}
2187
+
2188
+
2189
+	/**
2190
+	 * @param int    $EVT_ID
2191
+	 * @param string $event_status
2192
+	 * @return bool
2193
+	 * @throws EE_Error
2194
+	 * @throws ReflectionException
2195
+	 */
2196
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2197
+	{
2198
+		// grab event id
2199
+		if (! $EVT_ID) {
2200
+			$msg = esc_html__(
2201
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2202
+				'event_espresso'
2203
+			);
2204
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2205
+			return false;
2206
+		}
2207
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2208
+		// clean status
2209
+		$event_status = sanitize_key($event_status);
2210
+		// grab status
2211
+		if (empty($event_status)) {
2212
+			$msg = esc_html__(
2213
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2214
+				'event_espresso'
2215
+			);
2216
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2217
+			return false;
2218
+		}
2219
+		// was event trashed or restored ?
2220
+		switch ($event_status) {
2221
+			case 'draft':
2222
+				$action = 'restored from the trash';
2223
+				$hook   = 'AHEE_event_restored_from_trash';
2224
+				break;
2225
+			case 'trash':
2226
+				$action = 'moved to the trash';
2227
+				$hook   = 'AHEE_event_moved_to_trash';
2228
+				break;
2229
+			default:
2230
+				$action = 'updated';
2231
+				$hook   = false;
2232
+		}
2233
+		// use class to change status
2234
+		$this->_cpt_model_obj->set_status($event_status);
2235
+		$success = $this->_cpt_model_obj->save();
2236
+		if (! $success) {
2237
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2238
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2239
+			return false;
2240
+		}
2241
+		if ($hook) {
2242
+			do_action($hook);
2243
+		}
2244
+		return true;
2245
+	}
2246
+
2247
+
2248
+	/**
2249
+	 * @param array $event_ids
2250
+	 * @return array
2251
+	 * @since   4.10.23.p
2252
+	 */
2253
+	private function cleanEventIds(array $event_ids)
2254
+	{
2255
+		return array_map('absint', $event_ids);
2256
+	}
2257
+
2258
+
2259
+	/**
2260
+	 * @return array
2261
+	 * @since   4.10.23.p
2262
+	 */
2263
+	private function getEventIdsFromRequest()
2264
+	{
2265
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2266
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2267
+		} else {
2268
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2269
+		}
2270
+	}
2271
+
2272
+
2273
+	/**
2274
+	 * @param bool $preview_delete
2275
+	 * @throws EE_Error
2276
+	 */
2277
+	protected function _delete_event($preview_delete = true)
2278
+	{
2279
+		$this->_delete_events($preview_delete);
2280
+	}
2281
+
2282
+
2283
+	/**
2284
+	 * Gets the tree traversal batch persister.
2285
+	 *
2286
+	 * @return NodeGroupDao
2287
+	 * @throws InvalidArgumentException
2288
+	 * @throws InvalidDataTypeException
2289
+	 * @throws InvalidInterfaceException
2290
+	 * @since 4.10.12.p
2291
+	 */
2292
+	protected function getModelObjNodeGroupPersister()
2293
+	{
2294
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2295
+			$this->model_obj_node_group_persister =
2296
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2297
+		}
2298
+		return $this->model_obj_node_group_persister;
2299
+	}
2300
+
2301
+
2302
+	/**
2303
+	 * @param bool $preview_delete
2304
+	 * @return void
2305
+	 * @throws EE_Error
2306
+	 */
2307
+	protected function _delete_events($preview_delete = true)
2308
+	{
2309
+		$event_ids = $this->getEventIdsFromRequest();
2310
+		if ($preview_delete) {
2311
+			$this->generateDeletionPreview($event_ids);
2312
+		} else {
2313
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2314
+		}
2315
+	}
2316
+
2317
+
2318
+	/**
2319
+	 * @param array $event_ids
2320
+	 */
2321
+	protected function generateDeletionPreview(array $event_ids)
2322
+	{
2323
+		$event_ids = $this->cleanEventIds($event_ids);
2324
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2325
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2326
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2327
+			[
2328
+				'action'            => 'preview_deletion',
2329
+				'deletion_job_code' => $deletion_job_code,
2330
+			],
2331
+			$this->_admin_base_url
2332
+		);
2333
+		EEH_URL::safeRedirectAndExit(
2334
+			EE_Admin_Page::add_query_args_and_nonce(
2335
+				[
2336
+					'page'              => EED_Batch::PAGE_SLUG,
2337
+					'batch'             => EED_Batch::batch_job,
2338
+					'EVT_IDs'           => $event_ids,
2339
+					'deletion_job_code' => $deletion_job_code,
2340
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2341
+					'return_url'        => urlencode($return_url),
2342
+				],
2343
+				admin_url()
2344
+			)
2345
+		);
2346
+	}
2347
+
2348
+
2349
+	/**
2350
+	 * Checks for a POST submission
2351
+	 *
2352
+	 * @since 4.10.12.p
2353
+	 */
2354
+	protected function confirmDeletion()
2355
+	{
2356
+		$deletion_redirect_logic =
2357
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2358
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2359
+	}
2360
+
2361
+
2362
+	/**
2363
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2364
+	 *
2365
+	 * @throws EE_Error
2366
+	 * @since 4.10.12.p
2367
+	 */
2368
+	protected function previewDeletion()
2369
+	{
2370
+		$preview_deletion_logic =
2371
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2372
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2373
+		$this->display_admin_page_with_no_sidebar();
2374
+	}
2375
+
2376
+
2377
+	/**
2378
+	 * get total number of events
2379
+	 *
2380
+	 * @access public
2381
+	 * @return int
2382
+	 * @throws EE_Error
2383
+	 * @throws EE_Error
2384
+	 */
2385
+	public function total_events()
2386
+	{
2387
+		return EEM_Event::instance()->count(
2388
+			['caps' => 'read_admin'],
2389
+			'EVT_ID',
2390
+			true
2391
+		);
2392
+	}
2393
+
2394
+
2395
+	/**
2396
+	 * get total number of draft events
2397
+	 *
2398
+	 * @access public
2399
+	 * @return int
2400
+	 * @throws EE_Error
2401
+	 * @throws EE_Error
2402
+	 */
2403
+	public function total_events_draft()
2404
+	{
2405
+		return EEM_Event::instance()->count(
2406
+			[
2407
+				['status' => ['IN', ['draft', 'auto-draft']]],
2408
+				'caps' => 'read_admin',
2409
+			],
2410
+			'EVT_ID',
2411
+			true
2412
+		);
2413
+	}
2414
+
2415
+
2416
+	/**
2417
+	 * get total number of trashed events
2418
+	 *
2419
+	 * @access public
2420
+	 * @return int
2421
+	 * @throws EE_Error
2422
+	 * @throws EE_Error
2423
+	 */
2424
+	public function total_trashed_events()
2425
+	{
2426
+		return EEM_Event::instance()->count(
2427
+			[
2428
+				['status' => 'trash'],
2429
+				'caps' => 'read_admin',
2430
+			],
2431
+			'EVT_ID',
2432
+			true
2433
+		);
2434
+	}
2435
+
2436
+
2437
+	/**
2438
+	 *    _default_event_settings
2439
+	 *    This generates the Default Settings Tab
2440
+	 *
2441
+	 * @return void
2442
+	 * @throws DomainException
2443
+	 * @throws EE_Error
2444
+	 * @throws InvalidArgumentException
2445
+	 * @throws InvalidDataTypeException
2446
+	 * @throws InvalidInterfaceException
2447
+	 */
2448
+	protected function _default_event_settings()
2449
+	{
2450
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2451
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2452
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
2453
+			$this->_default_event_settings_form()->get_html(),
2454
+			'',
2455
+			'padding'
2456
+		);
2457
+		$this->display_admin_page_with_sidebar();
2458
+	}
2459
+
2460
+
2461
+	/**
2462
+	 * Return the form for event settings.
2463
+	 *
2464
+	 * @return EE_Form_Section_Proper
2465
+	 * @throws EE_Error
2466
+	 */
2467
+	protected function _default_event_settings_form()
2468
+	{
2469
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2470
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2471
+		// exclude
2472
+			[
2473
+				EEM_Registration::status_id_cancelled,
2474
+				EEM_Registration::status_id_declined,
2475
+				EEM_Registration::status_id_incomplete,
2476
+				EEM_Registration::status_id_wait_list,
2477
+			],
2478
+			true
2479
+		);
2480
+		// setup Advanced Editor ???
2481
+		if (
2482
+			$this->raw_req_action === 'default_event_settings'
2483
+			|| $this->raw_req_action === 'update_default_event_settings'
2484
+		) {
2485
+			$this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class);
2486
+		}
2487
+		return new EE_Form_Section_Proper(
2488
+			[
2489
+				'name'            => 'update_default_event_settings',
2490
+				'html_id'         => 'update_default_event_settings',
2491
+				'html_class'      => 'form-table',
2492
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2493
+				'subsections'     => apply_filters(
2494
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2495
+					[
2496
+						'defaults_section_header' => new EE_Form_Section_HTML(
2497
+							EEH_HTML::h2(
2498
+								esc_html__('Default Settings', 'event_espresso'),
2499
+								'',
2500
+								'ee-admin-settings-hdr'
2501
+							)
2502
+						),
2503
+						'default_reg_status'  => new EE_Select_Input(
2504
+							$registration_stati_for_selection,
2505
+							[
2506
+								'default'         => isset($registration_config->default_STS_ID)
2507
+													 && array_key_exists(
2508
+														 $registration_config->default_STS_ID,
2509
+														 $registration_stati_for_selection
2510
+													 )
2511
+									? sanitize_text_field($registration_config->default_STS_ID)
2512
+									: EEM_Registration::status_id_pending_payment,
2513
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2514
+													 . EEH_Template::get_help_tab_link(
2515
+														 'default_settings_status_help_tab'
2516
+													 ),
2517
+								'html_help_text'  => esc_html__(
2518
+									'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.',
2519
+									'event_espresso'
2520
+								),
2521
+							]
2522
+						),
2523
+						'default_max_tickets' => new EE_Integer_Input(
2524
+							[
2525
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2526
+									? $registration_config->default_maximum_number_of_tickets
2527
+									: EEM_Event::get_default_additional_limit(),
2528
+								'html_label_text' => esc_html__(
2529
+									'Default Maximum Tickets Allowed Per Order:',
2530
+									'event_espresso'
2531
+								)
2532
+													 . EEH_Template::get_help_tab_link(
2533
+														 'default_maximum_tickets_help_tab"'
2534
+													 ),
2535
+								'html_help_text'  => esc_html__(
2536
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2537
+									'event_espresso'
2538
+								),
2539
+							]
2540
+						),
2541
+					]
2542
+				),
2543
+			]
2544
+		);
2545
+	}
2546
+
2547
+
2548
+	/**
2549
+	 * @return void
2550
+	 * @throws EE_Error
2551
+	 * @throws InvalidArgumentException
2552
+	 * @throws InvalidDataTypeException
2553
+	 * @throws InvalidInterfaceException
2554
+	 */
2555
+	protected function _update_default_event_settings()
2556
+	{
2557
+		$form = $this->_default_event_settings_form();
2558
+		if ($form->was_submitted()) {
2559
+			$form->receive_form_submission();
2560
+			if ($form->is_valid()) {
2561
+				$registration_config = EE_Registry::instance()->CFG->registration;
2562
+				$valid_data          = $form->valid_data();
2563
+				if (isset($valid_data['default_reg_status'])) {
2564
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2565
+				}
2566
+				if (isset($valid_data['default_max_tickets'])) {
2567
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2568
+				}
2569
+				do_action(
2570
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2571
+					$valid_data,
2572
+					EE_Registry::instance()->CFG,
2573
+					$this
2574
+				);
2575
+				// update because data was valid!
2576
+				EE_Registry::instance()->CFG->update_espresso_config();
2577
+				EE_Error::overwrite_success();
2578
+				EE_Error::add_success(
2579
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2580
+				);
2581
+			}
2582
+		}
2583
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2584
+	}
2585
+
2586
+
2587
+	/*************        Templates        *************
21 2588
      *
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
-     * @var EE_Event
45
-     */
46
-    protected $_cpt_model_obj = false;
47
-
48
-
49
-    /**
50
-     * @var NodeGroupDao
51
-     */
52
-    protected $model_obj_node_group_persister;
53
-
54
-    /**
55
-     * @var AdvancedEditorAdminFormSection
56
-     */
57
-    protected $advanced_editor_admin_form;
58
-
59
-
60
-    /**
61
-     * Initialize page props for this admin page group.
62
-     */
63
-    protected function _init_page_props()
64
-    {
65
-        $this->page_slug        = EVENTS_PG_SLUG;
66
-        $this->page_label       = EVENTS_LABEL;
67
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
68
-        $this->_admin_base_path = EVENTS_ADMIN;
69
-        $this->_cpt_model_names = [
70
-            'create_new' => 'EEM_Event',
71
-            'edit'       => 'EEM_Event',
72
-        ];
73
-        $this->_cpt_edit_routes = [
74
-            'espresso_events' => 'edit',
75
-        ];
76
-        add_action(
77
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
78
-            [$this, 'verify_event_edit'],
79
-            10,
80
-            2
81
-        );
82
-    }
83
-
84
-
85
-    /**
86
-     * Sets the ajax hooks used for this admin page group.
87
-     */
88
-    protected function _ajax_hooks()
89
-    {
90
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
91
-    }
92
-
93
-
94
-    /**
95
-     * Sets the page properties for this admin page group.
96
-     */
97
-    protected function _define_page_props()
98
-    {
99
-        $this->_admin_page_title = EVENTS_LABEL;
100
-        $this->_labels           = [
101
-            'buttons'      => [
102
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
103
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
104
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
105
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
106
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
107
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
108
-            ],
109
-            'editor_title' => [
110
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
111
-            ],
112
-            'publishbox'   => [
113
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
114
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
115
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
116
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
117
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
118
-            ],
119
-        ];
120
-    }
121
-
122
-
123
-    /**
124
-     * Sets the page routes property for this admin page group.
125
-     */
126
-    protected function _set_page_routes()
127
-    {
128
-        // load formatter helper
129
-        // load field generator helper
130
-        // is there a evt_id in the request?
131
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
132
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
133
-
134
-        $this->_page_routes = [
135
-            'default'                       => [
136
-                'func'       => '_events_overview_list_table',
137
-                'capability' => 'ee_read_events',
138
-            ],
139
-            'create_new'                    => [
140
-                'func'       => '_create_new_cpt_item',
141
-                'capability' => 'ee_edit_events',
142
-            ],
143
-            'edit'                          => [
144
-                'func'       => '_edit_cpt_item',
145
-                'capability' => 'ee_edit_event',
146
-                'obj_id'     => $EVT_ID,
147
-            ],
148
-            'copy_event'                    => [
149
-                'func'       => '_copy_events',
150
-                'capability' => 'ee_edit_event',
151
-                'obj_id'     => $EVT_ID,
152
-                'noheader'   => true,
153
-            ],
154
-            'trash_event'                   => [
155
-                'func'       => '_trash_or_restore_event',
156
-                'args'       => ['event_status' => 'trash'],
157
-                'capability' => 'ee_delete_event',
158
-                'obj_id'     => $EVT_ID,
159
-                'noheader'   => true,
160
-            ],
161
-            'trash_events'                  => [
162
-                'func'       => '_trash_or_restore_events',
163
-                'args'       => ['event_status' => 'trash'],
164
-                'capability' => 'ee_delete_events',
165
-                'noheader'   => true,
166
-            ],
167
-            'restore_event'                 => [
168
-                'func'       => '_trash_or_restore_event',
169
-                'args'       => ['event_status' => 'draft'],
170
-                'capability' => 'ee_delete_event',
171
-                'obj_id'     => $EVT_ID,
172
-                'noheader'   => true,
173
-            ],
174
-            'restore_events'                => [
175
-                'func'       => '_trash_or_restore_events',
176
-                'args'       => ['event_status' => 'draft'],
177
-                'capability' => 'ee_delete_events',
178
-                'noheader'   => true,
179
-            ],
180
-            'delete_event'                  => [
181
-                'func'       => '_delete_event',
182
-                'capability' => 'ee_delete_event',
183
-                'obj_id'     => $EVT_ID,
184
-                'noheader'   => true,
185
-            ],
186
-            'delete_events'                 => [
187
-                'func'       => '_delete_events',
188
-                'capability' => 'ee_delete_events',
189
-                'noheader'   => true,
190
-            ],
191
-            'view_report'                   => [
192
-                'func'       => '_view_report',
193
-                'capability' => 'ee_edit_events',
194
-            ],
195
-            'default_event_settings'        => [
196
-                'func'       => '_default_event_settings',
197
-                'capability' => 'manage_options',
198
-            ],
199
-            'update_default_event_settings' => [
200
-                'func'       => '_update_default_event_settings',
201
-                'capability' => 'manage_options',
202
-                'noheader'   => true,
203
-            ],
204
-            'template_settings'             => [
205
-                'func'       => '_template_settings',
206
-                'capability' => 'manage_options',
207
-            ],
208
-            // event category tab related
209
-            'add_category'                  => [
210
-                'func'       => '_category_details',
211
-                'capability' => 'ee_edit_event_category',
212
-                'args'       => ['add'],
213
-            ],
214
-            'edit_category'                 => [
215
-                'func'       => '_category_details',
216
-                'capability' => 'ee_edit_event_category',
217
-                'args'       => ['edit'],
218
-            ],
219
-            'delete_categories'             => [
220
-                'func'       => '_delete_categories',
221
-                'capability' => 'ee_delete_event_category',
222
-                'noheader'   => true,
223
-            ],
224
-            'delete_category'               => [
225
-                'func'       => '_delete_categories',
226
-                'capability' => 'ee_delete_event_category',
227
-                'noheader'   => true,
228
-            ],
229
-            'insert_category'               => [
230
-                'func'       => '_insert_or_update_category',
231
-                'args'       => ['new_category' => true],
232
-                'capability' => 'ee_edit_event_category',
233
-                'noheader'   => true,
234
-            ],
235
-            'update_category'               => [
236
-                'func'       => '_insert_or_update_category',
237
-                'args'       => ['new_category' => false],
238
-                'capability' => 'ee_edit_event_category',
239
-                'noheader'   => true,
240
-            ],
241
-            'category_list'                 => [
242
-                'func'       => '_category_list_table',
243
-                'capability' => 'ee_manage_event_categories',
244
-            ],
245
-            'preview_deletion'              => [
246
-                'func'       => 'previewDeletion',
247
-                'capability' => 'ee_delete_events',
248
-            ],
249
-            'confirm_deletion'              => [
250
-                'func'       => 'confirmDeletion',
251
-                'capability' => 'ee_delete_events',
252
-                'noheader'   => true,
253
-            ],
254
-        ];
255
-    }
256
-
257
-
258
-    /**
259
-     * Set the _page_config property for this admin page group.
260
-     */
261
-    protected function _set_page_config()
262
-    {
263
-        $post_id            = $this->request->getRequestParam('post', 0, 'int');
264
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
265
-        $this->_page_config = [
266
-            'default'                => [
267
-                'nav'           => [
268
-                    'label' => esc_html__('Overview', 'event_espresso'),
269
-                    'order' => 10,
270
-                ],
271
-                'list_table'    => 'Events_Admin_List_Table',
272
-                'help_tabs'     => [
273
-                    'events_overview_help_tab'                       => [
274
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
275
-                        'filename' => 'events_overview',
276
-                    ],
277
-                    'events_overview_table_column_headings_help_tab' => [
278
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
279
-                        'filename' => 'events_overview_table_column_headings',
280
-                    ],
281
-                    'events_overview_filters_help_tab'               => [
282
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
283
-                        'filename' => 'events_overview_filters',
284
-                    ],
285
-                    'events_overview_view_help_tab'                  => [
286
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
287
-                        'filename' => 'events_overview_views',
288
-                    ],
289
-                    'events_overview_other_help_tab'                 => [
290
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
291
-                        'filename' => 'events_overview_other',
292
-                    ],
293
-                ],
294
-                'require_nonce' => false,
295
-            ],
296
-            'create_new'             => [
297
-                'nav'           => [
298
-                    'label'      => esc_html__('Add New Event', 'event_espresso'),
299
-                    'order'      => 5,
300
-                    'persistent' => false,
301
-                ],
302
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
303
-                'help_tabs'     => [
304
-                    'event_editor_help_tab'                            => [
305
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
306
-                        'filename' => 'event_editor',
307
-                    ],
308
-                    'event_editor_title_richtexteditor_help_tab'       => [
309
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
310
-                        'filename' => 'event_editor_title_richtexteditor',
311
-                    ],
312
-                    'event_editor_venue_details_help_tab'              => [
313
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
314
-                        'filename' => 'event_editor_venue_details',
315
-                    ],
316
-                    'event_editor_event_datetimes_help_tab'            => [
317
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
318
-                        'filename' => 'event_editor_event_datetimes',
319
-                    ],
320
-                    'event_editor_event_tickets_help_tab'              => [
321
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
322
-                        'filename' => 'event_editor_event_tickets',
323
-                    ],
324
-                    'event_editor_event_registration_options_help_tab' => [
325
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
326
-                        'filename' => 'event_editor_event_registration_options',
327
-                    ],
328
-                    'event_editor_tags_categories_help_tab'            => [
329
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
330
-                        'filename' => 'event_editor_tags_categories',
331
-                    ],
332
-                    'event_editor_questions_registrants_help_tab'      => [
333
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
334
-                        'filename' => 'event_editor_questions_registrants',
335
-                    ],
336
-                    'event_editor_save_new_event_help_tab'             => [
337
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
338
-                        'filename' => 'event_editor_save_new_event',
339
-                    ],
340
-                    'event_editor_other_help_tab'                      => [
341
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
342
-                        'filename' => 'event_editor_other',
343
-                    ],
344
-                ],
345
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
346
-                'require_nonce' => false,
347
-            ],
348
-            'edit'                   => [
349
-                'nav'           => [
350
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
351
-                    'order'      => 5,
352
-                    'persistent' => false,
353
-                    'url'        => $post_id
354
-                        ? EE_Admin_Page::add_query_args_and_nonce(
355
-                            ['post' => $post_id, 'action' => 'edit'],
356
-                            $this->_current_page_view_url
357
-                        )
358
-                        : $this->_admin_base_url,
359
-                ],
360
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
361
-                'help_tabs'     => [
362
-                    'event_editor_help_tab'                            => [
363
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
364
-                        'filename' => 'event_editor',
365
-                    ],
366
-                    'event_editor_title_richtexteditor_help_tab'       => [
367
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
368
-                        'filename' => 'event_editor_title_richtexteditor',
369
-                    ],
370
-                    'event_editor_venue_details_help_tab'              => [
371
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
372
-                        'filename' => 'event_editor_venue_details',
373
-                    ],
374
-                    'event_editor_event_datetimes_help_tab'            => [
375
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
376
-                        'filename' => 'event_editor_event_datetimes',
377
-                    ],
378
-                    'event_editor_event_tickets_help_tab'              => [
379
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
380
-                        'filename' => 'event_editor_event_tickets',
381
-                    ],
382
-                    'event_editor_event_registration_options_help_tab' => [
383
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
384
-                        'filename' => 'event_editor_event_registration_options',
385
-                    ],
386
-                    'event_editor_tags_categories_help_tab'            => [
387
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
388
-                        'filename' => 'event_editor_tags_categories',
389
-                    ],
390
-                    'event_editor_questions_registrants_help_tab'      => [
391
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
392
-                        'filename' => 'event_editor_questions_registrants',
393
-                    ],
394
-                    'event_editor_save_new_event_help_tab'             => [
395
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
396
-                        'filename' => 'event_editor_save_new_event',
397
-                    ],
398
-                    'event_editor_other_help_tab'                      => [
399
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
400
-                        'filename' => 'event_editor_other',
401
-                    ],
402
-                ],
403
-                'require_nonce' => false,
404
-            ],
405
-            'default_event_settings' => [
406
-                'nav'           => [
407
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
408
-                    'order' => 40,
409
-                ],
410
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
411
-                'labels'        => [
412
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
413
-                ],
414
-                'help_tabs'     => [
415
-                    'default_settings_help_tab'        => [
416
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
417
-                        'filename' => 'events_default_settings',
418
-                    ],
419
-                    'default_settings_status_help_tab' => [
420
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
421
-                        'filename' => 'events_default_settings_status',
422
-                    ],
423
-                    'default_maximum_tickets_help_tab' => [
424
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
425
-                        'filename' => 'events_default_settings_max_tickets',
426
-                    ],
427
-                ],
428
-                'require_nonce' => false,
429
-            ],
430
-            // template settings
431
-            'template_settings'      => [
432
-                'nav'           => [
433
-                    'label' => esc_html__('Templates', 'event_espresso'),
434
-                    'order' => 30,
435
-                ],
436
-                'metaboxes'     => $this->_default_espresso_metaboxes,
437
-                'help_tabs'     => [
438
-                    'general_settings_templates_help_tab' => [
439
-                        'title'    => esc_html__('Templates', 'event_espresso'),
440
-                        'filename' => 'general_settings_templates',
441
-                    ],
442
-                ],
443
-                'require_nonce' => false,
444
-            ],
445
-            // event category stuff
446
-            'add_category'           => [
447
-                'nav'           => [
448
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
449
-                    'order'      => 15,
450
-                    'persistent' => false,
451
-                ],
452
-                'help_tabs'     => [
453
-                    'add_category_help_tab' => [
454
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
455
-                        'filename' => 'events_add_category',
456
-                    ],
457
-                ],
458
-                'metaboxes'     => ['_publish_post_box'],
459
-                'require_nonce' => false,
460
-            ],
461
-            'edit_category'          => [
462
-                'nav'           => [
463
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
464
-                    'order'      => 15,
465
-                    'persistent' => false,
466
-                    'url'        => $EVT_CAT_ID
467
-                        ? add_query_arg(
468
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
469
-                            $this->_current_page_view_url
470
-                        )
471
-                        : $this->_admin_base_url,
472
-                ],
473
-                'help_tabs'     => [
474
-                    'edit_category_help_tab' => [
475
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
476
-                        'filename' => 'events_edit_category',
477
-                    ],
478
-                ],
479
-                'metaboxes'     => ['_publish_post_box'],
480
-                'require_nonce' => false,
481
-            ],
482
-            'category_list'          => [
483
-                'nav'           => [
484
-                    'label' => esc_html__('Categories', 'event_espresso'),
485
-                    'order' => 20,
486
-                ],
487
-                'list_table'    => 'Event_Categories_Admin_List_Table',
488
-                'help_tabs'     => [
489
-                    'events_categories_help_tab'                       => [
490
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
491
-                        'filename' => 'events_categories',
492
-                    ],
493
-                    'events_categories_table_column_headings_help_tab' => [
494
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
495
-                        'filename' => 'events_categories_table_column_headings',
496
-                    ],
497
-                    'events_categories_view_help_tab'                  => [
498
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
499
-                        'filename' => 'events_categories_views',
500
-                    ],
501
-                    'events_categories_other_help_tab'                 => [
502
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
503
-                        'filename' => 'events_categories_other',
504
-                    ],
505
-                ],
506
-                'metaboxes'     => $this->_default_espresso_metaboxes,
507
-                'require_nonce' => false,
508
-            ],
509
-            'preview_deletion'       => [
510
-                'nav'           => [
511
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
512
-                    'order'      => 15,
513
-                    'persistent' => false,
514
-                    'url'        => '',
515
-                ],
516
-                'require_nonce' => false,
517
-            ],
518
-        ];
519
-    }
520
-
521
-
522
-    /**
523
-     * Used to register any global screen options if necessary for every route in this admin page group.
524
-     */
525
-    protected function _add_screen_options()
526
-    {
527
-    }
528
-
529
-
530
-    /**
531
-     * Implementing the screen options for the 'default' route.
532
-     *
533
-     * @throws InvalidArgumentException
534
-     * @throws InvalidDataTypeException
535
-     * @throws InvalidInterfaceException
536
-     */
537
-    protected function _add_screen_options_default()
538
-    {
539
-        $this->_per_page_screen_option();
540
-    }
541
-
542
-
543
-    /**
544
-     * Implementing screen options for the category list route.
545
-     *
546
-     * @throws InvalidArgumentException
547
-     * @throws InvalidDataTypeException
548
-     * @throws InvalidInterfaceException
549
-     */
550
-    protected function _add_screen_options_category_list()
551
-    {
552
-        $page_title              = $this->_admin_page_title;
553
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
554
-        $this->_per_page_screen_option();
555
-        $this->_admin_page_title = $page_title;
556
-    }
557
-
558
-
559
-    /**
560
-     * Used to register any global feature pointers for the admin page group.
561
-     */
562
-    protected function _add_feature_pointers()
563
-    {
564
-    }
565
-
566
-
567
-    /**
568
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
569
-     */
570
-    public function load_scripts_styles()
571
-    {
572
-        wp_register_style(
573
-            'events-admin-css',
574
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
575
-            [],
576
-            EVENT_ESPRESSO_VERSION
577
-        );
578
-        wp_register_style(
579
-            'ee-cat-admin',
580
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
581
-            [],
582
-            EVENT_ESPRESSO_VERSION
583
-        );
584
-        wp_enqueue_style('events-admin-css');
585
-        wp_enqueue_style('ee-cat-admin');
586
-        // scripts
587
-        wp_register_script(
588
-            'event_editor_js',
589
-            EVENTS_ASSETS_URL . 'event_editor.js',
590
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
591
-            EVENT_ESPRESSO_VERSION,
592
-            true
593
-        );
594
-    }
595
-
596
-
597
-    /**
598
-     * Enqueuing scripts and styles specific to this view
599
-     */
600
-    public function load_scripts_styles_create_new()
601
-    {
602
-        $this->load_scripts_styles_edit();
603
-    }
604
-
605
-
606
-    /**
607
-     * Enqueuing scripts and styles specific to this view
608
-     */
609
-    public function load_scripts_styles_edit()
610
-    {
611
-        // styles
612
-        wp_enqueue_style('espresso-ui-theme');
613
-        wp_register_style(
614
-            'event-editor-css',
615
-            EVENTS_ASSETS_URL . 'event-editor.css',
616
-            ['ee-admin-css'],
617
-            EVENT_ESPRESSO_VERSION
618
-        );
619
-        wp_enqueue_style('event-editor-css');
620
-        // scripts
621
-        if (! $this->admin_config->useAdvancedEditor()) {
622
-            wp_register_script(
623
-                'event-datetime-metabox',
624
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
625
-                ['event_editor_js', 'ee-datepicker'],
626
-                EVENT_ESPRESSO_VERSION
627
-            );
628
-            wp_enqueue_script('event-datetime-metabox');
629
-        }
630
-    }
631
-
632
-
633
-    /**
634
-     * Populating the _views property for the category list table view.
635
-     */
636
-    protected function _set_list_table_views_category_list()
637
-    {
638
-        $this->_views = [
639
-            'all' => [
640
-                'slug'        => 'all',
641
-                'label'       => esc_html__('All', 'event_espresso'),
642
-                'count'       => 0,
643
-                'bulk_action' => [
644
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
645
-                ],
646
-            ],
647
-        ];
648
-    }
649
-
650
-
651
-    /**
652
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
653
-     */
654
-    public function admin_init()
655
-    {
656
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
657
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
658
-            'event_espresso'
659
-        );
660
-    }
661
-
662
-
663
-    /**
664
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
665
-     * group.
666
-     */
667
-    public function admin_notices()
668
-    {
669
-    }
670
-
671
-
672
-    /**
673
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
674
-     * this admin page group.
675
-     */
676
-    public function admin_footer_scripts()
677
-    {
678
-    }
679
-
680
-
681
-    /**
682
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
683
-     * warning (via EE_Error::add_error());
684
-     *
685
-     * @param EE_Event $event Event object
686
-     * @param string   $req_type
687
-     * @return void
688
-     * @throws EE_Error
689
-     * @throws ReflectionException
690
-     */
691
-    public function verify_event_edit($event = null, $req_type = '')
692
-    {
693
-        // don't need to do this when processing
694
-        if (! empty($req_type)) {
695
-            return;
696
-        }
697
-        // no event?
698
-        if (! $event instanceof EE_Event) {
699
-            $event = $this->_cpt_model_obj;
700
-        }
701
-        // STILL no event?
702
-        if (! $event instanceof EE_Event) {
703
-            return;
704
-        }
705
-        $orig_status = $event->status();
706
-        // first check if event is active.
707
-        if (
708
-            $orig_status === EEM_Event::cancelled
709
-            || $orig_status === EEM_Event::postponed
710
-            || $event->is_expired()
711
-            || $event->is_inactive()
712
-        ) {
713
-            return;
714
-        }
715
-        // made it here so it IS active... next check that any of the tickets are sold.
716
-        if ($event->is_sold_out(true)) {
717
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
718
-                EE_Error::add_attention(
719
-                    sprintf(
720
-                        esc_html__(
721
-                            '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.',
722
-                            'event_espresso'
723
-                        ),
724
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
725
-                    )
726
-                );
727
-            }
728
-            return;
729
-        }
730
-        if ($orig_status === EEM_Event::sold_out) {
731
-            EE_Error::add_attention(
732
-                sprintf(
733
-                    esc_html__(
734
-                        '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.',
735
-                        'event_espresso'
736
-                    ),
737
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
738
-                )
739
-            );
740
-        }
741
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
742
-        if (! $event->tickets_on_sale()) {
743
-            return;
744
-        }
745
-        // made it here so show warning
746
-        $this->_edit_event_warning();
747
-    }
748
-
749
-
750
-    /**
751
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
752
-     * When needed, hook this into a EE_Error::add_error() notice.
753
-     *
754
-     * @access protected
755
-     * @return void
756
-     */
757
-    protected function _edit_event_warning()
758
-    {
759
-        // we don't want to add warnings during these requests
760
-        if ($this->request->getRequestParam('action') === 'editpost') {
761
-            return;
762
-        }
763
-        EE_Error::add_attention(
764
-            sprintf(
765
-                esc_html__(
766
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
767
-                    'event_espresso'
768
-                ),
769
-                '<a class="espresso-help-tab-lnk ee-help-tab-link">',
770
-                '</a>'
771
-            )
772
-        );
773
-    }
774
-
775
-
776
-    /**
777
-     * When a user is creating a new event, notify them if they haven't set their timezone.
778
-     * Otherwise, do the normal logic
779
-     *
780
-     * @return void
781
-     * @throws EE_Error
782
-     * @throws InvalidArgumentException
783
-     * @throws InvalidDataTypeException
784
-     * @throws InvalidInterfaceException
785
-     */
786
-    protected function _create_new_cpt_item()
787
-    {
788
-        $has_timezone_string = get_option('timezone_string');
789
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
790
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
791
-            EE_Error::add_attention(
792
-                sprintf(
793
-                    esc_html__(
794
-                        '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',
795
-                        'event_espresso'
796
-                    ),
797
-                    '<br>',
798
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
799
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
800
-                    . '</select>',
801
-                    '<button class="button button--secondary timezone-submit">',
802
-                    '</button><span class="spinner"></span>'
803
-                ),
804
-                __FILE__,
805
-                __FUNCTION__,
806
-                __LINE__
807
-            );
808
-        }
809
-        parent::_create_new_cpt_item();
810
-    }
811
-
812
-
813
-    /**
814
-     * Sets the _views property for the default route in this admin page group.
815
-     */
816
-    protected function _set_list_table_views_default()
817
-    {
818
-        $this->_views = [
819
-            'all'   => [
820
-                'slug'        => 'all',
821
-                'label'       => esc_html__('View All Events', 'event_espresso'),
822
-                'count'       => 0,
823
-                'bulk_action' => [
824
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
825
-                ],
826
-            ],
827
-            'draft' => [
828
-                'slug'        => 'draft',
829
-                'label'       => esc_html__('Draft', 'event_espresso'),
830
-                'count'       => 0,
831
-                'bulk_action' => [
832
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
833
-                ],
834
-            ],
835
-        ];
836
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
837
-            $this->_views['trash'] = [
838
-                'slug'        => 'trash',
839
-                'label'       => esc_html__('Trash', 'event_espresso'),
840
-                'count'       => 0,
841
-                'bulk_action' => [
842
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
843
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
844
-                ],
845
-            ];
846
-        }
847
-    }
848
-
849
-
850
-    /**
851
-     * Provides the legend item array for the default list table view.
852
-     *
853
-     * @return array
854
-     * @throws EE_Error
855
-     * @throws EE_Error
856
-     */
857
-    protected function _event_legend_items()
858
-    {
859
-        $items    = [
860
-            'view_details'   => [
861
-                'class' => 'dashicons dashicons-visibility',
862
-                'desc'  => esc_html__('View Event', 'event_espresso'),
863
-            ],
864
-            'edit_event'     => [
865
-                'class' => 'dashicons dashicons-calendar-alt',
866
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
867
-            ],
868
-            'view_attendees' => [
869
-                'class' => 'dashicons dashicons-groups',
870
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
871
-            ],
872
-        ];
873
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
874
-        $statuses = [
875
-            'sold_out_status'  => [
876
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
877
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
878
-            ],
879
-            'active_status'    => [
880
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
881
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
882
-            ],
883
-            'upcoming_status'  => [
884
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
885
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
886
-            ],
887
-            'postponed_status' => [
888
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
889
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
890
-            ],
891
-            'cancelled_status' => [
892
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
893
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
894
-            ],
895
-            'expired_status'   => [
896
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
897
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
898
-            ],
899
-            'inactive_status'  => [
900
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
901
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
902
-            ],
903
-        ];
904
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
905
-        return array_merge($items, $statuses);
906
-    }
907
-
908
-
909
-    /**
910
-     * @return EEM_Event
911
-     * @throws EE_Error
912
-     * @throws InvalidArgumentException
913
-     * @throws InvalidDataTypeException
914
-     * @throws InvalidInterfaceException
915
-     * @throws ReflectionException
916
-     */
917
-    private function _event_model()
918
-    {
919
-        if (! $this->_event_model instanceof EEM_Event) {
920
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
921
-        }
922
-        return $this->_event_model;
923
-    }
924
-
925
-
926
-    /**
927
-     * Adds extra buttons to the WP CPT permalink field row.
928
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
929
-     *
930
-     * @param string $return    the current html
931
-     * @param int    $id        the post id for the page
932
-     * @param string $new_title What the title is
933
-     * @param string $new_slug  what the slug is
934
-     * @return string            The new html string for the permalink area
935
-     */
936
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
937
-    {
938
-        // make sure this is only when editing
939
-        if (! empty($id)) {
940
-            $post = get_post($id);
941
-            $return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
942
-                       . esc_html__('Shortcode', 'event_espresso')
943
-                       . '</a> ';
944
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
945
-                       . $post->ID
946
-                       . ']">';
947
-        }
948
-        return $return;
949
-    }
950
-
951
-
952
-    /**
953
-     * _events_overview_list_table
954
-     * This contains the logic for showing the events_overview list
955
-     *
956
-     * @access protected
957
-     * @return void
958
-     * @throws DomainException
959
-     * @throws EE_Error
960
-     * @throws InvalidArgumentException
961
-     * @throws InvalidDataTypeException
962
-     * @throws InvalidInterfaceException
963
-     */
964
-    protected function _events_overview_list_table()
965
-    {
966
-        $after_list_table                           = [];
967
-        $links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
968
-        $links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
969
-        $links_html .= EEH_HTML::div(
970
-            EEH_Template::get_button_or_link(
971
-                get_post_type_archive_link('espresso_events'),
972
-                esc_html__('View Event Archive Page', 'event_espresso'),
973
-                'button button--small button--secondary'
974
-            ),
975
-            '',
976
-            'ee-admin-button-row ee-admin-button-row--align-start'
977
-        );
978
-        $links_html .= EEH_HTML::divx();
979
-
980
-        $after_list_table['view_event_list_button'] = $links_html;
981
-
982
-        $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
983
-        $this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
984
-            'create_new',
985
-            'add',
986
-            [],
987
-            'add-new-h2'
988
-        );
989
-
990
-        $this->_template_args['after_list_table']   = array_merge(
991
-            (array) $this->_template_args['after_list_table'],
992
-            $after_list_table
993
-        );
994
-        $this->display_admin_list_table_page_with_no_sidebar();
995
-    }
996
-
997
-
998
-    /**
999
-     * this allows for extra misc actions in the default WP publish box
1000
-     *
1001
-     * @return void
1002
-     * @throws DomainException
1003
-     * @throws EE_Error
1004
-     * @throws InvalidArgumentException
1005
-     * @throws InvalidDataTypeException
1006
-     * @throws InvalidInterfaceException
1007
-     * @throws ReflectionException
1008
-     */
1009
-    public function extra_misc_actions_publish_box()
1010
-    {
1011
-        $this->_generate_publish_box_extra_content();
1012
-    }
1013
-
1014
-
1015
-    /**
1016
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1017
-     * saved.
1018
-     * Typically you would use this to save any additional data.
1019
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1020
-     * ALSO very important.  When a post transitions from scheduled to published,
1021
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1022
-     * other meta saves. So MAKE sure that you handle this accordingly.
1023
-     *
1024
-     * @access protected
1025
-     * @abstract
1026
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1027
-     * @param WP_Post $post    The post object of the cpt that was saved.
1028
-     * @return void
1029
-     * @throws EE_Error
1030
-     * @throws InvalidArgumentException
1031
-     * @throws InvalidDataTypeException
1032
-     * @throws InvalidInterfaceException
1033
-     * @throws ReflectionException
1034
-     */
1035
-    protected function _insert_update_cpt_item($post_id, $post)
1036
-    {
1037
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1038
-            // get out we're not processing an event save.
1039
-            return;
1040
-        }
1041
-        $event_values = [
1042
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1043
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1044
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1045
-        ];
1046
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1047
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1048
-            $event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1049
-                'display_ticket_selector',
1050
-                false,
1051
-                'bool'
1052
-            );
1053
-            $event_values['EVT_additional_limit']            = min(
1054
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1055
-                $this->request->getRequestParam('additional_limit', null, 'int')
1056
-            );
1057
-            $event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1058
-                'EVT_default_registration_status',
1059
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1060
-            );
1061
-
1062
-            $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1063
-            $event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1064
-            $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1065
-        }
1066
-        // update event
1067
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1068
-        // get event_object for other metaboxes...
1069
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1070
-        // i have to setup where conditions to override the filters in the model
1071
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1072
-        $event = $this->_event_model()->get_one(
1073
-            [
1074
-                [
1075
-                    $this->_event_model()->primary_key_name() => $post_id,
1076
-                    'OR'                                      => [
1077
-                        'status'   => $post->post_status,
1078
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1079
-                        // but the returned object here has a status of "publish", so use the original post status as well
1080
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1081
-                    ],
1082
-                ],
1083
-            ]
1084
-        );
1085
-
1086
-        // the following are default callbacks for event attachment updates
1087
-        // that can be overridden by caffeinated functionality and/or addons.
1088
-        $event_update_callbacks = [];
1089
-        if (! $this->admin_config->useAdvancedEditor()) {
1090
-            $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1091
-            $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1092
-        }
1093
-        $event_update_callbacks = apply_filters(
1094
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1095
-            $event_update_callbacks
1096
-        );
1097
-
1098
-        $att_success = true;
1099
-        foreach ($event_update_callbacks as $e_callback) {
1100
-            $_success = is_callable($e_callback)
1101
-                ? $e_callback($event, $this->request->requestParams())
1102
-                : false;
1103
-            // if ANY of these updates fail then we want the appropriate global error message
1104
-            $att_success = $_success !== false ? $att_success : false;
1105
-        }
1106
-        // any errors?
1107
-        if ($success && $att_success === false) {
1108
-            EE_Error::add_error(
1109
-                esc_html__(
1110
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1111
-                    'event_espresso'
1112
-                ),
1113
-                __FILE__,
1114
-                __FUNCTION__,
1115
-                __LINE__
1116
-            );
1117
-        } elseif ($success === false) {
1118
-            EE_Error::add_error(
1119
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1120
-                __FILE__,
1121
-                __FUNCTION__,
1122
-                __LINE__
1123
-            );
1124
-        }
1125
-    }
1126
-
1127
-
1128
-    /**
1129
-     * @param int $post_id
1130
-     * @param int $revision_id
1131
-     * @throws EE_Error
1132
-     * @throws EE_Error
1133
-     * @throws ReflectionException
1134
-     * @see parent::restore_item()
1135
-     */
1136
-    protected function _restore_cpt_item($post_id, $revision_id)
1137
-    {
1138
-        // copy existing event meta to new post
1139
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1140
-        if ($post_evt instanceof EE_Event) {
1141
-            // meta revision restore
1142
-            $post_evt->restore_revision($revision_id);
1143
-            // related objs restore
1144
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1145
-        }
1146
-    }
1147
-
1148
-
1149
-    /**
1150
-     * Attach the venue to the Event
1151
-     *
1152
-     * @param EE_Event $event Event Object to add the venue to
1153
-     * @param array    $data  The request data from the form
1154
-     * @return bool           Success or fail.
1155
-     * @throws EE_Error
1156
-     * @throws ReflectionException
1157
-     */
1158
-    protected function _default_venue_update(EE_Event $event, $data)
1159
-    {
1160
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1161
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1162
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1163
-        // very important.  If we don't have a venue name...
1164
-        // then we'll get out because not necessary to create empty venue
1165
-        if (empty($data['venue_title'])) {
1166
-            return false;
1167
-        }
1168
-        $venue_array = [
1169
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1170
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1171
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1172
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1173
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1174
-                ? $data['venue_short_description']
1175
-                : null,
1176
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1177
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1178
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1179
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1180
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1181
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1182
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1183
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1184
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1185
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1186
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1187
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1188
-            'status'              => 'publish',
1189
-        ];
1190
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1191
-        if (! empty($venue_id)) {
1192
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1193
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1194
-            // we've gotta make sure that the venue is always attached to a revision..
1195
-            // add_relation_to should take care of making sure that the relation is already present.
1196
-            $event->_add_relation_to($venue_id, 'Venue');
1197
-            return $rows_affected > 0;
1198
-        }
1199
-        // we insert the venue
1200
-        $venue_id = $venue_model->insert($venue_array);
1201
-        $event->_add_relation_to($venue_id, 'Venue');
1202
-        return ! empty($venue_id);
1203
-        // when we have the ancestor come in it's already been handled by the revision save.
1204
-    }
1205
-
1206
-
1207
-    /**
1208
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1209
-     *
1210
-     * @param EE_Event $event The Event object we're attaching data to
1211
-     * @param array    $data  The request data from the form
1212
-     * @return array
1213
-     * @throws EE_Error
1214
-     * @throws ReflectionException
1215
-     * @throws Exception
1216
-     */
1217
-    protected function _default_tickets_update(EE_Event $event, $data)
1218
-    {
1219
-        if ($this->admin_config->useAdvancedEditor()) {
1220
-            return [];
1221
-        }
1222
-        $datetime       = null;
1223
-        $saved_tickets  = [];
1224
-        $event_timezone = $event->get_timezone();
1225
-        $date_formats   = ['Y-m-d', 'h:i a'];
1226
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1227
-            // trim all values to ensure any excess whitespace is removed.
1228
-            $datetime_data                = array_map('trim', $datetime_data);
1229
-            $datetime_data['DTT_EVT_end'] =
1230
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1231
-                    ? $datetime_data['DTT_EVT_end']
1232
-                    : $datetime_data['DTT_EVT_start'];
1233
-            $datetime_values              = [
1234
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1235
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1236
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1237
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1238
-                'DTT_order'     => $row,
1239
-            ];
1240
-            // if we have an id then let's get existing object first and then set the new values.
1241
-            //  Otherwise we instantiate a new object for save.
1242
-            if (! empty($datetime_data['DTT_ID'])) {
1243
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1244
-                if (! $datetime instanceof EE_Datetime) {
1245
-                    throw new RuntimeException(
1246
-                        sprintf(
1247
-                            esc_html__(
1248
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1249
-                                'event_espresso'
1250
-                            ),
1251
-                            $datetime_data['DTT_ID']
1252
-                        )
1253
-                    );
1254
-                }
1255
-                $datetime->set_date_format($date_formats[0]);
1256
-                $datetime->set_time_format($date_formats[1]);
1257
-                foreach ($datetime_values as $field => $value) {
1258
-                    $datetime->set($field, $value);
1259
-                }
1260
-            } else {
1261
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1262
-            }
1263
-            if (! $datetime instanceof EE_Datetime) {
1264
-                throw new RuntimeException(
1265
-                    sprintf(
1266
-                        esc_html__(
1267
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1268
-                            'event_espresso'
1269
-                        ),
1270
-                        print_r($datetime_values, true)
1271
-                    )
1272
-                );
1273
-            }
1274
-            // before going any further make sure our dates are setup correctly
1275
-            // so that the end date is always equal or greater than the start date.
1276
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1277
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1278
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1279
-            }
1280
-            $datetime->save();
1281
-            $event->_add_relation_to($datetime, 'Datetime');
1282
-        }
1283
-        // no datetimes get deleted so we don't do any of that logic here.
1284
-        // update tickets next
1285
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1286
-
1287
-        // set up some default start and end dates in case those are not present in the incoming data
1288
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1289
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1290
-        // use the start date of the first datetime for the end date
1291
-        $first_datetime   = $event->first_datetime();
1292
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1293
-
1294
-        // now process the incoming data
1295
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1296
-            $update_prices = false;
1297
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1298
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1299
-                : 0;
1300
-            // trim inputs to ensure any excess whitespace is removed.
1301
-            $ticket_data   = array_map('trim', $ticket_data);
1302
-            $ticket_values = [
1303
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1304
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1305
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1306
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1307
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1308
-                    ? $ticket_data['TKT_start_date']
1309
-                    : $default_start_date,
1310
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1311
-                    ? $ticket_data['TKT_end_date']
1312
-                    : $default_end_date,
1313
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1314
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1315
-                    ? $ticket_data['TKT_qty']
1316
-                    : EE_INF,
1317
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1318
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1319
-                    ? $ticket_data['TKT_uses']
1320
-                    : EE_INF,
1321
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1322
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1323
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1324
-                'TKT_price'       => $ticket_price,
1325
-                'TKT_row'         => $row,
1326
-            ];
1327
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1328
-            // which means in turn that the prices will become new prices as well.
1329
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1330
-                $ticket_values['TKT_ID']         = 0;
1331
-                $ticket_values['TKT_is_default'] = 0;
1332
-                $update_prices                   = true;
1333
-            }
1334
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1335
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1336
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1337
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1338
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1339
-            if (! empty($ticket_data['TKT_ID'])) {
1340
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1341
-                if (! $existing_ticket instanceof EE_Ticket) {
1342
-                    throw new RuntimeException(
1343
-                        sprintf(
1344
-                            esc_html__(
1345
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1346
-                                'event_espresso'
1347
-                            ),
1348
-                            $ticket_data['TKT_ID']
1349
-                        )
1350
-                    );
1351
-                }
1352
-                $ticket_sold = $existing_ticket->count_related(
1353
-                    'Registration',
1354
-                    [
1355
-                            [
1356
-                                'STS_ID' => [
1357
-                                    'NOT IN',
1358
-                                    [EEM_Registration::status_id_incomplete],
1359
-                                ],
1360
-                            ],
1361
-                        ]
1362
-                ) > 0;
1363
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1364
-                // if they are different then we create a new ticket (if $ticket_sold)
1365
-                // if they aren't different then we go ahead and modify existing ticket.
1366
-                $create_new_ticket = $ticket_sold
1367
-                                     && $ticket_price !== $existing_ticket->price()
1368
-                                     && ! $existing_ticket->deleted();
1369
-                $existing_ticket->set_date_format($date_formats[0]);
1370
-                $existing_ticket->set_time_format($date_formats[1]);
1371
-                // set new values
1372
-                foreach ($ticket_values as $field => $value) {
1373
-                    if ($field == 'TKT_qty') {
1374
-                        $existing_ticket->set_qty($value);
1375
-                    } elseif ($field == 'TKT_price') {
1376
-                        $existing_ticket->set('TKT_price', $ticket_price);
1377
-                    } else {
1378
-                        $existing_ticket->set($field, $value);
1379
-                    }
1380
-                }
1381
-                $ticket = $existing_ticket;
1382
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1383
-                //  Otherwise we have to create a new ticket.
1384
-                if ($create_new_ticket) {
1385
-                    // archive the old ticket first
1386
-                    $existing_ticket->set('TKT_deleted', 1);
1387
-                    $existing_ticket->save();
1388
-                    // make sure this ticket is still recorded in our $saved_tickets
1389
-                    // so we don't run it through the regular trash routine.
1390
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1391
-                    // create new ticket that's a copy of the existing except,
1392
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1393
-                    $new_ticket = clone $existing_ticket;
1394
-                    $new_ticket->set('TKT_ID', 0);
1395
-                    $new_ticket->set('TKT_deleted', 0);
1396
-                    $new_ticket->set('TKT_sold', 0);
1397
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1398
-                    $update_prices = true;
1399
-                    $ticket        = $new_ticket;
1400
-                }
1401
-            } else {
1402
-                // no TKT_id so a new ticket
1403
-                $ticket_values['TKT_price'] = $ticket_price;
1404
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1405
-                $update_prices              = true;
1406
-            }
1407
-            if (! $ticket instanceof EE_Ticket) {
1408
-                throw new RuntimeException(
1409
-                    sprintf(
1410
-                        esc_html__(
1411
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1412
-                            'event_espresso'
1413
-                        ),
1414
-                        print_r($ticket_values, true)
1415
-                    )
1416
-                );
1417
-            }
1418
-            // cap ticket qty by datetime reg limits
1419
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1420
-            // update ticket.
1421
-            $ticket->save();
1422
-            // before going any further make sure our dates are setup correctly
1423
-            // so that the end date is always equal or greater than the start date.
1424
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1425
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1426
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1427
-                $ticket->save();
1428
-            }
1429
-            // initially let's add the ticket to the datetime
1430
-            $datetime->_add_relation_to($ticket, 'Ticket');
1431
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1432
-            // add prices to ticket
1433
-            $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1434
-                ? $data['edit_prices'][ $row ]
1435
-                : [];
1436
-            $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1437
-        }
1438
-        // however now we need to handle permanently deleting tickets via the ui.
1439
-        // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1440
-        // However, it does allow for deleting tickets that have no tickets sold,
1441
-        // in which case we want to get rid of permanently because there is no need to save in db.
1442
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1443
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1444
-        foreach ($tickets_removed as $id) {
1445
-            $id = absint($id);
1446
-            // get the ticket for this id
1447
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1448
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1449
-                continue;
1450
-            }
1451
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1452
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1453
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1454
-            foreach ($related_datetimes as $related_datetime) {
1455
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1456
-            }
1457
-            // need to do the same for prices (except these prices can also be deleted because again,
1458
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1459
-            $ticket_to_remove->delete_related_permanently('Price');
1460
-            // finally let's delete this ticket
1461
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1462
-            $ticket_to_remove->delete_permanently();
1463
-        }
1464
-        return [$datetime, $saved_tickets];
1465
-    }
1466
-
1467
-
1468
-    /**
1469
-     * This attaches a list of given prices to a ticket.
1470
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1471
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1472
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1473
-     *
1474
-     * @access  private
1475
-     * @param array     $prices_data Array of prices from the form.
1476
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1477
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1478
-     * @return  void
1479
-     * @throws EE_Error
1480
-     * @throws ReflectionException
1481
-     */
1482
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1483
-    {
1484
-        $timezone = $ticket->get_timezone();
1485
-        foreach ($prices_data as $row => $price_data) {
1486
-            $price_values = [
1487
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1488
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1489
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1490
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1491
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1492
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1493
-                'PRC_order'      => $row,
1494
-            ];
1495
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1496
-                $price_values['PRC_ID'] = 0;
1497
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1498
-            } else {
1499
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1500
-                // update this price with new values
1501
-                foreach ($price_values as $field => $new_price) {
1502
-                    $price->set($field, $new_price);
1503
-                }
1504
-            }
1505
-            if (! $price instanceof EE_Price) {
1506
-                throw new RuntimeException(
1507
-                    sprintf(
1508
-                        esc_html__(
1509
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1510
-                            'event_espresso'
1511
-                        ),
1512
-                        print_r($price_values, true)
1513
-                    )
1514
-                );
1515
-            }
1516
-            $price->save();
1517
-            $ticket->_add_relation_to($price, 'Price');
1518
-        }
1519
-    }
1520
-
1521
-
1522
-    /**
1523
-     * Add in our autosave ajax handlers
1524
-     *
1525
-     */
1526
-    protected function _ee_autosave_create_new()
1527
-    {
1528
-    }
1529
-
1530
-
1531
-    /**
1532
-     * More autosave handlers.
1533
-     */
1534
-    protected function _ee_autosave_edit()
1535
-    {
1536
-    }
1537
-
1538
-
1539
-    /**
1540
-     * @throws EE_Error
1541
-     * @throws ReflectionException
1542
-     */
1543
-    private function _generate_publish_box_extra_content()
1544
-    {
1545
-        // load formatter helper
1546
-        // args for getting related registrations
1547
-        $approved_query_args        = [
1548
-            [
1549
-                'REG_deleted' => 0,
1550
-                'STS_ID'      => EEM_Registration::status_id_approved,
1551
-            ],
1552
-        ];
1553
-        $not_approved_query_args    = [
1554
-            [
1555
-                'REG_deleted' => 0,
1556
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1557
-            ],
1558
-        ];
1559
-        $pending_payment_query_args = [
1560
-            [
1561
-                'REG_deleted' => 0,
1562
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1563
-            ],
1564
-        ];
1565
-        // publish box
1566
-        $publish_box_extra_args = [
1567
-            'view_approved_reg_url'        => add_query_arg(
1568
-                [
1569
-                    'action'      => 'default',
1570
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1571
-                    '_reg_status' => EEM_Registration::status_id_approved,
1572
-                ],
1573
-                REG_ADMIN_URL
1574
-            ),
1575
-            'view_not_approved_reg_url'    => add_query_arg(
1576
-                [
1577
-                    'action'      => 'default',
1578
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1579
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1580
-                ],
1581
-                REG_ADMIN_URL
1582
-            ),
1583
-            'view_pending_payment_reg_url' => add_query_arg(
1584
-                [
1585
-                    'action'      => 'default',
1586
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1587
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1588
-                ],
1589
-                REG_ADMIN_URL
1590
-            ),
1591
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1592
-                'Registration',
1593
-                $approved_query_args
1594
-            ),
1595
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1596
-                'Registration',
1597
-                $not_approved_query_args
1598
-            ),
1599
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1600
-                'Registration',
1601
-                $pending_payment_query_args
1602
-            ),
1603
-            'misc_pub_section_class'       => apply_filters(
1604
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1605
-                'misc-pub-section'
1606
-            ),
1607
-        ];
1608
-        ob_start();
1609
-        do_action(
1610
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1611
-            $this->_cpt_model_obj
1612
-        );
1613
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1614
-        // load template
1615
-        EEH_Template::display_template(
1616
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1617
-            $publish_box_extra_args
1618
-        );
1619
-    }
1620
-
1621
-
1622
-    /**
1623
-     * @return EE_Event
1624
-     */
1625
-    public function get_event_object()
1626
-    {
1627
-        return $this->_cpt_model_obj;
1628
-    }
1629
-
1630
-
1631
-
1632
-
1633
-    /** METABOXES * */
1634
-    /**
1635
-     * _register_event_editor_meta_boxes
1636
-     * add all metaboxes related to the event_editor
1637
-     *
1638
-     * @return void
1639
-     * @throws EE_Error
1640
-     * @throws ReflectionException
1641
-     */
1642
-    protected function _register_event_editor_meta_boxes()
1643
-    {
1644
-        $this->verify_cpt_object();
1645
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1646
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1647
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1648
-            $this->addMetaBox(
1649
-                'espresso_event_editor_event_options',
1650
-                esc_html__('Event Registration Options', 'event_espresso'),
1651
-                [$this, 'registration_options_meta_box'],
1652
-                $this->page_slug,
1653
-                'side'
1654
-            );
1655
-        }
1656
-        if (! $use_advanced_editor) {
1657
-            $this->addMetaBox(
1658
-                'espresso_event_editor_tickets',
1659
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1660
-                [$this, 'ticket_metabox'],
1661
-                $this->page_slug,
1662
-                'normal',
1663
-                'high'
1664
-            );
1665
-        } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1666
-            add_action(
1667
-                'add_meta_boxes_espresso_events',
1668
-                function () {
1669
-                    global $current_screen;
1670
-                    remove_meta_box('authordiv', $current_screen, 'normal');
1671
-                },
1672
-                99
1673
-            );
1674
-        }
1675
-        // NOTE: if you're looking for other metaboxes in here,
1676
-        // where a metabox has a related management page in the admin
1677
-        // you will find it setup in the related management page's "_Hooks" file.
1678
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1679
-    }
1680
-
1681
-
1682
-    /**
1683
-     * @throws DomainException
1684
-     * @throws EE_Error
1685
-     * @throws ReflectionException
1686
-     */
1687
-    public function ticket_metabox()
1688
-    {
1689
-        $existing_datetime_ids = $existing_ticket_ids = [];
1690
-        // defaults for template args
1691
-        $template_args = [
1692
-            'existing_datetime_ids'    => '',
1693
-            'event_datetime_help_link' => '',
1694
-            'ticket_options_help_link' => '',
1695
-            'time'                     => null,
1696
-            'ticket_rows'              => '',
1697
-            'existing_ticket_ids'      => '',
1698
-            'total_ticket_rows'        => 1,
1699
-            'ticket_js_structure'      => '',
1700
-            'trash_icon'               => 'dashicons dashicons-lock',
1701
-            'disabled'                 => '',
1702
-        ];
1703
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1704
-        /**
1705
-         * 1. Start with retrieving Datetimes
1706
-         * 2. Fore each datetime get related tickets
1707
-         * 3. For each ticket get related prices
1708
-         */
1709
-        /** @var EEM_Datetime $datetime_model */
1710
-        $datetime_model = EE_Registry::instance()->load_model('Datetime');
1711
-        /** @var EEM_Ticket $datetime_model */
1712
-        $ticket_model = EE_Registry::instance()->load_model('Ticket');
1713
-        $times        = $datetime_model->get_all_event_dates($event_id);
1714
-        /** @type EE_Datetime $first_datetime */
1715
-        $first_datetime = reset($times);
1716
-        // do we get related tickets?
1717
-        if (
1718
-            $first_datetime instanceof EE_Datetime
1719
-            && $first_datetime->ID() !== 0
1720
-        ) {
1721
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1722
-            $template_args['time']   = $first_datetime;
1723
-            $related_tickets         = $first_datetime->tickets(
1724
-                [
1725
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1726
-                    'default_where_conditions' => 'none',
1727
-                ]
1728
-            );
1729
-            if (! empty($related_tickets)) {
1730
-                $template_args['total_ticket_rows'] = count($related_tickets);
1731
-                $row                                = 0;
1732
-                foreach ($related_tickets as $ticket) {
1733
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1734
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1735
-                    $row++;
1736
-                }
1737
-            } else {
1738
-                $template_args['total_ticket_rows'] = 1;
1739
-                /** @type EE_Ticket $ticket */
1740
-                $ticket                       = $ticket_model->create_default_object();
1741
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1742
-            }
1743
-        } else {
1744
-            $template_args['time'] = $times[0];
1745
-            /** @type EE_Ticket[] $tickets */
1746
-            $tickets                      = $ticket_model->get_all_default_tickets();
1747
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1748
-            // NOTE: we're just sending the first default row
1749
-            // (decaf can't manage default tickets so this should be sufficient);
1750
-        }
1751
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1752
-            'event_editor_event_datetimes_help_tab'
1753
-        );
1754
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1755
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1756
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1757
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1758
-            $ticket_model->create_default_object(),
1759
-            true
1760
-        );
1761
-        $template                                  = apply_filters(
1762
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1763
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1764
-        );
1765
-        EEH_Template::display_template($template, $template_args);
1766
-    }
1767
-
1768
-
1769
-    /**
1770
-     * Setup an individual ticket form for the decaf event editor page
1771
-     *
1772
-     * @access private
1773
-     * @param EE_Ticket $ticket   the ticket object
1774
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1775
-     * @param int       $row
1776
-     * @return string generated html for the ticket row.
1777
-     * @throws EE_Error
1778
-     * @throws ReflectionException
1779
-     */
1780
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1781
-    {
1782
-        $template_args = [
1783
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1784
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1785
-                : '',
1786
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1787
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1788
-            'TKT_name'            => $ticket->get('TKT_name'),
1789
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1790
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1791
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1792
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1793
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1794
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1795
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1796
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1797
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1798
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1799
-                : ' disabled=disabled',
1800
-        ];
1801
-        $price         = $ticket->ID() !== 0
1802
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1803
-            : null;
1804
-        $price         = $price instanceof EE_Price
1805
-            ? $price
1806
-            : EEM_Price::instance()->create_default_object();
1807
-        $price_args    = [
1808
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1809
-            'PRC_amount'            => $price->get('PRC_amount'),
1810
-            'PRT_ID'                => $price->get('PRT_ID'),
1811
-            'PRC_ID'                => $price->get('PRC_ID'),
1812
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1813
-        ];
1814
-        // make sure we have default start and end dates if skeleton
1815
-        // handle rows that should NOT be empty
1816
-        if (empty($template_args['TKT_start_date'])) {
1817
-            // if empty then the start date will be now.
1818
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1819
-        }
1820
-        if (empty($template_args['TKT_end_date'])) {
1821
-            // get the earliest datetime (if present);
1822
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1823
-                ? $this->_cpt_model_obj->get_first_related(
1824
-                    'Datetime',
1825
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1826
-                )
1827
-                : null;
1828
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1829
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1830
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1831
-        }
1832
-        $template_args = array_merge($template_args, $price_args);
1833
-        $template      = apply_filters(
1834
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1835
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1836
-            $ticket
1837
-        );
1838
-        return EEH_Template::display_template($template, $template_args, true);
1839
-    }
1840
-
1841
-
1842
-    /**
1843
-     * @throws EE_Error
1844
-     * @throws ReflectionException
1845
-     */
1846
-    public function registration_options_meta_box()
1847
-    {
1848
-        $yes_no_values             = [
1849
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1850
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1851
-        ];
1852
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1853
-            [
1854
-                EEM_Registration::status_id_cancelled,
1855
-                EEM_Registration::status_id_declined,
1856
-                EEM_Registration::status_id_incomplete,
1857
-            ],
1858
-            true
1859
-        );
1860
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1861
-        $template_args['_event']                          = $this->_cpt_model_obj;
1862
-        $template_args['event']                           = $this->_cpt_model_obj;
1863
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1864
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1865
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1866
-            'default_reg_status',
1867
-            $default_reg_status_values,
1868
-            $this->_cpt_model_obj->default_registration_status()
1869
-        );
1870
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1871
-            'display_desc',
1872
-            $yes_no_values,
1873
-            $this->_cpt_model_obj->display_description()
1874
-        );
1875
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1876
-            'display_ticket_selector',
1877
-            $yes_no_values,
1878
-            $this->_cpt_model_obj->display_ticket_selector(),
1879
-            '',
1880
-            '',
1881
-            false
1882
-        );
1883
-        $template_args['additional_registration_options'] = apply_filters(
1884
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1885
-            '',
1886
-            $template_args,
1887
-            $yes_no_values,
1888
-            $default_reg_status_values
1889
-        );
1890
-        EEH_Template::display_template(
1891
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1892
-            $template_args
1893
-        );
1894
-    }
1895
-
1896
-
1897
-    /**
1898
-     * _get_events()
1899
-     * This method simply returns all the events (for the given _view and paging)
1900
-     *
1901
-     * @access public
1902
-     * @param int  $per_page     count of items per page (20 default);
1903
-     * @param int  $current_page what is the current page being viewed.
1904
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1905
-     *                           If FALSE then we return an array of event objects
1906
-     *                           that match the given _view and paging parameters.
1907
-     * @return array|int         an array of event objects or a count of them.
1908
-     * @throws Exception
1909
-     */
1910
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1911
-    {
1912
-        $EEM_Event   = $this->_event_model();
1913
-        $offset      = ($current_page - 1) * $per_page;
1914
-        $limit       = $count ? null : $offset . ',' . $per_page;
1915
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1916
-        $order       = $this->request->getRequestParam('order', 'DESC');
1917
-        $month_range = $this->request->getRequestParam('month_range');
1918
-        if ($month_range) {
1919
-            $pieces = explode(' ', $month_range, 3);
1920
-            // simulate the FIRST day of the month, that fixes issues for months like February
1921
-            // where PHP doesn't know what to assume for date.
1922
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1923
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1924
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1925
-        }
1926
-        $where  = [];
1927
-        $status = $this->request->getRequestParam('status');
1928
-        // determine what post_status our condition will have for the query.
1929
-        switch ($status) {
1930
-            case 'month':
1931
-            case 'today':
1932
-            case null:
1933
-            case 'all':
1934
-                break;
1935
-            case 'draft':
1936
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1937
-                break;
1938
-            default:
1939
-                $where['status'] = $status;
1940
-        }
1941
-        // categories? The default for all categories is -1
1942
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1943
-        if ($category !== -1) {
1944
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1945
-            $where['Term_Taxonomy.term_id']  = $category;
1946
-        }
1947
-        // date where conditions
1948
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1949
-        if ($month_range) {
1950
-            $DateTime = new DateTime(
1951
-                $year_r . '-' . $month_r . '-01 00:00:00',
1952
-                new DateTimeZone('UTC')
1953
-            );
1954
-            $start    = $DateTime->getTimestamp();
1955
-            // set the datetime to be the end of the month
1956
-            $DateTime->setDate(
1957
-                $year_r,
1958
-                $month_r,
1959
-                $DateTime->format('t')
1960
-            )->setTime(23, 59, 59);
1961
-            $end                             = $DateTime->getTimestamp();
1962
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1963
-        } elseif ($status === 'today') {
1964
-            $DateTime                        =
1965
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1966
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1967
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1968
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1969
-        } elseif ($status === 'month') {
1970
-            $now                             = date('Y-m-01');
1971
-            $DateTime                        =
1972
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1973
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1974
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1975
-                                                        ->setTime(23, 59, 59)
1976
-                                                        ->format(implode(' ', $start_formats));
1977
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1978
-        }
1979
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1980
-            $where['EVT_wp_user'] = get_current_user_id();
1981
-        } else {
1982
-            if (! isset($where['status'])) {
1983
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1984
-                    $where['OR'] = [
1985
-                        'status*restrict_private' => ['!=', 'private'],
1986
-                        'AND'                     => [
1987
-                            'status*inclusive' => ['=', 'private'],
1988
-                            'EVT_wp_user'      => get_current_user_id(),
1989
-                        ],
1990
-                    ];
1991
-                }
1992
-            }
1993
-        }
1994
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1995
-        if (
1996
-            $wp_user
1997
-            && $wp_user !== get_current_user_id()
1998
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1999
-        ) {
2000
-            $where['EVT_wp_user'] = $wp_user;
2001
-        }
2002
-        // search query handling
2003
-        $search_term = $this->request->getRequestParam('s');
2004
-        if ($search_term) {
2005
-            $search_term = '%' . $search_term . '%';
2006
-            $where['OR'] = [
2007
-                'EVT_name'       => ['LIKE', $search_term],
2008
-                'EVT_desc'       => ['LIKE', $search_term],
2009
-                'EVT_short_desc' => ['LIKE', $search_term],
2010
-            ];
2011
-        }
2012
-        // filter events by venue.
2013
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
2014
-        if ($venue) {
2015
-            $where['Venue.VNU_ID'] = $venue;
2016
-        }
2017
-        $request_params = $this->request->requestParams();
2018
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2019
-        $query_params   = apply_filters(
2020
-            'FHEE__Events_Admin_Page__get_events__query_params',
2021
-            [
2022
-                $where,
2023
-                'limit'    => $limit,
2024
-                'order_by' => $orderby,
2025
-                'order'    => $order,
2026
-                'group_by' => 'EVT_ID',
2027
-            ],
2028
-            $request_params
2029
-        );
2030
-
2031
-        // let's first check if we have special requests coming in.
2032
-        $active_status = $this->request->getRequestParam('active_status');
2033
-        if ($active_status) {
2034
-            switch ($active_status) {
2035
-                case 'upcoming':
2036
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
2037
-                case 'expired':
2038
-                    return $EEM_Event->get_expired_events($query_params, $count);
2039
-                case 'active':
2040
-                    return $EEM_Event->get_active_events($query_params, $count);
2041
-                case 'inactive':
2042
-                    return $EEM_Event->get_inactive_events($query_params, $count);
2043
-            }
2044
-        }
2045
-
2046
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2047
-    }
2048
-
2049
-
2050
-    /**
2051
-     * handling for WordPress CPT actions (trash, restore, delete)
2052
-     *
2053
-     * @param string $post_id
2054
-     * @throws EE_Error
2055
-     * @throws ReflectionException
2056
-     */
2057
-    public function trash_cpt_item($post_id)
2058
-    {
2059
-        $this->request->setRequestParam('EVT_ID', $post_id);
2060
-        $this->_trash_or_restore_event('trash', false);
2061
-    }
2062
-
2063
-
2064
-    /**
2065
-     * @param string $post_id
2066
-     * @throws EE_Error
2067
-     * @throws ReflectionException
2068
-     */
2069
-    public function restore_cpt_item($post_id)
2070
-    {
2071
-        $this->request->setRequestParam('EVT_ID', $post_id);
2072
-        $this->_trash_or_restore_event('draft', false);
2073
-    }
2074
-
2075
-
2076
-    /**
2077
-     * @param string $post_id
2078
-     * @throws EE_Error
2079
-     * @throws EE_Error
2080
-     */
2081
-    public function delete_cpt_item($post_id)
2082
-    {
2083
-        throw new EE_Error(
2084
-            esc_html__(
2085
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2086
-                'event_espresso'
2087
-            )
2088
-        );
2089
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2090
-        // $this->_delete_event();
2091
-    }
2092
-
2093
-
2094
-    /**
2095
-     * _trash_or_restore_event
2096
-     *
2097
-     * @access protected
2098
-     * @param string $event_status
2099
-     * @param bool   $redirect_after
2100
-     * @throws EE_Error
2101
-     * @throws EE_Error
2102
-     * @throws ReflectionException
2103
-     */
2104
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2105
-    {
2106
-        // determine the event id and set to array.
2107
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2108
-        // loop thru events
2109
-        if ($EVT_ID) {
2110
-            // clean status
2111
-            $event_status = sanitize_key($event_status);
2112
-            // grab status
2113
-            if (! empty($event_status)) {
2114
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2115
-            } else {
2116
-                $success = false;
2117
-                $msg     = esc_html__(
2118
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2119
-                    'event_espresso'
2120
-                );
2121
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2122
-            }
2123
-        } else {
2124
-            $success = false;
2125
-            $msg     = esc_html__(
2126
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2127
-                'event_espresso'
2128
-            );
2129
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2130
-        }
2131
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2132
-        if ($redirect_after) {
2133
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2134
-        }
2135
-    }
2136
-
2137
-
2138
-    /**
2139
-     * _trash_or_restore_events
2140
-     *
2141
-     * @access protected
2142
-     * @param string $event_status
2143
-     * @return void
2144
-     * @throws EE_Error
2145
-     * @throws EE_Error
2146
-     * @throws ReflectionException
2147
-     */
2148
-    protected function _trash_or_restore_events($event_status = 'trash')
2149
-    {
2150
-        // clean status
2151
-        $event_status = sanitize_key($event_status);
2152
-        // grab status
2153
-        if (! empty($event_status)) {
2154
-            $success = true;
2155
-            // determine the event id and set to array.
2156
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2157
-            // loop thru events
2158
-            foreach ($EVT_IDs as $EVT_ID) {
2159
-                if ($EVT_ID = absint($EVT_ID)) {
2160
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2161
-                    $success = $results !== false ? $success : false;
2162
-                } else {
2163
-                    $msg = sprintf(
2164
-                        esc_html__(
2165
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2166
-                            'event_espresso'
2167
-                        ),
2168
-                        $EVT_ID
2169
-                    );
2170
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2171
-                    $success = false;
2172
-                }
2173
-            }
2174
-        } else {
2175
-            $success = false;
2176
-            $msg     = esc_html__(
2177
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2178
-                'event_espresso'
2179
-            );
2180
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2181
-        }
2182
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2183
-        $success = $success ? 2 : false;
2184
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2185
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2186
-    }
2187
-
2188
-
2189
-    /**
2190
-     * @param int    $EVT_ID
2191
-     * @param string $event_status
2192
-     * @return bool
2193
-     * @throws EE_Error
2194
-     * @throws ReflectionException
2195
-     */
2196
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2197
-    {
2198
-        // grab event id
2199
-        if (! $EVT_ID) {
2200
-            $msg = esc_html__(
2201
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2202
-                'event_espresso'
2203
-            );
2204
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2205
-            return false;
2206
-        }
2207
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2208
-        // clean status
2209
-        $event_status = sanitize_key($event_status);
2210
-        // grab status
2211
-        if (empty($event_status)) {
2212
-            $msg = esc_html__(
2213
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2214
-                'event_espresso'
2215
-            );
2216
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2217
-            return false;
2218
-        }
2219
-        // was event trashed or restored ?
2220
-        switch ($event_status) {
2221
-            case 'draft':
2222
-                $action = 'restored from the trash';
2223
-                $hook   = 'AHEE_event_restored_from_trash';
2224
-                break;
2225
-            case 'trash':
2226
-                $action = 'moved to the trash';
2227
-                $hook   = 'AHEE_event_moved_to_trash';
2228
-                break;
2229
-            default:
2230
-                $action = 'updated';
2231
-                $hook   = false;
2232
-        }
2233
-        // use class to change status
2234
-        $this->_cpt_model_obj->set_status($event_status);
2235
-        $success = $this->_cpt_model_obj->save();
2236
-        if (! $success) {
2237
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2238
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2239
-            return false;
2240
-        }
2241
-        if ($hook) {
2242
-            do_action($hook);
2243
-        }
2244
-        return true;
2245
-    }
2246
-
2247
-
2248
-    /**
2249
-     * @param array $event_ids
2250
-     * @return array
2251
-     * @since   4.10.23.p
2252
-     */
2253
-    private function cleanEventIds(array $event_ids)
2254
-    {
2255
-        return array_map('absint', $event_ids);
2256
-    }
2257
-
2258
-
2259
-    /**
2260
-     * @return array
2261
-     * @since   4.10.23.p
2262
-     */
2263
-    private function getEventIdsFromRequest()
2264
-    {
2265
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2266
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2267
-        } else {
2268
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2269
-        }
2270
-    }
2271
-
2272
-
2273
-    /**
2274
-     * @param bool $preview_delete
2275
-     * @throws EE_Error
2276
-     */
2277
-    protected function _delete_event($preview_delete = true)
2278
-    {
2279
-        $this->_delete_events($preview_delete);
2280
-    }
2281
-
2282
-
2283
-    /**
2284
-     * Gets the tree traversal batch persister.
2285
-     *
2286
-     * @return NodeGroupDao
2287
-     * @throws InvalidArgumentException
2288
-     * @throws InvalidDataTypeException
2289
-     * @throws InvalidInterfaceException
2290
-     * @since 4.10.12.p
2291
-     */
2292
-    protected function getModelObjNodeGroupPersister()
2293
-    {
2294
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2295
-            $this->model_obj_node_group_persister =
2296
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2297
-        }
2298
-        return $this->model_obj_node_group_persister;
2299
-    }
2300
-
2301
-
2302
-    /**
2303
-     * @param bool $preview_delete
2304
-     * @return void
2305
-     * @throws EE_Error
2306
-     */
2307
-    protected function _delete_events($preview_delete = true)
2308
-    {
2309
-        $event_ids = $this->getEventIdsFromRequest();
2310
-        if ($preview_delete) {
2311
-            $this->generateDeletionPreview($event_ids);
2312
-        } else {
2313
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2314
-        }
2315
-    }
2316
-
2317
-
2318
-    /**
2319
-     * @param array $event_ids
2320
-     */
2321
-    protected function generateDeletionPreview(array $event_ids)
2322
-    {
2323
-        $event_ids = $this->cleanEventIds($event_ids);
2324
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2325
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2326
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2327
-            [
2328
-                'action'            => 'preview_deletion',
2329
-                'deletion_job_code' => $deletion_job_code,
2330
-            ],
2331
-            $this->_admin_base_url
2332
-        );
2333
-        EEH_URL::safeRedirectAndExit(
2334
-            EE_Admin_Page::add_query_args_and_nonce(
2335
-                [
2336
-                    'page'              => EED_Batch::PAGE_SLUG,
2337
-                    'batch'             => EED_Batch::batch_job,
2338
-                    'EVT_IDs'           => $event_ids,
2339
-                    'deletion_job_code' => $deletion_job_code,
2340
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2341
-                    'return_url'        => urlencode($return_url),
2342
-                ],
2343
-                admin_url()
2344
-            )
2345
-        );
2346
-    }
2347
-
2348
-
2349
-    /**
2350
-     * Checks for a POST submission
2351
-     *
2352
-     * @since 4.10.12.p
2353
-     */
2354
-    protected function confirmDeletion()
2355
-    {
2356
-        $deletion_redirect_logic =
2357
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2358
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2359
-    }
2360
-
2361
-
2362
-    /**
2363
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2364
-     *
2365
-     * @throws EE_Error
2366
-     * @since 4.10.12.p
2367
-     */
2368
-    protected function previewDeletion()
2369
-    {
2370
-        $preview_deletion_logic =
2371
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2372
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2373
-        $this->display_admin_page_with_no_sidebar();
2374
-    }
2375
-
2376
-
2377
-    /**
2378
-     * get total number of events
2379
-     *
2380
-     * @access public
2381
-     * @return int
2382
-     * @throws EE_Error
2383
-     * @throws EE_Error
2384
-     */
2385
-    public function total_events()
2386
-    {
2387
-        return EEM_Event::instance()->count(
2388
-            ['caps' => 'read_admin'],
2389
-            'EVT_ID',
2390
-            true
2391
-        );
2392
-    }
2393
-
2394
-
2395
-    /**
2396
-     * get total number of draft events
2397
-     *
2398
-     * @access public
2399
-     * @return int
2400
-     * @throws EE_Error
2401
-     * @throws EE_Error
2402
-     */
2403
-    public function total_events_draft()
2404
-    {
2405
-        return EEM_Event::instance()->count(
2406
-            [
2407
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2408
-                'caps' => 'read_admin',
2409
-            ],
2410
-            'EVT_ID',
2411
-            true
2412
-        );
2413
-    }
2414
-
2415
-
2416
-    /**
2417
-     * get total number of trashed events
2418
-     *
2419
-     * @access public
2420
-     * @return int
2421
-     * @throws EE_Error
2422
-     * @throws EE_Error
2423
-     */
2424
-    public function total_trashed_events()
2425
-    {
2426
-        return EEM_Event::instance()->count(
2427
-            [
2428
-                ['status' => 'trash'],
2429
-                'caps' => 'read_admin',
2430
-            ],
2431
-            'EVT_ID',
2432
-            true
2433
-        );
2434
-    }
2435
-
2436
-
2437
-    /**
2438
-     *    _default_event_settings
2439
-     *    This generates the Default Settings Tab
2440
-     *
2441
-     * @return void
2442
-     * @throws DomainException
2443
-     * @throws EE_Error
2444
-     * @throws InvalidArgumentException
2445
-     * @throws InvalidDataTypeException
2446
-     * @throws InvalidInterfaceException
2447
-     */
2448
-    protected function _default_event_settings()
2449
-    {
2450
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2451
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2452
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
2453
-            $this->_default_event_settings_form()->get_html(),
2454
-            '',
2455
-            'padding'
2456
-        );
2457
-        $this->display_admin_page_with_sidebar();
2458
-    }
2459
-
2460
-
2461
-    /**
2462
-     * Return the form for event settings.
2463
-     *
2464
-     * @return EE_Form_Section_Proper
2465
-     * @throws EE_Error
2466
-     */
2467
-    protected function _default_event_settings_form()
2468
-    {
2469
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2470
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2471
-        // exclude
2472
-            [
2473
-                EEM_Registration::status_id_cancelled,
2474
-                EEM_Registration::status_id_declined,
2475
-                EEM_Registration::status_id_incomplete,
2476
-                EEM_Registration::status_id_wait_list,
2477
-            ],
2478
-            true
2479
-        );
2480
-        // setup Advanced Editor ???
2481
-        if (
2482
-            $this->raw_req_action === 'default_event_settings'
2483
-            || $this->raw_req_action === 'update_default_event_settings'
2484
-        ) {
2485
-            $this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class);
2486
-        }
2487
-        return new EE_Form_Section_Proper(
2488
-            [
2489
-                'name'            => 'update_default_event_settings',
2490
-                'html_id'         => 'update_default_event_settings',
2491
-                'html_class'      => 'form-table',
2492
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2493
-                'subsections'     => apply_filters(
2494
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2495
-                    [
2496
-                        'defaults_section_header' => new EE_Form_Section_HTML(
2497
-                            EEH_HTML::h2(
2498
-                                esc_html__('Default Settings', 'event_espresso'),
2499
-                                '',
2500
-                                'ee-admin-settings-hdr'
2501
-                            )
2502
-                        ),
2503
-                        'default_reg_status'  => new EE_Select_Input(
2504
-                            $registration_stati_for_selection,
2505
-                            [
2506
-                                'default'         => isset($registration_config->default_STS_ID)
2507
-                                                     && array_key_exists(
2508
-                                                         $registration_config->default_STS_ID,
2509
-                                                         $registration_stati_for_selection
2510
-                                                     )
2511
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2512
-                                    : EEM_Registration::status_id_pending_payment,
2513
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2514
-                                                     . EEH_Template::get_help_tab_link(
2515
-                                                         'default_settings_status_help_tab'
2516
-                                                     ),
2517
-                                'html_help_text'  => esc_html__(
2518
-                                    '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.',
2519
-                                    'event_espresso'
2520
-                                ),
2521
-                            ]
2522
-                        ),
2523
-                        'default_max_tickets' => new EE_Integer_Input(
2524
-                            [
2525
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2526
-                                    ? $registration_config->default_maximum_number_of_tickets
2527
-                                    : EEM_Event::get_default_additional_limit(),
2528
-                                'html_label_text' => esc_html__(
2529
-                                    'Default Maximum Tickets Allowed Per Order:',
2530
-                                    'event_espresso'
2531
-                                )
2532
-                                                     . EEH_Template::get_help_tab_link(
2533
-                                                         'default_maximum_tickets_help_tab"'
2534
-                                                     ),
2535
-                                'html_help_text'  => esc_html__(
2536
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2537
-                                    'event_espresso'
2538
-                                ),
2539
-                            ]
2540
-                        ),
2541
-                    ]
2542
-                ),
2543
-            ]
2544
-        );
2545
-    }
2546
-
2547
-
2548
-    /**
2549
-     * @return void
2550
-     * @throws EE_Error
2551
-     * @throws InvalidArgumentException
2552
-     * @throws InvalidDataTypeException
2553
-     * @throws InvalidInterfaceException
2554
-     */
2555
-    protected function _update_default_event_settings()
2556
-    {
2557
-        $form = $this->_default_event_settings_form();
2558
-        if ($form->was_submitted()) {
2559
-            $form->receive_form_submission();
2560
-            if ($form->is_valid()) {
2561
-                $registration_config = EE_Registry::instance()->CFG->registration;
2562
-                $valid_data          = $form->valid_data();
2563
-                if (isset($valid_data['default_reg_status'])) {
2564
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2565
-                }
2566
-                if (isset($valid_data['default_max_tickets'])) {
2567
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2568
-                }
2569
-                do_action(
2570
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2571
-                    $valid_data,
2572
-                    EE_Registry::instance()->CFG,
2573
-                    $this
2574
-                );
2575
-                // update because data was valid!
2576
-                EE_Registry::instance()->CFG->update_espresso_config();
2577
-                EE_Error::overwrite_success();
2578
-                EE_Error::add_success(
2579
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2580
-                );
2581
-            }
2582
-        }
2583
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2584
-    }
2585
-
2586
-
2587
-    /*************        Templates        *************
2588
-     *
2589
-     * @throws EE_Error
2590
-     */
2591
-    protected function _template_settings()
2592
-    {
2593
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2594
-        $this->_template_args['preview_img']  = '<img src="'
2595
-                                                . EVENTS_ASSETS_URL
2596
-                                                . '/images/'
2597
-                                                . 'caffeinated_template_features.jpg" alt="'
2598
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2599
-                                                . '" />';
2600
-        $this->_template_args['preview_text'] = '<strong>'
2601
-                                                . esc_html__(
2602
-                                                    '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.',
2603
-                                                    'event_espresso'
2604
-                                                ) . '</strong>';
2605
-        $this->display_admin_caf_preview_page('template_settings_tab');
2606
-    }
2607
-
2608
-
2609
-    /** Event Category Stuff **/
2610
-    /**
2611
-     * set the _category property with the category object for the loaded page.
2612
-     *
2613
-     * @access private
2614
-     * @return void
2615
-     */
2616
-    private function _set_category_object()
2617
-    {
2618
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2619
-            return;
2620
-        } //already have the category object so get out.
2621
-        // set default category object
2622
-        $this->_set_empty_category_object();
2623
-        // only set if we've got an id
2624
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2625
-        if (! $category_ID) {
2626
-            return;
2627
-        }
2628
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2629
-        if (! empty($term)) {
2630
-            $this->_category->category_name       = $term->name;
2631
-            $this->_category->category_identifier = $term->slug;
2632
-            $this->_category->category_desc       = $term->description;
2633
-            $this->_category->id                  = $term->term_id;
2634
-            $this->_category->parent              = $term->parent;
2635
-        }
2636
-    }
2637
-
2638
-
2639
-    /**
2640
-     * Clears out category properties.
2641
-     */
2642
-    private function _set_empty_category_object()
2643
-    {
2644
-        $this->_category                = new stdClass();
2645
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2646
-        $this->_category->id            = $this->_category->parent = 0;
2647
-    }
2648
-
2649
-
2650
-    /**
2651
-     * @throws DomainException
2652
-     * @throws EE_Error
2653
-     * @throws InvalidArgumentException
2654
-     * @throws InvalidDataTypeException
2655
-     * @throws InvalidInterfaceException
2656
-     */
2657
-    protected function _category_list_table()
2658
-    {
2659
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2660
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2661
-        $this->_admin_page_title .= ' ';
2662
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2663
-            'add_category',
2664
-            'add_category',
2665
-            [],
2666
-            'add-new-h2'
2667
-        );
2668
-        $this->display_admin_list_table_page_with_sidebar();
2669
-    }
2670
-
2671
-
2672
-    /**
2673
-     * Output category details view.
2674
-     *
2675
-     * @throws EE_Error
2676
-     * @throws EE_Error
2677
-     */
2678
-    protected function _category_details($view)
2679
-    {
2680
-        // load formatter helper
2681
-        // load field generator helper
2682
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2683
-        $this->_set_add_edit_form_tags($route);
2684
-        $this->_set_category_object();
2685
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2686
-        $delete_action = 'delete_category';
2687
-        // custom redirect
2688
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2689
-            ['action' => 'category_list'],
2690
-            $this->_admin_base_url
2691
-        );
2692
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2693
-        // take care of contents
2694
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2695
-        $this->display_admin_page_with_sidebar();
2696
-    }
2697
-
2698
-
2699
-    /**
2700
-     * Output category details content.
2701
-     *
2702
-     * @throws DomainException
2703
-     */
2704
-    protected function _category_details_content()
2705
-    {
2706
-        $editor_args['category_desc'] = [
2707
-            'type'          => 'wp_editor',
2708
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2709
-            'class'         => 'my_editor_custom',
2710
-            'wpeditor_args' => ['media_buttons' => false],
2711
-        ];
2712
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2713
-        $all_terms                    = get_terms(
2714
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2715
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2716
-        );
2717
-        // setup category select for term parents.
2718
-        $category_select_values[] = [
2719
-            'text' => esc_html__('No Parent', 'event_espresso'),
2720
-            'id'   => 0,
2721
-        ];
2722
-        foreach ($all_terms as $term) {
2723
-            $category_select_values[] = [
2724
-                'text' => $term->name,
2725
-                'id'   => $term->term_id,
2726
-            ];
2727
-        }
2728
-        $category_select = EEH_Form_Fields::select_input(
2729
-            'category_parent',
2730
-            $category_select_values,
2731
-            $this->_category->parent
2732
-        );
2733
-        $template_args   = [
2734
-            'category'                 => $this->_category,
2735
-            'category_select'          => $category_select,
2736
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2737
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2738
-            'disable'                  => '',
2739
-            'disabled_message'         => false,
2740
-        ];
2741
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2742
-        return EEH_Template::display_template($template, $template_args, true);
2743
-    }
2744
-
2745
-
2746
-    /**
2747
-     * Handles deleting categories.
2748
-     *
2749
-     * @throws EE_Error
2750
-     */
2751
-    protected function _delete_categories()
2752
-    {
2753
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2754
-        foreach ($category_IDs as $category_ID) {
2755
-            $this->_delete_category($category_ID);
2756
-        }
2757
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2758
-        $query_args = [
2759
-            'action' => 'category_list',
2760
-        ];
2761
-        $this->_redirect_after_action(0, '', '', $query_args);
2762
-    }
2763
-
2764
-
2765
-    /**
2766
-     * Handles deleting specific category.
2767
-     *
2768
-     * @param int $cat_id
2769
-     */
2770
-    protected function _delete_category($cat_id)
2771
-    {
2772
-        $cat_id = absint($cat_id);
2773
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2774
-    }
2775
-
2776
-
2777
-    /**
2778
-     * Handles triggering the update or insertion of a new category.
2779
-     *
2780
-     * @param bool $new_category true means we're triggering the insert of a new category.
2781
-     * @throws EE_Error
2782
-     * @throws EE_Error
2783
-     */
2784
-    protected function _insert_or_update_category($new_category)
2785
-    {
2786
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2787
-        $success = 0; // we already have a success message so lets not send another.
2788
-        if ($cat_id) {
2789
-            $query_args = [
2790
-                'action'     => 'edit_category',
2791
-                'EVT_CAT_ID' => $cat_id,
2792
-            ];
2793
-        } else {
2794
-            $query_args = ['action' => 'add_category'];
2795
-        }
2796
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2797
-    }
2798
-
2799
-
2800
-    /**
2801
-     * Inserts or updates category
2802
-     *
2803
-     * @param bool $update (true indicates we're updating a category).
2804
-     * @return bool|mixed|string
2805
-     */
2806
-    private function _insert_category($update = false)
2807
-    {
2808
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2809
-        $category_name       = $this->request->getRequestParam('category_name', '');
2810
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2811
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2812
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2813
-
2814
-        if (empty($category_name)) {
2815
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2816
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2817
-            return false;
2818
-        }
2819
-        $term_args = [
2820
-            'name'        => $category_name,
2821
-            'description' => $category_desc,
2822
-            'parent'      => $category_parent,
2823
-        ];
2824
-        // was the category_identifier input disabled?
2825
-        if ($category_identifier) {
2826
-            $term_args['slug'] = $category_identifier;
2827
-        }
2828
-        $insert_ids = $update
2829
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2830
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2831
-        if (! is_array($insert_ids)) {
2832
-            $msg = esc_html__(
2833
-                'An error occurred and the category has not been saved to the database.',
2834
-                'event_espresso'
2835
-            );
2836
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2837
-        } else {
2838
-            $category_ID = $insert_ids['term_id'];
2839
-            $msg         = sprintf(
2840
-                esc_html__('The category %s was successfully saved', 'event_espresso'),
2841
-                $category_name
2842
-            );
2843
-            EE_Error::add_success($msg);
2844
-        }
2845
-        return $category_ID;
2846
-    }
2847
-
2848
-
2849
-    /**
2850
-     * Gets categories or count of categories matching the arguments in the request.
2851
-     *
2852
-     * @param int  $per_page
2853
-     * @param int  $current_page
2854
-     * @param bool $count
2855
-     * @return EE_Term_Taxonomy[]|int
2856
-     * @throws EE_Error
2857
-     */
2858
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2859
-    {
2860
-        // testing term stuff
2861
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2862
-        $order       = $this->request->getRequestParam('order', 'DESC');
2863
-        $limit       = ($current_page - 1) * $per_page;
2864
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2865
-        $search_term = $this->request->getRequestParam('s');
2866
-        if ($search_term) {
2867
-            $search_term = '%' . $search_term . '%';
2868
-            $where['OR'] = [
2869
-                'Term.name'   => ['LIKE', $search_term],
2870
-                'description' => ['LIKE', $search_term],
2871
-            ];
2872
-        }
2873
-        $query_params = [
2874
-            $where,
2875
-            'order_by'   => [$orderby => $order],
2876
-            'limit'      => $limit . ',' . $per_page,
2877
-            'force_join' => ['Term'],
2878
-        ];
2879
-        return $count
2880
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2881
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2882
-    }
2883
-
2884
-    /* end category stuff */
2885
-
2886
-
2887
-    /**************/
2888
-
2889
-
2890
-    /**
2891
-     * Callback for the `ee_save_timezone_setting` ajax action.
2892
-     *
2893
-     * @throws EE_Error
2894
-     * @throws InvalidArgumentException
2895
-     * @throws InvalidDataTypeException
2896
-     * @throws InvalidInterfaceException
2897
-     */
2898
-    public function saveTimezoneString()
2899
-    {
2900
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2901
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2902
-            EE_Error::add_error(
2903
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2904
-                __FILE__,
2905
-                __FUNCTION__,
2906
-                __LINE__
2907
-            );
2908
-            $this->_template_args['error'] = true;
2909
-            $this->_return_json();
2910
-        }
2911
-
2912
-        update_option('timezone_string', $timezone_string);
2913
-        EE_Error::add_success(
2914
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2915
-        );
2916
-        $this->_template_args['success'] = true;
2917
-        $this->_return_json(true, ['action' => 'create_new']);
2918
-    }
2919
-
2920
-
2921
-    /**
2922 2589
      * @throws EE_Error
2923
-     * @deprecated 4.10.25.p
2924 2590
      */
2925
-    public function save_timezonestring_setting()
2926
-    {
2927
-        $this->saveTimezoneString();
2928
-    }
2591
+	protected function _template_settings()
2592
+	{
2593
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2594
+		$this->_template_args['preview_img']  = '<img src="'
2595
+												. EVENTS_ASSETS_URL
2596
+												. '/images/'
2597
+												. 'caffeinated_template_features.jpg" alt="'
2598
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2599
+												. '" />';
2600
+		$this->_template_args['preview_text'] = '<strong>'
2601
+												. esc_html__(
2602
+													'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.',
2603
+													'event_espresso'
2604
+												) . '</strong>';
2605
+		$this->display_admin_caf_preview_page('template_settings_tab');
2606
+	}
2607
+
2608
+
2609
+	/** Event Category Stuff **/
2610
+	/**
2611
+	 * set the _category property with the category object for the loaded page.
2612
+	 *
2613
+	 * @access private
2614
+	 * @return void
2615
+	 */
2616
+	private function _set_category_object()
2617
+	{
2618
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2619
+			return;
2620
+		} //already have the category object so get out.
2621
+		// set default category object
2622
+		$this->_set_empty_category_object();
2623
+		// only set if we've got an id
2624
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2625
+		if (! $category_ID) {
2626
+			return;
2627
+		}
2628
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2629
+		if (! empty($term)) {
2630
+			$this->_category->category_name       = $term->name;
2631
+			$this->_category->category_identifier = $term->slug;
2632
+			$this->_category->category_desc       = $term->description;
2633
+			$this->_category->id                  = $term->term_id;
2634
+			$this->_category->parent              = $term->parent;
2635
+		}
2636
+	}
2637
+
2638
+
2639
+	/**
2640
+	 * Clears out category properties.
2641
+	 */
2642
+	private function _set_empty_category_object()
2643
+	{
2644
+		$this->_category                = new stdClass();
2645
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2646
+		$this->_category->id            = $this->_category->parent = 0;
2647
+	}
2648
+
2649
+
2650
+	/**
2651
+	 * @throws DomainException
2652
+	 * @throws EE_Error
2653
+	 * @throws InvalidArgumentException
2654
+	 * @throws InvalidDataTypeException
2655
+	 * @throws InvalidInterfaceException
2656
+	 */
2657
+	protected function _category_list_table()
2658
+	{
2659
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2660
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2661
+		$this->_admin_page_title .= ' ';
2662
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2663
+			'add_category',
2664
+			'add_category',
2665
+			[],
2666
+			'add-new-h2'
2667
+		);
2668
+		$this->display_admin_list_table_page_with_sidebar();
2669
+	}
2670
+
2671
+
2672
+	/**
2673
+	 * Output category details view.
2674
+	 *
2675
+	 * @throws EE_Error
2676
+	 * @throws EE_Error
2677
+	 */
2678
+	protected function _category_details($view)
2679
+	{
2680
+		// load formatter helper
2681
+		// load field generator helper
2682
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2683
+		$this->_set_add_edit_form_tags($route);
2684
+		$this->_set_category_object();
2685
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2686
+		$delete_action = 'delete_category';
2687
+		// custom redirect
2688
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2689
+			['action' => 'category_list'],
2690
+			$this->_admin_base_url
2691
+		);
2692
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2693
+		// take care of contents
2694
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2695
+		$this->display_admin_page_with_sidebar();
2696
+	}
2697
+
2698
+
2699
+	/**
2700
+	 * Output category details content.
2701
+	 *
2702
+	 * @throws DomainException
2703
+	 */
2704
+	protected function _category_details_content()
2705
+	{
2706
+		$editor_args['category_desc'] = [
2707
+			'type'          => 'wp_editor',
2708
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2709
+			'class'         => 'my_editor_custom',
2710
+			'wpeditor_args' => ['media_buttons' => false],
2711
+		];
2712
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2713
+		$all_terms                    = get_terms(
2714
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2715
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2716
+		);
2717
+		// setup category select for term parents.
2718
+		$category_select_values[] = [
2719
+			'text' => esc_html__('No Parent', 'event_espresso'),
2720
+			'id'   => 0,
2721
+		];
2722
+		foreach ($all_terms as $term) {
2723
+			$category_select_values[] = [
2724
+				'text' => $term->name,
2725
+				'id'   => $term->term_id,
2726
+			];
2727
+		}
2728
+		$category_select = EEH_Form_Fields::select_input(
2729
+			'category_parent',
2730
+			$category_select_values,
2731
+			$this->_category->parent
2732
+		);
2733
+		$template_args   = [
2734
+			'category'                 => $this->_category,
2735
+			'category_select'          => $category_select,
2736
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2737
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2738
+			'disable'                  => '',
2739
+			'disabled_message'         => false,
2740
+		];
2741
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2742
+		return EEH_Template::display_template($template, $template_args, true);
2743
+	}
2744
+
2745
+
2746
+	/**
2747
+	 * Handles deleting categories.
2748
+	 *
2749
+	 * @throws EE_Error
2750
+	 */
2751
+	protected function _delete_categories()
2752
+	{
2753
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2754
+		foreach ($category_IDs as $category_ID) {
2755
+			$this->_delete_category($category_ID);
2756
+		}
2757
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2758
+		$query_args = [
2759
+			'action' => 'category_list',
2760
+		];
2761
+		$this->_redirect_after_action(0, '', '', $query_args);
2762
+	}
2763
+
2764
+
2765
+	/**
2766
+	 * Handles deleting specific category.
2767
+	 *
2768
+	 * @param int $cat_id
2769
+	 */
2770
+	protected function _delete_category($cat_id)
2771
+	{
2772
+		$cat_id = absint($cat_id);
2773
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2774
+	}
2775
+
2776
+
2777
+	/**
2778
+	 * Handles triggering the update or insertion of a new category.
2779
+	 *
2780
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2781
+	 * @throws EE_Error
2782
+	 * @throws EE_Error
2783
+	 */
2784
+	protected function _insert_or_update_category($new_category)
2785
+	{
2786
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2787
+		$success = 0; // we already have a success message so lets not send another.
2788
+		if ($cat_id) {
2789
+			$query_args = [
2790
+				'action'     => 'edit_category',
2791
+				'EVT_CAT_ID' => $cat_id,
2792
+			];
2793
+		} else {
2794
+			$query_args = ['action' => 'add_category'];
2795
+		}
2796
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2797
+	}
2798
+
2799
+
2800
+	/**
2801
+	 * Inserts or updates category
2802
+	 *
2803
+	 * @param bool $update (true indicates we're updating a category).
2804
+	 * @return bool|mixed|string
2805
+	 */
2806
+	private function _insert_category($update = false)
2807
+	{
2808
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2809
+		$category_name       = $this->request->getRequestParam('category_name', '');
2810
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2811
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2812
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2813
+
2814
+		if (empty($category_name)) {
2815
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2816
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2817
+			return false;
2818
+		}
2819
+		$term_args = [
2820
+			'name'        => $category_name,
2821
+			'description' => $category_desc,
2822
+			'parent'      => $category_parent,
2823
+		];
2824
+		// was the category_identifier input disabled?
2825
+		if ($category_identifier) {
2826
+			$term_args['slug'] = $category_identifier;
2827
+		}
2828
+		$insert_ids = $update
2829
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2830
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2831
+		if (! is_array($insert_ids)) {
2832
+			$msg = esc_html__(
2833
+				'An error occurred and the category has not been saved to the database.',
2834
+				'event_espresso'
2835
+			);
2836
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2837
+		} else {
2838
+			$category_ID = $insert_ids['term_id'];
2839
+			$msg         = sprintf(
2840
+				esc_html__('The category %s was successfully saved', 'event_espresso'),
2841
+				$category_name
2842
+			);
2843
+			EE_Error::add_success($msg);
2844
+		}
2845
+		return $category_ID;
2846
+	}
2847
+
2848
+
2849
+	/**
2850
+	 * Gets categories or count of categories matching the arguments in the request.
2851
+	 *
2852
+	 * @param int  $per_page
2853
+	 * @param int  $current_page
2854
+	 * @param bool $count
2855
+	 * @return EE_Term_Taxonomy[]|int
2856
+	 * @throws EE_Error
2857
+	 */
2858
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2859
+	{
2860
+		// testing term stuff
2861
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2862
+		$order       = $this->request->getRequestParam('order', 'DESC');
2863
+		$limit       = ($current_page - 1) * $per_page;
2864
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2865
+		$search_term = $this->request->getRequestParam('s');
2866
+		if ($search_term) {
2867
+			$search_term = '%' . $search_term . '%';
2868
+			$where['OR'] = [
2869
+				'Term.name'   => ['LIKE', $search_term],
2870
+				'description' => ['LIKE', $search_term],
2871
+			];
2872
+		}
2873
+		$query_params = [
2874
+			$where,
2875
+			'order_by'   => [$orderby => $order],
2876
+			'limit'      => $limit . ',' . $per_page,
2877
+			'force_join' => ['Term'],
2878
+		];
2879
+		return $count
2880
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2881
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2882
+	}
2883
+
2884
+	/* end category stuff */
2885
+
2886
+
2887
+	/**************/
2888
+
2889
+
2890
+	/**
2891
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2892
+	 *
2893
+	 * @throws EE_Error
2894
+	 * @throws InvalidArgumentException
2895
+	 * @throws InvalidDataTypeException
2896
+	 * @throws InvalidInterfaceException
2897
+	 */
2898
+	public function saveTimezoneString()
2899
+	{
2900
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2901
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2902
+			EE_Error::add_error(
2903
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2904
+				__FILE__,
2905
+				__FUNCTION__,
2906
+				__LINE__
2907
+			);
2908
+			$this->_template_args['error'] = true;
2909
+			$this->_return_json();
2910
+		}
2911
+
2912
+		update_option('timezone_string', $timezone_string);
2913
+		EE_Error::add_success(
2914
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2915
+		);
2916
+		$this->_template_args['success'] = true;
2917
+		$this->_return_json(true, ['action' => 'create_new']);
2918
+	}
2919
+
2920
+
2921
+	/**
2922
+	 * @throws EE_Error
2923
+	 * @deprecated 4.10.25.p
2924
+	 */
2925
+	public function save_timezonestring_setting()
2926
+	{
2927
+		$this->saveTimezoneString();
2928
+	}
2929 2929
 }
Please login to merge, or discard this patch.
admin_pages/maintenance/Maintenance_Admin_Page.core.php 1 patch
Indentation   +947 added lines, -947 removed lines patch added patch discarded remove patch
@@ -14,952 +14,952 @@
 block discarded – undo
14 14
  */
15 15
 class Maintenance_Admin_Page extends EE_Admin_Page
16 16
 {
17
-    /**
18
-     * @var EE_Data_Migration_Manager
19
-     */
20
-    protected $migration_manager;
21
-
22
-    /**
23
-     * @var EE_Maintenance_Mode
24
-     */
25
-    protected $maintenance_mode;
26
-
27
-    /**
28
-     * @var EE_Form_Section_Proper
29
-     */
30
-    protected $datetime_fix_offset_form;
31
-
32
-
33
-    /**
34
-     * @param bool $routing
35
-     * @throws EE_Error
36
-     * @throws ReflectionException
37
-     */
38
-    public function __construct($routing = true)
39
-    {
40
-        $this->migration_manager = EE_Data_Migration_Manager::instance();
41
-        $this->maintenance_mode  = EE_Maintenance_Mode::instance();
42
-        parent::__construct($routing);
43
-    }
44
-
45
-
46
-    protected function _init_page_props()
47
-    {
48
-        $this->page_slug        = EE_MAINTENANCE_PG_SLUG;
49
-        $this->page_label       = EE_MAINTENANCE_LABEL;
50
-        $this->_admin_base_url  = EE_MAINTENANCE_ADMIN_URL;
51
-        $this->_admin_base_path = EE_MAINTENANCE_ADMIN;
52
-    }
53
-
54
-
55
-    protected function _ajax_hooks()
56
-    {
57
-        add_action('wp_ajax_migration_step', [$this, 'migration_step']);
58
-        add_action('wp_ajax_add_error_to_migrations_ran', [$this, 'add_error_to_migrations_ran']);
59
-    }
60
-
61
-
62
-    protected function _define_page_props()
63
-    {
64
-        $this->_admin_page_title = EE_MAINTENANCE_LABEL;
65
-        $this->_labels           = [
66
-            'buttons' => [
67
-                'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
68
-                'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
69
-            ],
70
-        ];
71
-    }
72
-
73
-
74
-    protected function _set_page_routes()
75
-    {
76
-        $this->_page_routes = [
77
-            'default'                             => [
78
-                'func'       => '_maintenance',
79
-                'capability' => 'manage_options',
80
-            ],
81
-            'change_maintenance_level'            => [
82
-                'func'       => '_change_maintenance_level',
83
-                'capability' => 'manage_options',
84
-                'noheader'   => true,
85
-            ],
86
-            'system_status'                       => [
87
-                'func'       => '_system_status',
88
-                'capability' => 'manage_options',
89
-            ],
90
-            'download_system_status'              => [
91
-                'func'       => '_download_system_status',
92
-                'capability' => 'manage_options',
93
-                'noheader'   => true,
94
-            ],
95
-            'send_migration_crash_report'         => [
96
-                'func'       => '_send_migration_crash_report',
97
-                'capability' => 'manage_options',
98
-                'noheader'   => true,
99
-            ],
100
-            'confirm_migration_crash_report_sent' => [
101
-                'func'       => '_confirm_migration_crash_report_sent',
102
-                'capability' => 'manage_options',
103
-            ],
104
-            'data_reset'                          => [
105
-                'func'       => '_data_reset_and_delete',
106
-                'capability' => 'manage_options',
107
-            ],
108
-            'reset_db'                            => [
109
-                'func'       => '_reset_db',
110
-                'capability' => 'manage_options',
111
-                'noheader'   => true,
112
-                'args'       => ['nuke_old_ee4_data' => true],
113
-            ],
114
-            'start_with_fresh_ee4_db'             => [
115
-                'func'       => '_reset_db',
116
-                'capability' => 'manage_options',
117
-                'noheader'   => true,
118
-                'args'       => ['nuke_old_ee4_data' => false],
119
-            ],
120
-            'delete_db'                           => [
121
-                'func'       => '_delete_db',
122
-                'capability' => 'manage_options',
123
-                'noheader'   => true,
124
-            ],
125
-            'rerun_migration_from_ee3'            => [
126
-                'func'       => '_rerun_migration_from_ee3',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ],
130
-            'reset_reservations'                  => [
131
-                'func'       => '_reset_reservations',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ],
135
-            'reset_capabilities'                  => [
136
-                'func'       => '_reset_capabilities',
137
-                'capability' => 'manage_options',
138
-                'noheader'   => true,
139
-            ],
140
-            'reattempt_migration'                 => [
141
-                'func'       => '_reattempt_migration',
142
-                'capability' => 'manage_options',
143
-                'noheader'   => true,
144
-            ],
145
-            'datetime_tools'                      => [
146
-                'func'       => '_datetime_tools',
147
-                'capability' => 'manage_options',
148
-            ],
149
-            'run_datetime_offset_fix'             => [
150
-                'func'               => '_apply_datetime_offset',
151
-                'noheader'           => true,
152
-                'headers_sent_route' => 'datetime_tools',
153
-                'capability'         => 'manage_options',
154
-            ],
155
-        ];
156
-    }
157
-
158
-
159
-    protected function _set_page_config()
160
-    {
161
-        $this->_page_config = [
162
-            'default'        => [
163
-                'nav'           => [
164
-                    'label' => esc_html__('Maintenance', 'event_espresso'),
165
-                    'order' => 10,
166
-                ],
167
-                'require_nonce' => false,
168
-            ],
169
-            'data_reset'     => [
170
-                'nav'           => [
171
-                    'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
172
-                    'order' => 20,
173
-                ],
174
-                'require_nonce' => false,
175
-            ],
176
-            'datetime_tools' => [
177
-                'nav'           => [
178
-                    'label' => esc_html__('Datetime Utilities', 'event_espresso'),
179
-                    'order' => 25,
180
-                ],
181
-                'require_nonce' => false,
182
-            ],
183
-            'system_status'  => [
184
-                'nav'           => [
185
-                    'label' => esc_html__("System Information", "event_espresso"),
186
-                    'order' => 30,
187
-                ],
188
-                'require_nonce' => false,
189
-            ],
190
-        ];
191
-    }
192
-
193
-
194
-    /**
195
-     * default maintenance page.
196
-     * If we're in maintenance mode level 2, then we need to show the migration scripts and all that UI.
197
-     *
198
-     * @throws EE_Error
199
-     */
200
-    public function _maintenance()
201
-    {
202
-        $show_maintenance_switch         = true;
203
-        $show_backup_db_text             = false;
204
-        $show_migration_progress         = false;
205
-        $script_names                    = [];
206
-        $addons_should_be_upgraded_first = false;
207
-        // it all depends on if we're in maintenance model level 1 (frontend-only) or
208
-        // level 2 (everything except maintenance page)
209
-        try {
210
-            // get the current maintenance level and check if
211
-            // we are removed
212
-            $mMode_level  = $this->maintenance_mode->level();
213
-            $placed_in_mm = $this->maintenance_mode->set_maintenance_mode_if_db_old();
214
-            if ($mMode_level == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
215
-                // we just took the site out of maintenance mode, so notify the user.
216
-                // unfortunately this message appears to be echoed on the NEXT page load...
217
-                // oh well, we should really be checking for this on addon deactivation anyways
218
-                EE_Error::add_attention(
219
-                    esc_html__(
220
-                        'Site taken out of maintenance mode because no data migration scripts are required',
221
-                        'event_espresso'
222
-                    )
223
-                );
224
-                $this->_process_notices(['page' => 'espresso_maintenance_settings']);
225
-            }
226
-            // in case an exception is thrown while trying to handle migrations
227
-            if ($mMode_level === EE_Maintenance_Mode::level_2_complete_maintenance) {
228
-                $show_maintenance_switch = false;
229
-                $show_migration_progress = true;
230
-                if (isset($this->_req_data['continue_migration'])) {
231
-                    $show_backup_db_text = false;
232
-                } else {
233
-                    $show_backup_db_text = true;
234
-                }
235
-                $scripts_needing_to_run          =
236
-                    $this->migration_manager->check_for_applicable_data_migration_scripts();
237
-                $addons_should_be_upgraded_first = $this->migration_manager->addons_need_updating();
238
-                $script_names                    = [];
239
-                $current_script                  = null;
240
-                foreach ($scripts_needing_to_run as $script) {
241
-                    if ($script instanceof EE_Data_Migration_Script_Base) {
242
-                        if (! $current_script) {
243
-                            $current_script = $script;
244
-                            $current_script->migration_page_hooks();
245
-                        }
246
-                        $script_names[] = $script->pretty_name();
247
-                    }
248
-                }
249
-            }
250
-            $most_recent_migration = $this->migration_manager->get_last_ran_script(true);
251
-            $exception_thrown      = false;
252
-        } catch (EE_Error $e) {
253
-            $this->migration_manager->add_error_to_migrations_ran($e->getMessage());
254
-            // now, just so we can display the page correctly, make an error migration script stage object
255
-            // and also put the error on it. It only persists for the duration of this request
256
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
257
-            $most_recent_migration->add_error($e->getMessage());
258
-            $exception_thrown = true;
259
-        }
260
-        $current_db_state = $this->migration_manager->ensure_current_database_state_is_set();
261
-        $current_db_state = str_replace('.decaf', '', $current_db_state);
262
-        if (
263
-            $exception_thrown
264
-            || (
265
-                $most_recent_migration instanceof EE_Data_Migration_Script_Base
266
-                && $most_recent_migration->is_broken()
267
-            )
268
-        ) {
269
-            $this->_template_path                =
270
-                EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
271
-            $this->_template_args['support_url'] = 'https://eventespresso.com/support/forums/';
272
-            $this->_template_args['next_url']    = EEH_URL::add_query_args_and_nonce(
273
-                [
274
-                    'action'  => 'confirm_migration_crash_report_sent',
275
-                    'success' => '0',
276
-                ],
277
-                EE_MAINTENANCE_ADMIN_URL
278
-            );
279
-        } elseif ($addons_should_be_upgraded_first) {
280
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
281
-        } else {
282
-            if (
283
-                $most_recent_migration instanceof EE_Data_Migration_Script_Base
284
-                && $most_recent_migration->can_continue()
285
-            ) {
286
-                $show_backup_db_text                    = false;
287
-                $show_continue_current_migration_script = true;
288
-                $show_most_recent_migration             = true;
289
-            } elseif (isset($this->_req_data['continue_migration'])) {
290
-                $show_most_recent_migration             = true;
291
-                $show_continue_current_migration_script = false;
292
-            } else {
293
-                $show_most_recent_migration             = false;
294
-                $show_continue_current_migration_script = false;
295
-            }
296
-            if (isset($current_script)) {
297
-                $migrates_to          = $current_script->migrates_to_version();
298
-                $plugin_slug          = $migrates_to['slug'];
299
-                $new_version          = $migrates_to['version'];
300
-                $this->_template_args = array_merge(
301
-                    $this->_template_args,
302
-                    [
303
-                        'current_db_state' => sprintf(
304
-                            esc_html__("EE%s (%s)", "event_espresso"),
305
-                            isset($current_db_state[ $plugin_slug ]) ? $current_db_state[ $plugin_slug ] : 3,
306
-                            $plugin_slug
307
-                        ),
308
-                        'next_db_state'    => sprintf(
309
-                            esc_html__("EE%s (%s)", 'event_espresso'),
310
-                            $new_version,
311
-                            $plugin_slug
312
-                        ),
313
-                    ]
314
-                );
315
-            } else {
316
-                $this->_template_args['current_db_state'] = null;
317
-                $this->_template_args['next_db_state']    = null;
318
-            }
319
-            $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
320
-            $this->_template_args = array_merge(
321
-                $this->_template_args,
322
-                [
323
-                    'show_most_recent_migration'             => $show_most_recent_migration,
324
-                    // flag for showing the most recent migration's status and/or errors
325
-                    'show_migration_progress'                => $show_migration_progress,
326
-                    // flag for showing the option to run migrations and see their progress
327
-                    'show_backup_db_text'                    => $show_backup_db_text,
328
-                    // flag for showing text telling the user to back up their DB
329
-                    'show_maintenance_switch'                => $show_maintenance_switch,
330
-                    // flag for showing the option to change maintenance mode between levels 0 and 1
331
-                    'script_names'                           => $script_names,
332
-                    // array of names of scripts that have run
333
-                    'show_continue_current_migration_script' => $show_continue_current_migration_script,
334
-                    // flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
335
-                    'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(
336
-                        ['action' => 'reset_db'],
337
-                        EE_MAINTENANCE_ADMIN_URL
338
-                    ),
339
-                    'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(
340
-                        ['action' => 'data_reset'],
341
-                        EE_MAINTENANCE_ADMIN_URL
342
-                    ),
343
-                    'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(
344
-                        ['action' => 'change_maintenance_level'],
345
-                        EE_MAINTENANCE_ADMIN_URL
346
-                    ),
347
-                    'ultimate_db_state'                      => sprintf(
348
-                        esc_html__("EE%s", 'event_espresso'),
349
-                        espresso_version()
350
-                    ),
351
-                ]
352
-            );
353
-        }
354
-        $this->_template_args['most_recent_migration'] =
355
-            $most_recent_migration;// the actual most recently ran migration
356
-        // now render the migration options part, and put it in a variable
357
-        $migration_options_template_file                = apply_filters(
358
-            'FHEE__ee_migration_page__migration_options_template',
359
-            EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
360
-        );
361
-        $migration_options_html                         = EEH_Template::display_template(
362
-            $migration_options_template_file,
363
-            $this->_template_args,
364
-            true
365
-        );
366
-        $this->_template_args['migration_options_html'] = $migration_options_html;
367
-        $this->_template_args['admin_page_content']     = EEH_Template::display_template(
368
-            $this->_template_path,
369
-            $this->_template_args,
370
-            true
371
-        );
372
-        $this->display_admin_page_with_sidebar();
373
-    }
374
-
375
-
376
-    /**
377
-     * returns JSON and executes another step of the currently-executing data migration (called via ajax)
378
-     *
379
-     * @throws EE_Error
380
-     */
381
-    public function migration_step()
382
-    {
383
-        $this->_template_args['data'] = $this->migration_manager->response_to_migration_ajax_request();
384
-        $this->_return_json();
385
-    }
386
-
387
-
388
-    /**
389
-     * Can be used by js when it notices a response with HTML in it in order
390
-     * to log the malformed response
391
-     *
392
-     * @throws EE_Error
393
-     */
394
-    public function add_error_to_migrations_ran()
395
-    {
396
-        $this->migration_manager->add_error_to_migrations_ran($this->_req_data['message']);
397
-        $this->_template_args['data'] = ['ok' => true];
398
-        $this->_return_json();
399
-    }
400
-
401
-
402
-    /**
403
-     * changes the maintenance level, provided there are still no migration scripts that should run
404
-     *
405
-     * @throws EE_Error
406
-     */
407
-    public function _change_maintenance_level()
408
-    {
409
-        $new_level = absint($this->_req_data['maintenance_mode_level']);
410
-        if (! $this->migration_manager->check_for_applicable_data_migration_scripts()) {
411
-            $this->maintenance_mode->set_maintenance_level($new_level);
412
-            $success = true;
413
-        } else {
414
-            $this->maintenance_mode->set_maintenance_mode_if_db_old();
415
-            $success = false;
416
-        }
417
-        $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
418
-    }
419
-
420
-
421
-    /**
422
-     * a tab with options for resetting and/or deleting EE data
423
-     *
424
-     * @throws EE_Error
425
-     * @throws DomainException
426
-     */
427
-    public function _data_reset_and_delete()
428
-    {
429
-        $this->_template_path                              =
430
-            EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
431
-        $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
432
-            'reset_reservations',
433
-            'reset_reservations',
434
-            [],
435
-            'button button--caution ee-confirm'
436
-        );
437
-        $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
438
-            'reset_capabilities',
439
-            'reset_capabilities',
440
-            [],
441
-            'button button--caution ee-confirm'
442
-        );
443
-        $this->_template_args['delete_db_url']             = EE_Admin_Page::add_query_args_and_nonce(
444
-            ['action' => 'delete_db'],
445
-            EE_MAINTENANCE_ADMIN_URL
446
-        );
447
-        $this->_template_args['reset_db_url']              = EE_Admin_Page::add_query_args_and_nonce(
448
-            ['action' => 'reset_db'],
449
-            EE_MAINTENANCE_ADMIN_URL
450
-        );
451
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
452
-            $this->_template_path,
453
-            $this->_template_args,
454
-            true
455
-        );
456
-        $this->display_admin_page_with_no_sidebar();
457
-    }
458
-
459
-
460
-    /**
461
-     * @throws EE_Error
462
-     * @throws ReflectionException
463
-     */
464
-    protected function _reset_reservations()
465
-    {
466
-        if (EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
467
-            EE_Error::add_success(
468
-                esc_html__(
469
-                    'Ticket and datetime reserved counts have been successfully reset.',
470
-                    'event_espresso'
471
-                )
472
-            );
473
-        } else {
474
-            EE_Error::add_success(
475
-                esc_html__(
476
-                    'Ticket and datetime reserved counts were correct and did not need resetting.',
477
-                    'event_espresso'
478
-                )
479
-            );
480
-        }
481
-        $this->_redirect_after_action(true, '', '', ['action' => 'data_reset'], true);
482
-    }
483
-
484
-
485
-    /**
486
-     * @throws EE_Error
487
-     */
488
-    protected function _reset_capabilities()
489
-    {
490
-        EE_Registry::instance()->CAP->init_caps(true);
491
-        EE_Error::add_success(
492
-            esc_html__(
493
-                'Default Event Espresso capabilities have been restored for all current roles.',
494
-                'event_espresso'
495
-            )
496
-        );
497
-        $this->_redirect_after_action(false, '', '', ['action' => 'data_reset'], true);
498
-    }
499
-
500
-
501
-    /**
502
-     * resets the DMSs, so we can attempt to continue migrating after a fatal error
503
-     * (only a good idea when someone has somehow tried ot fix whatever caused
504
-     * the fatal error in teh first place)
505
-     *
506
-     * @throws EE_Error
507
-     */
508
-    protected function _reattempt_migration()
509
-    {
510
-        $this->migration_manager->reattempt();
511
-        $this->_redirect_after_action(false, '', '', ['action' => 'default'], true);
512
-    }
513
-
514
-
515
-    /**
516
-     * shows the big ol' System Information page
517
-     *
518
-     * @throws EE_Error
519
-     */
520
-    public function _system_status()
521
-    {
522
-        $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
523
-        $this->_template_args['system_stati']               = EEM_System_Status::instance()->get_system_stati();
524
-        $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
525
-            [
526
-                'action' => 'download_system_status',
527
-            ],
528
-            EE_MAINTENANCE_ADMIN_URL
529
-        );
530
-        $this->_template_args['admin_page_content']         = EEH_Template::display_template(
531
-            $this->_template_path,
532
-            $this->_template_args,
533
-            true
534
-        );
535
-        $this->display_admin_page_with_no_sidebar();
536
-    }
537
-
538
-
539
-    /**
540
-     * Downloads an HTML file of the system status that can be easily stored or emailed
541
-     */
542
-    public function _download_system_status()
543
-    {
544
-        $status_info = EEM_System_Status::instance()->get_system_stati();
545
-        header('Content-Disposition: attachment');
546
-        header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html");
547
-        $output = '<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>';
548
-        $output .= '<h1>' . sprintf(
549
-            __('System Information for %1$s', 'event_espresso'),
550
-            esc_url_raw(site_url())
551
-        ) . '</h1>';
552
-        $output .= EEH_Template::layout_array_as_table($status_info);
553
-        echo esc_html($output);
554
-        die;
555
-    }
556
-
557
-
558
-    /**
559
-     * @throws EE_Error
560
-     */
561
-    public function _send_migration_crash_report()
562
-    {
563
-        $from      = $this->_req_data['from'];
564
-        $from_name = $this->_req_data['from_name'];
565
-        $body      = $this->_req_data['body'];
566
-        try {
567
-            $success = wp_mail(
568
-                EE_SUPPORT_EMAIL,
569
-                'Migration Crash Report',
570
-                $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
571
-                [
572
-                    "from:$from_name<$from>",
573
-                ]
574
-            );
575
-        } catch (Exception $e) {
576
-            $success = false;
577
-        }
578
-        $this->_redirect_after_action(
579
-            $success,
580
-            esc_html__("Migration Crash Report", "event_espresso"),
581
-            esc_html__("sent", "event_espresso"),
582
-            ['success' => $success, 'action' => 'confirm_migration_crash_report_sent']
583
-        );
584
-    }
585
-
586
-
587
-    /**
588
-     * @throws EE_Error
589
-     */
590
-    public function _confirm_migration_crash_report_sent()
591
-    {
592
-        try {
593
-            $most_recent_migration = $this->migration_manager->get_last_ran_script(true);
594
-        } catch (EE_Error $e) {
595
-            $this->migration_manager->add_error_to_migrations_ran($e->getMessage());
596
-            // now, just so we can display the page correctly, make an error migration script stage object
597
-            // and also put the error on it. It only persists for the duration of this request
598
-            $most_recent_migration = new EE_DMS_Unknown_1_0_0();
599
-            $most_recent_migration->add_error($e->getMessage());
600
-        }
601
-        $success                                       = $this->_req_data['success'] === '1';
602
-        $this->_template_args['success']               = $success;
603
-        $this->_template_args['most_recent_migration'] = $most_recent_migration;
604
-        $this->_template_args['reset_db_action_url']   = EE_Admin_Page::add_query_args_and_nonce(
605
-            ['action' => 'reset_db'],
606
-            EE_MAINTENANCE_ADMIN_URL
607
-        );
608
-        $this->_template_args['reset_db_page_url']     = EE_Admin_Page::add_query_args_and_nonce(
609
-            ['action' => 'data_reset'],
610
-            EE_MAINTENANCE_ADMIN_URL
611
-        );
612
-        $this->_template_args['reattempt_action_url']  = EE_Admin_Page::add_query_args_and_nonce(
613
-            ['action' => 'reattempt_migration'],
614
-            EE_MAINTENANCE_ADMIN_URL
615
-        );
616
-        $this->_template_path                          =
617
-            EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
618
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
619
-            $this->_template_path,
620
-            $this->_template_args,
621
-            true
622
-        );
623
-        $this->display_admin_page_with_sidebar();
624
-    }
625
-
626
-
627
-    /**
628
-     * Resets the entire EE4 database.
629
-     * only sets up ee4 database for a fresh install-
630
-     * doesn't actually clean out the old wp options, or cpts
631
-     * (although it does erase old ee table data)
632
-     *
633
-     * @param boolean $nuke_old_ee4_data controls whether we destroy the old ee4 data,
634
-     *                                   or just try initializing ee4 default data
635
-     * @throws EE_Error
636
-     * @throws ReflectionException
637
-     */
638
-    public function _reset_db($nuke_old_ee4_data = true)
639
-    {
640
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
641
-        if ($nuke_old_ee4_data) {
642
-            EEH_Activation::delete_all_espresso_cpt_data();
643
-            EEH_Activation::delete_all_espresso_tables_and_data(false);
644
-            EEH_Activation::remove_cron_tasks();
645
-        }
646
-        // make sure when we reset the registry's config that it
647
-        // switches to using the new singleton
648
-        EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
649
-        EE_System::instance()->initialize_db_if_no_migrations_required(true);
650
-        EE_System::instance()->redirect_to_about_ee();
651
-    }
652
-
653
-
654
-    /**
655
-     * Deletes ALL EE tables, Records, and Options from the database.
656
-     *
657
-     * @throws EE_Error
658
-     * @throws ReflectionException
659
-     */
660
-    public function _delete_db()
661
-    {
662
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
663
-        EEH_Activation::delete_all_espresso_cpt_data();
664
-        EEH_Activation::delete_all_espresso_tables_and_data();
665
-        EEH_Activation::remove_cron_tasks();
666
-        EEH_Activation::deactivate_event_espresso();
667
-        wp_safe_redirect(admin_url('plugins.php'));
668
-        exit;
669
-    }
670
-
671
-
672
-    /**
673
-     * sets up EE4 to rerun the migrations from ee3 to ee4
674
-     *
675
-     * @throws EE_Error
676
-     * @throws ReflectionException
677
-     */
678
-    public function _rerun_migration_from_ee3()
679
-    {
680
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
681
-        EEH_Activation::delete_all_espresso_cpt_data();
682
-        EEH_Activation::delete_all_espresso_tables_and_data(false);
683
-        // set the db state to something that will require migrations
684
-        update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
685
-        $this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
686
-        $this->_redirect_after_action(
687
-            true,
688
-            esc_html__("Database", 'event_espresso'),
689
-            esc_html__("reset", 'event_espresso')
690
-        );
691
-    }
692
-
693
-
694
-    // none of the below group are currently used for Gateway Settings
695
-    protected function _add_screen_options()
696
-    {
697
-    }
698
-
699
-
700
-    protected function _add_feature_pointers()
701
-    {
702
-    }
703
-
704
-
705
-    public function admin_init()
706
-    {
707
-    }
708
-
709
-
710
-    public function admin_notices()
711
-    {
712
-    }
713
-
714
-
715
-    public function admin_footer_scripts()
716
-    {
717
-    }
718
-
719
-
720
-    public function load_scripts_styles()
721
-    {
722
-        wp_enqueue_script('ee_admin_js');
723
-        wp_enqueue_script(
724
-            'ee-maintenance',
725
-            EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js',
726
-            ['jquery'],
727
-            EVENT_ESPRESSO_VERSION,
728
-            true
729
-        );
730
-        wp_register_style(
731
-            'espresso_maintenance',
732
-            EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css',
733
-            [],
734
-            EVENT_ESPRESSO_VERSION
735
-        );
736
-        wp_enqueue_style('espresso_maintenance');
737
-        // localize script stuff
738
-        wp_localize_script(
739
-            'ee-maintenance',
740
-            'ee_maintenance',
741
-            [
742
-                'migrating'                        => wp_strip_all_tags(__("Updating Database...", "event_espresso")),
743
-                'next'                             => wp_strip_all_tags(__("Next", "event_espresso")),
744
-                'fatal_error'                      => wp_strip_all_tags(__(
745
-                    "A Fatal Error Has Occurred",
746
-                    "event_espresso"
747
-                )),
748
-                'click_next_when_ready'            => wp_strip_all_tags(
749
-                    __(
750
-                        "The current Database Update has ended. Click 'next' when ready to proceed",
751
-                        "event_espresso"
752
-                    )
753
-                ),
754
-                'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
755
-                'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
756
-                'status_completed'                 => EE_Data_Migration_Manager::status_completed,
757
-                'confirm'                          => wp_strip_all_tags(
758
-                    __(
759
-                        'Are you sure you want to do this? It CANNOT be undone!',
760
-                        'event_espresso'
761
-                    )
762
-                ),
763
-                'confirm_skip_migration'           => wp_strip_all_tags(
764
-                    __(
765
-                        'You have chosen to NOT migrate your existing data. Are you sure you want to continue?',
766
-                        'event_espresso'
767
-                    )
768
-                ),
769
-            ]
770
-        );
771
-    }
772
-
773
-
774
-    public function load_scripts_styles_default()
775
-    {
776
-    }
777
-
778
-
779
-    /**
780
-     * Enqueue scripts and styles for the datetime tools page.
781
-     */
782
-    public function load_scripts_styles_datetime_tools()
783
-    {
784
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
785
-    }
786
-
787
-
788
-    /**
789
-     * @throws EE_Error
790
-     */
791
-    protected function _datetime_tools()
792
-    {
793
-        $form_action                                = EE_Admin_Page::add_query_args_and_nonce(
794
-            [
795
-                'action'        => 'run_datetime_offset_fix',
796
-                'return_action' => $this->_req_action,
797
-            ],
798
-            EE_MAINTENANCE_ADMIN_URL
799
-        );
800
-        $form                                       = $this->_get_datetime_offset_fix_form();
801
-        $this->_admin_page_title                    = esc_html__('Datetime Utilities', 'event_espresso');
802
-        $this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
803
-                                                      . $form->get_html_and_js()
804
-                                                      . $form->form_close();
805
-        $this->display_admin_page_with_sidebar();
806
-    }
807
-
808
-
809
-    /**
810
-     * @throws EE_Error
811
-     */
812
-    protected function _get_datetime_offset_fix_form()
813
-    {
814
-        if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
815
-            $this->datetime_fix_offset_form = new EE_Form_Section_Proper(
816
-                [
817
-                    'name'            => 'datetime_offset_fix_option',
818
-                    'layout_strategy' => new EE_Admin_Two_Column_Layout(),
819
-                    'subsections'     => [
820
-                        'title'                  => new EE_Form_Section_HTML(
821
-                            EEH_HTML::h2(
822
-                                esc_html__('Datetime Offset Tool', 'event_espresso')
823
-                            )
824
-                        ),
825
-                        'explanation'            => new EE_Form_Section_HTML(
826
-                            EEH_HTML::p(
827
-                                esc_html__(
828
-                                    'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
829
-                                    'event_espresso'
830
-                                )
831
-                            )
832
-                            . EEH_HTML::p(
833
-                                esc_html__(
834
-                                    'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied.  Decimals represent the fraction of hours, not minutes.',
835
-                                    'event_espresso'
836
-                                )
837
-                            )
838
-                        ),
839
-                        'offset_input'           => new EE_Float_Input(
840
-                            [
841
-                                'html_name'       => 'offset_for_datetimes',
842
-                                'html_label_text' => esc_html__(
843
-                                    'Offset to apply (in hours):',
844
-                                    'event_espresso'
845
-                                ),
846
-                                'min_value'       => '-12',
847
-                                'max_value'       => '14',
848
-                                'step_value'      => '.25',
849
-                                'default'         => DatetimeOffsetFix::getOffset(),
850
-                            ]
851
-                        ),
852
-                        'date_range_explanation' => new EE_Form_Section_HTML(
853
-                            EEH_HTML::p(
854
-                                esc_html__(
855
-                                    'Leave the following fields blank if you want the offset to be applied to all dates. If however, you want to just apply the offset to a specific range of dates you can restrict the offset application using these fields.',
856
-                                    'event_espresso'
857
-                                )
858
-                            )
859
-                            . EEH_HTML::p(
860
-                                EEH_HTML::strong(
861
-                                    sprintf(
862
-                                        esc_html__(
863
-                                            'Note: please enter the dates in UTC (You can use %1$sthis online tool%2$s to assist with conversions).',
864
-                                            'event_espresso'
865
-                                        ),
866
-                                        '<a href="https://www.timeanddate.com/worldclock/converter.html">',
867
-                                        '</a>'
868
-                                    )
869
-                                )
870
-                            )
871
-                        ),
872
-                        'date_range_start_date'  => new EE_Datepicker_Input(
873
-                            [
874
-                                'html_name'       => 'offset_date_start_range',
875
-                                'html_label_text' => esc_html__(
876
-                                    'Start Date for dates the offset applied to:',
877
-                                    'event_espresso'
878
-                                ),
879
-                            ]
880
-                        ),
881
-                        'date_range_end_date'    => new EE_Datepicker_Input(
882
-                            [
883
-                                'html_name'       => 'offset_date_end_range',
884
-                                'html_label_text' => esc_html__(
885
-                                    'End Date for dates the offset is applied to:',
886
-                                    'event_espresso'
887
-                                ),
888
-                            ]
889
-                        ),
890
-                        'submit'                 => new EE_Submit_Input(
891
-                            [
892
-                                'html_label_text' => '',
893
-                                'default'         => esc_html__('Apply Offset', 'event_espresso'),
894
-                            ]
895
-                        ),
896
-                    ],
897
-                ]
898
-            );
899
-        }
900
-        return $this->datetime_fix_offset_form;
901
-    }
902
-
903
-
904
-    /**
905
-     * Callback for the run_datetime_offset_fix route.
906
-     *
907
-     * @throws EE_Error
908
-     */
909
-    protected function _apply_datetime_offset()
910
-    {
911
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
912
-            $form = $this->_get_datetime_offset_fix_form();
913
-            $form->receive_form_submission($this->_req_data);
914
-            if ($form->is_valid()) {
915
-                // save offset data so batch processor can get it.
916
-                DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
917
-                $utc_timezone          = new DateTimeZone('UTC');
918
-                $date_range_start_date = DateTime::createFromFormat(
919
-                    'm/d/Y H:i:s',
920
-                    $form->get_input_value('date_range_start_date') . ' 00:00:00',
921
-                    $utc_timezone
922
-                );
923
-                $date_range_end_date   = DateTime::createFromFormat(
924
-                    'm/d/Y H:i:s',
925
-                    $form->get_input_value('date_range_end_date') . ' 23:59:59',
926
-                    $utc_timezone
927
-                );
928
-                if ($date_range_start_date instanceof DateTime) {
929
-                    DatetimeOffsetFix::updateStartDateRange(DbSafeDateTime::createFromDateTime($date_range_start_date));
930
-                }
931
-                if ($date_range_end_date instanceof DateTime) {
932
-                    DatetimeOffsetFix::updateEndDateRange(DbSafeDateTime::createFromDateTime($date_range_end_date));
933
-                }
934
-                // redirect to batch tool
935
-                wp_redirect(
936
-                    EE_Admin_Page::add_query_args_and_nonce(
937
-                        [
938
-                            'page'        => EED_Batch::PAGE_SLUG,
17
+	/**
18
+	 * @var EE_Data_Migration_Manager
19
+	 */
20
+	protected $migration_manager;
21
+
22
+	/**
23
+	 * @var EE_Maintenance_Mode
24
+	 */
25
+	protected $maintenance_mode;
26
+
27
+	/**
28
+	 * @var EE_Form_Section_Proper
29
+	 */
30
+	protected $datetime_fix_offset_form;
31
+
32
+
33
+	/**
34
+	 * @param bool $routing
35
+	 * @throws EE_Error
36
+	 * @throws ReflectionException
37
+	 */
38
+	public function __construct($routing = true)
39
+	{
40
+		$this->migration_manager = EE_Data_Migration_Manager::instance();
41
+		$this->maintenance_mode  = EE_Maintenance_Mode::instance();
42
+		parent::__construct($routing);
43
+	}
44
+
45
+
46
+	protected function _init_page_props()
47
+	{
48
+		$this->page_slug        = EE_MAINTENANCE_PG_SLUG;
49
+		$this->page_label       = EE_MAINTENANCE_LABEL;
50
+		$this->_admin_base_url  = EE_MAINTENANCE_ADMIN_URL;
51
+		$this->_admin_base_path = EE_MAINTENANCE_ADMIN;
52
+	}
53
+
54
+
55
+	protected function _ajax_hooks()
56
+	{
57
+		add_action('wp_ajax_migration_step', [$this, 'migration_step']);
58
+		add_action('wp_ajax_add_error_to_migrations_ran', [$this, 'add_error_to_migrations_ran']);
59
+	}
60
+
61
+
62
+	protected function _define_page_props()
63
+	{
64
+		$this->_admin_page_title = EE_MAINTENANCE_LABEL;
65
+		$this->_labels           = [
66
+			'buttons' => [
67
+				'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'),
68
+				'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'),
69
+			],
70
+		];
71
+	}
72
+
73
+
74
+	protected function _set_page_routes()
75
+	{
76
+		$this->_page_routes = [
77
+			'default'                             => [
78
+				'func'       => '_maintenance',
79
+				'capability' => 'manage_options',
80
+			],
81
+			'change_maintenance_level'            => [
82
+				'func'       => '_change_maintenance_level',
83
+				'capability' => 'manage_options',
84
+				'noheader'   => true,
85
+			],
86
+			'system_status'                       => [
87
+				'func'       => '_system_status',
88
+				'capability' => 'manage_options',
89
+			],
90
+			'download_system_status'              => [
91
+				'func'       => '_download_system_status',
92
+				'capability' => 'manage_options',
93
+				'noheader'   => true,
94
+			],
95
+			'send_migration_crash_report'         => [
96
+				'func'       => '_send_migration_crash_report',
97
+				'capability' => 'manage_options',
98
+				'noheader'   => true,
99
+			],
100
+			'confirm_migration_crash_report_sent' => [
101
+				'func'       => '_confirm_migration_crash_report_sent',
102
+				'capability' => 'manage_options',
103
+			],
104
+			'data_reset'                          => [
105
+				'func'       => '_data_reset_and_delete',
106
+				'capability' => 'manage_options',
107
+			],
108
+			'reset_db'                            => [
109
+				'func'       => '_reset_db',
110
+				'capability' => 'manage_options',
111
+				'noheader'   => true,
112
+				'args'       => ['nuke_old_ee4_data' => true],
113
+			],
114
+			'start_with_fresh_ee4_db'             => [
115
+				'func'       => '_reset_db',
116
+				'capability' => 'manage_options',
117
+				'noheader'   => true,
118
+				'args'       => ['nuke_old_ee4_data' => false],
119
+			],
120
+			'delete_db'                           => [
121
+				'func'       => '_delete_db',
122
+				'capability' => 'manage_options',
123
+				'noheader'   => true,
124
+			],
125
+			'rerun_migration_from_ee3'            => [
126
+				'func'       => '_rerun_migration_from_ee3',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			],
130
+			'reset_reservations'                  => [
131
+				'func'       => '_reset_reservations',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			],
135
+			'reset_capabilities'                  => [
136
+				'func'       => '_reset_capabilities',
137
+				'capability' => 'manage_options',
138
+				'noheader'   => true,
139
+			],
140
+			'reattempt_migration'                 => [
141
+				'func'       => '_reattempt_migration',
142
+				'capability' => 'manage_options',
143
+				'noheader'   => true,
144
+			],
145
+			'datetime_tools'                      => [
146
+				'func'       => '_datetime_tools',
147
+				'capability' => 'manage_options',
148
+			],
149
+			'run_datetime_offset_fix'             => [
150
+				'func'               => '_apply_datetime_offset',
151
+				'noheader'           => true,
152
+				'headers_sent_route' => 'datetime_tools',
153
+				'capability'         => 'manage_options',
154
+			],
155
+		];
156
+	}
157
+
158
+
159
+	protected function _set_page_config()
160
+	{
161
+		$this->_page_config = [
162
+			'default'        => [
163
+				'nav'           => [
164
+					'label' => esc_html__('Maintenance', 'event_espresso'),
165
+					'order' => 10,
166
+				],
167
+				'require_nonce' => false,
168
+			],
169
+			'data_reset'     => [
170
+				'nav'           => [
171
+					'label' => esc_html__('Reset/Delete Data', 'event_espresso'),
172
+					'order' => 20,
173
+				],
174
+				'require_nonce' => false,
175
+			],
176
+			'datetime_tools' => [
177
+				'nav'           => [
178
+					'label' => esc_html__('Datetime Utilities', 'event_espresso'),
179
+					'order' => 25,
180
+				],
181
+				'require_nonce' => false,
182
+			],
183
+			'system_status'  => [
184
+				'nav'           => [
185
+					'label' => esc_html__("System Information", "event_espresso"),
186
+					'order' => 30,
187
+				],
188
+				'require_nonce' => false,
189
+			],
190
+		];
191
+	}
192
+
193
+
194
+	/**
195
+	 * default maintenance page.
196
+	 * If we're in maintenance mode level 2, then we need to show the migration scripts and all that UI.
197
+	 *
198
+	 * @throws EE_Error
199
+	 */
200
+	public function _maintenance()
201
+	{
202
+		$show_maintenance_switch         = true;
203
+		$show_backup_db_text             = false;
204
+		$show_migration_progress         = false;
205
+		$script_names                    = [];
206
+		$addons_should_be_upgraded_first = false;
207
+		// it all depends on if we're in maintenance model level 1 (frontend-only) or
208
+		// level 2 (everything except maintenance page)
209
+		try {
210
+			// get the current maintenance level and check if
211
+			// we are removed
212
+			$mMode_level  = $this->maintenance_mode->level();
213
+			$placed_in_mm = $this->maintenance_mode->set_maintenance_mode_if_db_old();
214
+			if ($mMode_level == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
215
+				// we just took the site out of maintenance mode, so notify the user.
216
+				// unfortunately this message appears to be echoed on the NEXT page load...
217
+				// oh well, we should really be checking for this on addon deactivation anyways
218
+				EE_Error::add_attention(
219
+					esc_html__(
220
+						'Site taken out of maintenance mode because no data migration scripts are required',
221
+						'event_espresso'
222
+					)
223
+				);
224
+				$this->_process_notices(['page' => 'espresso_maintenance_settings']);
225
+			}
226
+			// in case an exception is thrown while trying to handle migrations
227
+			if ($mMode_level === EE_Maintenance_Mode::level_2_complete_maintenance) {
228
+				$show_maintenance_switch = false;
229
+				$show_migration_progress = true;
230
+				if (isset($this->_req_data['continue_migration'])) {
231
+					$show_backup_db_text = false;
232
+				} else {
233
+					$show_backup_db_text = true;
234
+				}
235
+				$scripts_needing_to_run          =
236
+					$this->migration_manager->check_for_applicable_data_migration_scripts();
237
+				$addons_should_be_upgraded_first = $this->migration_manager->addons_need_updating();
238
+				$script_names                    = [];
239
+				$current_script                  = null;
240
+				foreach ($scripts_needing_to_run as $script) {
241
+					if ($script instanceof EE_Data_Migration_Script_Base) {
242
+						if (! $current_script) {
243
+							$current_script = $script;
244
+							$current_script->migration_page_hooks();
245
+						}
246
+						$script_names[] = $script->pretty_name();
247
+					}
248
+				}
249
+			}
250
+			$most_recent_migration = $this->migration_manager->get_last_ran_script(true);
251
+			$exception_thrown      = false;
252
+		} catch (EE_Error $e) {
253
+			$this->migration_manager->add_error_to_migrations_ran($e->getMessage());
254
+			// now, just so we can display the page correctly, make an error migration script stage object
255
+			// and also put the error on it. It only persists for the duration of this request
256
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
257
+			$most_recent_migration->add_error($e->getMessage());
258
+			$exception_thrown = true;
259
+		}
260
+		$current_db_state = $this->migration_manager->ensure_current_database_state_is_set();
261
+		$current_db_state = str_replace('.decaf', '', $current_db_state);
262
+		if (
263
+			$exception_thrown
264
+			|| (
265
+				$most_recent_migration instanceof EE_Data_Migration_Script_Base
266
+				&& $most_recent_migration->is_broken()
267
+			)
268
+		) {
269
+			$this->_template_path                =
270
+				EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
271
+			$this->_template_args['support_url'] = 'https://eventespresso.com/support/forums/';
272
+			$this->_template_args['next_url']    = EEH_URL::add_query_args_and_nonce(
273
+				[
274
+					'action'  => 'confirm_migration_crash_report_sent',
275
+					'success' => '0',
276
+				],
277
+				EE_MAINTENANCE_ADMIN_URL
278
+			);
279
+		} elseif ($addons_should_be_upgraded_first) {
280
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
281
+		} else {
282
+			if (
283
+				$most_recent_migration instanceof EE_Data_Migration_Script_Base
284
+				&& $most_recent_migration->can_continue()
285
+			) {
286
+				$show_backup_db_text                    = false;
287
+				$show_continue_current_migration_script = true;
288
+				$show_most_recent_migration             = true;
289
+			} elseif (isset($this->_req_data['continue_migration'])) {
290
+				$show_most_recent_migration             = true;
291
+				$show_continue_current_migration_script = false;
292
+			} else {
293
+				$show_most_recent_migration             = false;
294
+				$show_continue_current_migration_script = false;
295
+			}
296
+			if (isset($current_script)) {
297
+				$migrates_to          = $current_script->migrates_to_version();
298
+				$plugin_slug          = $migrates_to['slug'];
299
+				$new_version          = $migrates_to['version'];
300
+				$this->_template_args = array_merge(
301
+					$this->_template_args,
302
+					[
303
+						'current_db_state' => sprintf(
304
+							esc_html__("EE%s (%s)", "event_espresso"),
305
+							isset($current_db_state[ $plugin_slug ]) ? $current_db_state[ $plugin_slug ] : 3,
306
+							$plugin_slug
307
+						),
308
+						'next_db_state'    => sprintf(
309
+							esc_html__("EE%s (%s)", 'event_espresso'),
310
+							$new_version,
311
+							$plugin_slug
312
+						),
313
+					]
314
+				);
315
+			} else {
316
+				$this->_template_args['current_db_state'] = null;
317
+				$this->_template_args['next_db_state']    = null;
318
+			}
319
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
320
+			$this->_template_args = array_merge(
321
+				$this->_template_args,
322
+				[
323
+					'show_most_recent_migration'             => $show_most_recent_migration,
324
+					// flag for showing the most recent migration's status and/or errors
325
+					'show_migration_progress'                => $show_migration_progress,
326
+					// flag for showing the option to run migrations and see their progress
327
+					'show_backup_db_text'                    => $show_backup_db_text,
328
+					// flag for showing text telling the user to back up their DB
329
+					'show_maintenance_switch'                => $show_maintenance_switch,
330
+					// flag for showing the option to change maintenance mode between levels 0 and 1
331
+					'script_names'                           => $script_names,
332
+					// array of names of scripts that have run
333
+					'show_continue_current_migration_script' => $show_continue_current_migration_script,
334
+					// flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
335
+					'reset_db_page_link'                     => EE_Admin_Page::add_query_args_and_nonce(
336
+						['action' => 'reset_db'],
337
+						EE_MAINTENANCE_ADMIN_URL
338
+					),
339
+					'data_reset_page'                        => EE_Admin_Page::add_query_args_and_nonce(
340
+						['action' => 'data_reset'],
341
+						EE_MAINTENANCE_ADMIN_URL
342
+					),
343
+					'update_migration_script_page_link'      => EE_Admin_Page::add_query_args_and_nonce(
344
+						['action' => 'change_maintenance_level'],
345
+						EE_MAINTENANCE_ADMIN_URL
346
+					),
347
+					'ultimate_db_state'                      => sprintf(
348
+						esc_html__("EE%s", 'event_espresso'),
349
+						espresso_version()
350
+					),
351
+				]
352
+			);
353
+		}
354
+		$this->_template_args['most_recent_migration'] =
355
+			$most_recent_migration;// the actual most recently ran migration
356
+		// now render the migration options part, and put it in a variable
357
+		$migration_options_template_file                = apply_filters(
358
+			'FHEE__ee_migration_page__migration_options_template',
359
+			EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php'
360
+		);
361
+		$migration_options_html                         = EEH_Template::display_template(
362
+			$migration_options_template_file,
363
+			$this->_template_args,
364
+			true
365
+		);
366
+		$this->_template_args['migration_options_html'] = $migration_options_html;
367
+		$this->_template_args['admin_page_content']     = EEH_Template::display_template(
368
+			$this->_template_path,
369
+			$this->_template_args,
370
+			true
371
+		);
372
+		$this->display_admin_page_with_sidebar();
373
+	}
374
+
375
+
376
+	/**
377
+	 * returns JSON and executes another step of the currently-executing data migration (called via ajax)
378
+	 *
379
+	 * @throws EE_Error
380
+	 */
381
+	public function migration_step()
382
+	{
383
+		$this->_template_args['data'] = $this->migration_manager->response_to_migration_ajax_request();
384
+		$this->_return_json();
385
+	}
386
+
387
+
388
+	/**
389
+	 * Can be used by js when it notices a response with HTML in it in order
390
+	 * to log the malformed response
391
+	 *
392
+	 * @throws EE_Error
393
+	 */
394
+	public function add_error_to_migrations_ran()
395
+	{
396
+		$this->migration_manager->add_error_to_migrations_ran($this->_req_data['message']);
397
+		$this->_template_args['data'] = ['ok' => true];
398
+		$this->_return_json();
399
+	}
400
+
401
+
402
+	/**
403
+	 * changes the maintenance level, provided there are still no migration scripts that should run
404
+	 *
405
+	 * @throws EE_Error
406
+	 */
407
+	public function _change_maintenance_level()
408
+	{
409
+		$new_level = absint($this->_req_data['maintenance_mode_level']);
410
+		if (! $this->migration_manager->check_for_applicable_data_migration_scripts()) {
411
+			$this->maintenance_mode->set_maintenance_level($new_level);
412
+			$success = true;
413
+		} else {
414
+			$this->maintenance_mode->set_maintenance_mode_if_db_old();
415
+			$success = false;
416
+		}
417
+		$this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso"));
418
+	}
419
+
420
+
421
+	/**
422
+	 * a tab with options for resetting and/or deleting EE data
423
+	 *
424
+	 * @throws EE_Error
425
+	 * @throws DomainException
426
+	 */
427
+	public function _data_reset_and_delete()
428
+	{
429
+		$this->_template_path                              =
430
+			EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
431
+		$this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button(
432
+			'reset_reservations',
433
+			'reset_reservations',
434
+			[],
435
+			'button button--caution ee-confirm'
436
+		);
437
+		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button(
438
+			'reset_capabilities',
439
+			'reset_capabilities',
440
+			[],
441
+			'button button--caution ee-confirm'
442
+		);
443
+		$this->_template_args['delete_db_url']             = EE_Admin_Page::add_query_args_and_nonce(
444
+			['action' => 'delete_db'],
445
+			EE_MAINTENANCE_ADMIN_URL
446
+		);
447
+		$this->_template_args['reset_db_url']              = EE_Admin_Page::add_query_args_and_nonce(
448
+			['action' => 'reset_db'],
449
+			EE_MAINTENANCE_ADMIN_URL
450
+		);
451
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
452
+			$this->_template_path,
453
+			$this->_template_args,
454
+			true
455
+		);
456
+		$this->display_admin_page_with_no_sidebar();
457
+	}
458
+
459
+
460
+	/**
461
+	 * @throws EE_Error
462
+	 * @throws ReflectionException
463
+	 */
464
+	protected function _reset_reservations()
465
+	{
466
+		if (EED_Ticket_Sales_Monitor::reset_reservation_counts()) {
467
+			EE_Error::add_success(
468
+				esc_html__(
469
+					'Ticket and datetime reserved counts have been successfully reset.',
470
+					'event_espresso'
471
+				)
472
+			);
473
+		} else {
474
+			EE_Error::add_success(
475
+				esc_html__(
476
+					'Ticket and datetime reserved counts were correct and did not need resetting.',
477
+					'event_espresso'
478
+				)
479
+			);
480
+		}
481
+		$this->_redirect_after_action(true, '', '', ['action' => 'data_reset'], true);
482
+	}
483
+
484
+
485
+	/**
486
+	 * @throws EE_Error
487
+	 */
488
+	protected function _reset_capabilities()
489
+	{
490
+		EE_Registry::instance()->CAP->init_caps(true);
491
+		EE_Error::add_success(
492
+			esc_html__(
493
+				'Default Event Espresso capabilities have been restored for all current roles.',
494
+				'event_espresso'
495
+			)
496
+		);
497
+		$this->_redirect_after_action(false, '', '', ['action' => 'data_reset'], true);
498
+	}
499
+
500
+
501
+	/**
502
+	 * resets the DMSs, so we can attempt to continue migrating after a fatal error
503
+	 * (only a good idea when someone has somehow tried ot fix whatever caused
504
+	 * the fatal error in teh first place)
505
+	 *
506
+	 * @throws EE_Error
507
+	 */
508
+	protected function _reattempt_migration()
509
+	{
510
+		$this->migration_manager->reattempt();
511
+		$this->_redirect_after_action(false, '', '', ['action' => 'default'], true);
512
+	}
513
+
514
+
515
+	/**
516
+	 * shows the big ol' System Information page
517
+	 *
518
+	 * @throws EE_Error
519
+	 */
520
+	public function _system_status()
521
+	{
522
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
523
+		$this->_template_args['system_stati']               = EEM_System_Status::instance()->get_system_stati();
524
+		$this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce(
525
+			[
526
+				'action' => 'download_system_status',
527
+			],
528
+			EE_MAINTENANCE_ADMIN_URL
529
+		);
530
+		$this->_template_args['admin_page_content']         = EEH_Template::display_template(
531
+			$this->_template_path,
532
+			$this->_template_args,
533
+			true
534
+		);
535
+		$this->display_admin_page_with_no_sidebar();
536
+	}
537
+
538
+
539
+	/**
540
+	 * Downloads an HTML file of the system status that can be easily stored or emailed
541
+	 */
542
+	public function _download_system_status()
543
+	{
544
+		$status_info = EEM_System_Status::instance()->get_system_stati();
545
+		header('Content-Disposition: attachment');
546
+		header("Content-Disposition: attachment; filename=system_status_" . sanitize_key(site_url()) . ".html");
547
+		$output = '<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>';
548
+		$output .= '<h1>' . sprintf(
549
+			__('System Information for %1$s', 'event_espresso'),
550
+			esc_url_raw(site_url())
551
+		) . '</h1>';
552
+		$output .= EEH_Template::layout_array_as_table($status_info);
553
+		echo esc_html($output);
554
+		die;
555
+	}
556
+
557
+
558
+	/**
559
+	 * @throws EE_Error
560
+	 */
561
+	public function _send_migration_crash_report()
562
+	{
563
+		$from      = $this->_req_data['from'];
564
+		$from_name = $this->_req_data['from_name'];
565
+		$body      = $this->_req_data['body'];
566
+		try {
567
+			$success = wp_mail(
568
+				EE_SUPPORT_EMAIL,
569
+				'Migration Crash Report',
570
+				$body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true),
571
+				[
572
+					"from:$from_name<$from>",
573
+				]
574
+			);
575
+		} catch (Exception $e) {
576
+			$success = false;
577
+		}
578
+		$this->_redirect_after_action(
579
+			$success,
580
+			esc_html__("Migration Crash Report", "event_espresso"),
581
+			esc_html__("sent", "event_espresso"),
582
+			['success' => $success, 'action' => 'confirm_migration_crash_report_sent']
583
+		);
584
+	}
585
+
586
+
587
+	/**
588
+	 * @throws EE_Error
589
+	 */
590
+	public function _confirm_migration_crash_report_sent()
591
+	{
592
+		try {
593
+			$most_recent_migration = $this->migration_manager->get_last_ran_script(true);
594
+		} catch (EE_Error $e) {
595
+			$this->migration_manager->add_error_to_migrations_ran($e->getMessage());
596
+			// now, just so we can display the page correctly, make an error migration script stage object
597
+			// and also put the error on it. It only persists for the duration of this request
598
+			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
599
+			$most_recent_migration->add_error($e->getMessage());
600
+		}
601
+		$success                                       = $this->_req_data['success'] === '1';
602
+		$this->_template_args['success']               = $success;
603
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;
604
+		$this->_template_args['reset_db_action_url']   = EE_Admin_Page::add_query_args_and_nonce(
605
+			['action' => 'reset_db'],
606
+			EE_MAINTENANCE_ADMIN_URL
607
+		);
608
+		$this->_template_args['reset_db_page_url']     = EE_Admin_Page::add_query_args_and_nonce(
609
+			['action' => 'data_reset'],
610
+			EE_MAINTENANCE_ADMIN_URL
611
+		);
612
+		$this->_template_args['reattempt_action_url']  = EE_Admin_Page::add_query_args_and_nonce(
613
+			['action' => 'reattempt_migration'],
614
+			EE_MAINTENANCE_ADMIN_URL
615
+		);
616
+		$this->_template_path                          =
617
+			EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
618
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
619
+			$this->_template_path,
620
+			$this->_template_args,
621
+			true
622
+		);
623
+		$this->display_admin_page_with_sidebar();
624
+	}
625
+
626
+
627
+	/**
628
+	 * Resets the entire EE4 database.
629
+	 * only sets up ee4 database for a fresh install-
630
+	 * doesn't actually clean out the old wp options, or cpts
631
+	 * (although it does erase old ee table data)
632
+	 *
633
+	 * @param boolean $nuke_old_ee4_data controls whether we destroy the old ee4 data,
634
+	 *                                   or just try initializing ee4 default data
635
+	 * @throws EE_Error
636
+	 * @throws ReflectionException
637
+	 */
638
+	public function _reset_db($nuke_old_ee4_data = true)
639
+	{
640
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
641
+		if ($nuke_old_ee4_data) {
642
+			EEH_Activation::delete_all_espresso_cpt_data();
643
+			EEH_Activation::delete_all_espresso_tables_and_data(false);
644
+			EEH_Activation::remove_cron_tasks();
645
+		}
646
+		// make sure when we reset the registry's config that it
647
+		// switches to using the new singleton
648
+		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true);
649
+		EE_System::instance()->initialize_db_if_no_migrations_required(true);
650
+		EE_System::instance()->redirect_to_about_ee();
651
+	}
652
+
653
+
654
+	/**
655
+	 * Deletes ALL EE tables, Records, and Options from the database.
656
+	 *
657
+	 * @throws EE_Error
658
+	 * @throws ReflectionException
659
+	 */
660
+	public function _delete_db()
661
+	{
662
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
663
+		EEH_Activation::delete_all_espresso_cpt_data();
664
+		EEH_Activation::delete_all_espresso_tables_and_data();
665
+		EEH_Activation::remove_cron_tasks();
666
+		EEH_Activation::deactivate_event_espresso();
667
+		wp_safe_redirect(admin_url('plugins.php'));
668
+		exit;
669
+	}
670
+
671
+
672
+	/**
673
+	 * sets up EE4 to rerun the migrations from ee3 to ee4
674
+	 *
675
+	 * @throws EE_Error
676
+	 * @throws ReflectionException
677
+	 */
678
+	public function _rerun_migration_from_ee3()
679
+	{
680
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
681
+		EEH_Activation::delete_all_espresso_cpt_data();
682
+		EEH_Activation::delete_all_espresso_tables_and_data(false);
683
+		// set the db state to something that will require migrations
684
+		update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0');
685
+		$this->maintenance_mode->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance);
686
+		$this->_redirect_after_action(
687
+			true,
688
+			esc_html__("Database", 'event_espresso'),
689
+			esc_html__("reset", 'event_espresso')
690
+		);
691
+	}
692
+
693
+
694
+	// none of the below group are currently used for Gateway Settings
695
+	protected function _add_screen_options()
696
+	{
697
+	}
698
+
699
+
700
+	protected function _add_feature_pointers()
701
+	{
702
+	}
703
+
704
+
705
+	public function admin_init()
706
+	{
707
+	}
708
+
709
+
710
+	public function admin_notices()
711
+	{
712
+	}
713
+
714
+
715
+	public function admin_footer_scripts()
716
+	{
717
+	}
718
+
719
+
720
+	public function load_scripts_styles()
721
+	{
722
+		wp_enqueue_script('ee_admin_js');
723
+		wp_enqueue_script(
724
+			'ee-maintenance',
725
+			EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.js',
726
+			['jquery'],
727
+			EVENT_ESPRESSO_VERSION,
728
+			true
729
+		);
730
+		wp_register_style(
731
+			'espresso_maintenance',
732
+			EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css',
733
+			[],
734
+			EVENT_ESPRESSO_VERSION
735
+		);
736
+		wp_enqueue_style('espresso_maintenance');
737
+		// localize script stuff
738
+		wp_localize_script(
739
+			'ee-maintenance',
740
+			'ee_maintenance',
741
+			[
742
+				'migrating'                        => wp_strip_all_tags(__("Updating Database...", "event_espresso")),
743
+				'next'                             => wp_strip_all_tags(__("Next", "event_espresso")),
744
+				'fatal_error'                      => wp_strip_all_tags(__(
745
+					"A Fatal Error Has Occurred",
746
+					"event_espresso"
747
+				)),
748
+				'click_next_when_ready'            => wp_strip_all_tags(
749
+					__(
750
+						"The current Database Update has ended. Click 'next' when ready to proceed",
751
+						"event_espresso"
752
+					)
753
+				),
754
+				'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts,
755
+				'status_fatal_error'               => EE_Data_Migration_Manager::status_fatal_error,
756
+				'status_completed'                 => EE_Data_Migration_Manager::status_completed,
757
+				'confirm'                          => wp_strip_all_tags(
758
+					__(
759
+						'Are you sure you want to do this? It CANNOT be undone!',
760
+						'event_espresso'
761
+					)
762
+				),
763
+				'confirm_skip_migration'           => wp_strip_all_tags(
764
+					__(
765
+						'You have chosen to NOT migrate your existing data. Are you sure you want to continue?',
766
+						'event_espresso'
767
+					)
768
+				),
769
+			]
770
+		);
771
+	}
772
+
773
+
774
+	public function load_scripts_styles_default()
775
+	{
776
+	}
777
+
778
+
779
+	/**
780
+	 * Enqueue scripts and styles for the datetime tools page.
781
+	 */
782
+	public function load_scripts_styles_datetime_tools()
783
+	{
784
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
785
+	}
786
+
787
+
788
+	/**
789
+	 * @throws EE_Error
790
+	 */
791
+	protected function _datetime_tools()
792
+	{
793
+		$form_action                                = EE_Admin_Page::add_query_args_and_nonce(
794
+			[
795
+				'action'        => 'run_datetime_offset_fix',
796
+				'return_action' => $this->_req_action,
797
+			],
798
+			EE_MAINTENANCE_ADMIN_URL
799
+		);
800
+		$form                                       = $this->_get_datetime_offset_fix_form();
801
+		$this->_admin_page_title                    = esc_html__('Datetime Utilities', 'event_espresso');
802
+		$this->_template_args['admin_page_content'] = $form->form_open($form_action, 'post')
803
+													  . $form->get_html_and_js()
804
+													  . $form->form_close();
805
+		$this->display_admin_page_with_sidebar();
806
+	}
807
+
808
+
809
+	/**
810
+	 * @throws EE_Error
811
+	 */
812
+	protected function _get_datetime_offset_fix_form()
813
+	{
814
+		if (! $this->datetime_fix_offset_form instanceof EE_Form_Section_Proper) {
815
+			$this->datetime_fix_offset_form = new EE_Form_Section_Proper(
816
+				[
817
+					'name'            => 'datetime_offset_fix_option',
818
+					'layout_strategy' => new EE_Admin_Two_Column_Layout(),
819
+					'subsections'     => [
820
+						'title'                  => new EE_Form_Section_HTML(
821
+							EEH_HTML::h2(
822
+								esc_html__('Datetime Offset Tool', 'event_espresso')
823
+							)
824
+						),
825
+						'explanation'            => new EE_Form_Section_HTML(
826
+							EEH_HTML::p(
827
+								esc_html__(
828
+									'Use this tool to automatically apply the provided offset to all Event Espresso records in your database that involve dates and times.',
829
+									'event_espresso'
830
+								)
831
+							)
832
+							. EEH_HTML::p(
833
+								esc_html__(
834
+									'Note: If you enter 1.25, that will result in the offset of 1 hour 15 minutes being applied.  Decimals represent the fraction of hours, not minutes.',
835
+									'event_espresso'
836
+								)
837
+							)
838
+						),
839
+						'offset_input'           => new EE_Float_Input(
840
+							[
841
+								'html_name'       => 'offset_for_datetimes',
842
+								'html_label_text' => esc_html__(
843
+									'Offset to apply (in hours):',
844
+									'event_espresso'
845
+								),
846
+								'min_value'       => '-12',
847
+								'max_value'       => '14',
848
+								'step_value'      => '.25',
849
+								'default'         => DatetimeOffsetFix::getOffset(),
850
+							]
851
+						),
852
+						'date_range_explanation' => new EE_Form_Section_HTML(
853
+							EEH_HTML::p(
854
+								esc_html__(
855
+									'Leave the following fields blank if you want the offset to be applied to all dates. If however, you want to just apply the offset to a specific range of dates you can restrict the offset application using these fields.',
856
+									'event_espresso'
857
+								)
858
+							)
859
+							. EEH_HTML::p(
860
+								EEH_HTML::strong(
861
+									sprintf(
862
+										esc_html__(
863
+											'Note: please enter the dates in UTC (You can use %1$sthis online tool%2$s to assist with conversions).',
864
+											'event_espresso'
865
+										),
866
+										'<a href="https://www.timeanddate.com/worldclock/converter.html">',
867
+										'</a>'
868
+									)
869
+								)
870
+							)
871
+						),
872
+						'date_range_start_date'  => new EE_Datepicker_Input(
873
+							[
874
+								'html_name'       => 'offset_date_start_range',
875
+								'html_label_text' => esc_html__(
876
+									'Start Date for dates the offset applied to:',
877
+									'event_espresso'
878
+								),
879
+							]
880
+						),
881
+						'date_range_end_date'    => new EE_Datepicker_Input(
882
+							[
883
+								'html_name'       => 'offset_date_end_range',
884
+								'html_label_text' => esc_html__(
885
+									'End Date for dates the offset is applied to:',
886
+									'event_espresso'
887
+								),
888
+							]
889
+						),
890
+						'submit'                 => new EE_Submit_Input(
891
+							[
892
+								'html_label_text' => '',
893
+								'default'         => esc_html__('Apply Offset', 'event_espresso'),
894
+							]
895
+						),
896
+					],
897
+				]
898
+			);
899
+		}
900
+		return $this->datetime_fix_offset_form;
901
+	}
902
+
903
+
904
+	/**
905
+	 * Callback for the run_datetime_offset_fix route.
906
+	 *
907
+	 * @throws EE_Error
908
+	 */
909
+	protected function _apply_datetime_offset()
910
+	{
911
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
912
+			$form = $this->_get_datetime_offset_fix_form();
913
+			$form->receive_form_submission($this->_req_data);
914
+			if ($form->is_valid()) {
915
+				// save offset data so batch processor can get it.
916
+				DatetimeOffsetFix::updateOffset($form->get_input_value('offset_input'));
917
+				$utc_timezone          = new DateTimeZone('UTC');
918
+				$date_range_start_date = DateTime::createFromFormat(
919
+					'm/d/Y H:i:s',
920
+					$form->get_input_value('date_range_start_date') . ' 00:00:00',
921
+					$utc_timezone
922
+				);
923
+				$date_range_end_date   = DateTime::createFromFormat(
924
+					'm/d/Y H:i:s',
925
+					$form->get_input_value('date_range_end_date') . ' 23:59:59',
926
+					$utc_timezone
927
+				);
928
+				if ($date_range_start_date instanceof DateTime) {
929
+					DatetimeOffsetFix::updateStartDateRange(DbSafeDateTime::createFromDateTime($date_range_start_date));
930
+				}
931
+				if ($date_range_end_date instanceof DateTime) {
932
+					DatetimeOffsetFix::updateEndDateRange(DbSafeDateTime::createFromDateTime($date_range_end_date));
933
+				}
934
+				// redirect to batch tool
935
+				wp_redirect(
936
+					EE_Admin_Page::add_query_args_and_nonce(
937
+						[
938
+							'page'        => EED_Batch::PAGE_SLUG,
939 939
 							'batch' 	  => EED_Batch::batch_job,
940
-                            'label'       => esc_html__('Applying Offset', 'event_espresso'),
941
-                            'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
942
-                            'return_url'  => urlencode(
943
-                                add_query_arg(
944
-                                    [
945
-                                        'action' => 'datetime_tools',
946
-                                    ],
947
-                                    EEH_URL::current_url_without_query_paramaters(
948
-                                        [
949
-                                            'return_action',
950
-                                            'run_datetime_offset_fix_nonce',
951
-                                            'return',
952
-                                            'datetime_tools_nonce',
953
-                                        ]
954
-                                    )
955
-                                )
956
-                            ),
957
-                        ],
958
-                        admin_url()
959
-                    )
960
-                );
961
-                exit;
962
-            }
963
-        }
964
-    }
940
+							'label'       => esc_html__('Applying Offset', 'event_espresso'),
941
+							'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\DatetimeOffsetFix'),
942
+							'return_url'  => urlencode(
943
+								add_query_arg(
944
+									[
945
+										'action' => 'datetime_tools',
946
+									],
947
+									EEH_URL::current_url_without_query_paramaters(
948
+										[
949
+											'return_action',
950
+											'run_datetime_offset_fix_nonce',
951
+											'return',
952
+											'datetime_tools_nonce',
953
+										]
954
+									)
955
+								)
956
+							),
957
+						],
958
+						admin_url()
959
+					)
960
+				);
961
+				exit;
962
+			}
963
+		}
964
+	}
965 965
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 2 patches
Indentation   +4178 added lines, -4178 removed lines patch added patch discarded remove patch
@@ -21,4264 +21,4264 @@
 block discarded – undo
21 21
  */
22 22
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
23 23
 {
24
-    /**
25
-     * @var EE_Admin_Config
26
-     */
27
-    protected $admin_config;
24
+	/**
25
+	 * @var EE_Admin_Config
26
+	 */
27
+	protected $admin_config;
28 28
 
29
-    /**
30
-     * @var LoaderInterface
31
-     */
32
-    protected $loader;
29
+	/**
30
+	 * @var LoaderInterface
31
+	 */
32
+	protected $loader;
33 33
 
34
-    /**
35
-     * @var RequestInterface
36
-     */
37
-    protected $request;
34
+	/**
35
+	 * @var RequestInterface
36
+	 */
37
+	protected $request;
38 38
 
39
-    // set in _init_page_props()
40
-    public $page_slug;
39
+	// set in _init_page_props()
40
+	public $page_slug;
41 41
 
42
-    public $page_label;
42
+	public $page_label;
43 43
 
44
-    public $page_folder;
44
+	public $page_folder;
45 45
 
46
-    // set in define_page_props()
47
-    protected $_admin_base_url;
46
+	// set in define_page_props()
47
+	protected $_admin_base_url;
48 48
 
49
-    protected $_admin_base_path;
49
+	protected $_admin_base_path;
50 50
 
51
-    protected $_admin_page_title;
51
+	protected $_admin_page_title;
52 52
 
53
-    protected $_labels;
53
+	protected $_labels;
54 54
 
55 55
 
56
-    // set early within EE_Admin_Init
57
-    protected $_wp_page_slug;
56
+	// set early within EE_Admin_Init
57
+	protected $_wp_page_slug;
58 58
 
59
-    // nav tabs
60
-    protected $_nav_tabs;
59
+	// nav tabs
60
+	protected $_nav_tabs;
61 61
 
62
-    protected $_default_nav_tab_name;
62
+	protected $_default_nav_tab_name;
63 63
 
64 64
 
65
-    // template variables (used by templates)
66
-    protected $_template_path;
65
+	// template variables (used by templates)
66
+	protected $_template_path;
67 67
 
68
-    protected $_column_template_path;
68
+	protected $_column_template_path;
69 69
 
70
-    /**
71
-     * @var array $_template_args
72
-     */
73
-    protected $_template_args = [];
70
+	/**
71
+	 * @var array $_template_args
72
+	 */
73
+	protected $_template_args = [];
74 74
 
75
-    /**
76
-     * this will hold the list table object for a given view.
77
-     *
78
-     * @var EE_Admin_List_Table $_list_table_object
79
-     */
80
-    protected $_list_table_object;
75
+	/**
76
+	 * this will hold the list table object for a given view.
77
+	 *
78
+	 * @var EE_Admin_List_Table $_list_table_object
79
+	 */
80
+	protected $_list_table_object;
81 81
 
82
-    // boolean
83
-    protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
82
+	// boolean
83
+	protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
84 84
 
85
-    protected $_routing;
85
+	protected $_routing;
86 86
 
87
-    // list table args
88
-    protected $_view;
87
+	// list table args
88
+	protected $_view;
89 89
 
90
-    protected $_views;
90
+	protected $_views;
91 91
 
92 92
 
93
-    // action => method pairs used for routing incoming requests
94
-    protected $_page_routes;
93
+	// action => method pairs used for routing incoming requests
94
+	protected $_page_routes;
95 95
 
96
-    /**
97
-     * @var array $_page_config
98
-     */
99
-    protected $_page_config;
96
+	/**
97
+	 * @var array $_page_config
98
+	 */
99
+	protected $_page_config;
100 100
 
101
-    /**
102
-     * the current page route and route config
103
-     *
104
-     * @var string $_route
105
-     */
106
-    protected $_route;
101
+	/**
102
+	 * the current page route and route config
103
+	 *
104
+	 * @var string $_route
105
+	 */
106
+	protected $_route;
107 107
 
108
-    /**
109
-     * @var string $_cpt_route
110
-     */
111
-    protected $_cpt_route;
108
+	/**
109
+	 * @var string $_cpt_route
110
+	 */
111
+	protected $_cpt_route;
112 112
 
113
-    /**
114
-     * @var array $_route_config
115
-     */
116
-    protected $_route_config;
113
+	/**
114
+	 * @var array $_route_config
115
+	 */
116
+	protected $_route_config;
117 117
 
118
-    /**
119
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
120
-     * actions.
121
-     *
122
-     * @since 4.6.x
123
-     * @var array.
124
-     */
125
-    protected $_default_route_query_args;
118
+	/**
119
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
120
+	 * actions.
121
+	 *
122
+	 * @since 4.6.x
123
+	 * @var array.
124
+	 */
125
+	protected $_default_route_query_args;
126 126
 
127
-    // set via request page and action args.
128
-    protected $_current_page;
127
+	// set via request page and action args.
128
+	protected $_current_page;
129 129
 
130
-    protected $_current_view;
130
+	protected $_current_view;
131 131
 
132
-    protected $_current_page_view_url;
132
+	protected $_current_page_view_url;
133 133
 
134
-    /**
135
-     * unprocessed value for the 'action' request param (default '')
136
-     *
137
-     * @var string
138
-     */
139
-    protected $raw_req_action = '';
134
+	/**
135
+	 * unprocessed value for the 'action' request param (default '')
136
+	 *
137
+	 * @var string
138
+	 */
139
+	protected $raw_req_action = '';
140 140
 
141
-    /**
142
-     * unprocessed value for the 'page' request param (default '')
143
-     *
144
-     * @var string
145
-     */
146
-    protected $raw_req_page = '';
147
-
148
-    /**
149
-     * sanitized request action (and nonce)
150
-     *
151
-     * @var string
152
-     */
153
-    protected $_req_action = '';
154
-
155
-    /**
156
-     * sanitized request action nonce
157
-     *
158
-     * @var string
159
-     */
160
-    protected $_req_nonce = '';
161
-
162
-    /**
163
-     * @var string
164
-     */
165
-    protected $_search_btn_label = '';
166
-
167
-    /**
168
-     * @var string
169
-     */
170
-    protected $_search_box_callback = '';
171
-
172
-    /**
173
-     * @var WP_Screen
174
-     */
175
-    protected $_current_screen;
176
-
177
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
178
-    protected $_hook_obj;
179
-
180
-    // for holding incoming request data
181
-    protected $_req_data = [];
182
-
183
-    // yes / no array for admin form fields
184
-    protected $_yes_no_values = [];
185
-
186
-    // some default things shared by all child classes
187
-    protected $_default_espresso_metaboxes = [
188
-        '_espresso_news_post_box',
189
-        '_espresso_links_post_box',
190
-        '_espresso_ratings_request',
191
-        '_espresso_sponsors_post_box',
192
-    ];
193
-
194
-    /**
195
-     * @var EE_Registry
196
-     */
197
-    protected $EE;
198
-
199
-
200
-    /**
201
-     * This is just a property that flags whether the given route is a caffeinated route or not.
202
-     *
203
-     * @var boolean
204
-     */
205
-    protected $_is_caf = false;
206
-
207
-    /**
208
-     * whether or not initializePage() has run
209
-     *
210
-     * @var boolean
211
-     */
212
-    protected $initialized = false;
213
-
214
-    /**
215
-     * @var FeatureFlags
216
-     */
217
-    protected $feature;
218
-
219
-
220
-    /**
221
-     * @var string
222
-     */
223
-    protected $class_name;
224
-
225
-    /**
226
-     * if the current class is an admin page extension, like: Extend_Events_Admin_Page,
227
-     * then this would be the parent classname: Events_Admin_Page
228
-     *
229
-     * @var string
230
-     */
231
-    protected $base_class_name;
232
-
233
-
234
-    /**
235
-     * @Constructor
236
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
237
-     * @throws InvalidArgumentException
238
-     * @throws InvalidDataTypeException
239
-     * @throws InvalidInterfaceException
240
-     * @throws ReflectionException
241
-     */
242
-    public function __construct($routing = true)
243
-    {
244
-        $this->loader = LoaderFactory::getLoader();
245
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
246
-        $this->feature = $this->loader->getShared(FeatureFlags::class);
247
-        $this->request = $this->loader->getShared(RequestInterface::class);
248
-        // routing enabled?
249
-        $this->_routing = $routing;
250
-
251
-        $this->class_name = get_class($this);
252
-        $this->base_class_name = strpos($this->class_name, 'Extend_') === 0
253
-            ? str_replace('Extend_', '', $this->class_name)
254
-            : '';
255
-
256
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
257
-            $this->_is_caf = true;
258
-        }
259
-        $this->_yes_no_values = [
260
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
261
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
262
-        ];
263
-        // set the _req_data property.
264
-        $this->_req_data = $this->request->requestParams();
265
-    }
266
-
267
-
268
-    /**
269
-     * @return EE_Admin_Config
270
-     */
271
-    public function adminConfig(): EE_Admin_Config
272
-    {
273
-        return $this->admin_config;
274
-    }
275
-
276
-
277
-    /**
278
-     * @return FeatureFlags
279
-     */
280
-    public function feature(): FeatureFlags
281
-    {
282
-        return $this->feature;
283
-    }
284
-
285
-
286
-    /**
287
-     * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
288
-     * for child classes that needed to set properties prior to these methods getting called,
289
-     * but also needed the parent class to have its construction completed as well.
290
-     * Bottom line is that constructors should ONLY be used for setting initial properties
291
-     * and any complex initialization logic should only run after instantiation is complete.
292
-     *
293
-     * This method gets called immediately after construction from within
294
-     *      EE_Admin_Page_Init::_initialize_admin_page()
295
-     *
296
-     * @throws EE_Error
297
-     * @throws InvalidArgumentException
298
-     * @throws InvalidDataTypeException
299
-     * @throws InvalidInterfaceException
300
-     * @throws ReflectionException
301
-     * @since $VID:$
302
-     */
303
-    public function initializePage()
304
-    {
305
-        if ($this->initialized) {
306
-            return;
307
-        }
308
-        // set initial page props (child method)
309
-        $this->_init_page_props();
310
-        // set global defaults
311
-        $this->_set_defaults();
312
-        // set early because incoming requests could be ajax related and we need to register those hooks.
313
-        $this->_global_ajax_hooks();
314
-        $this->_ajax_hooks();
315
-        // other_page_hooks have to be early too.
316
-        $this->_do_other_page_hooks();
317
-        // set up page dependencies
318
-        $this->_before_page_setup();
319
-        $this->_page_setup();
320
-        $this->initialized = true;
321
-    }
322
-
323
-
324
-    /**
325
-     * _init_page_props
326
-     * Child classes use to set at least the following properties:
327
-     * $page_slug.
328
-     * $page_label.
329
-     *
330
-     * @abstract
331
-     * @return void
332
-     */
333
-    abstract protected function _init_page_props();
334
-
335
-
336
-    /**
337
-     * _ajax_hooks
338
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
339
-     * Note: within the ajax callback methods.
340
-     *
341
-     * @abstract
342
-     * @return void
343
-     */
344
-    abstract protected function _ajax_hooks();
345
-
346
-
347
-    /**
348
-     * _define_page_props
349
-     * child classes define page properties in here.  Must include at least:
350
-     * $_admin_base_url = base_url for all admin pages
351
-     * $_admin_page_title = default admin_page_title for admin pages
352
-     * $_labels = array of default labels for various automatically generated elements:
353
-     *    array(
354
-     *        'buttons' => array(
355
-     *            'add' => esc_html__('label for add new button'),
356
-     *            'edit' => esc_html__('label for edit button'),
357
-     *            'delete' => esc_html__('label for delete button')
358
-     *            )
359
-     *        )
360
-     *
361
-     * @abstract
362
-     * @return void
363
-     */
364
-    abstract protected function _define_page_props();
365
-
366
-
367
-    /**
368
-     * _set_page_routes
369
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
370
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
371
-     * have a 'default' route. Here's the format
372
-     * $this->_page_routes = array(
373
-     *        'default' => array(
374
-     *            'func' => '_default_method_handling_route',
375
-     *            'args' => array('array','of','args'),
376
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
377
-     *            ajax request, backend processing)
378
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
379
-     *            headers route after.  The string you enter here should match the defined route reference for a
380
-     *            headers sent route.
381
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
382
-     *            this route.
383
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
384
-     *            checks).
385
-     *        ),
386
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
387
-     *        handling method.
388
-     *        )
389
-     * )
390
-     *
391
-     * @abstract
392
-     * @return void
393
-     */
394
-    abstract protected function _set_page_routes();
395
-
396
-
397
-    /**
398
-     * _set_page_config
399
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
400
-     * array corresponds to the page_route for the loaded page. Format:
401
-     * $this->_page_config = array(
402
-     *        'default' => array(
403
-     *            'labels' => array(
404
-     *                'buttons' => array(
405
-     *                    'add' => esc_html__('label for adding item'),
406
-     *                    'edit' => esc_html__('label for editing item'),
407
-     *                    'delete' => esc_html__('label for deleting item')
408
-     *                ),
409
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
410
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
411
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
412
-     *            _define_page_props() method
413
-     *            'nav' => array(
414
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
415
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
416
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
417
-     *                'order' => 10, //required to indicate tab position.
418
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
419
-     *                displayed then add this parameter.
420
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
421
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
422
-     *            metaboxes set for eventespresso admin pages.
423
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
424
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
425
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
426
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
427
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
428
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
429
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
430
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
431
-     *            want to display.
432
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
433
-     *                'tab_id' => array(
434
-     *                    'title' => 'tab_title',
435
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
436
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
437
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
438
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
439
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
440
-     *                    attempt to use the callback which should match the name of a method in the class
441
-     *                    ),
442
-     *                'tab2_id' => array(
443
-     *                    'title' => 'tab2 title',
444
-     *                    'filename' => 'file_name_2'
445
-     *                    'callback' => 'callback_method_for_content',
446
-     *                 ),
447
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
448
-     *            help tab area on an admin page. @return void
449
-     *
450
-     * @abstract
451
-     */
452
-    abstract protected function _set_page_config();
453
-
454
-
455
-    /**
456
-     * _add_screen_options
457
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
458
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
459
-     * to a particular view.
460
-     *
461
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
462
-     *         see also WP_Screen object documents...
463
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
464
-     * @abstract
465
-     * @return void
466
-     */
467
-    abstract protected function _add_screen_options();
468
-
469
-
470
-    /**
471
-     * _add_feature_pointers
472
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
473
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
474
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
475
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
476
-     * extended) also see:
477
-     *
478
-     * @link   http://eamann.com/tech/wordpress-portland/
479
-     * @abstract
480
-     * @return void
481
-     */
482
-    abstract protected function _add_feature_pointers();
483
-
484
-
485
-    /**
486
-     * load_scripts_styles
487
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
488
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
489
-     * scripts/styles per view by putting them in a dynamic function in this format
490
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
491
-     *
492
-     * @abstract
493
-     * @return void
494
-     */
495
-    abstract public function load_scripts_styles();
496
-
497
-
498
-    /**
499
-     * admin_init
500
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
501
-     * all pages/views loaded by child class.
502
-     *
503
-     * @abstract
504
-     * @return void
505
-     */
506
-    abstract public function admin_init();
507
-
508
-
509
-    /**
510
-     * admin_notices
511
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
512
-     * all pages/views loaded by child class.
513
-     *
514
-     * @abstract
515
-     * @return void
516
-     */
517
-    abstract public function admin_notices();
518
-
519
-
520
-    /**
521
-     * admin_footer_scripts
522
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
523
-     * will apply to all pages/views loaded by child class.
524
-     *
525
-     * @return void
526
-     */
527
-    abstract public function admin_footer_scripts();
528
-
529
-
530
-    /**
531
-     * admin_footer
532
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
533
-     * apply to all pages/views loaded by child class.
534
-     *
535
-     * @return void
536
-     */
537
-    public function admin_footer()
538
-    {
539
-    }
540
-
541
-
542
-    /**
543
-     * _global_ajax_hooks
544
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
545
-     * Note: within the ajax callback methods.
546
-     *
547
-     * @abstract
548
-     * @return void
549
-     */
550
-    protected function _global_ajax_hooks()
551
-    {
552
-        // for lazy loading of metabox content
553
-        add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
554
-
555
-        add_action(
556
-            'wp_ajax_espresso_hide_status_change_notice',
557
-            [$this, 'hideStatusChangeNotice']
558
-        );
559
-        add_action(
560
-            'wp_ajax_nopriv_espresso_hide_status_change_notice',
561
-            [$this, 'hideStatusChangeNotice']
562
-        );
563
-    }
564
-
565
-
566
-    public function ajax_metabox_content()
567
-    {
568
-        $content_id  = $this->request->getRequestParam('contentid', '');
569
-        $content_url = $this->request->getRequestParam('contenturl', '', 'url');
570
-        EE_Admin_Page::cached_rss_display($content_id, $content_url);
571
-        wp_die();
572
-    }
573
-
574
-
575
-    public function hideStatusChangeNotice()
576
-    {
577
-        $response = [];
578
-        try {
579
-            /** @var StatusChangeNotice $status_change_notice */
580
-            $status_change_notice = $this->loader->getShared(
581
-                'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
582
-            );
583
-            $response['success'] = $status_change_notice->dismiss() > -1;
584
-        } catch (Exception $exception) {
585
-            $response['errors'] = $exception->getMessage();
586
-        }
587
-        echo wp_json_encode($response);
588
-        exit();
589
-    }
590
-
591
-
592
-    /**
593
-     * allows extending classes do something specific before the parent constructor runs _page_setup().
594
-     *
595
-     * @return void
596
-     */
597
-    protected function _before_page_setup()
598
-    {
599
-        // default is to do nothing
600
-    }
601
-
602
-
603
-    /**
604
-     * Makes sure any things that need to be loaded early get handled.
605
-     * We also escape early here if the page requested doesn't match the object.
606
-     *
607
-     * @final
608
-     * @return void
609
-     * @throws EE_Error
610
-     * @throws InvalidArgumentException
611
-     * @throws ReflectionException
612
-     * @throws InvalidDataTypeException
613
-     * @throws InvalidInterfaceException
614
-     */
615
-    final protected function _page_setup()
616
-    {
617
-        // requires?
618
-        // admin_init stuff - global - we're setting this REALLY early
619
-        // so if EE_Admin pages have to hook into other WP pages they can.
620
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
621
-        add_action('admin_init', [$this, 'admin_init_global'], 5);
622
-        // next verify if we need to load anything...
623
-        $this->_current_page = $this->request->getRequestParam('page', '', 'key');
624
-        $this->page_folder   = strtolower(
625
-            str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name)
626
-        );
627
-        global $ee_menu_slugs;
628
-        $ee_menu_slugs = (array) $ee_menu_slugs;
629
-        if (
630
-            ! $this->request->isAjax()
631
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
632
-        ) {
633
-            return;
634
-        }
635
-        // because WP List tables have two duplicate select inputs for choosing bulk actions,
636
-        // we need to copy the action from the second to the first
637
-        $action     = $this->request->getRequestParam('action', '-1', 'key');
638
-        $action2    = $this->request->getRequestParam('action2', '-1', 'key');
639
-        $action     = $action !== '-1' ? $action : $action2;
640
-        $req_action = $action !== '-1' ? $action : 'default';
641
-
642
-        // if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
643
-        // then let's use the route as the action.
644
-        // This covers cases where we're coming in from a list table that isn't on the default route.
645
-        $route = $this->request->getRequestParam('route');
646
-        $this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
647
-            ? $route
648
-            : $req_action;
649
-
650
-        $this->_current_view = $this->_req_action;
651
-        $this->_req_nonce    = $this->_req_action . '_nonce';
652
-        $this->_define_page_props();
653
-        $this->_current_page_view_url = add_query_arg(
654
-            ['page' => $this->_current_page, 'action' => $this->_current_view],
655
-            $this->_admin_base_url
656
-        );
657
-        // set page configs
658
-        $this->_set_page_routes();
659
-        $this->_set_page_config();
660
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
661
-        if ($this->request->requestParamIsSet('wp_referer')) {
662
-            $wp_referer = $this->request->getRequestParam('wp_referer');
663
-            if ($wp_referer) {
664
-                $this->_default_route_query_args['wp_referer'] = $wp_referer;
665
-            }
666
-        }
667
-        // for caffeinated and other extended functionality.
668
-        //  If there is a _extend_page_config method
669
-        // then let's run that to modify the all the various page configuration arrays
670
-        if (method_exists($this, '_extend_page_config')) {
671
-            $this->_extend_page_config();
672
-        }
673
-        // for CPT and other extended functionality.
674
-        // If there is an _extend_page_config_for_cpt
675
-        // then let's run that to modify all the various page configuration arrays.
676
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
677
-            $this->_extend_page_config_for_cpt();
678
-        }
679
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
680
-        $this->_page_routes = apply_filters(
681
-            'FHEE__' . $this->class_name . '__page_setup__page_routes',
682
-            $this->_page_routes,
683
-            $this
684
-        );
685
-        $this->_page_config = apply_filters(
686
-            'FHEE__' . $this->class_name . '__page_setup__page_config',
687
-            $this->_page_config,
688
-            $this
689
-        );
690
-        if ($this->base_class_name !== '') {
691
-            $this->_page_routes = apply_filters(
692
-                'FHEE__' . $this->base_class_name . '__page_setup__page_routes',
693
-                $this->_page_routes,
694
-                $this
695
-            );
696
-            $this->_page_config = apply_filters(
697
-                'FHEE__' . $this->base_class_name . '__page_setup__page_config',
698
-                $this->_page_config,
699
-                $this
700
-            );
701
-        }
702
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
703
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
704
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
705
-            add_action(
706
-                'AHEE__EE_Admin_Page__route_admin_request',
707
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
708
-                10,
709
-                2
710
-            );
711
-        }
712
-        // next route only if routing enabled
713
-        if ($this->_routing && ! $this->request->isAjax()) {
714
-            $this->_verify_routes();
715
-            // next let's just check user_access and kill if no access
716
-            $this->check_user_access();
717
-            if ($this->_is_UI_request) {
718
-                // admin_init stuff - global, all views for this page class, specific view
719
-                add_action('admin_init', [$this, 'admin_init'], 10);
720
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
721
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
722
-                }
723
-            } else {
724
-                // hijack regular WP loading and route admin request immediately
725
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
726
-                $this->route_admin_request();
727
-            }
728
-        }
729
-    }
730
-
731
-
732
-    /**
733
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
734
-     *
735
-     * @return void
736
-     * @throws EE_Error
737
-     */
738
-    private function _do_other_page_hooks()
739
-    {
740
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
741
-        foreach ($registered_pages as $page) {
742
-            // now let's setup the file name and class that should be present
743
-            $classname = str_replace('.class.php', '', $page);
744
-            // autoloaders should take care of loading file
745
-            if (! class_exists($classname)) {
746
-                $error_msg[] = sprintf(
747
-                    esc_html__(
748
-                        'Something went wrong with loading the %s admin hooks page.',
749
-                        'event_espresso'
750
-                    ),
751
-                    $page
752
-                );
753
-                $error_msg[] = $error_msg[0]
754
-                               . "\r\n"
755
-                               . sprintf(
756
-                                   esc_html__(
757
-                                       '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',
758
-                                       'event_espresso'
759
-                                   ),
760
-                                   $page,
761
-                                   '<br />',
762
-                                   '<strong>' . $classname . '</strong>'
763
-                               );
764
-                throw new EE_Error(implode('||', $error_msg));
765
-            }
766
-            // notice we are passing the instance of this class to the hook object.
767
-            $this->loader->getShared($classname, [$this]);
768
-        }
769
-    }
770
-
771
-
772
-    /**
773
-     * @throws ReflectionException
774
-     * @throws EE_Error
775
-     */
776
-    public function load_page_dependencies()
777
-    {
778
-        try {
779
-            $this->_load_page_dependencies();
780
-        } catch (EE_Error $e) {
781
-            $e->get_error();
782
-        }
783
-    }
784
-
785
-
786
-    /**
787
-     * load_page_dependencies
788
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
789
-     *
790
-     * @return void
791
-     * @throws DomainException
792
-     * @throws EE_Error
793
-     * @throws InvalidArgumentException
794
-     * @throws InvalidDataTypeException
795
-     * @throws InvalidInterfaceException
796
-     */
797
-    protected function _load_page_dependencies()
798
-    {
799
-        // let's set the current_screen and screen options to override what WP set
800
-        $this->_current_screen = get_current_screen();
801
-        // load admin_notices - global, page class, and view specific
802
-        add_action('admin_notices', [$this, 'admin_notices_global'], 5);
803
-        add_action('admin_notices', [$this, 'admin_notices'], 10);
804
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
805
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
806
-        }
807
-        // load network admin_notices - global, page class, and view specific
808
-        add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
809
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
810
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
811
-        }
812
-        // this will save any per_page screen options if they are present
813
-        $this->_set_per_page_screen_options();
814
-        // setup list table properties
815
-        $this->_set_list_table();
816
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
817
-        // However in some cases the metaboxes will need to be added within a route handling callback.
818
-        $this->_add_registered_meta_boxes();
819
-        $this->_add_screen_columns();
820
-        // add screen options - global, page child class, and view specific
821
-        $this->_add_global_screen_options();
822
-        $this->_add_screen_options();
823
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
824
-        if (method_exists($this, $add_screen_options)) {
825
-            $this->{$add_screen_options}();
826
-        }
827
-        // add help tab(s) - set via page_config and qtips.
828
-        $this->_add_help_tabs();
829
-        $this->_add_qtips();
830
-        // add feature_pointers - global, page child class, and view specific
831
-        $this->_add_feature_pointers();
832
-        $this->_add_global_feature_pointers();
833
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
834
-        if (method_exists($this, $add_feature_pointer)) {
835
-            $this->{$add_feature_pointer}();
836
-        }
837
-        // enqueue scripts/styles - global, page class, and view specific
838
-        add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
839
-        add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
840
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
841
-            add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
842
-        }
843
-        add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
844
-        // admin_print_footer_scripts - global, page child class, and view specific.
845
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
846
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
847
-        // is a good use case. Notice the late priority we're giving these
848
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
849
-        add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
850
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
851
-            add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
852
-        }
853
-        // admin footer scripts
854
-        add_action('admin_footer', [$this, 'admin_footer_global'], 99);
855
-        add_action('admin_footer', [$this, 'admin_footer'], 100);
856
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
857
-            add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
858
-        }
859
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
860
-        // targeted hook
861
-        do_action(
862
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
863
-        );
864
-    }
865
-
866
-
867
-    /**
868
-     * _set_defaults
869
-     * This sets some global defaults for class properties.
870
-     */
871
-    private function _set_defaults()
872
-    {
873
-        $this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
874
-        $this->_event                = $this->_template_path = $this->_column_template_path = null;
875
-        $this->_nav_tabs             = $this->_views = $this->_page_routes = [];
876
-        $this->_page_config          = $this->_default_route_query_args = [];
877
-        $this->_default_nav_tab_name = 'overview';
878
-        // init template args
879
-        $this->_template_args = [
880
-            'admin_page_header'  => '',
881
-            'admin_page_content' => '',
882
-            'post_body_content'  => '',
883
-            'before_list_table'  => '',
884
-            'after_list_table'   => '',
885
-        ];
886
-    }
887
-
888
-
889
-    /**
890
-     * route_admin_request
891
-     *
892
-     * @return void
893
-     * @throws InvalidArgumentException
894
-     * @throws InvalidInterfaceException
895
-     * @throws InvalidDataTypeException
896
-     * @throws EE_Error
897
-     * @throws ReflectionException
898
-     * @see    _route_admin_request()
899
-     */
900
-    public function route_admin_request()
901
-    {
902
-        try {
903
-            $this->_route_admin_request();
904
-        } catch (EE_Error $e) {
905
-            $e->get_error();
906
-        }
907
-    }
908
-
909
-
910
-    public function set_wp_page_slug($wp_page_slug)
911
-    {
912
-        $this->_wp_page_slug = $wp_page_slug;
913
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
914
-        if (is_network_admin()) {
915
-            $this->_wp_page_slug .= '-network';
916
-        }
917
-    }
918
-
919
-
920
-    /**
921
-     * _verify_routes
922
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
923
-     * we know if we need to drop out.
924
-     *
925
-     * @return bool
926
-     * @throws EE_Error
927
-     */
928
-    protected function _verify_routes()
929
-    {
930
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
931
-        if (! $this->_current_page && ! $this->request->isAjax()) {
932
-            return false;
933
-        }
934
-        $this->_route = false;
935
-        // check that the page_routes array is not empty
936
-        if (empty($this->_page_routes)) {
937
-            // user error msg
938
-            $error_msg = sprintf(
939
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
940
-                $this->_admin_page_title
941
-            );
942
-            // developer error msg
943
-            $error_msg .= '||' . $error_msg
944
-                          . esc_html__(
945
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
946
-                              'event_espresso'
947
-                          );
948
-            throw new EE_Error($error_msg);
949
-        }
950
-        // and that the requested page route exists
951
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
952
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
953
-            $this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
954
-        } else {
955
-            // user error msg
956
-            $error_msg = sprintf(
957
-                esc_html__(
958
-                    'The requested page route does not exist for the %s admin page.',
959
-                    'event_espresso'
960
-                ),
961
-                $this->_admin_page_title
962
-            );
963
-            // developer error msg
964
-            $error_msg .= '||' . $error_msg
965
-                          . sprintf(
966
-                              esc_html__(
967
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
968
-                                  'event_espresso'
969
-                              ),
970
-                              $this->_req_action
971
-                          );
972
-            throw new EE_Error($error_msg);
973
-        }
974
-        // and that a default route exists
975
-        if (! array_key_exists('default', $this->_page_routes)) {
976
-            // user error msg
977
-            $error_msg = sprintf(
978
-                esc_html__(
979
-                    'A default page route has not been set for the % admin page.',
980
-                    'event_espresso'
981
-                ),
982
-                $this->_admin_page_title
983
-            );
984
-            // developer error msg
985
-            $error_msg .= '||' . $error_msg
986
-                          . esc_html__(
987
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
988
-                              'event_espresso'
989
-                          );
990
-            throw new EE_Error($error_msg);
991
-        }
992
-
993
-        // first lets' catch if the UI request has EVER been set.
994
-        if ($this->_is_UI_request === null) {
995
-            // lets set if this is a UI request or not.
996
-            $this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
997
-            // wait a minute... we might have a noheader in the route array
998
-            $this->_is_UI_request = ! (
999
-                is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
1000
-            )
1001
-                ? $this->_is_UI_request
1002
-                : false;
1003
-        }
1004
-        $this->_set_current_labels();
1005
-        return true;
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
1011
-     *
1012
-     * @param string $route the route name we're verifying
1013
-     * @return bool we'll throw an exception if this isn't a valid route.
1014
-     * @throws EE_Error
1015
-     */
1016
-    protected function _verify_route($route)
1017
-    {
1018
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
1019
-            return true;
1020
-        }
1021
-        // user error msg
1022
-        $error_msg = sprintf(
1023
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
1024
-            $this->_admin_page_title
1025
-        );
1026
-        // developer error msg
1027
-        $error_msg .= '||' . $error_msg
1028
-                      . sprintf(
1029
-                          esc_html__(
1030
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
1031
-                              'event_espresso'
1032
-                          ),
1033
-                          $route
1034
-                      );
1035
-        throw new EE_Error($error_msg);
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * perform nonce verification
1041
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1042
-     * using this method (and save retyping!)
1043
-     *
1044
-     * @param string $nonce     The nonce sent
1045
-     * @param string $nonce_ref The nonce reference string (name0)
1046
-     * @return void
1047
-     * @throws EE_Error
1048
-     * @throws InvalidArgumentException
1049
-     * @throws InvalidDataTypeException
1050
-     * @throws InvalidInterfaceException
1051
-     */
1052
-    protected function _verify_nonce($nonce, $nonce_ref)
1053
-    {
1054
-        // verify nonce against expected value
1055
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
1056
-            // these are not the droids you are looking for !!!
1057
-            $msg = sprintf(
1058
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
1059
-                '<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
1060
-                '</a>'
1061
-            );
1062
-            if (WP_DEBUG) {
1063
-                $msg .= "\n  ";
1064
-                $msg .= sprintf(
1065
-                    esc_html__(
1066
-                        'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1067
-                        'event_espresso'
1068
-                    ),
1069
-                    __CLASS__
1070
-                );
1071
-            }
1072
-            if (! $this->request->isAjax()) {
1073
-                wp_die($msg);
1074
-            }
1075
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1076
-            $this->_return_json();
1077
-        }
1078
-    }
1079
-
1080
-
1081
-    /**
1082
-     * _route_admin_request()
1083
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1084
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1085
-     * in the page routes and then will try to load the corresponding method.
1086
-     *
1087
-     * @return void
1088
-     * @throws EE_Error
1089
-     * @throws InvalidArgumentException
1090
-     * @throws InvalidDataTypeException
1091
-     * @throws InvalidInterfaceException
1092
-     * @throws ReflectionException
1093
-     */
1094
-    protected function _route_admin_request()
1095
-    {
1096
-        if (! $this->_is_UI_request) {
1097
-            $this->_verify_routes();
1098
-        }
1099
-        $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1100
-        if ($this->_req_action !== 'default' && $nonce_check) {
1101
-            // set nonce from post data
1102
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
1103
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1104
-        }
1105
-        // set the nav_tabs array but ONLY if this is  UI_request
1106
-        if ($this->_is_UI_request) {
1107
-            $this->_set_nav_tabs();
1108
-        }
1109
-        // grab callback function
1110
-        $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1111
-        // check if callback has args
1112
-        $args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1113
-        $error_msg = '';
1114
-        // action right before calling route
1115
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1116
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1117
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1118
-        }
1119
-        // strip _wp_http_referer from the server REQUEST_URI
1120
-        // else it grows in length on every submission due to recursion,
1121
-        // ultimately causing a "Request-URI Too Large" error
1122
-        $request_uri = remove_query_arg(
1123
-            '_wp_http_referer',
1124
-            wp_unslash($this->request->getServerParam('REQUEST_URI'))
1125
-        );
1126
-        // set new value in both our Request object and the super global
1127
-        $this->request->setServerParam('REQUEST_URI', $request_uri, true);
1128
-        if (! empty($func)) {
1129
-            if (is_array($func)) {
1130
-                [$class, $method] = $func;
1131
-            } elseif (strpos($func, '::') !== false) {
1132
-                [$class, $method] = explode('::', $func);
1133
-            } else {
1134
-                $class  = $this;
1135
-                $method = $func;
1136
-            }
1137
-            if (! (is_object($class) && $class === $this)) {
1138
-                // send along this admin page object for access by addons.
1139
-                $args['admin_page_object'] = $this;
1140
-            }
1141
-            if (
1142
-                // is it a method on a class that doesn't work?
1143
-                (
1144
-                    (
1145
-                        method_exists($class, $method)
1146
-                        && call_user_func_array([$class, $method], $args) === false
1147
-                    )
1148
-                    && (
1149
-                        // is it a standalone function that doesn't work?
1150
-                        function_exists($method)
1151
-                        && call_user_func_array(
1152
-                            $func,
1153
-                            array_merge(['admin_page_object' => $this], $args)
1154
-                        ) === false
1155
-                    )
1156
-                )
1157
-                || (
1158
-                    // is it neither a class method NOR a standalone function?
1159
-                    ! method_exists($class, $method)
1160
-                    && ! function_exists($method)
1161
-                )
1162
-            ) {
1163
-                // user error msg
1164
-                $error_msg = esc_html__(
1165
-                    'An error occurred. The  requested page route could not be found.',
1166
-                    'event_espresso'
1167
-                );
1168
-                // developer error msg
1169
-                $error_msg .= '||';
1170
-                $error_msg .= sprintf(
1171
-                    esc_html__(
1172
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1173
-                        'event_espresso'
1174
-                    ),
1175
-                    $method
1176
-                );
1177
-            }
1178
-            if (! empty($error_msg)) {
1179
-                throw new EE_Error($error_msg);
1180
-            }
1181
-        }
1182
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1183
-        // then we need to reset the routing properties to the new route.
1184
-        // 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.
1185
-        if (
1186
-            $this->_is_UI_request === false
1187
-            && is_array($this->_route)
1188
-            && ! empty($this->_route['headers_sent_route'])
1189
-        ) {
1190
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1191
-        }
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * This method just allows the resetting of page properties in the case where a no headers
1197
-     * route redirects to a headers route in its route config.
1198
-     *
1199
-     * @param string $new_route New (non header) route to redirect to.
1200
-     * @return   void
1201
-     * @throws ReflectionException
1202
-     * @throws InvalidArgumentException
1203
-     * @throws InvalidInterfaceException
1204
-     * @throws InvalidDataTypeException
1205
-     * @throws EE_Error
1206
-     * @since   4.3.0
1207
-     */
1208
-    protected function _reset_routing_properties($new_route)
1209
-    {
1210
-        $this->_is_UI_request = true;
1211
-        // now we set the current route to whatever the headers_sent_route is set at
1212
-        $this->request->setRequestParam('action', $new_route);
1213
-        // rerun page setup
1214
-        $this->_page_setup();
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * _add_query_arg
1220
-     * adds nonce to array of arguments then calls WP add_query_arg function
1221
-     *(internally just uses EEH_URL's function with the same name)
1222
-     *
1223
-     * @param array  $args
1224
-     * @param string $url
1225
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1226
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1227
-     *                                        Example usage: If the current page is:
1228
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1229
-     *                                        &action=default&event_id=20&month_range=March%202015
1230
-     *                                        &_wpnonce=5467821
1231
-     *                                        and you call:
1232
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1233
-     *                                        array(
1234
-     *                                        'action' => 'resend_something',
1235
-     *                                        'page=>espresso_registrations'
1236
-     *                                        ),
1237
-     *                                        $some_url,
1238
-     *                                        true
1239
-     *                                        );
1240
-     *                                        It will produce a url in this structure:
1241
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1242
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1243
-     *                                        month_range]=March%202015
1244
-     * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1245
-     * @return string
1246
-     */
1247
-    public static function add_query_args_and_nonce(
1248
-        $args = [],
1249
-        $url = '',
1250
-        $sticky = false,
1251
-        $exclude_nonce = false
1252
-    ) {
1253
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1254
-        if ($sticky) {
1255
-            /** @var RequestInterface $request */
1256
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1257
-            $request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1258
-            $request->unSetServerParam('_wp_http_referer', true);
1259
-            foreach ($request->requestParams() as $key => $value) {
1260
-                // do not add nonces
1261
-                if (strpos($key, 'nonce') !== false) {
1262
-                    continue;
1263
-                }
1264
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1265
-            }
1266
-        }
1267
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1268
-    }
1269
-
1270
-
1271
-    /**
1272
-     * This returns a generated link that will load the related help tab.
1273
-     *
1274
-     * @param string $help_tab_id the id for the connected help tab
1275
-     * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1276
-     * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1277
-     * @return string              generated link
1278
-     * @uses EEH_Template::get_help_tab_link()
1279
-     */
1280
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1281
-    {
1282
-        return EEH_Template::get_help_tab_link(
1283
-            $help_tab_id,
1284
-            $this->page_slug,
1285
-            $this->_req_action,
1286
-            $icon_style,
1287
-            $help_text
1288
-        );
1289
-    }
1290
-
1291
-
1292
-    /**
1293
-     * _add_help_tabs
1294
-     * Note child classes define their help tabs within the page_config array.
1295
-     *
1296
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1297
-     * @return void
1298
-     * @throws DomainException
1299
-     * @throws EE_Error
1300
-     * @throws ReflectionException
1301
-     */
1302
-    protected function _add_help_tabs()
1303
-    {
1304
-        if (isset($this->_page_config[ $this->_req_action ])) {
1305
-            $config = $this->_page_config[ $this->_req_action ];
1306
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1307
-            if (is_array($config) && isset($config['help_sidebar'])) {
1308
-                // check that the callback given is valid
1309
-                if (! method_exists($this, $config['help_sidebar'])) {
1310
-                    throw new EE_Error(
1311
-                        sprintf(
1312
-                            esc_html__(
1313
-                                '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',
1314
-                                'event_espresso'
1315
-                            ),
1316
-                            $config['help_sidebar'],
1317
-                            $this->class_name
1318
-                        )
1319
-                    );
1320
-                }
1321
-                $content = apply_filters(
1322
-                    'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar',
1323
-                    $this->{$config['help_sidebar']}()
1324
-                );
1325
-                $this->_current_screen->set_help_sidebar($content);
1326
-            }
1327
-            if (! isset($config['help_tabs'])) {
1328
-                return;
1329
-            } //no help tabs for this route
1330
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1331
-                // we're here so there ARE help tabs!
1332
-                // make sure we've got what we need
1333
-                if (! isset($cfg['title'])) {
1334
-                    throw new EE_Error(
1335
-                        esc_html__(
1336
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1337
-                            'event_espresso'
1338
-                        )
1339
-                    );
1340
-                }
1341
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1342
-                    throw new EE_Error(
1343
-                        esc_html__(
1344
-                            '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',
1345
-                            'event_espresso'
1346
-                        )
1347
-                    );
1348
-                }
1349
-                // first priority goes to content.
1350
-                if (! empty($cfg['content'])) {
1351
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1352
-                    // second priority goes to filename
1353
-                } elseif (! empty($cfg['filename'])) {
1354
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1355
-                    // 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)
1356
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1357
-                                                             . basename($this->_get_dir())
1358
-                                                             . '/help_tabs/'
1359
-                                                             . $cfg['filename']
1360
-                                                             . '.help_tab.php' : $file_path;
1361
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1362
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1363
-                        EE_Error::add_error(
1364
-                            sprintf(
1365
-                                esc_html__(
1366
-                                    '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',
1367
-                                    'event_espresso'
1368
-                                ),
1369
-                                $tab_id,
1370
-                                key($config),
1371
-                                $file_path
1372
-                            ),
1373
-                            __FILE__,
1374
-                            __FUNCTION__,
1375
-                            __LINE__
1376
-                        );
1377
-                        return;
1378
-                    }
1379
-                    $template_args['admin_page_obj'] = $this;
1380
-                    $content                         = EEH_Template::display_template(
1381
-                        $file_path,
1382
-                        $template_args,
1383
-                        true
1384
-                    );
1385
-                } else {
1386
-                    $content = '';
1387
-                }
1388
-                // check if callback is valid
1389
-                if (
1390
-                    empty($content)
1391
-                    && (
1392
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1393
-                    )
1394
-                ) {
1395
-                    EE_Error::add_error(
1396
-                        sprintf(
1397
-                            esc_html__(
1398
-                                '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.',
1399
-                                'event_espresso'
1400
-                            ),
1401
-                            $cfg['title']
1402
-                        ),
1403
-                        __FILE__,
1404
-                        __FUNCTION__,
1405
-                        __LINE__
1406
-                    );
1407
-                    return;
1408
-                }
1409
-                // setup config array for help tab method
1410
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1411
-                $_ht = [
1412
-                    'id'       => $id,
1413
-                    'title'    => $cfg['title'],
1414
-                    'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1415
-                    'content'  => $content,
1416
-                ];
1417
-                $this->_current_screen->add_help_tab($_ht);
1418
-            }
1419
-        }
1420
-    }
1421
-
1422
-
1423
-    /**
1424
-     * This simply sets up any qtips that have been defined in the page config
1425
-     *
1426
-     * @return void
1427
-     * @throws ReflectionException
1428
-     * @throws EE_Error
1429
-     */
1430
-    protected function _add_qtips()
1431
-    {
1432
-        if (isset($this->_route_config['qtips'])) {
1433
-            $qtips = (array) $this->_route_config['qtips'];
1434
-            // load qtip loader
1435
-            $path = [
1436
-                $this->_get_dir() . '/qtips/',
1437
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1438
-            ];
1439
-            EEH_Qtip_Loader::instance()->register($qtips, $path);
1440
-        }
1441
-    }
1442
-
1443
-
1444
-    /**
1445
-     * _set_nav_tabs
1446
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1447
-     * wish to add additional tabs or modify accordingly.
1448
-     *
1449
-     * @return void
1450
-     * @throws InvalidArgumentException
1451
-     * @throws InvalidInterfaceException
1452
-     * @throws InvalidDataTypeException
1453
-     */
1454
-    protected function _set_nav_tabs()
1455
-    {
1456
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1457
-        $i = 0;
1458
-        foreach ($this->_page_config as $slug => $config) {
1459
-            if (! is_array($config) || empty($config['nav'])) {
1460
-                continue;
1461
-            }
1462
-            // no nav tab for this config
1463
-            // check for persistent flag
1464
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1465
-                // nav tab is only to appear when route requested.
1466
-                continue;
1467
-            }
1468
-            if (! $this->check_user_access($slug, true)) {
1469
-                // no nav tab because current user does not have access.
1470
-                continue;
1471
-            }
1472
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1473
-            $this->_nav_tabs[ $slug ] = [
1474
-                'url'       => isset($config['nav']['url'])
1475
-                    ? $config['nav']['url']
1476
-                    : EE_Admin_Page::add_query_args_and_nonce(
1477
-                        ['action' => $slug],
1478
-                        $this->_admin_base_url
1479
-                    ),
1480
-                'link_text' => isset($config['nav']['label'])
1481
-                    ? $config['nav']['label']
1482
-                    : ucwords(
1483
-                        str_replace('_', ' ', $slug)
1484
-                    ),
1485
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1486
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1487
-            ];
1488
-            $i++;
1489
-        }
1490
-        // if $this->_nav_tabs is empty then lets set the default
1491
-        if (empty($this->_nav_tabs)) {
1492
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1493
-                'url'       => $this->_admin_base_url,
1494
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1495
-                'css_class' => 'nav-tab-active',
1496
-                'order'     => 10,
1497
-            ];
1498
-        }
1499
-        // now let's sort the tabs according to order
1500
-        usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1501
-    }
1502
-
1503
-
1504
-    /**
1505
-     * _set_current_labels
1506
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1507
-     * property array
1508
-     *
1509
-     * @return void
1510
-     */
1511
-    private function _set_current_labels()
1512
-    {
1513
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1514
-            foreach ($this->_route_config['labels'] as $label => $text) {
1515
-                if (is_array($text)) {
1516
-                    foreach ($text as $sublabel => $subtext) {
1517
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1518
-                    }
1519
-                } else {
1520
-                    $this->_labels[ $label ] = $text;
1521
-                }
1522
-            }
1523
-        }
1524
-    }
1525
-
1526
-
1527
-    /**
1528
-     *        verifies user access for this admin page
1529
-     *
1530
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1531
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1532
-     *                               return false if verify fail.
1533
-     * @return bool
1534
-     * @throws InvalidArgumentException
1535
-     * @throws InvalidDataTypeException
1536
-     * @throws InvalidInterfaceException
1537
-     */
1538
-    public function check_user_access($route_to_check = '', $verify_only = false)
1539
-    {
1540
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1541
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1542
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1543
-                          && is_array($this->_page_routes[ $route_to_check ])
1544
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1545
-            ? $this->_page_routes[ $route_to_check ]['capability']
141
+	/**
142
+	 * unprocessed value for the 'page' request param (default '')
143
+	 *
144
+	 * @var string
145
+	 */
146
+	protected $raw_req_page = '';
147
+
148
+	/**
149
+	 * sanitized request action (and nonce)
150
+	 *
151
+	 * @var string
152
+	 */
153
+	protected $_req_action = '';
154
+
155
+	/**
156
+	 * sanitized request action nonce
157
+	 *
158
+	 * @var string
159
+	 */
160
+	protected $_req_nonce = '';
161
+
162
+	/**
163
+	 * @var string
164
+	 */
165
+	protected $_search_btn_label = '';
166
+
167
+	/**
168
+	 * @var string
169
+	 */
170
+	protected $_search_box_callback = '';
171
+
172
+	/**
173
+	 * @var WP_Screen
174
+	 */
175
+	protected $_current_screen;
176
+
177
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
178
+	protected $_hook_obj;
179
+
180
+	// for holding incoming request data
181
+	protected $_req_data = [];
182
+
183
+	// yes / no array for admin form fields
184
+	protected $_yes_no_values = [];
185
+
186
+	// some default things shared by all child classes
187
+	protected $_default_espresso_metaboxes = [
188
+		'_espresso_news_post_box',
189
+		'_espresso_links_post_box',
190
+		'_espresso_ratings_request',
191
+		'_espresso_sponsors_post_box',
192
+	];
193
+
194
+	/**
195
+	 * @var EE_Registry
196
+	 */
197
+	protected $EE;
198
+
199
+
200
+	/**
201
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
202
+	 *
203
+	 * @var boolean
204
+	 */
205
+	protected $_is_caf = false;
206
+
207
+	/**
208
+	 * whether or not initializePage() has run
209
+	 *
210
+	 * @var boolean
211
+	 */
212
+	protected $initialized = false;
213
+
214
+	/**
215
+	 * @var FeatureFlags
216
+	 */
217
+	protected $feature;
218
+
219
+
220
+	/**
221
+	 * @var string
222
+	 */
223
+	protected $class_name;
224
+
225
+	/**
226
+	 * if the current class is an admin page extension, like: Extend_Events_Admin_Page,
227
+	 * then this would be the parent classname: Events_Admin_Page
228
+	 *
229
+	 * @var string
230
+	 */
231
+	protected $base_class_name;
232
+
233
+
234
+	/**
235
+	 * @Constructor
236
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
237
+	 * @throws InvalidArgumentException
238
+	 * @throws InvalidDataTypeException
239
+	 * @throws InvalidInterfaceException
240
+	 * @throws ReflectionException
241
+	 */
242
+	public function __construct($routing = true)
243
+	{
244
+		$this->loader = LoaderFactory::getLoader();
245
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
246
+		$this->feature = $this->loader->getShared(FeatureFlags::class);
247
+		$this->request = $this->loader->getShared(RequestInterface::class);
248
+		// routing enabled?
249
+		$this->_routing = $routing;
250
+
251
+		$this->class_name = get_class($this);
252
+		$this->base_class_name = strpos($this->class_name, 'Extend_') === 0
253
+			? str_replace('Extend_', '', $this->class_name)
254
+			: '';
255
+
256
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
257
+			$this->_is_caf = true;
258
+		}
259
+		$this->_yes_no_values = [
260
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
261
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
262
+		];
263
+		// set the _req_data property.
264
+		$this->_req_data = $this->request->requestParams();
265
+	}
266
+
267
+
268
+	/**
269
+	 * @return EE_Admin_Config
270
+	 */
271
+	public function adminConfig(): EE_Admin_Config
272
+	{
273
+		return $this->admin_config;
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return FeatureFlags
279
+	 */
280
+	public function feature(): FeatureFlags
281
+	{
282
+		return $this->feature;
283
+	}
284
+
285
+
286
+	/**
287
+	 * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
288
+	 * for child classes that needed to set properties prior to these methods getting called,
289
+	 * but also needed the parent class to have its construction completed as well.
290
+	 * Bottom line is that constructors should ONLY be used for setting initial properties
291
+	 * and any complex initialization logic should only run after instantiation is complete.
292
+	 *
293
+	 * This method gets called immediately after construction from within
294
+	 *      EE_Admin_Page_Init::_initialize_admin_page()
295
+	 *
296
+	 * @throws EE_Error
297
+	 * @throws InvalidArgumentException
298
+	 * @throws InvalidDataTypeException
299
+	 * @throws InvalidInterfaceException
300
+	 * @throws ReflectionException
301
+	 * @since $VID:$
302
+	 */
303
+	public function initializePage()
304
+	{
305
+		if ($this->initialized) {
306
+			return;
307
+		}
308
+		// set initial page props (child method)
309
+		$this->_init_page_props();
310
+		// set global defaults
311
+		$this->_set_defaults();
312
+		// set early because incoming requests could be ajax related and we need to register those hooks.
313
+		$this->_global_ajax_hooks();
314
+		$this->_ajax_hooks();
315
+		// other_page_hooks have to be early too.
316
+		$this->_do_other_page_hooks();
317
+		// set up page dependencies
318
+		$this->_before_page_setup();
319
+		$this->_page_setup();
320
+		$this->initialized = true;
321
+	}
322
+
323
+
324
+	/**
325
+	 * _init_page_props
326
+	 * Child classes use to set at least the following properties:
327
+	 * $page_slug.
328
+	 * $page_label.
329
+	 *
330
+	 * @abstract
331
+	 * @return void
332
+	 */
333
+	abstract protected function _init_page_props();
334
+
335
+
336
+	/**
337
+	 * _ajax_hooks
338
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
339
+	 * Note: within the ajax callback methods.
340
+	 *
341
+	 * @abstract
342
+	 * @return void
343
+	 */
344
+	abstract protected function _ajax_hooks();
345
+
346
+
347
+	/**
348
+	 * _define_page_props
349
+	 * child classes define page properties in here.  Must include at least:
350
+	 * $_admin_base_url = base_url for all admin pages
351
+	 * $_admin_page_title = default admin_page_title for admin pages
352
+	 * $_labels = array of default labels for various automatically generated elements:
353
+	 *    array(
354
+	 *        'buttons' => array(
355
+	 *            'add' => esc_html__('label for add new button'),
356
+	 *            'edit' => esc_html__('label for edit button'),
357
+	 *            'delete' => esc_html__('label for delete button')
358
+	 *            )
359
+	 *        )
360
+	 *
361
+	 * @abstract
362
+	 * @return void
363
+	 */
364
+	abstract protected function _define_page_props();
365
+
366
+
367
+	/**
368
+	 * _set_page_routes
369
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
370
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
371
+	 * have a 'default' route. Here's the format
372
+	 * $this->_page_routes = array(
373
+	 *        'default' => array(
374
+	 *            'func' => '_default_method_handling_route',
375
+	 *            'args' => array('array','of','args'),
376
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
377
+	 *            ajax request, backend processing)
378
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
379
+	 *            headers route after.  The string you enter here should match the defined route reference for a
380
+	 *            headers sent route.
381
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
382
+	 *            this route.
383
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
384
+	 *            checks).
385
+	 *        ),
386
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
387
+	 *        handling method.
388
+	 *        )
389
+	 * )
390
+	 *
391
+	 * @abstract
392
+	 * @return void
393
+	 */
394
+	abstract protected function _set_page_routes();
395
+
396
+
397
+	/**
398
+	 * _set_page_config
399
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
400
+	 * array corresponds to the page_route for the loaded page. Format:
401
+	 * $this->_page_config = array(
402
+	 *        'default' => array(
403
+	 *            'labels' => array(
404
+	 *                'buttons' => array(
405
+	 *                    'add' => esc_html__('label for adding item'),
406
+	 *                    'edit' => esc_html__('label for editing item'),
407
+	 *                    'delete' => esc_html__('label for deleting item')
408
+	 *                ),
409
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
410
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
411
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
412
+	 *            _define_page_props() method
413
+	 *            'nav' => array(
414
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
415
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
416
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
417
+	 *                'order' => 10, //required to indicate tab position.
418
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
419
+	 *                displayed then add this parameter.
420
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
421
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
422
+	 *            metaboxes set for eventespresso admin pages.
423
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
424
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
425
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
426
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
427
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
428
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
429
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
430
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
431
+	 *            want to display.
432
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
433
+	 *                'tab_id' => array(
434
+	 *                    'title' => 'tab_title',
435
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
436
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
437
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
438
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
439
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
440
+	 *                    attempt to use the callback which should match the name of a method in the class
441
+	 *                    ),
442
+	 *                'tab2_id' => array(
443
+	 *                    'title' => 'tab2 title',
444
+	 *                    'filename' => 'file_name_2'
445
+	 *                    'callback' => 'callback_method_for_content',
446
+	 *                 ),
447
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
448
+	 *            help tab area on an admin page. @return void
449
+	 *
450
+	 * @abstract
451
+	 */
452
+	abstract protected function _set_page_config();
453
+
454
+
455
+	/**
456
+	 * _add_screen_options
457
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
458
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
459
+	 * to a particular view.
460
+	 *
461
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
462
+	 *         see also WP_Screen object documents...
463
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
464
+	 * @abstract
465
+	 * @return void
466
+	 */
467
+	abstract protected function _add_screen_options();
468
+
469
+
470
+	/**
471
+	 * _add_feature_pointers
472
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
473
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
474
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
475
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
476
+	 * extended) also see:
477
+	 *
478
+	 * @link   http://eamann.com/tech/wordpress-portland/
479
+	 * @abstract
480
+	 * @return void
481
+	 */
482
+	abstract protected function _add_feature_pointers();
483
+
484
+
485
+	/**
486
+	 * load_scripts_styles
487
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
488
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
489
+	 * scripts/styles per view by putting them in a dynamic function in this format
490
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
491
+	 *
492
+	 * @abstract
493
+	 * @return void
494
+	 */
495
+	abstract public function load_scripts_styles();
496
+
497
+
498
+	/**
499
+	 * admin_init
500
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
501
+	 * all pages/views loaded by child class.
502
+	 *
503
+	 * @abstract
504
+	 * @return void
505
+	 */
506
+	abstract public function admin_init();
507
+
508
+
509
+	/**
510
+	 * admin_notices
511
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
512
+	 * all pages/views loaded by child class.
513
+	 *
514
+	 * @abstract
515
+	 * @return void
516
+	 */
517
+	abstract public function admin_notices();
518
+
519
+
520
+	/**
521
+	 * admin_footer_scripts
522
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
523
+	 * will apply to all pages/views loaded by child class.
524
+	 *
525
+	 * @return void
526
+	 */
527
+	abstract public function admin_footer_scripts();
528
+
529
+
530
+	/**
531
+	 * admin_footer
532
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
533
+	 * apply to all pages/views loaded by child class.
534
+	 *
535
+	 * @return void
536
+	 */
537
+	public function admin_footer()
538
+	{
539
+	}
540
+
541
+
542
+	/**
543
+	 * _global_ajax_hooks
544
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
545
+	 * Note: within the ajax callback methods.
546
+	 *
547
+	 * @abstract
548
+	 * @return void
549
+	 */
550
+	protected function _global_ajax_hooks()
551
+	{
552
+		// for lazy loading of metabox content
553
+		add_action('wp_ajax_espresso-ajax-content', [$this, 'ajax_metabox_content'], 10);
554
+
555
+		add_action(
556
+			'wp_ajax_espresso_hide_status_change_notice',
557
+			[$this, 'hideStatusChangeNotice']
558
+		);
559
+		add_action(
560
+			'wp_ajax_nopriv_espresso_hide_status_change_notice',
561
+			[$this, 'hideStatusChangeNotice']
562
+		);
563
+	}
564
+
565
+
566
+	public function ajax_metabox_content()
567
+	{
568
+		$content_id  = $this->request->getRequestParam('contentid', '');
569
+		$content_url = $this->request->getRequestParam('contenturl', '', 'url');
570
+		EE_Admin_Page::cached_rss_display($content_id, $content_url);
571
+		wp_die();
572
+	}
573
+
574
+
575
+	public function hideStatusChangeNotice()
576
+	{
577
+		$response = [];
578
+		try {
579
+			/** @var StatusChangeNotice $status_change_notice */
580
+			$status_change_notice = $this->loader->getShared(
581
+				'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
582
+			);
583
+			$response['success'] = $status_change_notice->dismiss() > -1;
584
+		} catch (Exception $exception) {
585
+			$response['errors'] = $exception->getMessage();
586
+		}
587
+		echo wp_json_encode($response);
588
+		exit();
589
+	}
590
+
591
+
592
+	/**
593
+	 * allows extending classes do something specific before the parent constructor runs _page_setup().
594
+	 *
595
+	 * @return void
596
+	 */
597
+	protected function _before_page_setup()
598
+	{
599
+		// default is to do nothing
600
+	}
601
+
602
+
603
+	/**
604
+	 * Makes sure any things that need to be loaded early get handled.
605
+	 * We also escape early here if the page requested doesn't match the object.
606
+	 *
607
+	 * @final
608
+	 * @return void
609
+	 * @throws EE_Error
610
+	 * @throws InvalidArgumentException
611
+	 * @throws ReflectionException
612
+	 * @throws InvalidDataTypeException
613
+	 * @throws InvalidInterfaceException
614
+	 */
615
+	final protected function _page_setup()
616
+	{
617
+		// requires?
618
+		// admin_init stuff - global - we're setting this REALLY early
619
+		// so if EE_Admin pages have to hook into other WP pages they can.
620
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
621
+		add_action('admin_init', [$this, 'admin_init_global'], 5);
622
+		// next verify if we need to load anything...
623
+		$this->_current_page = $this->request->getRequestParam('page', '', 'key');
624
+		$this->page_folder   = strtolower(
625
+			str_replace(['_Admin_Page', 'Extend_'], '', $this->class_name)
626
+		);
627
+		global $ee_menu_slugs;
628
+		$ee_menu_slugs = (array) $ee_menu_slugs;
629
+		if (
630
+			! $this->request->isAjax()
631
+			&& (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
632
+		) {
633
+			return;
634
+		}
635
+		// because WP List tables have two duplicate select inputs for choosing bulk actions,
636
+		// we need to copy the action from the second to the first
637
+		$action     = $this->request->getRequestParam('action', '-1', 'key');
638
+		$action2    = $this->request->getRequestParam('action2', '-1', 'key');
639
+		$action     = $action !== '-1' ? $action : $action2;
640
+		$req_action = $action !== '-1' ? $action : 'default';
641
+
642
+		// if a specific 'route' has been set, and the action is 'default' OR we are doing_ajax
643
+		// then let's use the route as the action.
644
+		// This covers cases where we're coming in from a list table that isn't on the default route.
645
+		$route = $this->request->getRequestParam('route');
646
+		$this->_req_action = $route && ($req_action === 'default' || $this->request->isAjax())
647
+			? $route
648
+			: $req_action;
649
+
650
+		$this->_current_view = $this->_req_action;
651
+		$this->_req_nonce    = $this->_req_action . '_nonce';
652
+		$this->_define_page_props();
653
+		$this->_current_page_view_url = add_query_arg(
654
+			['page' => $this->_current_page, 'action' => $this->_current_view],
655
+			$this->_admin_base_url
656
+		);
657
+		// set page configs
658
+		$this->_set_page_routes();
659
+		$this->_set_page_config();
660
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
661
+		if ($this->request->requestParamIsSet('wp_referer')) {
662
+			$wp_referer = $this->request->getRequestParam('wp_referer');
663
+			if ($wp_referer) {
664
+				$this->_default_route_query_args['wp_referer'] = $wp_referer;
665
+			}
666
+		}
667
+		// for caffeinated and other extended functionality.
668
+		//  If there is a _extend_page_config method
669
+		// then let's run that to modify the all the various page configuration arrays
670
+		if (method_exists($this, '_extend_page_config')) {
671
+			$this->_extend_page_config();
672
+		}
673
+		// for CPT and other extended functionality.
674
+		// If there is an _extend_page_config_for_cpt
675
+		// then let's run that to modify all the various page configuration arrays.
676
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
677
+			$this->_extend_page_config_for_cpt();
678
+		}
679
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
680
+		$this->_page_routes = apply_filters(
681
+			'FHEE__' . $this->class_name . '__page_setup__page_routes',
682
+			$this->_page_routes,
683
+			$this
684
+		);
685
+		$this->_page_config = apply_filters(
686
+			'FHEE__' . $this->class_name . '__page_setup__page_config',
687
+			$this->_page_config,
688
+			$this
689
+		);
690
+		if ($this->base_class_name !== '') {
691
+			$this->_page_routes = apply_filters(
692
+				'FHEE__' . $this->base_class_name . '__page_setup__page_routes',
693
+				$this->_page_routes,
694
+				$this
695
+			);
696
+			$this->_page_config = apply_filters(
697
+				'FHEE__' . $this->base_class_name . '__page_setup__page_config',
698
+				$this->_page_config,
699
+				$this
700
+			);
701
+		}
702
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
703
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
704
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
705
+			add_action(
706
+				'AHEE__EE_Admin_Page__route_admin_request',
707
+				[$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
708
+				10,
709
+				2
710
+			);
711
+		}
712
+		// next route only if routing enabled
713
+		if ($this->_routing && ! $this->request->isAjax()) {
714
+			$this->_verify_routes();
715
+			// next let's just check user_access and kill if no access
716
+			$this->check_user_access();
717
+			if ($this->_is_UI_request) {
718
+				// admin_init stuff - global, all views for this page class, specific view
719
+				add_action('admin_init', [$this, 'admin_init'], 10);
720
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
721
+					add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
722
+				}
723
+			} else {
724
+				// hijack regular WP loading and route admin request immediately
725
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
726
+				$this->route_admin_request();
727
+			}
728
+		}
729
+	}
730
+
731
+
732
+	/**
733
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
734
+	 *
735
+	 * @return void
736
+	 * @throws EE_Error
737
+	 */
738
+	private function _do_other_page_hooks()
739
+	{
740
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
741
+		foreach ($registered_pages as $page) {
742
+			// now let's setup the file name and class that should be present
743
+			$classname = str_replace('.class.php', '', $page);
744
+			// autoloaders should take care of loading file
745
+			if (! class_exists($classname)) {
746
+				$error_msg[] = sprintf(
747
+					esc_html__(
748
+						'Something went wrong with loading the %s admin hooks page.',
749
+						'event_espresso'
750
+					),
751
+					$page
752
+				);
753
+				$error_msg[] = $error_msg[0]
754
+							   . "\r\n"
755
+							   . sprintf(
756
+								   esc_html__(
757
+									   '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',
758
+									   'event_espresso'
759
+								   ),
760
+								   $page,
761
+								   '<br />',
762
+								   '<strong>' . $classname . '</strong>'
763
+							   );
764
+				throw new EE_Error(implode('||', $error_msg));
765
+			}
766
+			// notice we are passing the instance of this class to the hook object.
767
+			$this->loader->getShared($classname, [$this]);
768
+		}
769
+	}
770
+
771
+
772
+	/**
773
+	 * @throws ReflectionException
774
+	 * @throws EE_Error
775
+	 */
776
+	public function load_page_dependencies()
777
+	{
778
+		try {
779
+			$this->_load_page_dependencies();
780
+		} catch (EE_Error $e) {
781
+			$e->get_error();
782
+		}
783
+	}
784
+
785
+
786
+	/**
787
+	 * load_page_dependencies
788
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
789
+	 *
790
+	 * @return void
791
+	 * @throws DomainException
792
+	 * @throws EE_Error
793
+	 * @throws InvalidArgumentException
794
+	 * @throws InvalidDataTypeException
795
+	 * @throws InvalidInterfaceException
796
+	 */
797
+	protected function _load_page_dependencies()
798
+	{
799
+		// let's set the current_screen and screen options to override what WP set
800
+		$this->_current_screen = get_current_screen();
801
+		// load admin_notices - global, page class, and view specific
802
+		add_action('admin_notices', [$this, 'admin_notices_global'], 5);
803
+		add_action('admin_notices', [$this, 'admin_notices'], 10);
804
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
805
+			add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
806
+		}
807
+		// load network admin_notices - global, page class, and view specific
808
+		add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
809
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
810
+			add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
811
+		}
812
+		// this will save any per_page screen options if they are present
813
+		$this->_set_per_page_screen_options();
814
+		// setup list table properties
815
+		$this->_set_list_table();
816
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
817
+		// However in some cases the metaboxes will need to be added within a route handling callback.
818
+		$this->_add_registered_meta_boxes();
819
+		$this->_add_screen_columns();
820
+		// add screen options - global, page child class, and view specific
821
+		$this->_add_global_screen_options();
822
+		$this->_add_screen_options();
823
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
824
+		if (method_exists($this, $add_screen_options)) {
825
+			$this->{$add_screen_options}();
826
+		}
827
+		// add help tab(s) - set via page_config and qtips.
828
+		$this->_add_help_tabs();
829
+		$this->_add_qtips();
830
+		// add feature_pointers - global, page child class, and view specific
831
+		$this->_add_feature_pointers();
832
+		$this->_add_global_feature_pointers();
833
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
834
+		if (method_exists($this, $add_feature_pointer)) {
835
+			$this->{$add_feature_pointer}();
836
+		}
837
+		// enqueue scripts/styles - global, page class, and view specific
838
+		add_action('admin_enqueue_scripts', [$this, 'load_global_scripts_styles'], 5);
839
+		add_action('admin_enqueue_scripts', [$this, 'load_scripts_styles'], 10);
840
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
841
+			add_action('admin_enqueue_scripts', [$this, "load_scripts_styles_{$this->_current_view}"], 15);
842
+		}
843
+		add_action('admin_enqueue_scripts', [$this, 'admin_footer_scripts_eei18n_js_strings'], 100);
844
+		// admin_print_footer_scripts - global, page child class, and view specific.
845
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
846
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
847
+		// is a good use case. Notice the late priority we're giving these
848
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts_global'], 99);
849
+		add_action('admin_print_footer_scripts', [$this, 'admin_footer_scripts'], 100);
850
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
851
+			add_action('admin_print_footer_scripts', [$this, "admin_footer_scripts_{$this->_current_view}"], 101);
852
+		}
853
+		// admin footer scripts
854
+		add_action('admin_footer', [$this, 'admin_footer_global'], 99);
855
+		add_action('admin_footer', [$this, 'admin_footer'], 100);
856
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
857
+			add_action('admin_footer', [$this, "admin_footer_{$this->_current_view}"], 101);
858
+		}
859
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
860
+		// targeted hook
861
+		do_action(
862
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
863
+		);
864
+	}
865
+
866
+
867
+	/**
868
+	 * _set_defaults
869
+	 * This sets some global defaults for class properties.
870
+	 */
871
+	private function _set_defaults()
872
+	{
873
+		$this->_current_screen       = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
874
+		$this->_event                = $this->_template_path = $this->_column_template_path = null;
875
+		$this->_nav_tabs             = $this->_views = $this->_page_routes = [];
876
+		$this->_page_config          = $this->_default_route_query_args = [];
877
+		$this->_default_nav_tab_name = 'overview';
878
+		// init template args
879
+		$this->_template_args = [
880
+			'admin_page_header'  => '',
881
+			'admin_page_content' => '',
882
+			'post_body_content'  => '',
883
+			'before_list_table'  => '',
884
+			'after_list_table'   => '',
885
+		];
886
+	}
887
+
888
+
889
+	/**
890
+	 * route_admin_request
891
+	 *
892
+	 * @return void
893
+	 * @throws InvalidArgumentException
894
+	 * @throws InvalidInterfaceException
895
+	 * @throws InvalidDataTypeException
896
+	 * @throws EE_Error
897
+	 * @throws ReflectionException
898
+	 * @see    _route_admin_request()
899
+	 */
900
+	public function route_admin_request()
901
+	{
902
+		try {
903
+			$this->_route_admin_request();
904
+		} catch (EE_Error $e) {
905
+			$e->get_error();
906
+		}
907
+	}
908
+
909
+
910
+	public function set_wp_page_slug($wp_page_slug)
911
+	{
912
+		$this->_wp_page_slug = $wp_page_slug;
913
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
914
+		if (is_network_admin()) {
915
+			$this->_wp_page_slug .= '-network';
916
+		}
917
+	}
918
+
919
+
920
+	/**
921
+	 * _verify_routes
922
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
923
+	 * we know if we need to drop out.
924
+	 *
925
+	 * @return bool
926
+	 * @throws EE_Error
927
+	 */
928
+	protected function _verify_routes()
929
+	{
930
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
931
+		if (! $this->_current_page && ! $this->request->isAjax()) {
932
+			return false;
933
+		}
934
+		$this->_route = false;
935
+		// check that the page_routes array is not empty
936
+		if (empty($this->_page_routes)) {
937
+			// user error msg
938
+			$error_msg = sprintf(
939
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
940
+				$this->_admin_page_title
941
+			);
942
+			// developer error msg
943
+			$error_msg .= '||' . $error_msg
944
+						  . esc_html__(
945
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
946
+							  'event_espresso'
947
+						  );
948
+			throw new EE_Error($error_msg);
949
+		}
950
+		// and that the requested page route exists
951
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
952
+			$this->_route        = $this->_page_routes[ $this->_req_action ];
953
+			$this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
954
+		} else {
955
+			// user error msg
956
+			$error_msg = sprintf(
957
+				esc_html__(
958
+					'The requested page route does not exist for the %s admin page.',
959
+					'event_espresso'
960
+				),
961
+				$this->_admin_page_title
962
+			);
963
+			// developer error msg
964
+			$error_msg .= '||' . $error_msg
965
+						  . sprintf(
966
+							  esc_html__(
967
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
968
+								  'event_espresso'
969
+							  ),
970
+							  $this->_req_action
971
+						  );
972
+			throw new EE_Error($error_msg);
973
+		}
974
+		// and that a default route exists
975
+		if (! array_key_exists('default', $this->_page_routes)) {
976
+			// user error msg
977
+			$error_msg = sprintf(
978
+				esc_html__(
979
+					'A default page route has not been set for the % admin page.',
980
+					'event_espresso'
981
+				),
982
+				$this->_admin_page_title
983
+			);
984
+			// developer error msg
985
+			$error_msg .= '||' . $error_msg
986
+						  . esc_html__(
987
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
988
+							  'event_espresso'
989
+						  );
990
+			throw new EE_Error($error_msg);
991
+		}
992
+
993
+		// first lets' catch if the UI request has EVER been set.
994
+		if ($this->_is_UI_request === null) {
995
+			// lets set if this is a UI request or not.
996
+			$this->_is_UI_request = ! $this->request->getRequestParam('noheader', false, 'bool');
997
+			// wait a minute... we might have a noheader in the route array
998
+			$this->_is_UI_request = ! (
999
+				is_array($this->_route) && isset($this->_route['noheader']) && $this->_route['noheader']
1000
+			)
1001
+				? $this->_is_UI_request
1002
+				: false;
1003
+		}
1004
+		$this->_set_current_labels();
1005
+		return true;
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
1011
+	 *
1012
+	 * @param string $route the route name we're verifying
1013
+	 * @return bool we'll throw an exception if this isn't a valid route.
1014
+	 * @throws EE_Error
1015
+	 */
1016
+	protected function _verify_route($route)
1017
+	{
1018
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
1019
+			return true;
1020
+		}
1021
+		// user error msg
1022
+		$error_msg = sprintf(
1023
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
1024
+			$this->_admin_page_title
1025
+		);
1026
+		// developer error msg
1027
+		$error_msg .= '||' . $error_msg
1028
+					  . sprintf(
1029
+						  esc_html__(
1030
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
1031
+							  'event_espresso'
1032
+						  ),
1033
+						  $route
1034
+					  );
1035
+		throw new EE_Error($error_msg);
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * perform nonce verification
1041
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
1042
+	 * using this method (and save retyping!)
1043
+	 *
1044
+	 * @param string $nonce     The nonce sent
1045
+	 * @param string $nonce_ref The nonce reference string (name0)
1046
+	 * @return void
1047
+	 * @throws EE_Error
1048
+	 * @throws InvalidArgumentException
1049
+	 * @throws InvalidDataTypeException
1050
+	 * @throws InvalidInterfaceException
1051
+	 */
1052
+	protected function _verify_nonce($nonce, $nonce_ref)
1053
+	{
1054
+		// verify nonce against expected value
1055
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
1056
+			// these are not the droids you are looking for !!!
1057
+			$msg = sprintf(
1058
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
1059
+				'<a href="https://www.youtube.com/watch?v=56_S0WeTkzs">',
1060
+				'</a>'
1061
+			);
1062
+			if (WP_DEBUG) {
1063
+				$msg .= "\n  ";
1064
+				$msg .= sprintf(
1065
+					esc_html__(
1066
+						'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1067
+						'event_espresso'
1068
+					),
1069
+					__CLASS__
1070
+				);
1071
+			}
1072
+			if (! $this->request->isAjax()) {
1073
+				wp_die($msg);
1074
+			}
1075
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1076
+			$this->_return_json();
1077
+		}
1078
+	}
1079
+
1080
+
1081
+	/**
1082
+	 * _route_admin_request()
1083
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1084
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1085
+	 * in the page routes and then will try to load the corresponding method.
1086
+	 *
1087
+	 * @return void
1088
+	 * @throws EE_Error
1089
+	 * @throws InvalidArgumentException
1090
+	 * @throws InvalidDataTypeException
1091
+	 * @throws InvalidInterfaceException
1092
+	 * @throws ReflectionException
1093
+	 */
1094
+	protected function _route_admin_request()
1095
+	{
1096
+		if (! $this->_is_UI_request) {
1097
+			$this->_verify_routes();
1098
+		}
1099
+		$nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
1100
+		if ($this->_req_action !== 'default' && $nonce_check) {
1101
+			// set nonce from post data
1102
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
1103
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1104
+		}
1105
+		// set the nav_tabs array but ONLY if this is  UI_request
1106
+		if ($this->_is_UI_request) {
1107
+			$this->_set_nav_tabs();
1108
+		}
1109
+		// grab callback function
1110
+		$func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1111
+		// check if callback has args
1112
+		$args      = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : [];
1113
+		$error_msg = '';
1114
+		// action right before calling route
1115
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1116
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1117
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1118
+		}
1119
+		// strip _wp_http_referer from the server REQUEST_URI
1120
+		// else it grows in length on every submission due to recursion,
1121
+		// ultimately causing a "Request-URI Too Large" error
1122
+		$request_uri = remove_query_arg(
1123
+			'_wp_http_referer',
1124
+			wp_unslash($this->request->getServerParam('REQUEST_URI'))
1125
+		);
1126
+		// set new value in both our Request object and the super global
1127
+		$this->request->setServerParam('REQUEST_URI', $request_uri, true);
1128
+		if (! empty($func)) {
1129
+			if (is_array($func)) {
1130
+				[$class, $method] = $func;
1131
+			} elseif (strpos($func, '::') !== false) {
1132
+				[$class, $method] = explode('::', $func);
1133
+			} else {
1134
+				$class  = $this;
1135
+				$method = $func;
1136
+			}
1137
+			if (! (is_object($class) && $class === $this)) {
1138
+				// send along this admin page object for access by addons.
1139
+				$args['admin_page_object'] = $this;
1140
+			}
1141
+			if (
1142
+				// is it a method on a class that doesn't work?
1143
+				(
1144
+					(
1145
+						method_exists($class, $method)
1146
+						&& call_user_func_array([$class, $method], $args) === false
1147
+					)
1148
+					&& (
1149
+						// is it a standalone function that doesn't work?
1150
+						function_exists($method)
1151
+						&& call_user_func_array(
1152
+							$func,
1153
+							array_merge(['admin_page_object' => $this], $args)
1154
+						) === false
1155
+					)
1156
+				)
1157
+				|| (
1158
+					// is it neither a class method NOR a standalone function?
1159
+					! method_exists($class, $method)
1160
+					&& ! function_exists($method)
1161
+				)
1162
+			) {
1163
+				// user error msg
1164
+				$error_msg = esc_html__(
1165
+					'An error occurred. The  requested page route could not be found.',
1166
+					'event_espresso'
1167
+				);
1168
+				// developer error msg
1169
+				$error_msg .= '||';
1170
+				$error_msg .= sprintf(
1171
+					esc_html__(
1172
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1173
+						'event_espresso'
1174
+					),
1175
+					$method
1176
+				);
1177
+			}
1178
+			if (! empty($error_msg)) {
1179
+				throw new EE_Error($error_msg);
1180
+			}
1181
+		}
1182
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1183
+		// then we need to reset the routing properties to the new route.
1184
+		// 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.
1185
+		if (
1186
+			$this->_is_UI_request === false
1187
+			&& is_array($this->_route)
1188
+			&& ! empty($this->_route['headers_sent_route'])
1189
+		) {
1190
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1191
+		}
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * This method just allows the resetting of page properties in the case where a no headers
1197
+	 * route redirects to a headers route in its route config.
1198
+	 *
1199
+	 * @param string $new_route New (non header) route to redirect to.
1200
+	 * @return   void
1201
+	 * @throws ReflectionException
1202
+	 * @throws InvalidArgumentException
1203
+	 * @throws InvalidInterfaceException
1204
+	 * @throws InvalidDataTypeException
1205
+	 * @throws EE_Error
1206
+	 * @since   4.3.0
1207
+	 */
1208
+	protected function _reset_routing_properties($new_route)
1209
+	{
1210
+		$this->_is_UI_request = true;
1211
+		// now we set the current route to whatever the headers_sent_route is set at
1212
+		$this->request->setRequestParam('action', $new_route);
1213
+		// rerun page setup
1214
+		$this->_page_setup();
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * _add_query_arg
1220
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1221
+	 *(internally just uses EEH_URL's function with the same name)
1222
+	 *
1223
+	 * @param array  $args
1224
+	 * @param string $url
1225
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1226
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1227
+	 *                                        Example usage: If the current page is:
1228
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1229
+	 *                                        &action=default&event_id=20&month_range=March%202015
1230
+	 *                                        &_wpnonce=5467821
1231
+	 *                                        and you call:
1232
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1233
+	 *                                        array(
1234
+	 *                                        'action' => 'resend_something',
1235
+	 *                                        'page=>espresso_registrations'
1236
+	 *                                        ),
1237
+	 *                                        $some_url,
1238
+	 *                                        true
1239
+	 *                                        );
1240
+	 *                                        It will produce a url in this structure:
1241
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1242
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1243
+	 *                                        month_range]=March%202015
1244
+	 * @param bool   $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1245
+	 * @return string
1246
+	 */
1247
+	public static function add_query_args_and_nonce(
1248
+		$args = [],
1249
+		$url = '',
1250
+		$sticky = false,
1251
+		$exclude_nonce = false
1252
+	) {
1253
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1254
+		if ($sticky) {
1255
+			/** @var RequestInterface $request */
1256
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1257
+			$request->unSetRequestParams(['_wp_http_referer', 'wp_referer'], true);
1258
+			$request->unSetServerParam('_wp_http_referer', true);
1259
+			foreach ($request->requestParams() as $key => $value) {
1260
+				// do not add nonces
1261
+				if (strpos($key, 'nonce') !== false) {
1262
+					continue;
1263
+				}
1264
+				$args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1265
+			}
1266
+		}
1267
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1268
+	}
1269
+
1270
+
1271
+	/**
1272
+	 * This returns a generated link that will load the related help tab.
1273
+	 *
1274
+	 * @param string $help_tab_id the id for the connected help tab
1275
+	 * @param string $icon_style  (optional) include css class for the style you want to use for the help icon.
1276
+	 * @param string $help_text   (optional) send help text you want to use for the link if default not to be used
1277
+	 * @return string              generated link
1278
+	 * @uses EEH_Template::get_help_tab_link()
1279
+	 */
1280
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1281
+	{
1282
+		return EEH_Template::get_help_tab_link(
1283
+			$help_tab_id,
1284
+			$this->page_slug,
1285
+			$this->_req_action,
1286
+			$icon_style,
1287
+			$help_text
1288
+		);
1289
+	}
1290
+
1291
+
1292
+	/**
1293
+	 * _add_help_tabs
1294
+	 * Note child classes define their help tabs within the page_config array.
1295
+	 *
1296
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1297
+	 * @return void
1298
+	 * @throws DomainException
1299
+	 * @throws EE_Error
1300
+	 * @throws ReflectionException
1301
+	 */
1302
+	protected function _add_help_tabs()
1303
+	{
1304
+		if (isset($this->_page_config[ $this->_req_action ])) {
1305
+			$config = $this->_page_config[ $this->_req_action ];
1306
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1307
+			if (is_array($config) && isset($config['help_sidebar'])) {
1308
+				// check that the callback given is valid
1309
+				if (! method_exists($this, $config['help_sidebar'])) {
1310
+					throw new EE_Error(
1311
+						sprintf(
1312
+							esc_html__(
1313
+								'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',
1314
+								'event_espresso'
1315
+							),
1316
+							$config['help_sidebar'],
1317
+							$this->class_name
1318
+						)
1319
+					);
1320
+				}
1321
+				$content = apply_filters(
1322
+					'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar',
1323
+					$this->{$config['help_sidebar']}()
1324
+				);
1325
+				$this->_current_screen->set_help_sidebar($content);
1326
+			}
1327
+			if (! isset($config['help_tabs'])) {
1328
+				return;
1329
+			} //no help tabs for this route
1330
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1331
+				// we're here so there ARE help tabs!
1332
+				// make sure we've got what we need
1333
+				if (! isset($cfg['title'])) {
1334
+					throw new EE_Error(
1335
+						esc_html__(
1336
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1337
+							'event_espresso'
1338
+						)
1339
+					);
1340
+				}
1341
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1342
+					throw new EE_Error(
1343
+						esc_html__(
1344
+							'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',
1345
+							'event_espresso'
1346
+						)
1347
+					);
1348
+				}
1349
+				// first priority goes to content.
1350
+				if (! empty($cfg['content'])) {
1351
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1352
+					// second priority goes to filename
1353
+				} elseif (! empty($cfg['filename'])) {
1354
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1355
+					// 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)
1356
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1357
+															 . basename($this->_get_dir())
1358
+															 . '/help_tabs/'
1359
+															 . $cfg['filename']
1360
+															 . '.help_tab.php' : $file_path;
1361
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1362
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1363
+						EE_Error::add_error(
1364
+							sprintf(
1365
+								esc_html__(
1366
+									'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',
1367
+									'event_espresso'
1368
+								),
1369
+								$tab_id,
1370
+								key($config),
1371
+								$file_path
1372
+							),
1373
+							__FILE__,
1374
+							__FUNCTION__,
1375
+							__LINE__
1376
+						);
1377
+						return;
1378
+					}
1379
+					$template_args['admin_page_obj'] = $this;
1380
+					$content                         = EEH_Template::display_template(
1381
+						$file_path,
1382
+						$template_args,
1383
+						true
1384
+					);
1385
+				} else {
1386
+					$content = '';
1387
+				}
1388
+				// check if callback is valid
1389
+				if (
1390
+					empty($content)
1391
+					&& (
1392
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1393
+					)
1394
+				) {
1395
+					EE_Error::add_error(
1396
+						sprintf(
1397
+							esc_html__(
1398
+								'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.',
1399
+								'event_espresso'
1400
+							),
1401
+							$cfg['title']
1402
+						),
1403
+						__FILE__,
1404
+						__FUNCTION__,
1405
+						__LINE__
1406
+					);
1407
+					return;
1408
+				}
1409
+				// setup config array for help tab method
1410
+				$id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1411
+				$_ht = [
1412
+					'id'       => $id,
1413
+					'title'    => $cfg['title'],
1414
+					'callback' => isset($cfg['callback']) && empty($content) ? [$this, $cfg['callback']] : null,
1415
+					'content'  => $content,
1416
+				];
1417
+				$this->_current_screen->add_help_tab($_ht);
1418
+			}
1419
+		}
1420
+	}
1421
+
1422
+
1423
+	/**
1424
+	 * This simply sets up any qtips that have been defined in the page config
1425
+	 *
1426
+	 * @return void
1427
+	 * @throws ReflectionException
1428
+	 * @throws EE_Error
1429
+	 */
1430
+	protected function _add_qtips()
1431
+	{
1432
+		if (isset($this->_route_config['qtips'])) {
1433
+			$qtips = (array) $this->_route_config['qtips'];
1434
+			// load qtip loader
1435
+			$path = [
1436
+				$this->_get_dir() . '/qtips/',
1437
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1438
+			];
1439
+			EEH_Qtip_Loader::instance()->register($qtips, $path);
1440
+		}
1441
+	}
1442
+
1443
+
1444
+	/**
1445
+	 * _set_nav_tabs
1446
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1447
+	 * wish to add additional tabs or modify accordingly.
1448
+	 *
1449
+	 * @return void
1450
+	 * @throws InvalidArgumentException
1451
+	 * @throws InvalidInterfaceException
1452
+	 * @throws InvalidDataTypeException
1453
+	 */
1454
+	protected function _set_nav_tabs()
1455
+	{
1456
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1457
+		$i = 0;
1458
+		foreach ($this->_page_config as $slug => $config) {
1459
+			if (! is_array($config) || empty($config['nav'])) {
1460
+				continue;
1461
+			}
1462
+			// no nav tab for this config
1463
+			// check for persistent flag
1464
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1465
+				// nav tab is only to appear when route requested.
1466
+				continue;
1467
+			}
1468
+			if (! $this->check_user_access($slug, true)) {
1469
+				// no nav tab because current user does not have access.
1470
+				continue;
1471
+			}
1472
+			$css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1473
+			$this->_nav_tabs[ $slug ] = [
1474
+				'url'       => isset($config['nav']['url'])
1475
+					? $config['nav']['url']
1476
+					: EE_Admin_Page::add_query_args_and_nonce(
1477
+						['action' => $slug],
1478
+						$this->_admin_base_url
1479
+					),
1480
+				'link_text' => isset($config['nav']['label'])
1481
+					? $config['nav']['label']
1482
+					: ucwords(
1483
+						str_replace('_', ' ', $slug)
1484
+					),
1485
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1486
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1487
+			];
1488
+			$i++;
1489
+		}
1490
+		// if $this->_nav_tabs is empty then lets set the default
1491
+		if (empty($this->_nav_tabs)) {
1492
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1493
+				'url'       => $this->_admin_base_url,
1494
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1495
+				'css_class' => 'nav-tab-active',
1496
+				'order'     => 10,
1497
+			];
1498
+		}
1499
+		// now let's sort the tabs according to order
1500
+		usort($this->_nav_tabs, [$this, '_sort_nav_tabs']);
1501
+	}
1502
+
1503
+
1504
+	/**
1505
+	 * _set_current_labels
1506
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1507
+	 * property array
1508
+	 *
1509
+	 * @return void
1510
+	 */
1511
+	private function _set_current_labels()
1512
+	{
1513
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1514
+			foreach ($this->_route_config['labels'] as $label => $text) {
1515
+				if (is_array($text)) {
1516
+					foreach ($text as $sublabel => $subtext) {
1517
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1518
+					}
1519
+				} else {
1520
+					$this->_labels[ $label ] = $text;
1521
+				}
1522
+			}
1523
+		}
1524
+	}
1525
+
1526
+
1527
+	/**
1528
+	 *        verifies user access for this admin page
1529
+	 *
1530
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1531
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1532
+	 *                               return false if verify fail.
1533
+	 * @return bool
1534
+	 * @throws InvalidArgumentException
1535
+	 * @throws InvalidDataTypeException
1536
+	 * @throws InvalidInterfaceException
1537
+	 */
1538
+	public function check_user_access($route_to_check = '', $verify_only = false)
1539
+	{
1540
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1541
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1542
+		$capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1543
+						  && is_array($this->_page_routes[ $route_to_check ])
1544
+						  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1545
+			? $this->_page_routes[ $route_to_check ]['capability']
1546 1546
 			: null;
1547 1547
 
1548
-        if (empty($capability) && empty($route_to_check)) {
1549
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1550
-                : $this->_route['capability'];
1551
-        } else {
1552
-            $capability = empty($capability) ? 'manage_options' : $capability;
1553
-        }
1554
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1555
-        if (
1556
-            ! $this->request->isAjax()
1557
-            && (
1558
-                ! function_exists('is_admin')
1559
-                || ! EE_Registry::instance()->CAP->current_user_can(
1560
-                    $capability,
1561
-                    $this->page_slug
1562
-                    . '_'
1563
-                    . $route_to_check,
1564
-                    $id
1565
-                )
1566
-            )
1567
-        ) {
1568
-            if ($verify_only) {
1569
-                return false;
1570
-            }
1571
-            if (is_user_logged_in()) {
1572
-                wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1573
-            } else {
1574
-                return false;
1575
-            }
1576
-        }
1577
-        return true;
1578
-    }
1579
-
1580
-
1581
-    /**
1582
-     * @param string                 $box_id
1583
-     * @param string                 $title
1584
-     * @param callable|string|null   $callback
1585
-     * @param string|array|WP_Screen $screen
1586
-     * @param string                 $context
1587
-     * @param string                 $priority
1588
-     * @param array|null             $callback_args
1589
-     */
1590
-    protected function addMetaBox(
1591
-        string $box_id,
1592
-        string $title,
1593
-        $callback,
1594
-        $screen,
1595
-        string $context = 'normal',
1596
-        string $priority = 'default',
1597
-        ?array $callback_args = null
1598
-    ) {
1599
-        if (! is_callable($callback)) {
1600
-            return;
1601
-        }
1602
-
1603
-        add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args);
1604
-        add_filter(
1605
-            "postbox_classes_{$this->_wp_page_slug}_{$box_id}",
1606
-            function ($classes) {
1607
-                array_push($classes, 'ee-admin-container');
1608
-                return $classes;
1609
-            }
1610
-        );
1611
-    }
1612
-
1613
-
1614
-    /**
1615
-     * admin_init_global
1616
-     * This runs all the code that we want executed within the WP admin_init hook.
1617
-     * This method executes for ALL EE Admin pages.
1618
-     *
1619
-     * @return void
1620
-     */
1621
-    public function admin_init_global()
1622
-    {
1623
-    }
1624
-
1625
-
1626
-    /**
1627
-     * wp_loaded_global
1628
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1629
-     * EE_Admin page and will execute on every EE Admin Page load
1630
-     *
1631
-     * @return void
1632
-     */
1633
-    public function wp_loaded()
1634
-    {
1635
-    }
1636
-
1637
-
1638
-    /**
1639
-     * admin_notices
1640
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1641
-     * ALL EE_Admin pages.
1642
-     *
1643
-     * @return void
1644
-     */
1645
-    public function admin_notices_global()
1646
-    {
1647
-        $this->_display_no_javascript_warning();
1648
-        $this->_display_espresso_notices();
1649
-    }
1650
-
1651
-
1652
-    public function network_admin_notices_global()
1653
-    {
1654
-        $this->_display_no_javascript_warning();
1655
-        $this->_display_espresso_notices();
1656
-    }
1657
-
1658
-
1659
-    /**
1660
-     * admin_footer_scripts_global
1661
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1662
-     * will apply on ALL EE_Admin pages.
1663
-     *
1664
-     * @return void
1665
-     */
1666
-    public function admin_footer_scripts_global()
1667
-    {
1668
-        $this->_add_admin_page_ajax_loading_img();
1669
-        $this->_add_admin_page_overlay();
1670
-        // if metaboxes are present we need to add the nonce field
1671
-        if (
1672
-            isset($this->_route_config['metaboxes'])
1673
-            || isset($this->_route_config['list_table'])
1674
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1675
-        ) {
1676
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1677
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1678
-        }
1679
-    }
1680
-
1681
-
1682
-    /**
1683
-     * admin_footer_global
1684
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1685
-     * This particular method will apply on ALL EE_Admin Pages.
1686
-     *
1687
-     * @return void
1688
-     */
1689
-    public function admin_footer_global()
1690
-    {
1691
-        // dialog container for dialog helper
1692
-        echo '
1548
+		if (empty($capability) && empty($route_to_check)) {
1549
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1550
+				: $this->_route['capability'];
1551
+		} else {
1552
+			$capability = empty($capability) ? 'manage_options' : $capability;
1553
+		}
1554
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1555
+		if (
1556
+			! $this->request->isAjax()
1557
+			&& (
1558
+				! function_exists('is_admin')
1559
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1560
+					$capability,
1561
+					$this->page_slug
1562
+					. '_'
1563
+					. $route_to_check,
1564
+					$id
1565
+				)
1566
+			)
1567
+		) {
1568
+			if ($verify_only) {
1569
+				return false;
1570
+			}
1571
+			if (is_user_logged_in()) {
1572
+				wp_die(esc_html__('You do not have access to this route.', 'event_espresso'));
1573
+			} else {
1574
+				return false;
1575
+			}
1576
+		}
1577
+		return true;
1578
+	}
1579
+
1580
+
1581
+	/**
1582
+	 * @param string                 $box_id
1583
+	 * @param string                 $title
1584
+	 * @param callable|string|null   $callback
1585
+	 * @param string|array|WP_Screen $screen
1586
+	 * @param string                 $context
1587
+	 * @param string                 $priority
1588
+	 * @param array|null             $callback_args
1589
+	 */
1590
+	protected function addMetaBox(
1591
+		string $box_id,
1592
+		string $title,
1593
+		$callback,
1594
+		$screen,
1595
+		string $context = 'normal',
1596
+		string $priority = 'default',
1597
+		?array $callback_args = null
1598
+	) {
1599
+		if (! is_callable($callback)) {
1600
+			return;
1601
+		}
1602
+
1603
+		add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args);
1604
+		add_filter(
1605
+			"postbox_classes_{$this->_wp_page_slug}_{$box_id}",
1606
+			function ($classes) {
1607
+				array_push($classes, 'ee-admin-container');
1608
+				return $classes;
1609
+			}
1610
+		);
1611
+	}
1612
+
1613
+
1614
+	/**
1615
+	 * admin_init_global
1616
+	 * This runs all the code that we want executed within the WP admin_init hook.
1617
+	 * This method executes for ALL EE Admin pages.
1618
+	 *
1619
+	 * @return void
1620
+	 */
1621
+	public function admin_init_global()
1622
+	{
1623
+	}
1624
+
1625
+
1626
+	/**
1627
+	 * wp_loaded_global
1628
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1629
+	 * EE_Admin page and will execute on every EE Admin Page load
1630
+	 *
1631
+	 * @return void
1632
+	 */
1633
+	public function wp_loaded()
1634
+	{
1635
+	}
1636
+
1637
+
1638
+	/**
1639
+	 * admin_notices
1640
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1641
+	 * ALL EE_Admin pages.
1642
+	 *
1643
+	 * @return void
1644
+	 */
1645
+	public function admin_notices_global()
1646
+	{
1647
+		$this->_display_no_javascript_warning();
1648
+		$this->_display_espresso_notices();
1649
+	}
1650
+
1651
+
1652
+	public function network_admin_notices_global()
1653
+	{
1654
+		$this->_display_no_javascript_warning();
1655
+		$this->_display_espresso_notices();
1656
+	}
1657
+
1658
+
1659
+	/**
1660
+	 * admin_footer_scripts_global
1661
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1662
+	 * will apply on ALL EE_Admin pages.
1663
+	 *
1664
+	 * @return void
1665
+	 */
1666
+	public function admin_footer_scripts_global()
1667
+	{
1668
+		$this->_add_admin_page_ajax_loading_img();
1669
+		$this->_add_admin_page_overlay();
1670
+		// if metaboxes are present we need to add the nonce field
1671
+		if (
1672
+			isset($this->_route_config['metaboxes'])
1673
+			|| isset($this->_route_config['list_table'])
1674
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1675
+		) {
1676
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1677
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1678
+		}
1679
+	}
1680
+
1681
+
1682
+	/**
1683
+	 * admin_footer_global
1684
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1685
+	 * This particular method will apply on ALL EE_Admin Pages.
1686
+	 *
1687
+	 * @return void
1688
+	 */
1689
+	public function admin_footer_global()
1690
+	{
1691
+		// dialog container for dialog helper
1692
+		echo '
1693 1693
         <div class="ee-admin-dialog-container auto-hide hidden">
1694 1694
             <div class="ee-notices"></div>
1695 1695
             <div class="ee-admin-dialog-container-inner-content"></div>
1696 1696
         </div>
1697 1697
         ';
1698 1698
 
1699
-        // current set timezone for timezone js
1700
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1701
-    }
1702
-
1703
-
1704
-    /**
1705
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1706
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1707
-     * help popups then in your templates or your content you set "triggers" for the content using the
1708
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1709
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1710
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1711
-     * for the
1712
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1713
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1714
-     *    'help_trigger_id' => array(
1715
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1716
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1717
-     *    )
1718
-     * );
1719
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1720
-     *
1721
-     * @param array $help_array
1722
-     * @param bool  $display
1723
-     * @return string content
1724
-     * @throws DomainException
1725
-     * @throws EE_Error
1726
-     */
1727
-    protected function _set_help_popup_content($help_array = [], $display = false)
1728
-    {
1729
-        $content    = '';
1730
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1731
-        // loop through the array and setup content
1732
-        foreach ($help_array as $trigger => $help) {
1733
-            // make sure the array is setup properly
1734
-            if (! isset($help['title'], $help['content'])) {
1735
-                throw new EE_Error(
1736
-                    esc_html__(
1737
-                        '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',
1738
-                        'event_espresso'
1739
-                    )
1740
-                );
1741
-            }
1742
-            // we're good so let's setup the template vars and then assign parsed template content to our content.
1743
-            $template_args = [
1744
-                'help_popup_id'      => $trigger,
1745
-                'help_popup_title'   => $help['title'],
1746
-                'help_popup_content' => $help['content'],
1747
-            ];
1748
-            $content       .= EEH_Template::display_template(
1749
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1750
-                $template_args,
1751
-                true
1752
-            );
1753
-        }
1754
-        if ($display) {
1755
-            echo $content; // already escaped
1756
-            return '';
1757
-        }
1758
-        return $content;
1759
-    }
1760
-
1761
-
1762
-    /**
1763
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1764
-     *
1765
-     * @return array properly formatted array for help popup content
1766
-     * @throws EE_Error
1767
-     */
1768
-    private function _get_help_content()
1769
-    {
1770
-        // what is the method we're looking for?
1771
-        $method_name = '_help_popup_content_' . $this->_req_action;
1772
-        // if method doesn't exist let's get out.
1773
-        if (! method_exists($this, $method_name)) {
1774
-            return [];
1775
-        }
1776
-        // k we're good to go let's retrieve the help array
1777
-        $help_array = $this->{$method_name}();
1778
-        // make sure we've got an array!
1779
-        if (! is_array($help_array)) {
1780
-            throw new EE_Error(
1781
-                esc_html__(
1782
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1783
-                    'event_espresso'
1784
-                )
1785
-            );
1786
-        }
1787
-        return $help_array;
1788
-    }
1789
-
1790
-
1791
-    /**
1792
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1793
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1794
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1795
-     *
1796
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1797
-     * @param boolean $display    if false then we return the trigger string
1798
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1799
-     * @return string
1800
-     * @throws DomainException
1801
-     * @throws EE_Error
1802
-     */
1803
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1804
-    {
1805
-        if ($this->request->isAjax()) {
1806
-            return '';
1807
-        }
1808
-        // 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
1809
-        $help_array   = $this->_get_help_content();
1810
-        $help_content = '';
1811
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1812
-            $help_array[ $trigger_id ] = [
1813
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1814
-                'content' => esc_html__(
1815
-                    '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.)',
1816
-                    'event_espresso'
1817
-                ),
1818
-            ];
1819
-            $help_content = $this->_set_help_popup_content($help_array);
1820
-        }
1821
-        // let's setup the trigger
1822
-        $content = '<a class="ee-dialog" href="?height='
1823
-                   . esc_attr($dimensions[0])
1824
-                   . '&width='
1825
-                   . esc_attr($dimensions[1])
1826
-                   . '&inlineId='
1827
-                   . esc_attr($trigger_id)
1828
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1829
-        $content .= $help_content;
1830
-        if ($display) {
1831
-            echo $content; // already escaped
1832
-            return '';
1833
-        }
1834
-        return $content;
1835
-    }
1836
-
1837
-
1838
-    /**
1839
-     * _add_global_screen_options
1840
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1841
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1842
-     *
1843
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1844
-     *         see also WP_Screen object documents...
1845
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1846
-     * @abstract
1847
-     * @return void
1848
-     */
1849
-    private function _add_global_screen_options()
1850
-    {
1851
-    }
1852
-
1853
-
1854
-    /**
1855
-     * _add_global_feature_pointers
1856
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1857
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1858
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1859
-     *
1860
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1861
-     *         extended) also see:
1862
-     * @link   http://eamann.com/tech/wordpress-portland/
1863
-     * @abstract
1864
-     * @return void
1865
-     */
1866
-    private function _add_global_feature_pointers()
1867
-    {
1868
-    }
1869
-
1870
-
1871
-    /**
1872
-     * load_global_scripts_styles
1873
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1874
-     *
1875
-     * @return void
1876
-     */
1877
-    public function load_global_scripts_styles()
1878
-    {
1879
-        // add debugging styles
1880
-        if (WP_DEBUG) {
1881
-            add_action('admin_head', [$this, 'add_xdebug_style']);
1882
-        }
1883
-        // taking care of metaboxes
1884
-        if (
1885
-            empty($this->_cpt_route)
1886
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1887
-        ) {
1888
-            wp_enqueue_script('dashboard');
1889
-        }
1890
-
1891
-        wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH);
1892
-        wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN);
1893
-        // LOCALIZED DATA
1894
-        // localize script for ajax lazy loading
1895
-        wp_localize_script(
1896
-            EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1897
-            'eeLazyLoadingContainers',
1898
-            apply_filters(
1899
-                'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1900
-                ['espresso_news_post_box_content']
1901
-            )
1902
-        );
1903
-        StatusChangeNotice::loadAssets();
1904
-
1905
-        add_filter(
1906
-            'admin_body_class',
1907
-            function ($classes) {
1908
-                if (strpos($classes, 'espresso-admin') === false) {
1909
-                    $classes .= ' espresso-admin';
1910
-                }
1911
-                return $classes;
1912
-            }
1913
-        );
1914
-    }
1915
-
1916
-
1917
-    /**
1918
-     *        admin_footer_scripts_eei18n_js_strings
1919
-     *
1920
-     * @return        void
1921
-     */
1922
-    public function admin_footer_scripts_eei18n_js_strings()
1923
-    {
1924
-        EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1925
-        EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1926
-            __(
1927
-                '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!!!',
1928
-                'event_espresso'
1929
-            )
1930
-        );
1931
-        EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1932
-        EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1933
-        EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1934
-        EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1935
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1936
-        EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1937
-        EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1938
-        EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1939
-        EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1940
-        EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1941
-        EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1942
-        EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1943
-        EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1944
-        EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1945
-        EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1946
-        EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1947
-        EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1948
-        EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1949
-        EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1950
-        EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1951
-        EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1952
-        EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1953
-        EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1954
-        EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1955
-        EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1956
-        EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1957
-        EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1958
-        EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1959
-        EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1960
-        EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1961
-        EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1962
-        EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1963
-        EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1964
-        EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1965
-        EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1966
-        EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1967
-        EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1968
-        EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1969
-    }
1970
-
1971
-
1972
-    /**
1973
-     *        load enhanced xdebug styles for ppl with failing eyesight
1974
-     *
1975
-     * @return        void
1976
-     */
1977
-    public function add_xdebug_style()
1978
-    {
1979
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1980
-    }
1981
-
1982
-
1983
-    /************************/
1984
-    /** LIST TABLE METHODS **/
1985
-    /************************/
1986
-    /**
1987
-     * this sets up the list table if the current view requires it.
1988
-     *
1989
-     * @return void
1990
-     * @throws EE_Error
1991
-     * @throws InvalidArgumentException
1992
-     * @throws InvalidDataTypeException
1993
-     * @throws InvalidInterfaceException
1994
-     */
1995
-    protected function _set_list_table()
1996
-    {
1997
-        // first is this a list_table view?
1998
-        if (! isset($this->_route_config['list_table'])) {
1999
-            return;
2000
-        } //not a list_table view so get out.
2001
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2002
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2003
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2004
-            // user error msg
2005
-            $error_msg = esc_html__(
2006
-                'An error occurred. The requested list table views could not be found.',
2007
-                'event_espresso'
2008
-            );
2009
-            // developer error msg
2010
-            $error_msg .= '||'
2011
-                          . sprintf(
2012
-                              esc_html__(
2013
-                                  '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.',
2014
-                                  'event_espresso'
2015
-                              ),
2016
-                              $this->_req_action,
2017
-                              $list_table_view
2018
-                          );
2019
-            throw new EE_Error($error_msg);
2020
-        }
2021
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2022
-        $this->_views = apply_filters(
2023
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2024
-            $this->_views
2025
-        );
2026
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2027
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2028
-        $this->_set_list_table_view();
2029
-        $this->_set_list_table_object();
2030
-    }
2031
-
2032
-
2033
-    /**
2034
-     * set current view for List Table
2035
-     *
2036
-     * @return void
2037
-     */
2038
-    protected function _set_list_table_view()
2039
-    {
2040
-        $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2041
-        $status = $this->request->getRequestParam('status', null, 'key');
2042
-        $this->_view = $status && array_key_exists($status, $this->_views)
2043
-            ? $status
2044
-            : $this->_view;
2045
-    }
2046
-
2047
-
2048
-    /**
2049
-     * _set_list_table_object
2050
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2051
-     *
2052
-     * @throws InvalidInterfaceException
2053
-     * @throws InvalidArgumentException
2054
-     * @throws InvalidDataTypeException
2055
-     * @throws EE_Error
2056
-     * @throws InvalidInterfaceException
2057
-     */
2058
-    protected function _set_list_table_object()
2059
-    {
2060
-        if (isset($this->_route_config['list_table'])) {
2061
-            if (! class_exists($this->_route_config['list_table'])) {
2062
-                throw new EE_Error(
2063
-                    sprintf(
2064
-                        esc_html__(
2065
-                            '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.',
2066
-                            'event_espresso'
2067
-                        ),
2068
-                        $this->_route_config['list_table'],
2069
-                        $this->class_name
2070
-                    )
2071
-                );
2072
-            }
2073
-            $this->_list_table_object = $this->loader->getShared(
2074
-                $this->_route_config['list_table'],
2075
-                [$this]
2076
-            );
2077
-        }
2078
-    }
2079
-
2080
-
2081
-    /**
2082
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2083
-     *
2084
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2085
-     *                                                    urls.  The array should be indexed by the view it is being
2086
-     *                                                    added to.
2087
-     * @return array
2088
-     */
2089
-    public function get_list_table_view_RLs($extra_query_args = [])
2090
-    {
2091
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2092
-        if (empty($this->_views)) {
2093
-            $this->_views = [];
2094
-        }
2095
-        // cycle thru views
2096
-        foreach ($this->_views as $key => $view) {
2097
-            $query_args = [];
2098
-            // check for current view
2099
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2100
-            $query_args['action']                        = $this->_req_action;
2101
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2102
-            $query_args['status']                        = $view['slug'];
2103
-            // merge any other arguments sent in.
2104
-            if (isset($extra_query_args[ $view['slug'] ])) {
2105
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2106
-                    $query_args[] = $extra_query_arg;
2107
-                }
2108
-            }
2109
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2110
-        }
2111
-        return $this->_views;
2112
-    }
2113
-
2114
-
2115
-    /**
2116
-     * _entries_per_page_dropdown
2117
-     * generates a dropdown box for selecting the number of visible rows in an admin page list table
2118
-     *
2119
-     * @param int $max_entries total number of rows in the table
2120
-     * @return string
2121
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2122
-     *         WP does it.
2123
-     */
2124
-    protected function _entries_per_page_dropdown($max_entries = 0)
2125
-    {
2126
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2127
-        $values   = [10, 25, 50, 100];
2128
-        $per_page = $this->request->getRequestParam('per_page', 10, 'int');
2129
-        if ($max_entries) {
2130
-            $values[] = $max_entries;
2131
-            sort($values);
2132
-        }
2133
-        $entries_per_page_dropdown = '
1699
+		// current set timezone for timezone js
1700
+		echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1701
+	}
1702
+
1703
+
1704
+	/**
1705
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1706
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1707
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1708
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1709
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1710
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1711
+	 * for the
1712
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1713
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1714
+	 *    'help_trigger_id' => array(
1715
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1716
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1717
+	 *    )
1718
+	 * );
1719
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1720
+	 *
1721
+	 * @param array $help_array
1722
+	 * @param bool  $display
1723
+	 * @return string content
1724
+	 * @throws DomainException
1725
+	 * @throws EE_Error
1726
+	 */
1727
+	protected function _set_help_popup_content($help_array = [], $display = false)
1728
+	{
1729
+		$content    = '';
1730
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1731
+		// loop through the array and setup content
1732
+		foreach ($help_array as $trigger => $help) {
1733
+			// make sure the array is setup properly
1734
+			if (! isset($help['title'], $help['content'])) {
1735
+				throw new EE_Error(
1736
+					esc_html__(
1737
+						'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',
1738
+						'event_espresso'
1739
+					)
1740
+				);
1741
+			}
1742
+			// we're good so let's setup the template vars and then assign parsed template content to our content.
1743
+			$template_args = [
1744
+				'help_popup_id'      => $trigger,
1745
+				'help_popup_title'   => $help['title'],
1746
+				'help_popup_content' => $help['content'],
1747
+			];
1748
+			$content       .= EEH_Template::display_template(
1749
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1750
+				$template_args,
1751
+				true
1752
+			);
1753
+		}
1754
+		if ($display) {
1755
+			echo $content; // already escaped
1756
+			return '';
1757
+		}
1758
+		return $content;
1759
+	}
1760
+
1761
+
1762
+	/**
1763
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1764
+	 *
1765
+	 * @return array properly formatted array for help popup content
1766
+	 * @throws EE_Error
1767
+	 */
1768
+	private function _get_help_content()
1769
+	{
1770
+		// what is the method we're looking for?
1771
+		$method_name = '_help_popup_content_' . $this->_req_action;
1772
+		// if method doesn't exist let's get out.
1773
+		if (! method_exists($this, $method_name)) {
1774
+			return [];
1775
+		}
1776
+		// k we're good to go let's retrieve the help array
1777
+		$help_array = $this->{$method_name}();
1778
+		// make sure we've got an array!
1779
+		if (! is_array($help_array)) {
1780
+			throw new EE_Error(
1781
+				esc_html__(
1782
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1783
+					'event_espresso'
1784
+				)
1785
+			);
1786
+		}
1787
+		return $help_array;
1788
+	}
1789
+
1790
+
1791
+	/**
1792
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1793
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1794
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1795
+	 *
1796
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1797
+	 * @param boolean $display    if false then we return the trigger string
1798
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1799
+	 * @return string
1800
+	 * @throws DomainException
1801
+	 * @throws EE_Error
1802
+	 */
1803
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = ['400', '640'])
1804
+	{
1805
+		if ($this->request->isAjax()) {
1806
+			return '';
1807
+		}
1808
+		// 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
1809
+		$help_array   = $this->_get_help_content();
1810
+		$help_content = '';
1811
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1812
+			$help_array[ $trigger_id ] = [
1813
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1814
+				'content' => esc_html__(
1815
+					'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.)',
1816
+					'event_espresso'
1817
+				),
1818
+			];
1819
+			$help_content = $this->_set_help_popup_content($help_array);
1820
+		}
1821
+		// let's setup the trigger
1822
+		$content = '<a class="ee-dialog" href="?height='
1823
+				   . esc_attr($dimensions[0])
1824
+				   . '&width='
1825
+				   . esc_attr($dimensions[1])
1826
+				   . '&inlineId='
1827
+				   . esc_attr($trigger_id)
1828
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1829
+		$content .= $help_content;
1830
+		if ($display) {
1831
+			echo $content; // already escaped
1832
+			return '';
1833
+		}
1834
+		return $content;
1835
+	}
1836
+
1837
+
1838
+	/**
1839
+	 * _add_global_screen_options
1840
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1841
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1842
+	 *
1843
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1844
+	 *         see also WP_Screen object documents...
1845
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1846
+	 * @abstract
1847
+	 * @return void
1848
+	 */
1849
+	private function _add_global_screen_options()
1850
+	{
1851
+	}
1852
+
1853
+
1854
+	/**
1855
+	 * _add_global_feature_pointers
1856
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1857
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1858
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1859
+	 *
1860
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1861
+	 *         extended) also see:
1862
+	 * @link   http://eamann.com/tech/wordpress-portland/
1863
+	 * @abstract
1864
+	 * @return void
1865
+	 */
1866
+	private function _add_global_feature_pointers()
1867
+	{
1868
+	}
1869
+
1870
+
1871
+	/**
1872
+	 * load_global_scripts_styles
1873
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1874
+	 *
1875
+	 * @return void
1876
+	 */
1877
+	public function load_global_scripts_styles()
1878
+	{
1879
+		// add debugging styles
1880
+		if (WP_DEBUG) {
1881
+			add_action('admin_head', [$this, 'add_xdebug_style']);
1882
+		}
1883
+		// taking care of metaboxes
1884
+		if (
1885
+			empty($this->_cpt_route)
1886
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1887
+		) {
1888
+			wp_enqueue_script('dashboard');
1889
+		}
1890
+
1891
+		wp_enqueue_script(JqueryAssetManager::JS_HANDLE_JQUERY_UI_TOUCH_PUNCH);
1892
+		wp_enqueue_script(EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN);
1893
+		// LOCALIZED DATA
1894
+		// localize script for ajax lazy loading
1895
+		wp_localize_script(
1896
+			EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1897
+			'eeLazyLoadingContainers',
1898
+			apply_filters(
1899
+				'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1900
+				['espresso_news_post_box_content']
1901
+			)
1902
+		);
1903
+		StatusChangeNotice::loadAssets();
1904
+
1905
+		add_filter(
1906
+			'admin_body_class',
1907
+			function ($classes) {
1908
+				if (strpos($classes, 'espresso-admin') === false) {
1909
+					$classes .= ' espresso-admin';
1910
+				}
1911
+				return $classes;
1912
+			}
1913
+		);
1914
+	}
1915
+
1916
+
1917
+	/**
1918
+	 *        admin_footer_scripts_eei18n_js_strings
1919
+	 *
1920
+	 * @return        void
1921
+	 */
1922
+	public function admin_footer_scripts_eei18n_js_strings()
1923
+	{
1924
+		EE_Registry::$i18n_js_strings['ajax_url']       = WP_AJAX_URL;
1925
+		EE_Registry::$i18n_js_strings['confirm_delete'] = wp_strip_all_tags(
1926
+			__(
1927
+				'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!!!',
1928
+				'event_espresso'
1929
+			)
1930
+		);
1931
+		EE_Registry::$i18n_js_strings['January']        = wp_strip_all_tags(__('January', 'event_espresso'));
1932
+		EE_Registry::$i18n_js_strings['February']       = wp_strip_all_tags(__('February', 'event_espresso'));
1933
+		EE_Registry::$i18n_js_strings['March']          = wp_strip_all_tags(__('March', 'event_espresso'));
1934
+		EE_Registry::$i18n_js_strings['April']          = wp_strip_all_tags(__('April', 'event_espresso'));
1935
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1936
+		EE_Registry::$i18n_js_strings['June']           = wp_strip_all_tags(__('June', 'event_espresso'));
1937
+		EE_Registry::$i18n_js_strings['July']           = wp_strip_all_tags(__('July', 'event_espresso'));
1938
+		EE_Registry::$i18n_js_strings['August']         = wp_strip_all_tags(__('August', 'event_espresso'));
1939
+		EE_Registry::$i18n_js_strings['September']      = wp_strip_all_tags(__('September', 'event_espresso'));
1940
+		EE_Registry::$i18n_js_strings['October']        = wp_strip_all_tags(__('October', 'event_espresso'));
1941
+		EE_Registry::$i18n_js_strings['November']       = wp_strip_all_tags(__('November', 'event_espresso'));
1942
+		EE_Registry::$i18n_js_strings['December']       = wp_strip_all_tags(__('December', 'event_espresso'));
1943
+		EE_Registry::$i18n_js_strings['Jan']            = wp_strip_all_tags(__('Jan', 'event_espresso'));
1944
+		EE_Registry::$i18n_js_strings['Feb']            = wp_strip_all_tags(__('Feb', 'event_espresso'));
1945
+		EE_Registry::$i18n_js_strings['Mar']            = wp_strip_all_tags(__('Mar', 'event_espresso'));
1946
+		EE_Registry::$i18n_js_strings['Apr']            = wp_strip_all_tags(__('Apr', 'event_espresso'));
1947
+		EE_Registry::$i18n_js_strings['May']            = wp_strip_all_tags(__('May', 'event_espresso'));
1948
+		EE_Registry::$i18n_js_strings['Jun']            = wp_strip_all_tags(__('Jun', 'event_espresso'));
1949
+		EE_Registry::$i18n_js_strings['Jul']            = wp_strip_all_tags(__('Jul', 'event_espresso'));
1950
+		EE_Registry::$i18n_js_strings['Aug']            = wp_strip_all_tags(__('Aug', 'event_espresso'));
1951
+		EE_Registry::$i18n_js_strings['Sep']            = wp_strip_all_tags(__('Sep', 'event_espresso'));
1952
+		EE_Registry::$i18n_js_strings['Oct']            = wp_strip_all_tags(__('Oct', 'event_espresso'));
1953
+		EE_Registry::$i18n_js_strings['Nov']            = wp_strip_all_tags(__('Nov', 'event_espresso'));
1954
+		EE_Registry::$i18n_js_strings['Dec']            = wp_strip_all_tags(__('Dec', 'event_espresso'));
1955
+		EE_Registry::$i18n_js_strings['Sunday']         = wp_strip_all_tags(__('Sunday', 'event_espresso'));
1956
+		EE_Registry::$i18n_js_strings['Monday']         = wp_strip_all_tags(__('Monday', 'event_espresso'));
1957
+		EE_Registry::$i18n_js_strings['Tuesday']        = wp_strip_all_tags(__('Tuesday', 'event_espresso'));
1958
+		EE_Registry::$i18n_js_strings['Wednesday']      = wp_strip_all_tags(__('Wednesday', 'event_espresso'));
1959
+		EE_Registry::$i18n_js_strings['Thursday']       = wp_strip_all_tags(__('Thursday', 'event_espresso'));
1960
+		EE_Registry::$i18n_js_strings['Friday']         = wp_strip_all_tags(__('Friday', 'event_espresso'));
1961
+		EE_Registry::$i18n_js_strings['Saturday']       = wp_strip_all_tags(__('Saturday', 'event_espresso'));
1962
+		EE_Registry::$i18n_js_strings['Sun']            = wp_strip_all_tags(__('Sun', 'event_espresso'));
1963
+		EE_Registry::$i18n_js_strings['Mon']            = wp_strip_all_tags(__('Mon', 'event_espresso'));
1964
+		EE_Registry::$i18n_js_strings['Tue']            = wp_strip_all_tags(__('Tue', 'event_espresso'));
1965
+		EE_Registry::$i18n_js_strings['Wed']            = wp_strip_all_tags(__('Wed', 'event_espresso'));
1966
+		EE_Registry::$i18n_js_strings['Thu']            = wp_strip_all_tags(__('Thu', 'event_espresso'));
1967
+		EE_Registry::$i18n_js_strings['Fri']            = wp_strip_all_tags(__('Fri', 'event_espresso'));
1968
+		EE_Registry::$i18n_js_strings['Sat']            = wp_strip_all_tags(__('Sat', 'event_espresso'));
1969
+	}
1970
+
1971
+
1972
+	/**
1973
+	 *        load enhanced xdebug styles for ppl with failing eyesight
1974
+	 *
1975
+	 * @return        void
1976
+	 */
1977
+	public function add_xdebug_style()
1978
+	{
1979
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
1980
+	}
1981
+
1982
+
1983
+	/************************/
1984
+	/** LIST TABLE METHODS **/
1985
+	/************************/
1986
+	/**
1987
+	 * this sets up the list table if the current view requires it.
1988
+	 *
1989
+	 * @return void
1990
+	 * @throws EE_Error
1991
+	 * @throws InvalidArgumentException
1992
+	 * @throws InvalidDataTypeException
1993
+	 * @throws InvalidInterfaceException
1994
+	 */
1995
+	protected function _set_list_table()
1996
+	{
1997
+		// first is this a list_table view?
1998
+		if (! isset($this->_route_config['list_table'])) {
1999
+			return;
2000
+		} //not a list_table view so get out.
2001
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2002
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2003
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2004
+			// user error msg
2005
+			$error_msg = esc_html__(
2006
+				'An error occurred. The requested list table views could not be found.',
2007
+				'event_espresso'
2008
+			);
2009
+			// developer error msg
2010
+			$error_msg .= '||'
2011
+						  . sprintf(
2012
+							  esc_html__(
2013
+								  '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.',
2014
+								  'event_espresso'
2015
+							  ),
2016
+							  $this->_req_action,
2017
+							  $list_table_view
2018
+						  );
2019
+			throw new EE_Error($error_msg);
2020
+		}
2021
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2022
+		$this->_views = apply_filters(
2023
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2024
+			$this->_views
2025
+		);
2026
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2027
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2028
+		$this->_set_list_table_view();
2029
+		$this->_set_list_table_object();
2030
+	}
2031
+
2032
+
2033
+	/**
2034
+	 * set current view for List Table
2035
+	 *
2036
+	 * @return void
2037
+	 */
2038
+	protected function _set_list_table_view()
2039
+	{
2040
+		$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2041
+		$status = $this->request->getRequestParam('status', null, 'key');
2042
+		$this->_view = $status && array_key_exists($status, $this->_views)
2043
+			? $status
2044
+			: $this->_view;
2045
+	}
2046
+
2047
+
2048
+	/**
2049
+	 * _set_list_table_object
2050
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2051
+	 *
2052
+	 * @throws InvalidInterfaceException
2053
+	 * @throws InvalidArgumentException
2054
+	 * @throws InvalidDataTypeException
2055
+	 * @throws EE_Error
2056
+	 * @throws InvalidInterfaceException
2057
+	 */
2058
+	protected function _set_list_table_object()
2059
+	{
2060
+		if (isset($this->_route_config['list_table'])) {
2061
+			if (! class_exists($this->_route_config['list_table'])) {
2062
+				throw new EE_Error(
2063
+					sprintf(
2064
+						esc_html__(
2065
+							'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.',
2066
+							'event_espresso'
2067
+						),
2068
+						$this->_route_config['list_table'],
2069
+						$this->class_name
2070
+					)
2071
+				);
2072
+			}
2073
+			$this->_list_table_object = $this->loader->getShared(
2074
+				$this->_route_config['list_table'],
2075
+				[$this]
2076
+			);
2077
+		}
2078
+	}
2079
+
2080
+
2081
+	/**
2082
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2083
+	 *
2084
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2085
+	 *                                                    urls.  The array should be indexed by the view it is being
2086
+	 *                                                    added to.
2087
+	 * @return array
2088
+	 */
2089
+	public function get_list_table_view_RLs($extra_query_args = [])
2090
+	{
2091
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2092
+		if (empty($this->_views)) {
2093
+			$this->_views = [];
2094
+		}
2095
+		// cycle thru views
2096
+		foreach ($this->_views as $key => $view) {
2097
+			$query_args = [];
2098
+			// check for current view
2099
+			$this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2100
+			$query_args['action']                        = $this->_req_action;
2101
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2102
+			$query_args['status']                        = $view['slug'];
2103
+			// merge any other arguments sent in.
2104
+			if (isset($extra_query_args[ $view['slug'] ])) {
2105
+				foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2106
+					$query_args[] = $extra_query_arg;
2107
+				}
2108
+			}
2109
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2110
+		}
2111
+		return $this->_views;
2112
+	}
2113
+
2114
+
2115
+	/**
2116
+	 * _entries_per_page_dropdown
2117
+	 * generates a dropdown box for selecting the number of visible rows in an admin page list table
2118
+	 *
2119
+	 * @param int $max_entries total number of rows in the table
2120
+	 * @return string
2121
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2122
+	 *         WP does it.
2123
+	 */
2124
+	protected function _entries_per_page_dropdown($max_entries = 0)
2125
+	{
2126
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2127
+		$values   = [10, 25, 50, 100];
2128
+		$per_page = $this->request->getRequestParam('per_page', 10, 'int');
2129
+		if ($max_entries) {
2130
+			$values[] = $max_entries;
2131
+			sort($values);
2132
+		}
2133
+		$entries_per_page_dropdown = '
2134 2134
 			<div id="entries-per-page-dv" class="alignleft actions">
2135 2135
 				<label class="hide-if-no-js">
2136 2136
 					Show
2137 2137
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2138
-        foreach ($values as $value) {
2139
-            if ($value < $max_entries) {
2140
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2141
-                $entries_per_page_dropdown .= '
2138
+		foreach ($values as $value) {
2139
+			if ($value < $max_entries) {
2140
+				$selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2141
+				$entries_per_page_dropdown .= '
2142 2142
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2143
-            }
2144
-        }
2145
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2146
-        $entries_per_page_dropdown .= '
2143
+			}
2144
+		}
2145
+		$selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2146
+		$entries_per_page_dropdown .= '
2147 2147
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2148
-        $entries_per_page_dropdown .= '
2148
+		$entries_per_page_dropdown .= '
2149 2149
 					</select>
2150 2150
 					entries
2151 2151
 				</label>
2152 2152
 				<input id="entries-per-page-btn" class="button button--secondary" type="submit" value="Go" >
2153 2153
 			</div>
2154 2154
 		';
2155
-        return $entries_per_page_dropdown;
2156
-    }
2157
-
2158
-
2159
-    /**
2160
-     *        _set_search_attributes
2161
-     *
2162
-     * @return        void
2163
-     */
2164
-    public function _set_search_attributes()
2165
-    {
2166
-        $this->_template_args['search']['btn_label'] = sprintf(
2167
-            esc_html__('Search %s', 'event_espresso'),
2168
-            empty($this->_search_btn_label) ? $this->page_label
2169
-                : $this->_search_btn_label
2170
-        );
2171
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2172
-    }
2173
-
2174
-
2175
-
2176
-    /*** END LIST TABLE METHODS **/
2177
-
2178
-
2179
-    /**
2180
-     * _add_registered_metaboxes
2181
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2182
-     *
2183
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2184
-     * @return void
2185
-     * @throws EE_Error
2186
-     */
2187
-    private function _add_registered_meta_boxes()
2188
-    {
2189
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2190
-        // we only add meta boxes if the page_route calls for it
2191
-        if (
2192
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2193
-            && is_array(
2194
-                $this->_route_config['metaboxes']
2195
-            )
2196
-        ) {
2197
-            // this simply loops through the callbacks provided
2198
-            // and checks if there is a corresponding callback registered by the child
2199
-            // if there is then we go ahead and process the metabox loader.
2200
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2201
-                // first check for Closures
2202
-                if ($metabox_callback instanceof Closure) {
2203
-                    $result = $metabox_callback();
2204
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2205
-                    $result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2206
-                } else {
2207
-                    $result = $this->{$metabox_callback}();
2208
-                }
2209
-                if ($result === false) {
2210
-                    // user error msg
2211
-                    $error_msg = esc_html__(
2212
-                        'An error occurred. The  requested metabox could not be found.',
2213
-                        'event_espresso'
2214
-                    );
2215
-                    // developer error msg
2216
-                    $error_msg .= '||'
2217
-                                  . sprintf(
2218
-                                      esc_html__(
2219
-                                          '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.',
2220
-                                          'event_espresso'
2221
-                                      ),
2222
-                                      $metabox_callback
2223
-                                  );
2224
-                    throw new EE_Error($error_msg);
2225
-                }
2226
-            }
2227
-        }
2228
-    }
2229
-
2230
-
2231
-    /**
2232
-     * _add_screen_columns
2233
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2234
-     * the dynamic column template and we'll setup the column options for the page.
2235
-     *
2236
-     * @return void
2237
-     */
2238
-    private function _add_screen_columns()
2239
-    {
2240
-        if (
2241
-            is_array($this->_route_config)
2242
-            && isset($this->_route_config['columns'])
2243
-            && is_array($this->_route_config['columns'])
2244
-            && count($this->_route_config['columns']) === 2
2245
-        ) {
2246
-            add_screen_option(
2247
-                'layout_columns',
2248
-                [
2249
-                    'max'     => (int) $this->_route_config['columns'][0],
2250
-                    'default' => (int) $this->_route_config['columns'][1],
2251
-                ]
2252
-            );
2253
-            $this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2254
-            $screen_id                                           = $this->_current_screen->id;
2255
-            $screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2256
-            $total_columns                                       = ! empty($screen_columns)
2257
-                ? $screen_columns
2258
-                : $this->_route_config['columns'][1];
2259
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2260
-            $this->_template_args['current_page']                = $this->_wp_page_slug;
2261
-            $this->_template_args['screen']                      = $this->_current_screen;
2262
-            $this->_column_template_path                         = EE_ADMIN_TEMPLATE
2263
-                                                                   . 'admin_details_metabox_column_wrapper.template.php';
2264
-            // finally if we don't have has_metaboxes set in the route config
2265
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2266
-            $this->_route_config['has_metaboxes'] = true;
2267
-        }
2268
-    }
2269
-
2270
-
2271
-
2272
-    /** GLOBALLY AVAILABLE METABOXES **/
2273
-
2274
-
2275
-    /**
2276
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2277
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2278
-     * these get loaded on.
2279
-     */
2280
-    private function _espresso_news_post_box()
2281
-    {
2282
-        $news_box_title = apply_filters(
2283
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2284
-            esc_html__('New @ Event Espresso', 'event_espresso')
2285
-        );
2286
-        $this->addMetaBox(
2287
-            'espresso_news_post_box',
2288
-            $news_box_title,
2289
-            [
2290
-                $this,
2291
-                'espresso_news_post_box',
2292
-            ],
2293
-            $this->_wp_page_slug,
2294
-            'side',
2295
-            'low'
2296
-        );
2297
-    }
2298
-
2299
-
2300
-    /**
2301
-     * Code for setting up espresso ratings request metabox.
2302
-     */
2303
-    protected function _espresso_ratings_request()
2304
-    {
2305
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2306
-            return;
2307
-        }
2308
-        $ratings_box_title = apply_filters(
2309
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2310
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2311
-        );
2312
-        $this->addMetaBox(
2313
-            'espresso_ratings_request',
2314
-            $ratings_box_title,
2315
-            [
2316
-                $this,
2317
-                'espresso_ratings_request',
2318
-            ],
2319
-            $this->_wp_page_slug,
2320
-            'side'
2321
-        );
2322
-    }
2323
-
2324
-
2325
-    /**
2326
-     * Code for setting up espresso ratings request metabox content.
2327
-     *
2328
-     * @throws DomainException
2329
-     */
2330
-    public function espresso_ratings_request()
2331
-    {
2332
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2333
-    }
2334
-
2335
-
2336
-    public static function cached_rss_display($rss_id, $url)
2337
-    {
2338
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2339
-                     . esc_html__('Loading&#8230;', 'event_espresso')
2340
-                     . '</p><p class="hide-if-js">'
2341
-                     . esc_html__('This widget requires JavaScript.', 'event_espresso')
2342
-                     . '</p>';
2343
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2344
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2345
-        $post      = '</div>' . "\n";
2346
-        $cache_key = 'ee_rss_' . md5($rss_id);
2347
-        $output    = get_transient($cache_key);
2348
-        if ($output !== false) {
2349
-            echo $pre . $output . $post; // already escaped
2350
-            return true;
2351
-        }
2352
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2353
-            echo $pre . $loading . $post; // already escaped
2354
-            return false;
2355
-        }
2356
-        ob_start();
2357
-        wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2358
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2359
-        return true;
2360
-    }
2361
-
2362
-
2363
-    public function espresso_news_post_box()
2364
-    {
2365
-        ?>
2155
+		return $entries_per_page_dropdown;
2156
+	}
2157
+
2158
+
2159
+	/**
2160
+	 *        _set_search_attributes
2161
+	 *
2162
+	 * @return        void
2163
+	 */
2164
+	public function _set_search_attributes()
2165
+	{
2166
+		$this->_template_args['search']['btn_label'] = sprintf(
2167
+			esc_html__('Search %s', 'event_espresso'),
2168
+			empty($this->_search_btn_label) ? $this->page_label
2169
+				: $this->_search_btn_label
2170
+		);
2171
+		$this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2172
+	}
2173
+
2174
+
2175
+
2176
+	/*** END LIST TABLE METHODS **/
2177
+
2178
+
2179
+	/**
2180
+	 * _add_registered_metaboxes
2181
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2182
+	 *
2183
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2184
+	 * @return void
2185
+	 * @throws EE_Error
2186
+	 */
2187
+	private function _add_registered_meta_boxes()
2188
+	{
2189
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2190
+		// we only add meta boxes if the page_route calls for it
2191
+		if (
2192
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2193
+			&& is_array(
2194
+				$this->_route_config['metaboxes']
2195
+			)
2196
+		) {
2197
+			// this simply loops through the callbacks provided
2198
+			// and checks if there is a corresponding callback registered by the child
2199
+			// if there is then we go ahead and process the metabox loader.
2200
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2201
+				// first check for Closures
2202
+				if ($metabox_callback instanceof Closure) {
2203
+					$result = $metabox_callback();
2204
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2205
+					$result = call_user_func([$metabox_callback[0], $metabox_callback[1]]);
2206
+				} else {
2207
+					$result = $this->{$metabox_callback}();
2208
+				}
2209
+				if ($result === false) {
2210
+					// user error msg
2211
+					$error_msg = esc_html__(
2212
+						'An error occurred. The  requested metabox could not be found.',
2213
+						'event_espresso'
2214
+					);
2215
+					// developer error msg
2216
+					$error_msg .= '||'
2217
+								  . sprintf(
2218
+									  esc_html__(
2219
+										  '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.',
2220
+										  'event_espresso'
2221
+									  ),
2222
+									  $metabox_callback
2223
+								  );
2224
+					throw new EE_Error($error_msg);
2225
+				}
2226
+			}
2227
+		}
2228
+	}
2229
+
2230
+
2231
+	/**
2232
+	 * _add_screen_columns
2233
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2234
+	 * the dynamic column template and we'll setup the column options for the page.
2235
+	 *
2236
+	 * @return void
2237
+	 */
2238
+	private function _add_screen_columns()
2239
+	{
2240
+		if (
2241
+			is_array($this->_route_config)
2242
+			&& isset($this->_route_config['columns'])
2243
+			&& is_array($this->_route_config['columns'])
2244
+			&& count($this->_route_config['columns']) === 2
2245
+		) {
2246
+			add_screen_option(
2247
+				'layout_columns',
2248
+				[
2249
+					'max'     => (int) $this->_route_config['columns'][0],
2250
+					'default' => (int) $this->_route_config['columns'][1],
2251
+				]
2252
+			);
2253
+			$this->_template_args['num_columns']                 = $this->_route_config['columns'][0];
2254
+			$screen_id                                           = $this->_current_screen->id;
2255
+			$screen_columns                                      = (int) get_user_option("screen_layout_{$screen_id}");
2256
+			$total_columns                                       = ! empty($screen_columns)
2257
+				? $screen_columns
2258
+				: $this->_route_config['columns'][1];
2259
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2260
+			$this->_template_args['current_page']                = $this->_wp_page_slug;
2261
+			$this->_template_args['screen']                      = $this->_current_screen;
2262
+			$this->_column_template_path                         = EE_ADMIN_TEMPLATE
2263
+																   . 'admin_details_metabox_column_wrapper.template.php';
2264
+			// finally if we don't have has_metaboxes set in the route config
2265
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2266
+			$this->_route_config['has_metaboxes'] = true;
2267
+		}
2268
+	}
2269
+
2270
+
2271
+
2272
+	/** GLOBALLY AVAILABLE METABOXES **/
2273
+
2274
+
2275
+	/**
2276
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2277
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2278
+	 * these get loaded on.
2279
+	 */
2280
+	private function _espresso_news_post_box()
2281
+	{
2282
+		$news_box_title = apply_filters(
2283
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2284
+			esc_html__('New @ Event Espresso', 'event_espresso')
2285
+		);
2286
+		$this->addMetaBox(
2287
+			'espresso_news_post_box',
2288
+			$news_box_title,
2289
+			[
2290
+				$this,
2291
+				'espresso_news_post_box',
2292
+			],
2293
+			$this->_wp_page_slug,
2294
+			'side',
2295
+			'low'
2296
+		);
2297
+	}
2298
+
2299
+
2300
+	/**
2301
+	 * Code for setting up espresso ratings request metabox.
2302
+	 */
2303
+	protected function _espresso_ratings_request()
2304
+	{
2305
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2306
+			return;
2307
+		}
2308
+		$ratings_box_title = apply_filters(
2309
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2310
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2311
+		);
2312
+		$this->addMetaBox(
2313
+			'espresso_ratings_request',
2314
+			$ratings_box_title,
2315
+			[
2316
+				$this,
2317
+				'espresso_ratings_request',
2318
+			],
2319
+			$this->_wp_page_slug,
2320
+			'side'
2321
+		);
2322
+	}
2323
+
2324
+
2325
+	/**
2326
+	 * Code for setting up espresso ratings request metabox content.
2327
+	 *
2328
+	 * @throws DomainException
2329
+	 */
2330
+	public function espresso_ratings_request()
2331
+	{
2332
+		EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2333
+	}
2334
+
2335
+
2336
+	public static function cached_rss_display($rss_id, $url)
2337
+	{
2338
+		$loading   = '<p class="widget-loading hide-if-no-js">'
2339
+					 . esc_html__('Loading&#8230;', 'event_espresso')
2340
+					 . '</p><p class="hide-if-js">'
2341
+					 . esc_html__('This widget requires JavaScript.', 'event_espresso')
2342
+					 . '</p>';
2343
+		$pre       = '<div class="espresso-rss-display">' . "\n\t";
2344
+		$pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2345
+		$post      = '</div>' . "\n";
2346
+		$cache_key = 'ee_rss_' . md5($rss_id);
2347
+		$output    = get_transient($cache_key);
2348
+		if ($output !== false) {
2349
+			echo $pre . $output . $post; // already escaped
2350
+			return true;
2351
+		}
2352
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2353
+			echo $pre . $loading . $post; // already escaped
2354
+			return false;
2355
+		}
2356
+		ob_start();
2357
+		wp_widget_rss_output($url, ['show_date' => 0, 'items' => 5]);
2358
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2359
+		return true;
2360
+	}
2361
+
2362
+
2363
+	public function espresso_news_post_box()
2364
+	{
2365
+		?>
2366 2366
         <div class="padding">
2367 2367
             <div id="espresso_news_post_box_content" class="infolinks">
2368 2368
                 <?php
2369
-                // Get RSS Feed(s)
2370
-                EE_Admin_Page::cached_rss_display(
2371
-                    'espresso_news_post_box_content',
2372
-                    esc_url_raw(
2373
-                        apply_filters(
2374
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2375
-                            'https://eventespresso.com/feed/'
2376
-                        )
2377
-                    )
2378
-                );
2379
-                ?>
2369
+				// Get RSS Feed(s)
2370
+				EE_Admin_Page::cached_rss_display(
2371
+					'espresso_news_post_box_content',
2372
+					esc_url_raw(
2373
+						apply_filters(
2374
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2375
+							'https://eventespresso.com/feed/'
2376
+						)
2377
+					)
2378
+				);
2379
+				?>
2380 2380
             </div>
2381 2381
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2382 2382
         </div>
2383 2383
         <?php
2384
-    }
2385
-
2386
-
2387
-    private function _espresso_links_post_box()
2388
-    {
2389
-        // Hiding until we actually have content to put in here...
2390
-        // $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2391
-    }
2392
-
2393
-
2394
-    public function espresso_links_post_box()
2395
-    {
2396
-        // Hiding until we actually have content to put in here...
2397
-        // EEH_Template::display_template(
2398
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2399
-        // );
2400
-    }
2401
-
2402
-
2403
-    protected function _espresso_sponsors_post_box()
2404
-    {
2405
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2406
-            $this->addMetaBox(
2407
-                'espresso_sponsors_post_box',
2408
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2409
-                [$this, 'espresso_sponsors_post_box'],
2410
-                $this->_wp_page_slug,
2411
-                'side'
2412
-            );
2413
-        }
2414
-    }
2415
-
2416
-
2417
-    public function espresso_sponsors_post_box()
2418
-    {
2419
-        EEH_Template::display_template(
2420
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2421
-        );
2422
-    }
2423
-
2424
-
2425
-    private function _publish_post_box()
2426
-    {
2427
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2428
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2429
-        // then we'll use that for the metabox label.
2430
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2431
-        if (! empty($this->_labels['publishbox'])) {
2432
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2433
-                : $this->_labels['publishbox'];
2434
-        } else {
2435
-            $box_label = esc_html__('Publish', 'event_espresso');
2436
-        }
2437
-        $box_label = apply_filters(
2438
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2439
-            $box_label,
2440
-            $this->_req_action,
2441
-            $this
2442
-        );
2443
-        $this->addMetaBox(
2444
-            $meta_box_ref,
2445
-            $box_label,
2446
-            [$this, 'editor_overview'],
2447
-            $this->_current_screen->id,
2448
-            'side',
2449
-            'high'
2450
-        );
2451
-    }
2452
-
2453
-
2454
-    public function editor_overview()
2455
-    {
2456
-        // if we have extra content set let's add it in if not make sure its empty
2457
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2458
-            ? $this->_template_args['publish_box_extra_content']
2459
-            : '';
2460
-        echo EEH_Template::display_template(
2461
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2462
-            $this->_template_args,
2463
-            true
2464
-        );
2465
-    }
2466
-
2467
-
2468
-    /** end of globally available metaboxes section **/
2469
-
2470
-
2471
-    /**
2472
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2473
-     * protected method.
2474
-     *
2475
-     * @param string $name
2476
-     * @param int    $id
2477
-     * @param bool   $delete
2478
-     * @param string $save_close_redirect_URL
2479
-     * @param bool   $both_btns
2480
-     * @throws EE_Error
2481
-     * @throws InvalidArgumentException
2482
-     * @throws InvalidDataTypeException
2483
-     * @throws InvalidInterfaceException
2484
-     * @see   $this->_set_publish_post_box_vars for param details
2485
-     * @since 4.6.0
2486
-     */
2487
-    public function set_publish_post_box_vars(
2488
-        $name = '',
2489
-        $id = 0,
2490
-        $delete = false,
2491
-        $save_close_redirect_URL = '',
2492
-        $both_btns = true
2493
-    ) {
2494
-        $this->_set_publish_post_box_vars(
2495
-            $name,
2496
-            $id,
2497
-            $delete,
2498
-            $save_close_redirect_URL,
2499
-            $both_btns
2500
-        );
2501
-    }
2502
-
2503
-
2504
-    /**
2505
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2506
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2507
-     * save, and save and close buttons to work properly, then you will want to include a
2508
-     * values for the name and id arguments.
2509
-     *
2510
-     * @param string  $name                       key used for the action ID (i.e. event_id)
2511
-     * @param int     $id                         id attached to the item published
2512
-     * @param string  $delete                     page route callback for the delete action
2513
-     * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2514
-     * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2515
-     *                                            the Save button
2516
-     * @throws EE_Error
2517
-     * @throws InvalidArgumentException
2518
-     * @throws InvalidDataTypeException
2519
-     * @throws InvalidInterfaceException
2520
-     * @todo  Add in validation for name/id arguments.
2521
-     */
2522
-    protected function _set_publish_post_box_vars(
2523
-        $name = '',
2524
-        $id = 0,
2525
-        $delete = '',
2526
-        $save_close_redirect_URL = '',
2527
-        $both_btns = true
2528
-    ) {
2529
-        // if Save & Close, use a custom redirect URL or default to the main page?
2530
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2531
-            ? $save_close_redirect_URL
2532
-            : $this->_admin_base_url;
2533
-        // create the Save & Close and Save buttons
2534
-        $this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2535
-        // if we have extra content set let's add it in if not make sure its empty
2536
-        $this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2537
-        $delete_link = '';
2538
-        if ($delete && ! empty($id)) {
2539
-            // make sure we have a default if just true is sent.
2540
-            $delete           = ! empty($delete) ? $delete : 'delete';
2541
-            $delete_link      = $this->get_action_link_or_button(
2542
-                $delete,
2543
-                $delete,
2544
-                [$name => $id],
2545
-                'submitdelete deletion button button--outline button--caution'
2546
-            );
2547
-        }
2548
-        $this->_template_args['publish_delete_link'] = $delete_link;
2549
-        if (! empty($name) && ! empty($id)) {
2550
-            $hidden_field_arr[ $name ] = [
2551
-                'type'  => 'hidden',
2552
-                'value' => $id,
2553
-            ];
2554
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2555
-        } else {
2556
-            $hf = '';
2557
-        }
2558
-        // add hidden field
2559
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2560
-            ? $hf[ $name ]['field']
2561
-            : $hf;
2562
-    }
2563
-
2564
-
2565
-    /**
2566
-     * displays an error message to ppl who have javascript disabled
2567
-     *
2568
-     * @return void
2569
-     */
2570
-    private function _display_no_javascript_warning()
2571
-    {
2572
-        ?>
2384
+	}
2385
+
2386
+
2387
+	private function _espresso_links_post_box()
2388
+	{
2389
+		// Hiding until we actually have content to put in here...
2390
+		// $this->addMetaBox('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2391
+	}
2392
+
2393
+
2394
+	public function espresso_links_post_box()
2395
+	{
2396
+		// Hiding until we actually have content to put in here...
2397
+		// EEH_Template::display_template(
2398
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2399
+		// );
2400
+	}
2401
+
2402
+
2403
+	protected function _espresso_sponsors_post_box()
2404
+	{
2405
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2406
+			$this->addMetaBox(
2407
+				'espresso_sponsors_post_box',
2408
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2409
+				[$this, 'espresso_sponsors_post_box'],
2410
+				$this->_wp_page_slug,
2411
+				'side'
2412
+			);
2413
+		}
2414
+	}
2415
+
2416
+
2417
+	public function espresso_sponsors_post_box()
2418
+	{
2419
+		EEH_Template::display_template(
2420
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2421
+		);
2422
+	}
2423
+
2424
+
2425
+	private function _publish_post_box()
2426
+	{
2427
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2428
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2429
+		// then we'll use that for the metabox label.
2430
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2431
+		if (! empty($this->_labels['publishbox'])) {
2432
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2433
+				: $this->_labels['publishbox'];
2434
+		} else {
2435
+			$box_label = esc_html__('Publish', 'event_espresso');
2436
+		}
2437
+		$box_label = apply_filters(
2438
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2439
+			$box_label,
2440
+			$this->_req_action,
2441
+			$this
2442
+		);
2443
+		$this->addMetaBox(
2444
+			$meta_box_ref,
2445
+			$box_label,
2446
+			[$this, 'editor_overview'],
2447
+			$this->_current_screen->id,
2448
+			'side',
2449
+			'high'
2450
+		);
2451
+	}
2452
+
2453
+
2454
+	public function editor_overview()
2455
+	{
2456
+		// if we have extra content set let's add it in if not make sure its empty
2457
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2458
+			? $this->_template_args['publish_box_extra_content']
2459
+			: '';
2460
+		echo EEH_Template::display_template(
2461
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2462
+			$this->_template_args,
2463
+			true
2464
+		);
2465
+	}
2466
+
2467
+
2468
+	/** end of globally available metaboxes section **/
2469
+
2470
+
2471
+	/**
2472
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2473
+	 * protected method.
2474
+	 *
2475
+	 * @param string $name
2476
+	 * @param int    $id
2477
+	 * @param bool   $delete
2478
+	 * @param string $save_close_redirect_URL
2479
+	 * @param bool   $both_btns
2480
+	 * @throws EE_Error
2481
+	 * @throws InvalidArgumentException
2482
+	 * @throws InvalidDataTypeException
2483
+	 * @throws InvalidInterfaceException
2484
+	 * @see   $this->_set_publish_post_box_vars for param details
2485
+	 * @since 4.6.0
2486
+	 */
2487
+	public function set_publish_post_box_vars(
2488
+		$name = '',
2489
+		$id = 0,
2490
+		$delete = false,
2491
+		$save_close_redirect_URL = '',
2492
+		$both_btns = true
2493
+	) {
2494
+		$this->_set_publish_post_box_vars(
2495
+			$name,
2496
+			$id,
2497
+			$delete,
2498
+			$save_close_redirect_URL,
2499
+			$both_btns
2500
+		);
2501
+	}
2502
+
2503
+
2504
+	/**
2505
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2506
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2507
+	 * save, and save and close buttons to work properly, then you will want to include a
2508
+	 * values for the name and id arguments.
2509
+	 *
2510
+	 * @param string  $name                       key used for the action ID (i.e. event_id)
2511
+	 * @param int     $id                         id attached to the item published
2512
+	 * @param string  $delete                     page route callback for the delete action
2513
+	 * @param string  $save_close_redirect_URL    custom URL to redirect to after Save & Close has been completed
2514
+	 * @param boolean $both_btns                  whether to display BOTH the "Save & Close" and "Save" buttons or just
2515
+	 *                                            the Save button
2516
+	 * @throws EE_Error
2517
+	 * @throws InvalidArgumentException
2518
+	 * @throws InvalidDataTypeException
2519
+	 * @throws InvalidInterfaceException
2520
+	 * @todo  Add in validation for name/id arguments.
2521
+	 */
2522
+	protected function _set_publish_post_box_vars(
2523
+		$name = '',
2524
+		$id = 0,
2525
+		$delete = '',
2526
+		$save_close_redirect_URL = '',
2527
+		$both_btns = true
2528
+	) {
2529
+		// if Save & Close, use a custom redirect URL or default to the main page?
2530
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2531
+			? $save_close_redirect_URL
2532
+			: $this->_admin_base_url;
2533
+		// create the Save & Close and Save buttons
2534
+		$this->_set_save_buttons($both_btns, [], [], $save_close_redirect_URL);
2535
+		// if we have extra content set let's add it in if not make sure its empty
2536
+		$this->_template_args['publish_box_extra_content'] = $this->_template_args['publish_box_extra_content'] ?? '';
2537
+		$delete_link = '';
2538
+		if ($delete && ! empty($id)) {
2539
+			// make sure we have a default if just true is sent.
2540
+			$delete           = ! empty($delete) ? $delete : 'delete';
2541
+			$delete_link      = $this->get_action_link_or_button(
2542
+				$delete,
2543
+				$delete,
2544
+				[$name => $id],
2545
+				'submitdelete deletion button button--outline button--caution'
2546
+			);
2547
+		}
2548
+		$this->_template_args['publish_delete_link'] = $delete_link;
2549
+		if (! empty($name) && ! empty($id)) {
2550
+			$hidden_field_arr[ $name ] = [
2551
+				'type'  => 'hidden',
2552
+				'value' => $id,
2553
+			];
2554
+			$hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2555
+		} else {
2556
+			$hf = '';
2557
+		}
2558
+		// add hidden field
2559
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2560
+			? $hf[ $name ]['field']
2561
+			: $hf;
2562
+	}
2563
+
2564
+
2565
+	/**
2566
+	 * displays an error message to ppl who have javascript disabled
2567
+	 *
2568
+	 * @return void
2569
+	 */
2570
+	private function _display_no_javascript_warning()
2571
+	{
2572
+		?>
2573 2573
         <noscript>
2574 2574
             <div id="no-js-message" class="error">
2575 2575
                 <p style="font-size:1.3em;">
2576 2576
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2577 2577
                     <?php esc_html_e(
2578
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2579
-                        'event_espresso'
2580
-                    ); ?>
2578
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2579
+						'event_espresso'
2580
+					); ?>
2581 2581
                 </p>
2582 2582
             </div>
2583 2583
         </noscript>
2584 2584
         <?php
2585
-    }
2586
-
2587
-
2588
-    /**
2589
-     * displays espresso success and/or error notices
2590
-     *
2591
-     * @return void
2592
-     */
2593
-    protected function _display_espresso_notices()
2594
-    {
2595
-        $notices = $this->_get_transient(true);
2596
-        echo stripslashes($notices);
2597
-    }
2598
-
2599
-
2600
-    /**
2601
-     * spinny things pacify the masses
2602
-     *
2603
-     * @return void
2604
-     */
2605
-    protected function _add_admin_page_ajax_loading_img()
2606
-    {
2607
-        ?>
2585
+	}
2586
+
2587
+
2588
+	/**
2589
+	 * displays espresso success and/or error notices
2590
+	 *
2591
+	 * @return void
2592
+	 */
2593
+	protected function _display_espresso_notices()
2594
+	{
2595
+		$notices = $this->_get_transient(true);
2596
+		echo stripslashes($notices);
2597
+	}
2598
+
2599
+
2600
+	/**
2601
+	 * spinny things pacify the masses
2602
+	 *
2603
+	 * @return void
2604
+	 */
2605
+	protected function _add_admin_page_ajax_loading_img()
2606
+	{
2607
+		?>
2608 2608
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2609 2609
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2610
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2610
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2611 2611
         </div>
2612 2612
         <?php
2613
-    }
2613
+	}
2614 2614
 
2615 2615
 
2616
-    /**
2617
-     * add admin page overlay for modal boxes
2618
-     *
2619
-     * @return void
2620
-     */
2621
-    protected function _add_admin_page_overlay()
2622
-    {
2623
-        ?>
2616
+	/**
2617
+	 * add admin page overlay for modal boxes
2618
+	 *
2619
+	 * @return void
2620
+	 */
2621
+	protected function _add_admin_page_overlay()
2622
+	{
2623
+		?>
2624 2624
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2625 2625
         <?php
2626
-    }
2627
-
2628
-
2629
-    /**
2630
-     * facade for $this->addMetaBox()
2631
-     *
2632
-     * @param string  $action        where the metabox gets displayed
2633
-     * @param string  $title         Title of Metabox (output in metabox header)
2634
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2635
-     *                               instead of the one created in here.
2636
-     * @param array   $callback_args an array of args supplied for the metabox
2637
-     * @param string  $column        what metabox column
2638
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2639
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2640
-     *                               created but just set our own callback for wp's add_meta_box.
2641
-     * @throws DomainException
2642
-     */
2643
-    public function _add_admin_page_meta_box(
2644
-        $action,
2645
-        $title,
2646
-        $callback,
2647
-        $callback_args,
2648
-        $column = 'normal',
2649
-        $priority = 'high',
2650
-        $create_func = true
2651
-    ) {
2652
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2653
-        // 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.
2654
-        if (empty($callback_args) && $create_func) {
2655
-            $callback_args = [
2656
-                'template_path' => $this->_template_path,
2657
-                'template_args' => $this->_template_args,
2658
-            ];
2659
-        }
2660
-        // 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)
2661
-        $call_back_func = $create_func
2662
-            ? static function ($post, $metabox) {
2663
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2664
-                echo EEH_Template::display_template(
2665
-                    $metabox['args']['template_path'],
2666
-                    $metabox['args']['template_args'],
2667
-                    true
2668
-                );
2669
-            }
2670
-            : $callback;
2671
-        $this->addMetaBox(
2672
-            str_replace('_', '-', $action) . '-mbox',
2673
-            $title,
2674
-            $call_back_func,
2675
-            $this->_wp_page_slug,
2676
-            $column,
2677
-            $priority,
2678
-            $callback_args
2679
-        );
2680
-    }
2681
-
2682
-
2683
-    /**
2684
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2685
-     *
2686
-     * @throws DomainException
2687
-     * @throws EE_Error
2688
-     * @throws InvalidArgumentException
2689
-     * @throws InvalidDataTypeException
2690
-     * @throws InvalidInterfaceException
2691
-     */
2692
-    public function display_admin_page_with_metabox_columns()
2693
-    {
2694
-        $this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2695
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2696
-            $this->_column_template_path,
2697
-            $this->_template_args,
2698
-            true
2699
-        );
2700
-        // the final wrapper
2701
-        $this->admin_page_wrapper();
2702
-    }
2703
-
2704
-
2705
-    /**
2706
-     * generates  HTML wrapper for an admin details page
2707
-     *
2708
-     * @return void
2709
-     * @throws DomainException
2710
-     * @throws EE_Error
2711
-     * @throws InvalidArgumentException
2712
-     * @throws InvalidDataTypeException
2713
-     * @throws InvalidInterfaceException
2714
-     */
2715
-    public function display_admin_page_with_sidebar()
2716
-    {
2717
-        $this->_display_admin_page(true);
2718
-    }
2719
-
2720
-
2721
-    /**
2722
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2723
-     *
2724
-     * @return void
2725
-     * @throws DomainException
2726
-     * @throws EE_Error
2727
-     * @throws InvalidArgumentException
2728
-     * @throws InvalidDataTypeException
2729
-     * @throws InvalidInterfaceException
2730
-     */
2731
-    public function display_admin_page_with_no_sidebar()
2732
-    {
2733
-        $this->_display_admin_page();
2734
-    }
2735
-
2736
-
2737
-    /**
2738
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2739
-     *
2740
-     * @return void
2741
-     * @throws DomainException
2742
-     * @throws EE_Error
2743
-     * @throws InvalidArgumentException
2744
-     * @throws InvalidDataTypeException
2745
-     * @throws InvalidInterfaceException
2746
-     */
2747
-    public function display_about_admin_page()
2748
-    {
2749
-        $this->_display_admin_page(false, true);
2750
-    }
2751
-
2752
-
2753
-    /**
2754
-     * display_admin_page
2755
-     * contains the code for actually displaying an admin page
2756
-     *
2757
-     * @param boolean $sidebar true with sidebar, false without
2758
-     * @param boolean $about   use the about admin wrapper instead of the default.
2759
-     * @return void
2760
-     * @throws DomainException
2761
-     * @throws EE_Error
2762
-     * @throws InvalidArgumentException
2763
-     * @throws InvalidDataTypeException
2764
-     * @throws InvalidInterfaceException
2765
-     */
2766
-    private function _display_admin_page($sidebar = false, $about = false)
2767
-    {
2768
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2769
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2770
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2771
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2772
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2773
-
2774
-        $post_body_content = $this->_template_args['before_admin_page_content'] ?? '';
2775
-
2776
-        $this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status'
2777
-                                                 && $this->_req_action !== 'data_reset'
2778
-                                                 && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages'
2779
-                                                 && strpos($post_body_content, 'wp-list-table') === false;
2780
-
2781
-        $this->_template_args['current_page']              = $this->_wp_page_slug;
2782
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2783
-            ? 'poststuff'
2784
-            : 'espresso-default-admin';
2785
-        $this->_template_args['admin_page_wrapper_div_class'] = str_replace(
2786
-            'event-espresso_page_espresso_',
2787
-            '',
2788
-            $this->_wp_page_slug
2789
-        ) . ' ' . $this->_req_action . '-route';
2790
-
2791
-        $template_path = $sidebar
2792
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2793
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2794
-        if ($this->request->isAjax()) {
2795
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2796
-        }
2797
-        $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2798
-
2799
-        $this->_template_args['post_body_content']         = $this->_template_args['admin_page_content'] ?? '';
2800
-        $this->_template_args['before_admin_page_content'] = $post_body_content;
2801
-        $this->_template_args['after_admin_page_content']  = $this->_template_args['after_admin_page_content'] ?? '';
2802
-        $this->_template_args['admin_page_content']        = EEH_Template::display_template(
2803
-            $template_path,
2804
-            $this->_template_args,
2805
-            true
2806
-        );
2807
-        // the final template wrapper
2808
-        $this->admin_page_wrapper($about);
2809
-    }
2810
-
2811
-
2812
-    /**
2813
-     * This is used to display caf preview pages.
2814
-     *
2815
-     * @param string $utm_campaign_source what is the key used for google analytics link
2816
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2817
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2818
-     * @return void
2819
-     * @throws DomainException
2820
-     * @throws EE_Error
2821
-     * @throws InvalidArgumentException
2822
-     * @throws InvalidDataTypeException
2823
-     * @throws InvalidInterfaceException
2824
-     * @since 4.3.2
2825
-     */
2826
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2827
-    {
2828
-        // let's generate a default preview action button if there isn't one already present.
2829
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2830
-            'Upgrade to Event Espresso 4 Right Now',
2831
-            'event_espresso'
2832
-        );
2833
-        $buy_now_url                                   = add_query_arg(
2834
-            [
2835
-                'ee_ver'       => 'ee4',
2836
-                'utm_source'   => 'ee4_plugin_admin',
2837
-                'utm_medium'   => 'link',
2838
-                'utm_campaign' => $utm_campaign_source,
2839
-                'utm_content'  => 'buy_now_button',
2840
-            ],
2841
-            'https://eventespresso.com/pricing/'
2842
-        );
2843
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2844
-            ? $this->get_action_link_or_button(
2845
-                '',
2846
-                'buy_now',
2847
-                [],
2848
-                'button button--primary button--big',
2849
-                esc_url_raw($buy_now_url),
2850
-                true
2851
-            )
2852
-            : $this->_template_args['preview_action_button'];
2853
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2854
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2855
-            $this->_template_args,
2856
-            true
2857
-        );
2858
-        $this->_display_admin_page($display_sidebar);
2859
-    }
2860
-
2861
-
2862
-    /**
2863
-     * display_admin_list_table_page_with_sidebar
2864
-     * generates HTML wrapper for an admin_page with list_table
2865
-     *
2866
-     * @return void
2867
-     * @throws DomainException
2868
-     * @throws EE_Error
2869
-     * @throws InvalidArgumentException
2870
-     * @throws InvalidDataTypeException
2871
-     * @throws InvalidInterfaceException
2872
-     */
2873
-    public function display_admin_list_table_page_with_sidebar()
2874
-    {
2875
-        $this->_display_admin_list_table_page(true);
2876
-    }
2877
-
2878
-
2879
-    /**
2880
-     * display_admin_list_table_page_with_no_sidebar
2881
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2882
-     *
2883
-     * @return void
2884
-     * @throws DomainException
2885
-     * @throws EE_Error
2886
-     * @throws InvalidArgumentException
2887
-     * @throws InvalidDataTypeException
2888
-     * @throws InvalidInterfaceException
2889
-     */
2890
-    public function display_admin_list_table_page_with_no_sidebar()
2891
-    {
2892
-        $this->_display_admin_list_table_page();
2893
-    }
2894
-
2895
-
2896
-    /**
2897
-     * generates html wrapper for an admin_list_table page
2898
-     *
2899
-     * @param boolean $sidebar whether to display with sidebar or not.
2900
-     * @return void
2901
-     * @throws DomainException
2902
-     * @throws EE_Error
2903
-     * @throws InvalidArgumentException
2904
-     * @throws InvalidDataTypeException
2905
-     * @throws InvalidInterfaceException
2906
-     */
2907
-    private function _display_admin_list_table_page($sidebar = false)
2908
-    {
2909
-        // setup search attributes
2910
-        $this->_set_search_attributes();
2911
-        $this->_template_args['current_page']     = $this->_wp_page_slug;
2912
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2913
-        $this->_template_args['table_url']        = $this->request->isAjax()
2914
-            ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2915
-            : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2916
-        $this->_template_args['list_table']       = $this->_list_table_object;
2917
-        $this->_template_args['current_route']    = $this->_req_action;
2918
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2919
-        $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2920
-        if (! empty($ajax_sorting_callback)) {
2921
-            $sortable_list_table_form_fields = wp_nonce_field(
2922
-                $ajax_sorting_callback . '_nonce',
2923
-                $ajax_sorting_callback . '_nonce',
2924
-                false,
2925
-                false
2926
-            );
2927
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2928
-                                                . $this->page_slug
2929
-                                                . '" />';
2930
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2931
-                                                . $ajax_sorting_callback
2932
-                                                . '" />';
2933
-        } else {
2934
-            $sortable_list_table_form_fields = '';
2935
-        }
2936
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2937
-
2938
-        $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? '';
2939
-
2940
-        $nonce_ref          = $this->_req_action . '_nonce';
2941
-        $hidden_form_fields .= '
2626
+	}
2627
+
2628
+
2629
+	/**
2630
+	 * facade for $this->addMetaBox()
2631
+	 *
2632
+	 * @param string  $action        where the metabox gets displayed
2633
+	 * @param string  $title         Title of Metabox (output in metabox header)
2634
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2635
+	 *                               instead of the one created in here.
2636
+	 * @param array   $callback_args an array of args supplied for the metabox
2637
+	 * @param string  $column        what metabox column
2638
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2639
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2640
+	 *                               created but just set our own callback for wp's add_meta_box.
2641
+	 * @throws DomainException
2642
+	 */
2643
+	public function _add_admin_page_meta_box(
2644
+		$action,
2645
+		$title,
2646
+		$callback,
2647
+		$callback_args,
2648
+		$column = 'normal',
2649
+		$priority = 'high',
2650
+		$create_func = true
2651
+	) {
2652
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2653
+		// 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.
2654
+		if (empty($callback_args) && $create_func) {
2655
+			$callback_args = [
2656
+				'template_path' => $this->_template_path,
2657
+				'template_args' => $this->_template_args,
2658
+			];
2659
+		}
2660
+		// 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)
2661
+		$call_back_func = $create_func
2662
+			? static function ($post, $metabox) {
2663
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2664
+				echo EEH_Template::display_template(
2665
+					$metabox['args']['template_path'],
2666
+					$metabox['args']['template_args'],
2667
+					true
2668
+				);
2669
+			}
2670
+			: $callback;
2671
+		$this->addMetaBox(
2672
+			str_replace('_', '-', $action) . '-mbox',
2673
+			$title,
2674
+			$call_back_func,
2675
+			$this->_wp_page_slug,
2676
+			$column,
2677
+			$priority,
2678
+			$callback_args
2679
+		);
2680
+	}
2681
+
2682
+
2683
+	/**
2684
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2685
+	 *
2686
+	 * @throws DomainException
2687
+	 * @throws EE_Error
2688
+	 * @throws InvalidArgumentException
2689
+	 * @throws InvalidDataTypeException
2690
+	 * @throws InvalidInterfaceException
2691
+	 */
2692
+	public function display_admin_page_with_metabox_columns()
2693
+	{
2694
+		$this->_template_args['post_body_content']  = $this->_template_args['admin_page_content'];
2695
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2696
+			$this->_column_template_path,
2697
+			$this->_template_args,
2698
+			true
2699
+		);
2700
+		// the final wrapper
2701
+		$this->admin_page_wrapper();
2702
+	}
2703
+
2704
+
2705
+	/**
2706
+	 * generates  HTML wrapper for an admin details page
2707
+	 *
2708
+	 * @return void
2709
+	 * @throws DomainException
2710
+	 * @throws EE_Error
2711
+	 * @throws InvalidArgumentException
2712
+	 * @throws InvalidDataTypeException
2713
+	 * @throws InvalidInterfaceException
2714
+	 */
2715
+	public function display_admin_page_with_sidebar()
2716
+	{
2717
+		$this->_display_admin_page(true);
2718
+	}
2719
+
2720
+
2721
+	/**
2722
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2723
+	 *
2724
+	 * @return void
2725
+	 * @throws DomainException
2726
+	 * @throws EE_Error
2727
+	 * @throws InvalidArgumentException
2728
+	 * @throws InvalidDataTypeException
2729
+	 * @throws InvalidInterfaceException
2730
+	 */
2731
+	public function display_admin_page_with_no_sidebar()
2732
+	{
2733
+		$this->_display_admin_page();
2734
+	}
2735
+
2736
+
2737
+	/**
2738
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2739
+	 *
2740
+	 * @return void
2741
+	 * @throws DomainException
2742
+	 * @throws EE_Error
2743
+	 * @throws InvalidArgumentException
2744
+	 * @throws InvalidDataTypeException
2745
+	 * @throws InvalidInterfaceException
2746
+	 */
2747
+	public function display_about_admin_page()
2748
+	{
2749
+		$this->_display_admin_page(false, true);
2750
+	}
2751
+
2752
+
2753
+	/**
2754
+	 * display_admin_page
2755
+	 * contains the code for actually displaying an admin page
2756
+	 *
2757
+	 * @param boolean $sidebar true with sidebar, false without
2758
+	 * @param boolean $about   use the about admin wrapper instead of the default.
2759
+	 * @return void
2760
+	 * @throws DomainException
2761
+	 * @throws EE_Error
2762
+	 * @throws InvalidArgumentException
2763
+	 * @throws InvalidDataTypeException
2764
+	 * @throws InvalidInterfaceException
2765
+	 */
2766
+	private function _display_admin_page($sidebar = false, $about = false)
2767
+	{
2768
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2769
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2770
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2771
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2772
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2773
+
2774
+		$post_body_content = $this->_template_args['before_admin_page_content'] ?? '';
2775
+
2776
+		$this->_template_args['add_page_frame'] = $this->_req_action !== 'system_status'
2777
+												 && $this->_req_action !== 'data_reset'
2778
+												 && $this->_wp_page_slug !== 'event-espresso_page_espresso_packages'
2779
+												 && strpos($post_body_content, 'wp-list-table') === false;
2780
+
2781
+		$this->_template_args['current_page']              = $this->_wp_page_slug;
2782
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2783
+			? 'poststuff'
2784
+			: 'espresso-default-admin';
2785
+		$this->_template_args['admin_page_wrapper_div_class'] = str_replace(
2786
+			'event-espresso_page_espresso_',
2787
+			'',
2788
+			$this->_wp_page_slug
2789
+		) . ' ' . $this->_req_action . '-route';
2790
+
2791
+		$template_path = $sidebar
2792
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2793
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2794
+		if ($this->request->isAjax()) {
2795
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2796
+		}
2797
+		$template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2798
+
2799
+		$this->_template_args['post_body_content']         = $this->_template_args['admin_page_content'] ?? '';
2800
+		$this->_template_args['before_admin_page_content'] = $post_body_content;
2801
+		$this->_template_args['after_admin_page_content']  = $this->_template_args['after_admin_page_content'] ?? '';
2802
+		$this->_template_args['admin_page_content']        = EEH_Template::display_template(
2803
+			$template_path,
2804
+			$this->_template_args,
2805
+			true
2806
+		);
2807
+		// the final template wrapper
2808
+		$this->admin_page_wrapper($about);
2809
+	}
2810
+
2811
+
2812
+	/**
2813
+	 * This is used to display caf preview pages.
2814
+	 *
2815
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2816
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2817
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2818
+	 * @return void
2819
+	 * @throws DomainException
2820
+	 * @throws EE_Error
2821
+	 * @throws InvalidArgumentException
2822
+	 * @throws InvalidDataTypeException
2823
+	 * @throws InvalidInterfaceException
2824
+	 * @since 4.3.2
2825
+	 */
2826
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2827
+	{
2828
+		// let's generate a default preview action button if there isn't one already present.
2829
+		$this->_labels['buttons']['buy_now']           = esc_html__(
2830
+			'Upgrade to Event Espresso 4 Right Now',
2831
+			'event_espresso'
2832
+		);
2833
+		$buy_now_url                                   = add_query_arg(
2834
+			[
2835
+				'ee_ver'       => 'ee4',
2836
+				'utm_source'   => 'ee4_plugin_admin',
2837
+				'utm_medium'   => 'link',
2838
+				'utm_campaign' => $utm_campaign_source,
2839
+				'utm_content'  => 'buy_now_button',
2840
+			],
2841
+			'https://eventespresso.com/pricing/'
2842
+		);
2843
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2844
+			? $this->get_action_link_or_button(
2845
+				'',
2846
+				'buy_now',
2847
+				[],
2848
+				'button button--primary button--big',
2849
+				esc_url_raw($buy_now_url),
2850
+				true
2851
+			)
2852
+			: $this->_template_args['preview_action_button'];
2853
+		$this->_template_args['admin_page_content']    = EEH_Template::display_template(
2854
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2855
+			$this->_template_args,
2856
+			true
2857
+		);
2858
+		$this->_display_admin_page($display_sidebar);
2859
+	}
2860
+
2861
+
2862
+	/**
2863
+	 * display_admin_list_table_page_with_sidebar
2864
+	 * generates HTML wrapper for an admin_page with list_table
2865
+	 *
2866
+	 * @return void
2867
+	 * @throws DomainException
2868
+	 * @throws EE_Error
2869
+	 * @throws InvalidArgumentException
2870
+	 * @throws InvalidDataTypeException
2871
+	 * @throws InvalidInterfaceException
2872
+	 */
2873
+	public function display_admin_list_table_page_with_sidebar()
2874
+	{
2875
+		$this->_display_admin_list_table_page(true);
2876
+	}
2877
+
2878
+
2879
+	/**
2880
+	 * display_admin_list_table_page_with_no_sidebar
2881
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2882
+	 *
2883
+	 * @return void
2884
+	 * @throws DomainException
2885
+	 * @throws EE_Error
2886
+	 * @throws InvalidArgumentException
2887
+	 * @throws InvalidDataTypeException
2888
+	 * @throws InvalidInterfaceException
2889
+	 */
2890
+	public function display_admin_list_table_page_with_no_sidebar()
2891
+	{
2892
+		$this->_display_admin_list_table_page();
2893
+	}
2894
+
2895
+
2896
+	/**
2897
+	 * generates html wrapper for an admin_list_table page
2898
+	 *
2899
+	 * @param boolean $sidebar whether to display with sidebar or not.
2900
+	 * @return void
2901
+	 * @throws DomainException
2902
+	 * @throws EE_Error
2903
+	 * @throws InvalidArgumentException
2904
+	 * @throws InvalidDataTypeException
2905
+	 * @throws InvalidInterfaceException
2906
+	 */
2907
+	private function _display_admin_list_table_page($sidebar = false)
2908
+	{
2909
+		// setup search attributes
2910
+		$this->_set_search_attributes();
2911
+		$this->_template_args['current_page']     = $this->_wp_page_slug;
2912
+		$template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2913
+		$this->_template_args['table_url']        = $this->request->isAjax()
2914
+			? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2915
+			: add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
2916
+		$this->_template_args['list_table']       = $this->_list_table_object;
2917
+		$this->_template_args['current_route']    = $this->_req_action;
2918
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2919
+		$ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2920
+		if (! empty($ajax_sorting_callback)) {
2921
+			$sortable_list_table_form_fields = wp_nonce_field(
2922
+				$ajax_sorting_callback . '_nonce',
2923
+				$ajax_sorting_callback . '_nonce',
2924
+				false,
2925
+				false
2926
+			);
2927
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2928
+												. $this->page_slug
2929
+												. '" />';
2930
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2931
+												. $ajax_sorting_callback
2932
+												. '" />';
2933
+		} else {
2934
+			$sortable_list_table_form_fields = '';
2935
+		}
2936
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
2937
+
2938
+		$hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? '';
2939
+
2940
+		$nonce_ref          = $this->_req_action . '_nonce';
2941
+		$hidden_form_fields .= '
2942 2942
             <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2943 2943
 
2944
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2945
-        // display message about search results?
2946
-        $search = $this->request->getRequestParam('s');
2947
-        $this->_template_args['before_list_table'] .= ! empty($search)
2948
-            ? '<p class="ee-search-results">' . sprintf(
2949
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2950
-                trim($search, '%')
2951
-            ) . '</p>'
2952
-            : '';
2953
-        // filter before_list_table template arg
2954
-        $this->_template_args['before_list_table'] = apply_filters(
2955
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2956
-            $this->_template_args['before_list_table'],
2957
-            $this->page_slug,
2958
-            $this->request->requestParams(),
2959
-            $this->_req_action
2960
-        );
2961
-        // convert to array and filter again
2962
-        // arrays are easier to inject new items in a specific location,
2963
-        // but would not be backwards compatible, so we have to add a new filter
2964
-        $this->_template_args['before_list_table'] = implode(
2965
-            " \n",
2966
-            (array) apply_filters(
2967
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2968
-                (array) $this->_template_args['before_list_table'],
2969
-                $this->page_slug,
2970
-                $this->request->requestParams(),
2971
-                $this->_req_action
2972
-            )
2973
-        );
2974
-        // filter after_list_table template arg
2975
-        $this->_template_args['after_list_table'] = apply_filters(
2976
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2977
-            $this->_template_args['after_list_table'],
2978
-            $this->page_slug,
2979
-            $this->request->requestParams(),
2980
-            $this->_req_action
2981
-        );
2982
-        // convert to array and filter again
2983
-        // arrays are easier to inject new items in a specific location,
2984
-        // but would not be backwards compatible, so we have to add a new filter
2985
-        $this->_template_args['after_list_table']   = implode(
2986
-            " \n",
2987
-            (array) apply_filters(
2988
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2989
-                (array) $this->_template_args['after_list_table'],
2990
-                $this->page_slug,
2991
-                $this->request->requestParams(),
2992
-                $this->_req_action
2993
-            )
2994
-        );
2995
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2996
-            $template_path,
2997
-            $this->_template_args,
2998
-            true
2999
-        );
3000
-        // the final template wrapper
3001
-        if ($sidebar) {
3002
-            $this->display_admin_page_with_sidebar();
3003
-        } else {
3004
-            $this->display_admin_page_with_no_sidebar();
3005
-        }
3006
-    }
3007
-
3008
-
3009
-    /**
3010
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3011
-     * html string for the legend.
3012
-     * $items are expected in an array in the following format:
3013
-     * $legend_items = array(
3014
-     *        'item_id' => array(
3015
-     *            'icon' => 'http://url_to_icon_being_described.png',
3016
-     *            'desc' => esc_html__('localized description of item');
3017
-     *        )
3018
-     * );
3019
-     *
3020
-     * @param array $items see above for format of array
3021
-     * @return string html string of legend
3022
-     * @throws DomainException
3023
-     */
3024
-    protected function _display_legend($items)
3025
-    {
3026
-        $this->_template_args['items'] = apply_filters(
3027
-            'FHEE__EE_Admin_Page___display_legend__items',
3028
-            (array) $items,
3029
-            $this
3030
-        );
3031
-        /** @var StatusChangeNotice $status_change_notice */
3032
-        $status_change_notice = $this->loader->getShared(
3033
-            'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
3034
-        );
3035
-        $this->_template_args['status_change_notice'] = $status_change_notice->display(
3036
-            '__admin-legend',
3037
-            $this->page_slug
3038
-        );
3039
-        return EEH_Template::display_template(
3040
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3041
-            $this->_template_args,
3042
-            true
3043
-        );
3044
-    }
3045
-
3046
-
3047
-    /**
3048
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3049
-     * The returned json object is created from an array in the following format:
3050
-     * array(
3051
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3052
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3053
-     *  'notices' => '', // - contains any EE_Error formatted notices
3054
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3055
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3056
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3057
-     *  that might be included in here)
3058
-     * )
3059
-     * The json object is populated by whatever is set in the $_template_args property.
3060
-     *
3061
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3062
-     *                                 instead of displayed.
3063
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3064
-     * @return void
3065
-     * @throws EE_Error
3066
-     * @throws InvalidArgumentException
3067
-     * @throws InvalidDataTypeException
3068
-     * @throws InvalidInterfaceException
3069
-     */
3070
-    protected function _return_json($sticky_notices = false, $notices_arguments = [])
3071
-    {
3072
-        // make sure any EE_Error notices have been handled.
3073
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3074
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3075
-        unset($this->_template_args['data']);
3076
-        $json = [
3077
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3078
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3079
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3080
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3081
-            'notices'   => EE_Error::get_notices(),
3082
-            'content'   => isset($this->_template_args['admin_page_content'])
3083
-                ? $this->_template_args['admin_page_content'] : '',
3084
-            'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3085
-            'isEEajax'  => true
3086
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3087
-        ];
3088
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3089
-        if (null === error_get_last() || ! headers_sent()) {
3090
-            header('Content-Type: application/json; charset=UTF-8');
3091
-        }
3092
-        echo wp_json_encode($json);
3093
-        exit();
3094
-    }
3095
-
3096
-
3097
-    /**
3098
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3099
-     *
3100
-     * @return void
3101
-     * @throws EE_Error
3102
-     * @throws InvalidArgumentException
3103
-     * @throws InvalidDataTypeException
3104
-     * @throws InvalidInterfaceException
3105
-     */
3106
-    public function return_json()
3107
-    {
3108
-        if ($this->request->isAjax()) {
3109
-            $this->_return_json();
3110
-        } else {
3111
-            throw new EE_Error(
3112
-                sprintf(
3113
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3114
-                    __FUNCTION__
3115
-                )
3116
-            );
3117
-        }
3118
-    }
3119
-
3120
-
3121
-    /**
3122
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3123
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3124
-     *
3125
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3126
-     */
3127
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3128
-    {
3129
-        $this->_hook_obj = $hook_obj;
3130
-    }
3131
-
3132
-
3133
-    /**
3134
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3135
-     *
3136
-     * @param boolean $about whether to use the special about page wrapper or default.
3137
-     * @return void
3138
-     * @throws DomainException
3139
-     * @throws EE_Error
3140
-     * @throws InvalidArgumentException
3141
-     * @throws InvalidDataTypeException
3142
-     * @throws InvalidInterfaceException
3143
-     */
3144
-    public function admin_page_wrapper($about = false)
3145
-    {
3146
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3147
-        $this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3148
-        $this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3149
-        $this->_template_args['admin_page_title']          = $this->_admin_page_title;
3150
-
3151
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3152
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3153
-            $this->_template_args['before_admin_page_content'] ?? ''
3154
-        );
3155
-
3156
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3157
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3158
-            $this->_template_args['after_admin_page_content'] ?? ''
3159
-        );
3160
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3161
-
3162
-        if ($this->request->isAjax()) {
3163
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3164
-                // $template_path,
3165
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3166
-                $this->_template_args,
3167
-                true
3168
-            );
3169
-            $this->_return_json();
3170
-        }
3171
-        // load settings page wrapper template
3172
-        $template_path = $about
3173
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3174
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3175
-
3176
-        EEH_Template::display_template($template_path, $this->_template_args);
3177
-    }
3178
-
3179
-
3180
-    /**
3181
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3182
-     *
3183
-     * @return string html
3184
-     * @throws EE_Error
3185
-     */
3186
-    protected function _get_main_nav_tabs()
3187
-    {
3188
-        // let's generate the html using the EEH_Tabbed_Content helper.
3189
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3190
-        // (rather than setting in the page_routes array)
3191
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3192
-    }
3193
-
3194
-
3195
-    /**
3196
-     *        sort nav tabs
3197
-     *
3198
-     * @param $a
3199
-     * @param $b
3200
-     * @return int
3201
-     */
3202
-    private function _sort_nav_tabs($a, $b)
3203
-    {
3204
-        if ($a['order'] === $b['order']) {
3205
-            return 0;
3206
-        }
3207
-        return ($a['order'] < $b['order']) ? -1 : 1;
3208
-    }
3209
-
3210
-
3211
-    /**
3212
-     * generates HTML for the forms used on admin pages
3213
-     *
3214
-     * @param array  $input_vars - array of input field details
3215
-     * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3216
-     * @param bool   $id
3217
-     * @return array|string
3218
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3219
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3220
-     */
3221
-    protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3222
-    {
3223
-        return $generator === 'string'
3224
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3225
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3226
-    }
3227
-
3228
-
3229
-    /**
3230
-     * generates the "Save" and "Save & Close" buttons for edit forms
3231
-     *
3232
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3233
-     *                                   Close" button.
3234
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3235
-     *                                   'Save', [1] => 'save & close')
3236
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3237
-     *                                   via the "name" value in the button).  We can also use this to just dump
3238
-     *                                   default actions by submitting some other value.
3239
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3240
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3241
-     *                                   close (normal form handling).
3242
-     */
3243
-    protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3244
-    {
3245
-        // make sure $text and $actions are in an array
3246
-        $text          = (array) $text;
3247
-        $actions       = (array) $actions;
3248
-        $referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3249
-        $button_text   = ! empty($text)
3250
-            ? $text
3251
-            : [
3252
-                esc_html__('Save', 'event_espresso'),
3253
-                esc_html__('Save and Close', 'event_espresso'),
3254
-            ];
3255
-        $default_names = ['save', 'save_and_close'];
3256
-        $buttons = '';
3257
-        foreach ($button_text as $key => $button) {
3258
-            $ref     = $default_names[ $key ];
3259
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3260
-            $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" '
3261
-                        . 'value="' . $button . '" name="' . $name . '" '
3262
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3263
-            if (! $both) {
3264
-                break;
3265
-            }
3266
-        }
3267
-        // add in a hidden index for the current page (so save and close redirects properly)
3268
-        $buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3269
-                   . $referrer_url
3270
-                   . '" />';
3271
-        $this->_template_args['save_buttons'] = $buttons;
3272
-    }
3273
-
3274
-
3275
-    /**
3276
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3277
-     *
3278
-     * @param string $route
3279
-     * @param array  $additional_hidden_fields
3280
-     * @see   $this->_set_add_edit_form_tags() for details on params
3281
-     * @since 4.6.0
3282
-     */
3283
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3284
-    {
3285
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3286
-    }
3287
-
3288
-
3289
-    /**
3290
-     * set form open and close tags on add/edit pages.
3291
-     *
3292
-     * @param string $route                    the route you want the form to direct to
3293
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3294
-     * @return void
3295
-     */
3296
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3297
-    {
3298
-        if (empty($route)) {
3299
-            $user_msg = esc_html__(
3300
-                'An error occurred. No action was set for this page\'s form.',
3301
-                'event_espresso'
3302
-            );
3303
-            $dev_msg  = $user_msg . "\n"
3304
-                        . sprintf(
3305
-                            esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3306
-                            __FUNCTION__,
3307
-                            __CLASS__
3308
-                        );
3309
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3310
-        }
3311
-        // open form
3312
-        $action = $this->_admin_base_url;
3313
-        $this->_template_args['before_admin_page_content'] = "
2944
+		$this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2945
+		// display message about search results?
2946
+		$search = $this->request->getRequestParam('s');
2947
+		$this->_template_args['before_list_table'] .= ! empty($search)
2948
+			? '<p class="ee-search-results">' . sprintf(
2949
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2950
+				trim($search, '%')
2951
+			) . '</p>'
2952
+			: '';
2953
+		// filter before_list_table template arg
2954
+		$this->_template_args['before_list_table'] = apply_filters(
2955
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
2956
+			$this->_template_args['before_list_table'],
2957
+			$this->page_slug,
2958
+			$this->request->requestParams(),
2959
+			$this->_req_action
2960
+		);
2961
+		// convert to array and filter again
2962
+		// arrays are easier to inject new items in a specific location,
2963
+		// but would not be backwards compatible, so we have to add a new filter
2964
+		$this->_template_args['before_list_table'] = implode(
2965
+			" \n",
2966
+			(array) apply_filters(
2967
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
2968
+				(array) $this->_template_args['before_list_table'],
2969
+				$this->page_slug,
2970
+				$this->request->requestParams(),
2971
+				$this->_req_action
2972
+			)
2973
+		);
2974
+		// filter after_list_table template arg
2975
+		$this->_template_args['after_list_table'] = apply_filters(
2976
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
2977
+			$this->_template_args['after_list_table'],
2978
+			$this->page_slug,
2979
+			$this->request->requestParams(),
2980
+			$this->_req_action
2981
+		);
2982
+		// convert to array and filter again
2983
+		// arrays are easier to inject new items in a specific location,
2984
+		// but would not be backwards compatible, so we have to add a new filter
2985
+		$this->_template_args['after_list_table']   = implode(
2986
+			" \n",
2987
+			(array) apply_filters(
2988
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
2989
+				(array) $this->_template_args['after_list_table'],
2990
+				$this->page_slug,
2991
+				$this->request->requestParams(),
2992
+				$this->_req_action
2993
+			)
2994
+		);
2995
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2996
+			$template_path,
2997
+			$this->_template_args,
2998
+			true
2999
+		);
3000
+		// the final template wrapper
3001
+		if ($sidebar) {
3002
+			$this->display_admin_page_with_sidebar();
3003
+		} else {
3004
+			$this->display_admin_page_with_no_sidebar();
3005
+		}
3006
+	}
3007
+
3008
+
3009
+	/**
3010
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3011
+	 * html string for the legend.
3012
+	 * $items are expected in an array in the following format:
3013
+	 * $legend_items = array(
3014
+	 *        'item_id' => array(
3015
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3016
+	 *            'desc' => esc_html__('localized description of item');
3017
+	 *        )
3018
+	 * );
3019
+	 *
3020
+	 * @param array $items see above for format of array
3021
+	 * @return string html string of legend
3022
+	 * @throws DomainException
3023
+	 */
3024
+	protected function _display_legend($items)
3025
+	{
3026
+		$this->_template_args['items'] = apply_filters(
3027
+			'FHEE__EE_Admin_Page___display_legend__items',
3028
+			(array) $items,
3029
+			$this
3030
+		);
3031
+		/** @var StatusChangeNotice $status_change_notice */
3032
+		$status_change_notice = $this->loader->getShared(
3033
+			'EventEspresso\core\domain\services\admin\notices\status_change\StatusChangeNotice'
3034
+		);
3035
+		$this->_template_args['status_change_notice'] = $status_change_notice->display(
3036
+			'__admin-legend',
3037
+			$this->page_slug
3038
+		);
3039
+		return EEH_Template::display_template(
3040
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3041
+			$this->_template_args,
3042
+			true
3043
+		);
3044
+	}
3045
+
3046
+
3047
+	/**
3048
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3049
+	 * The returned json object is created from an array in the following format:
3050
+	 * array(
3051
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3052
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3053
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3054
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3055
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3056
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3057
+	 *  that might be included in here)
3058
+	 * )
3059
+	 * The json object is populated by whatever is set in the $_template_args property.
3060
+	 *
3061
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3062
+	 *                                 instead of displayed.
3063
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3064
+	 * @return void
3065
+	 * @throws EE_Error
3066
+	 * @throws InvalidArgumentException
3067
+	 * @throws InvalidDataTypeException
3068
+	 * @throws InvalidInterfaceException
3069
+	 */
3070
+	protected function _return_json($sticky_notices = false, $notices_arguments = [])
3071
+	{
3072
+		// make sure any EE_Error notices have been handled.
3073
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3074
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : [];
3075
+		unset($this->_template_args['data']);
3076
+		$json = [
3077
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3078
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3079
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3080
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3081
+			'notices'   => EE_Error::get_notices(),
3082
+			'content'   => isset($this->_template_args['admin_page_content'])
3083
+				? $this->_template_args['admin_page_content'] : '',
3084
+			'data'      => array_merge($data, ['template_args' => $this->_template_args]),
3085
+			'isEEajax'  => true
3086
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3087
+		];
3088
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3089
+		if (null === error_get_last() || ! headers_sent()) {
3090
+			header('Content-Type: application/json; charset=UTF-8');
3091
+		}
3092
+		echo wp_json_encode($json);
3093
+		exit();
3094
+	}
3095
+
3096
+
3097
+	/**
3098
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3099
+	 *
3100
+	 * @return void
3101
+	 * @throws EE_Error
3102
+	 * @throws InvalidArgumentException
3103
+	 * @throws InvalidDataTypeException
3104
+	 * @throws InvalidInterfaceException
3105
+	 */
3106
+	public function return_json()
3107
+	{
3108
+		if ($this->request->isAjax()) {
3109
+			$this->_return_json();
3110
+		} else {
3111
+			throw new EE_Error(
3112
+				sprintf(
3113
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3114
+					__FUNCTION__
3115
+				)
3116
+			);
3117
+		}
3118
+	}
3119
+
3120
+
3121
+	/**
3122
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3123
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3124
+	 *
3125
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3126
+	 */
3127
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3128
+	{
3129
+		$this->_hook_obj = $hook_obj;
3130
+	}
3131
+
3132
+
3133
+	/**
3134
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3135
+	 *
3136
+	 * @param boolean $about whether to use the special about page wrapper or default.
3137
+	 * @return void
3138
+	 * @throws DomainException
3139
+	 * @throws EE_Error
3140
+	 * @throws InvalidArgumentException
3141
+	 * @throws InvalidDataTypeException
3142
+	 * @throws InvalidInterfaceException
3143
+	 */
3144
+	public function admin_page_wrapper($about = false)
3145
+	{
3146
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3147
+		$this->_nav_tabs                                   = $this->_get_main_nav_tabs();
3148
+		$this->_template_args['nav_tabs']                  = $this->_nav_tabs;
3149
+		$this->_template_args['admin_page_title']          = $this->_admin_page_title;
3150
+
3151
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3152
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3153
+			$this->_template_args['before_admin_page_content'] ?? ''
3154
+		);
3155
+
3156
+		$this->_template_args['after_admin_page_content']  = apply_filters(
3157
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3158
+			$this->_template_args['after_admin_page_content'] ?? ''
3159
+		);
3160
+		$this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3161
+
3162
+		if ($this->request->isAjax()) {
3163
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3164
+				// $template_path,
3165
+				EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3166
+				$this->_template_args,
3167
+				true
3168
+			);
3169
+			$this->_return_json();
3170
+		}
3171
+		// load settings page wrapper template
3172
+		$template_path = $about
3173
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3174
+			: EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3175
+
3176
+		EEH_Template::display_template($template_path, $this->_template_args);
3177
+	}
3178
+
3179
+
3180
+	/**
3181
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3182
+	 *
3183
+	 * @return string html
3184
+	 * @throws EE_Error
3185
+	 */
3186
+	protected function _get_main_nav_tabs()
3187
+	{
3188
+		// let's generate the html using the EEH_Tabbed_Content helper.
3189
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3190
+		// (rather than setting in the page_routes array)
3191
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3192
+	}
3193
+
3194
+
3195
+	/**
3196
+	 *        sort nav tabs
3197
+	 *
3198
+	 * @param $a
3199
+	 * @param $b
3200
+	 * @return int
3201
+	 */
3202
+	private function _sort_nav_tabs($a, $b)
3203
+	{
3204
+		if ($a['order'] === $b['order']) {
3205
+			return 0;
3206
+		}
3207
+		return ($a['order'] < $b['order']) ? -1 : 1;
3208
+	}
3209
+
3210
+
3211
+	/**
3212
+	 * generates HTML for the forms used on admin pages
3213
+	 *
3214
+	 * @param array  $input_vars - array of input field details
3215
+	 * @param string $generator  indicates which generator to use: options are 'string' or 'array'
3216
+	 * @param bool   $id
3217
+	 * @return array|string
3218
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3219
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3220
+	 */
3221
+	protected function _generate_admin_form_fields($input_vars = [], $generator = 'string', $id = false)
3222
+	{
3223
+		return $generator === 'string'
3224
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3225
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3226
+	}
3227
+
3228
+
3229
+	/**
3230
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3231
+	 *
3232
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3233
+	 *                                   Close" button.
3234
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3235
+	 *                                   'Save', [1] => 'save & close')
3236
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3237
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3238
+	 *                                   default actions by submitting some other value.
3239
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3240
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3241
+	 *                                   close (normal form handling).
3242
+	 */
3243
+	protected function _set_save_buttons($both = true, $text = [], $actions = [], $referrer = null)
3244
+	{
3245
+		// make sure $text and $actions are in an array
3246
+		$text          = (array) $text;
3247
+		$actions       = (array) $actions;
3248
+		$referrer_url  = ! empty($referrer) ? $referrer : $this->request->getServerParam('REQUEST_URI');
3249
+		$button_text   = ! empty($text)
3250
+			? $text
3251
+			: [
3252
+				esc_html__('Save', 'event_espresso'),
3253
+				esc_html__('Save and Close', 'event_espresso'),
3254
+			];
3255
+		$default_names = ['save', 'save_and_close'];
3256
+		$buttons = '';
3257
+		foreach ($button_text as $key => $button) {
3258
+			$ref     = $default_names[ $key ];
3259
+			$name    = ! empty($actions) ? $actions[ $key ] : $ref;
3260
+			$buttons .= '<input type="submit" class="button button--primary ' . $ref . '" '
3261
+						. 'value="' . $button . '" name="' . $name . '" '
3262
+						. 'id="' . $this->_current_view . '_' . $ref . '" />';
3263
+			if (! $both) {
3264
+				break;
3265
+			}
3266
+		}
3267
+		// add in a hidden index for the current page (so save and close redirects properly)
3268
+		$buttons .= '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3269
+				   . $referrer_url
3270
+				   . '" />';
3271
+		$this->_template_args['save_buttons'] = $buttons;
3272
+	}
3273
+
3274
+
3275
+	/**
3276
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3277
+	 *
3278
+	 * @param string $route
3279
+	 * @param array  $additional_hidden_fields
3280
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3281
+	 * @since 4.6.0
3282
+	 */
3283
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3284
+	{
3285
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3286
+	}
3287
+
3288
+
3289
+	/**
3290
+	 * set form open and close tags on add/edit pages.
3291
+	 *
3292
+	 * @param string $route                    the route you want the form to direct to
3293
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3294
+	 * @return void
3295
+	 */
3296
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = [])
3297
+	{
3298
+		if (empty($route)) {
3299
+			$user_msg = esc_html__(
3300
+				'An error occurred. No action was set for this page\'s form.',
3301
+				'event_espresso'
3302
+			);
3303
+			$dev_msg  = $user_msg . "\n"
3304
+						. sprintf(
3305
+							esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3306
+							__FUNCTION__,
3307
+							__CLASS__
3308
+						);
3309
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3310
+		}
3311
+		// open form
3312
+		$action = $this->_admin_base_url;
3313
+		$this->_template_args['before_admin_page_content'] = "
3314 3314
             <form name='form' method='post' action='{$action}' id='{$route}_event_form' class='ee-admin-page-form' >
3315 3315
             ";
3316
-        // add nonce
3317
-        $nonce                                             =
3318
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3319
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3320
-        // add REQUIRED form action
3321
-        $hidden_fields = [
3322
-            'action' => ['type' => 'hidden', 'value' => $route],
3323
-        ];
3324
-        // merge arrays
3325
-        $hidden_fields = is_array($additional_hidden_fields)
3326
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3327
-            : $hidden_fields;
3328
-        // generate form fields
3329
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3330
-        // add fields to form
3331
-        foreach ((array) $form_fields as $form_field) {
3332
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3333
-        }
3334
-        // close form
3335
-        $this->_template_args['after_admin_page_content'] = '</form>';
3336
-    }
3337
-
3338
-
3339
-    /**
3340
-     * Public Wrapper for _redirect_after_action() method since its
3341
-     * discovered it would be useful for external code to have access.
3342
-     *
3343
-     * @param bool   $success
3344
-     * @param string $what
3345
-     * @param string $action_desc
3346
-     * @param array  $query_args
3347
-     * @param bool   $override_overwrite
3348
-     * @throws EE_Error
3349
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3350
-     * @since 4.5.0
3351
-     */
3352
-    public function redirect_after_action(
3353
-        $success = false,
3354
-        $what = 'item',
3355
-        $action_desc = 'processed',
3356
-        $query_args = [],
3357
-        $override_overwrite = false
3358
-    ) {
3359
-        $this->_redirect_after_action(
3360
-            $success,
3361
-            $what,
3362
-            $action_desc,
3363
-            $query_args,
3364
-            $override_overwrite
3365
-        );
3366
-    }
3367
-
3368
-
3369
-    /**
3370
-     * Helper method for merging existing request data with the returned redirect url.
3371
-     *
3372
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3373
-     * filters are still applied.
3374
-     *
3375
-     * @param array $new_route_data
3376
-     * @return array
3377
-     */
3378
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3379
-    {
3380
-        foreach ($this->request->requestParams() as $ref => $value) {
3381
-            // unset nonces
3382
-            if (strpos($ref, 'nonce') !== false) {
3383
-                $this->request->unSetRequestParam($ref);
3384
-                continue;
3385
-            }
3386
-            // urlencode values.
3387
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3388
-            $this->request->setRequestParam($ref, $value);
3389
-        }
3390
-        return array_merge($this->request->requestParams(), $new_route_data);
3391
-    }
3392
-
3393
-
3394
-    /**
3395
-     * @param int|float|string $success      - whether success was for two or more records, or just one, or none
3396
-     * @param string           $what         - what the action was performed on
3397
-     * @param string           $action_desc  - what was done ie: updated, deleted, etc
3398
-     * @param array $query_args              - an array of query_args to be added to the URL to redirect to
3399
-     * @param BOOL $override_overwrite       - by default all EE_Error::success messages are overwritten,
3400
-     *                                         this allows you to override this so that they show.
3401
-     * @return void
3402
-     * @throws EE_Error
3403
-     * @throws InvalidArgumentException
3404
-     * @throws InvalidDataTypeException
3405
-     * @throws InvalidInterfaceException
3406
-     */
3407
-    protected function _redirect_after_action(
3408
-        $success = 0,
3409
-        string $what = 'item',
3410
-        string $action_desc = 'processed',
3411
-        array $query_args = [],
3412
-        bool $override_overwrite = false
3413
-    ) {
3414
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3415
-        $notices      = EE_Error::get_notices(false);
3416
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3417
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3418
-            EE_Error::overwrite_success();
3419
-        }
3420
-        if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3421
-            // how many records affected ? more than one record ? or just one ?
3422
-            EE_Error::add_success(
3423
-                sprintf(
3424
-                    esc_html(
3425
-                        _n(
3426
-                            'The "%1$s" has been successfully %2$s.',
3427
-                            'The "%1$s" have been successfully %2$s.',
3428
-                            $success,
3429
-                            'event_espresso'
3430
-                        )
3431
-                    ),
3432
-                    $what,
3433
-                    $action_desc
3434
-                ),
3435
-                __FILE__,
3436
-                __FUNCTION__,
3437
-                __LINE__
3438
-            );
3439
-        }
3440
-        // check that $query_args isn't something crazy
3441
-        if (! is_array($query_args)) {
3442
-            $query_args = [];
3443
-        }
3444
-        /**
3445
-         * Allow injecting actions before the query_args are modified for possible different
3446
-         * redirections on save and close actions
3447
-         *
3448
-         * @param array $query_args       The original query_args array coming into the
3449
-         *                                method.
3450
-         * @since 4.2.0
3451
-         */
3452
-        do_action(
3453
-            "AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3454
-            $query_args
3455
-        );
3456
-        // set redirect url.
3457
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3458
-        // otherwise we go with whatever is set as the _admin_base_url
3459
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3460
-        // calculate where we're going (if we have a "save and close" button pushed)
3461
-        if (
3462
-            $this->request->requestParamIsSet('save_and_close')
3463
-            && $this->request->requestParamIsSet('save_and_close_referrer')
3464
-        ) {
3465
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3466
-            $parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3467
-            // regenerate query args array from referrer URL
3468
-            parse_str($parsed_url['query'], $query_args);
3469
-            // correct page and action will be in the query args now
3470
-            $redirect_url = admin_url('admin.php');
3471
-        }
3472
-        // merge any default query_args set in _default_route_query_args property
3473
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3474
-            $args_to_merge = [];
3475
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3476
-                // is there a wp_referer array in our _default_route_query_args property?
3477
-                if ($query_param === 'wp_referer') {
3478
-                    $query_value = (array) $query_value;
3479
-                    foreach ($query_value as $reference => $value) {
3480
-                        if (strpos($reference, 'nonce') !== false) {
3481
-                            continue;
3482
-                        }
3483
-                        // finally we will override any arguments in the referer with
3484
-                        // what might be set on the _default_route_query_args array.
3485
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3486
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3487
-                        } else {
3488
-                            $args_to_merge[ $reference ] = urlencode($value);
3489
-                        }
3490
-                    }
3491
-                    continue;
3492
-                }
3493
-                $args_to_merge[ $query_param ] = $query_value;
3494
-            }
3495
-            // now let's merge these arguments but override with what was specifically sent in to the
3496
-            // redirect.
3497
-            $query_args = array_merge($args_to_merge, $query_args);
3498
-        }
3499
-        $this->_process_notices($query_args);
3500
-        // generate redirect url
3501
-        // if redirecting to anything other than the main page, add a nonce
3502
-        if (isset($query_args['action'])) {
3503
-            // manually generate wp_nonce and merge that with the query vars
3504
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3505
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3506
-        }
3507
-        // we're adding some hooks and filters in here for processing any things just before redirects
3508
-        // (example: an admin page has done an insert or update and we want to run something after that).
3509
-        do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args);
3510
-        $redirect_url = apply_filters(
3511
-            'FHEE_redirect_' . $this->class_name . $this->_req_action,
3512
-            EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3513
-            $query_args
3514
-        );
3515
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3516
-        if ($this->request->isAjax()) {
3517
-            $default_data                    = [
3518
-                'close'        => true,
3519
-                'redirect_url' => $redirect_url,
3520
-                'where'        => 'main',
3521
-                'what'         => 'append',
3522
-            ];
3523
-            $this->_template_args['success'] = $success;
3524
-            $this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3525
-                $default_data,
3526
-                $this->_template_args['data']
3527
-            ) : $default_data;
3528
-            $this->_return_json();
3529
-        }
3530
-        wp_safe_redirect($redirect_url);
3531
-        exit();
3532
-    }
3533
-
3534
-
3535
-    /**
3536
-     * process any notices before redirecting (or returning ajax request)
3537
-     * This method sets the $this->_template_args['notices'] attribute;
3538
-     *
3539
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3540
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3541
-     *                                  page_routes haven't been defined yet.
3542
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3543
-     *                                  still save a transient for the notice.
3544
-     * @return void
3545
-     * @throws EE_Error
3546
-     * @throws InvalidArgumentException
3547
-     * @throws InvalidDataTypeException
3548
-     * @throws InvalidInterfaceException
3549
-     */
3550
-    protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3551
-    {
3552
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3553
-        if ($this->request->isAjax()) {
3554
-            $notices = EE_Error::get_notices(false);
3555
-            if (empty($this->_template_args['success'])) {
3556
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3557
-            }
3558
-            if (empty($this->_template_args['errors'])) {
3559
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3560
-            }
3561
-            if (empty($this->_template_args['attention'])) {
3562
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3563
-            }
3564
-        }
3565
-        $this->_template_args['notices'] = EE_Error::get_notices();
3566
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3567
-        if (! $this->request->isAjax() || $sticky_notices) {
3568
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3569
-            $this->_add_transient(
3570
-                $route,
3571
-                $this->_template_args['notices'],
3572
-                true,
3573
-                $skip_route_verify
3574
-            );
3575
-        }
3576
-    }
3577
-
3578
-
3579
-    /**
3580
-     * get_action_link_or_button
3581
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3582
-     *
3583
-     * @param string $action        use this to indicate which action the url is generated with.
3584
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3585
-     *                              property.
3586
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3587
-     * @param string $class         Use this to give the class for the button. Defaults to 'button--primary'
3588
-     * @param string $base_url      If this is not provided
3589
-     *                              the _admin_base_url will be used as the default for the button base_url.
3590
-     *                              Otherwise this value will be used.
3591
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3592
-     * @return string
3593
-     * @throws InvalidArgumentException
3594
-     * @throws InvalidInterfaceException
3595
-     * @throws InvalidDataTypeException
3596
-     * @throws EE_Error
3597
-     */
3598
-    public function get_action_link_or_button(
3599
-        $action,
3600
-        $type = 'add',
3601
-        $extra_request = [],
3602
-        $class = 'button--primary',
3603
-        $base_url = '',
3604
-        $exclude_nonce = false
3605
-    ) {
3606
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3607
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3608
-            throw new EE_Error(
3609
-                sprintf(
3610
-                    esc_html__(
3611
-                        'There is no page route for given action for the button.  This action was given: %s',
3612
-                        'event_espresso'
3613
-                    ),
3614
-                    $action
3615
-                )
3616
-            );
3617
-        }
3618
-        if (! isset($this->_labels['buttons'][ $type ])) {
3619
-            throw new EE_Error(
3620
-                sprintf(
3621
-                    esc_html__(
3622
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3623
-                        'event_espresso'
3624
-                    ),
3625
-                    $type
3626
-                )
3627
-            );
3628
-        }
3629
-        // finally check user access for this button.
3630
-        $has_access = $this->check_user_access($action, true);
3631
-        if (! $has_access) {
3632
-            return '';
3633
-        }
3634
-        $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3635
-        $query_args = [
3636
-            'action' => $action,
3637
-        ];
3638
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3639
-        if (! empty($extra_request)) {
3640
-            $query_args = array_merge($extra_request, $query_args);
3641
-        }
3642
-        $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3643
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3644
-    }
3645
-
3646
-
3647
-    /**
3648
-     * _per_page_screen_option
3649
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3650
-     *
3651
-     * @return void
3652
-     * @throws InvalidArgumentException
3653
-     * @throws InvalidInterfaceException
3654
-     * @throws InvalidDataTypeException
3655
-     */
3656
-    protected function _per_page_screen_option()
3657
-    {
3658
-        $option = 'per_page';
3659
-        $args   = [
3660
-            'label'   => apply_filters(
3661
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3662
-                $this->_admin_page_title,
3663
-                $this
3664
-            ),
3665
-            'default' => (int) apply_filters(
3666
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3667
-                20
3668
-            ),
3669
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3670
-        ];
3671
-        // ONLY add the screen option if the user has access to it.
3672
-        if ($this->check_user_access($this->_current_view, true)) {
3673
-            add_screen_option($option, $args);
3674
-        }
3675
-    }
3676
-
3677
-
3678
-    /**
3679
-     * set_per_page_screen_option
3680
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3681
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3682
-     * admin_menu.
3683
-     *
3684
-     * @return void
3685
-     */
3686
-    private function _set_per_page_screen_options()
3687
-    {
3688
-        if ($this->request->requestParamIsSet('wp_screen_options')) {
3689
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3690
-            if (! $user = wp_get_current_user()) {
3691
-                return;
3692
-            }
3693
-            $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3694
-            if (! $option) {
3695
-                return;
3696
-            }
3697
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3698
-            $map_option = $option;
3699
-            $option     = str_replace('-', '_', $option);
3700
-            switch ($map_option) {
3701
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3702
-                    $max_value = apply_filters(
3703
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3704
-                        999,
3705
-                        $this->_current_page,
3706
-                        $this->_current_view
3707
-                    );
3708
-                    if ($value < 1) {
3709
-                        return;
3710
-                    }
3711
-                    $value = min($value, $max_value);
3712
-                    break;
3713
-                default:
3714
-                    $value = apply_filters(
3715
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3716
-                        false,
3717
-                        $option,
3718
-                        $value
3719
-                    );
3720
-                    if (false === $value) {
3721
-                        return;
3722
-                    }
3723
-                    break;
3724
-            }
3725
-            update_user_meta($user->ID, $option, $value);
3726
-            wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3727
-            exit;
3728
-        }
3729
-    }
3730
-
3731
-
3732
-    /**
3733
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3734
-     *
3735
-     * @param array $data array that will be assigned to template args.
3736
-     */
3737
-    public function set_template_args($data)
3738
-    {
3739
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3740
-    }
3741
-
3742
-
3743
-    /**
3744
-     * This makes available the WP transient system for temporarily moving data between routes
3745
-     *
3746
-     * @param string $route             the route that should receive the transient
3747
-     * @param array  $data              the data that gets sent
3748
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3749
-     *                                  normal route transient.
3750
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3751
-     *                                  when we are adding a transient before page_routes have been defined.
3752
-     * @return void
3753
-     * @throws EE_Error
3754
-     */
3755
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3756
-    {
3757
-        $user_id = get_current_user_id();
3758
-        if (! $skip_route_verify) {
3759
-            $this->_verify_route($route);
3760
-        }
3761
-        // now let's set the string for what kind of transient we're setting
3762
-        $transient = $notices
3763
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3764
-            : 'rte_tx_' . $route . '_' . $user_id;
3765
-        $data      = $notices ? ['notices' => $data] : $data;
3766
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3767
-        $existing = is_multisite() && is_network_admin()
3768
-            ? get_site_transient($transient)
3769
-            : get_transient($transient);
3770
-        if ($existing) {
3771
-            $data = array_merge((array) $data, (array) $existing);
3772
-        }
3773
-        if (is_multisite() && is_network_admin()) {
3774
-            set_site_transient($transient, $data, 8);
3775
-        } else {
3776
-            set_transient($transient, $data, 8);
3777
-        }
3778
-    }
3779
-
3780
-
3781
-    /**
3782
-     * this retrieves the temporary transient that has been set for moving data between routes.
3783
-     *
3784
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3785
-     * @param string $route
3786
-     * @return mixed data
3787
-     */
3788
-    protected function _get_transient($notices = false, $route = '')
3789
-    {
3790
-        $user_id   = get_current_user_id();
3791
-        $route     = ! $route ? $this->_req_action : $route;
3792
-        $transient = $notices
3793
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3794
-            : 'rte_tx_' . $route . '_' . $user_id;
3795
-        $data      = is_multisite() && is_network_admin()
3796
-            ? get_site_transient($transient)
3797
-            : get_transient($transient);
3798
-        // delete transient after retrieval (just in case it hasn't expired);
3799
-        if (is_multisite() && is_network_admin()) {
3800
-            delete_site_transient($transient);
3801
-        } else {
3802
-            delete_transient($transient);
3803
-        }
3804
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3805
-    }
3806
-
3807
-
3808
-    /**
3809
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3810
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3811
-     * default route callback on the EE_Admin page you want it run.)
3812
-     *
3813
-     * @return void
3814
-     */
3815
-    protected function _transient_garbage_collection()
3816
-    {
3817
-        global $wpdb;
3818
-        // retrieve all existing transients
3819
-        $query =
3820
-            "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3821
-        if ($results = $wpdb->get_results($query)) {
3822
-            foreach ($results as $result) {
3823
-                $transient = str_replace('_transient_', '', $result->option_name);
3824
-                get_transient($transient);
3825
-                if (is_multisite() && is_network_admin()) {
3826
-                    get_site_transient($transient);
3827
-                }
3828
-            }
3829
-        }
3830
-    }
3831
-
3832
-
3833
-    /**
3834
-     * get_view
3835
-     *
3836
-     * @return string content of _view property
3837
-     */
3838
-    public function get_view()
3839
-    {
3840
-        return $this->_view;
3841
-    }
3842
-
3843
-
3844
-    /**
3845
-     * getter for the protected $_views property
3846
-     *
3847
-     * @return array
3848
-     */
3849
-    public function get_views()
3850
-    {
3851
-        return $this->_views;
3852
-    }
3853
-
3854
-
3855
-    /**
3856
-     * get_current_page
3857
-     *
3858
-     * @return string _current_page property value
3859
-     */
3860
-    public function get_current_page()
3861
-    {
3862
-        return $this->_current_page;
3863
-    }
3864
-
3865
-
3866
-    /**
3867
-     * get_current_view
3868
-     *
3869
-     * @return string _current_view property value
3870
-     */
3871
-    public function get_current_view()
3872
-    {
3873
-        return $this->_current_view;
3874
-    }
3875
-
3876
-
3877
-    /**
3878
-     * get_current_screen
3879
-     *
3880
-     * @return object The current WP_Screen object
3881
-     */
3882
-    public function get_current_screen()
3883
-    {
3884
-        return $this->_current_screen;
3885
-    }
3886
-
3887
-
3888
-    /**
3889
-     * get_current_page_view_url
3890
-     *
3891
-     * @return string This returns the url for the current_page_view.
3892
-     */
3893
-    public function get_current_page_view_url()
3894
-    {
3895
-        return $this->_current_page_view_url;
3896
-    }
3897
-
3898
-
3899
-    /**
3900
-     * just returns the Request
3901
-     *
3902
-     * @return RequestInterface
3903
-     */
3904
-    public function get_request()
3905
-    {
3906
-        return $this->request;
3907
-    }
3908
-
3909
-
3910
-    /**
3911
-     * just returns the _req_data property
3912
-     *
3913
-     * @return array
3914
-     */
3915
-    public function get_request_data()
3916
-    {
3917
-        return $this->request->requestParams();
3918
-    }
3919
-
3920
-
3921
-    /**
3922
-     * returns the _req_data protected property
3923
-     *
3924
-     * @return string
3925
-     */
3926
-    public function get_req_action()
3927
-    {
3928
-        return $this->_req_action;
3929
-    }
3930
-
3931
-
3932
-    /**
3933
-     * @return bool  value of $_is_caf property
3934
-     */
3935
-    public function is_caf()
3936
-    {
3937
-        return $this->_is_caf;
3938
-    }
3939
-
3940
-
3941
-    /**
3942
-     * @return mixed
3943
-     */
3944
-    public function default_espresso_metaboxes()
3945
-    {
3946
-        return $this->_default_espresso_metaboxes;
3947
-    }
3948
-
3949
-
3950
-    /**
3951
-     * @return mixed
3952
-     */
3953
-    public function admin_base_url()
3954
-    {
3955
-        return $this->_admin_base_url;
3956
-    }
3957
-
3958
-
3959
-    /**
3960
-     * @return mixed
3961
-     */
3962
-    public function wp_page_slug()
3963
-    {
3964
-        return $this->_wp_page_slug;
3965
-    }
3966
-
3967
-
3968
-    /**
3969
-     * updates  espresso configuration settings
3970
-     *
3971
-     * @param string                   $tab
3972
-     * @param EE_Config_Base|EE_Config $config
3973
-     * @param string                   $file file where error occurred
3974
-     * @param string                   $func function  where error occurred
3975
-     * @param string                   $line line no where error occurred
3976
-     * @return boolean
3977
-     */
3978
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3979
-    {
3980
-        // remove any options that are NOT going to be saved with the config settings.
3981
-        if (isset($config->core->ee_ueip_optin)) {
3982
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
3983
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3984
-            update_option('ee_ueip_has_notified', true);
3985
-        }
3986
-        // and save it (note we're also doing the network save here)
3987
-        $net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3988
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
3989
-        if ($config_saved && $net_saved) {
3990
-            EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3991
-            return true;
3992
-        }
3993
-        EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3994
-        return false;
3995
-    }
3996
-
3997
-
3998
-    /**
3999
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4000
-     *
4001
-     * @return array
4002
-     */
4003
-    public function get_yes_no_values()
4004
-    {
4005
-        return $this->_yes_no_values;
4006
-    }
4007
-
4008
-
4009
-    /**
4010
-     * @return string
4011
-     * @throws ReflectionException
4012
-     * @since $VID:$
4013
-     */
4014
-    protected function _get_dir()
4015
-    {
4016
-        $reflector = new ReflectionClass($this->class_name);
4017
-        return dirname($reflector->getFileName());
4018
-    }
4019
-
4020
-
4021
-    /**
4022
-     * A helper for getting a "next link".
4023
-     *
4024
-     * @param string $url   The url to link to
4025
-     * @param string $class The class to use.
4026
-     * @return string
4027
-     */
4028
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4029
-    {
4030
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4031
-    }
4032
-
4033
-
4034
-    /**
4035
-     * A helper for getting a "previous link".
4036
-     *
4037
-     * @param string $url   The url to link to
4038
-     * @param string $class The class to use.
4039
-     * @return string
4040
-     */
4041
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4042
-    {
4043
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4044
-    }
4045
-
4046
-
4047
-
4048
-
4049
-
4050
-
4051
-
4052
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4053
-
4054
-
4055
-    /**
4056
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4057
-     * 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
4058
-     * _req_data array.
4059
-     *
4060
-     * @return bool success/fail
4061
-     * @throws EE_Error
4062
-     * @throws InvalidArgumentException
4063
-     * @throws ReflectionException
4064
-     * @throws InvalidDataTypeException
4065
-     * @throws InvalidInterfaceException
4066
-     */
4067
-    protected function _process_resend_registration()
4068
-    {
4069
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4070
-        do_action(
4071
-            'AHEE__EE_Admin_Page___process_resend_registration',
4072
-            $this->_template_args['success'],
4073
-            $this->request->requestParams()
4074
-        );
4075
-        return $this->_template_args['success'];
4076
-    }
4077
-
4078
-
4079
-    /**
4080
-     * This automatically processes any payment message notifications when manual payment has been applied.
4081
-     *
4082
-     * @param EE_Payment $payment
4083
-     * @return bool success/fail
4084
-     */
4085
-    protected function _process_payment_notification(EE_Payment $payment)
4086
-    {
4087
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4088
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4089
-        $this->_template_args['success'] = apply_filters(
4090
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4091
-            false,
4092
-            $payment
4093
-        );
4094
-        return $this->_template_args['success'];
4095
-    }
4096
-
4097
-
4098
-    /**
4099
-     * @param EEM_Base      $entity_model
4100
-     * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4101
-     * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4102
-     * @param string        $delete_column  name of the field that denotes whether entity is trashed
4103
-     * @param callable|null $callback       called after entity is trashed, restored, or deleted
4104
-     * @return int|float
4105
-     * @throws EE_Error
4106
-     */
4107
-    protected function trashRestoreDeleteEntities(
4108
-        EEM_Base $entity_model,
4109
-        string $entity_PK_name,
4110
-        string $action = EE_Admin_List_Table::ACTION_DELETE,
4111
-        string $delete_column = '',
4112
-        callable $callback = null
4113
-    ) {
4114
-        $entity_PK      = $entity_model->get_primary_key_field();
4115
-        $entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4116
-        $entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4117
-        // grab ID if deleting a single entity
4118
-        if ($this->request->requestParamIsSet($entity_PK_name)) {
4119
-            $ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4120
-            return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4121
-        }
4122
-        // or grab checkbox array if bulk deleting
4123
-        $checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4124
-        if (empty($checkboxes)) {
4125
-            return 0;
4126
-        }
4127
-        $success = 0;
4128
-        $IDs     = array_keys($checkboxes);
4129
-        // cycle thru bulk action checkboxes
4130
-        foreach ($IDs as $ID) {
4131
-            // increment $success
4132
-            if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4133
-                $success++;
4134
-            }
4135
-        }
4136
-        $count = (int) count($checkboxes);
4137
-        // if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4138
-        // otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4139
-        return $success === $count ? $count : $success / $count;
4140
-    }
4141
-
4142
-
4143
-    /**
4144
-     * @param EE_Primary_Key_Field_Base $entity_PK
4145
-     * @return string
4146
-     * @throws EE_Error
4147
-     * @since   $VID:$
4148
-     */
4149
-    private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string
4150
-    {
4151
-        $entity_PK_type = $entity_PK->getSchemaType();
4152
-        switch ($entity_PK_type) {
4153
-            case 'boolean':
4154
-                return 'bool';
4155
-            case 'integer':
4156
-                return 'int';
4157
-            case 'number':
4158
-                return 'float';
4159
-            case 'string':
4160
-                return 'string';
4161
-        }
4162
-        throw new RuntimeException(
4163
-            sprintf(
4164
-                esc_html__(
4165
-                    '"%1$s" is an invalid schema type for the %2$s primary key.',
4166
-                    'event_espresso'
4167
-                ),
4168
-                $entity_PK_type,
4169
-                $entity_PK->get_name()
4170
-            )
4171
-        );
4172
-    }
4173
-
4174
-
4175
-    /**
4176
-     * @param EEM_Base      $entity_model
4177
-     * @param int|string    $entity_ID
4178
-     * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4179
-     * @param string        $delete_column name of the field that denotes whether entity is trashed
4180
-     * @param callable|null $callback      called after entity is trashed, restored, or deleted
4181
-     * @return bool
4182
-     */
4183
-    protected function trashRestoreDeleteEntity(
4184
-        EEM_Base $entity_model,
4185
-        $entity_ID,
4186
-        string $action,
4187
-        string $delete_column,
4188
-        ?callable $callback = null
4189
-    ): bool {
4190
-        $entity_ID = absint($entity_ID);
4191
-        if (! $entity_ID) {
4192
-            $this->trashRestoreDeleteError($action, $entity_model);
4193
-        }
4194
-        $result = 0;
4195
-        try {
4196
-            switch ($action) {
4197
-                case EE_Admin_List_Table::ACTION_DELETE:
4198
-                    $result = (bool) $entity_model->delete_permanently_by_ID($entity_ID);
4199
-                    break;
4200
-                case EE_Admin_List_Table::ACTION_RESTORE:
4201
-                    $this->validateDeleteColumn($entity_model, $delete_column);
4202
-                    $result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID);
4203
-                    break;
4204
-                case EE_Admin_List_Table::ACTION_TRASH:
4205
-                    $this->validateDeleteColumn($entity_model, $delete_column);
4206
-                    $result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID);
4207
-                    break;
4208
-            }
4209
-        } catch (Exception $exception) {
4210
-            $this->trashRestoreDeleteError($action, $entity_model, $exception);
4211
-        }
4212
-        if (is_callable($callback)) {
4213
-            call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4214
-        }
4215
-        return $result;
4216
-    }
4217
-
4218
-
4219
-    /**
4220
-     * @param EEM_Base $entity_model
4221
-     * @param string   $delete_column
4222
-     * @since $VID:$
4223
-     */
4224
-    private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column)
4225
-    {
4226
-        if (empty($delete_column)) {
4227
-            throw new DomainException(
4228
-                sprintf(
4229
-                    esc_html__(
4230
-                        'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4231
-                        'event_espresso'
4232
-                    ),
4233
-                    $entity_model->get_this_model_name()
4234
-                )
4235
-            );
4236
-        }
4237
-        if (! $entity_model->has_field($delete_column)) {
4238
-            throw new DomainException(
4239
-                sprintf(
4240
-                    esc_html__(
4241
-                        'The %1$s field does not exist on the %2$s model.',
4242
-                        'event_espresso'
4243
-                    ),
4244
-                    $delete_column,
4245
-                    $entity_model->get_this_model_name()
4246
-                )
4247
-            );
4248
-        }
4249
-    }
4250
-
4251
-
4252
-    /**
4253
-     * @param EEM_Base       $entity_model
4254
-     * @param Exception|null $exception
4255
-     * @param string         $action
4256
-     * @since $VID:$
4257
-     */
4258
-    private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null)
4259
-    {
4260
-        if ($exception instanceof Exception) {
4261
-            throw new RuntimeException(
4262
-                sprintf(
4263
-                    esc_html__(
4264
-                        'Could not %1$s the %2$s because the following error occurred: %3$s',
4265
-                        'event_espresso'
4266
-                    ),
4267
-                    $action,
4268
-                    $entity_model->get_this_model_name(),
4269
-                    $exception->getMessage()
4270
-                )
4271
-            );
4272
-        }
4273
-        throw new RuntimeException(
4274
-            sprintf(
4275
-                esc_html__(
4276
-                    'Could not %1$s the %2$s because an invalid ID was received.',
4277
-                    'event_espresso'
4278
-                ),
4279
-                $action,
4280
-                $entity_model->get_this_model_name()
4281
-            )
4282
-        );
4283
-    }
3316
+		// add nonce
3317
+		$nonce                                             =
3318
+			wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3319
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3320
+		// add REQUIRED form action
3321
+		$hidden_fields = [
3322
+			'action' => ['type' => 'hidden', 'value' => $route],
3323
+		];
3324
+		// merge arrays
3325
+		$hidden_fields = is_array($additional_hidden_fields)
3326
+			? array_merge($hidden_fields, $additional_hidden_fields)
3327
+			: $hidden_fields;
3328
+		// generate form fields
3329
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3330
+		// add fields to form
3331
+		foreach ((array) $form_fields as $form_field) {
3332
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3333
+		}
3334
+		// close form
3335
+		$this->_template_args['after_admin_page_content'] = '</form>';
3336
+	}
3337
+
3338
+
3339
+	/**
3340
+	 * Public Wrapper for _redirect_after_action() method since its
3341
+	 * discovered it would be useful for external code to have access.
3342
+	 *
3343
+	 * @param bool   $success
3344
+	 * @param string $what
3345
+	 * @param string $action_desc
3346
+	 * @param array  $query_args
3347
+	 * @param bool   $override_overwrite
3348
+	 * @throws EE_Error
3349
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3350
+	 * @since 4.5.0
3351
+	 */
3352
+	public function redirect_after_action(
3353
+		$success = false,
3354
+		$what = 'item',
3355
+		$action_desc = 'processed',
3356
+		$query_args = [],
3357
+		$override_overwrite = false
3358
+	) {
3359
+		$this->_redirect_after_action(
3360
+			$success,
3361
+			$what,
3362
+			$action_desc,
3363
+			$query_args,
3364
+			$override_overwrite
3365
+		);
3366
+	}
3367
+
3368
+
3369
+	/**
3370
+	 * Helper method for merging existing request data with the returned redirect url.
3371
+	 *
3372
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3373
+	 * filters are still applied.
3374
+	 *
3375
+	 * @param array $new_route_data
3376
+	 * @return array
3377
+	 */
3378
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3379
+	{
3380
+		foreach ($this->request->requestParams() as $ref => $value) {
3381
+			// unset nonces
3382
+			if (strpos($ref, 'nonce') !== false) {
3383
+				$this->request->unSetRequestParam($ref);
3384
+				continue;
3385
+			}
3386
+			// urlencode values.
3387
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3388
+			$this->request->setRequestParam($ref, $value);
3389
+		}
3390
+		return array_merge($this->request->requestParams(), $new_route_data);
3391
+	}
3392
+
3393
+
3394
+	/**
3395
+	 * @param int|float|string $success      - whether success was for two or more records, or just one, or none
3396
+	 * @param string           $what         - what the action was performed on
3397
+	 * @param string           $action_desc  - what was done ie: updated, deleted, etc
3398
+	 * @param array $query_args              - an array of query_args to be added to the URL to redirect to
3399
+	 * @param BOOL $override_overwrite       - by default all EE_Error::success messages are overwritten,
3400
+	 *                                         this allows you to override this so that they show.
3401
+	 * @return void
3402
+	 * @throws EE_Error
3403
+	 * @throws InvalidArgumentException
3404
+	 * @throws InvalidDataTypeException
3405
+	 * @throws InvalidInterfaceException
3406
+	 */
3407
+	protected function _redirect_after_action(
3408
+		$success = 0,
3409
+		string $what = 'item',
3410
+		string $action_desc = 'processed',
3411
+		array $query_args = [],
3412
+		bool $override_overwrite = false
3413
+	) {
3414
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3415
+		$notices      = EE_Error::get_notices(false);
3416
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3417
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3418
+			EE_Error::overwrite_success();
3419
+		}
3420
+		if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3421
+			// how many records affected ? more than one record ? or just one ?
3422
+			EE_Error::add_success(
3423
+				sprintf(
3424
+					esc_html(
3425
+						_n(
3426
+							'The "%1$s" has been successfully %2$s.',
3427
+							'The "%1$s" have been successfully %2$s.',
3428
+							$success,
3429
+							'event_espresso'
3430
+						)
3431
+					),
3432
+					$what,
3433
+					$action_desc
3434
+				),
3435
+				__FILE__,
3436
+				__FUNCTION__,
3437
+				__LINE__
3438
+			);
3439
+		}
3440
+		// check that $query_args isn't something crazy
3441
+		if (! is_array($query_args)) {
3442
+			$query_args = [];
3443
+		}
3444
+		/**
3445
+		 * Allow injecting actions before the query_args are modified for possible different
3446
+		 * redirections on save and close actions
3447
+		 *
3448
+		 * @param array $query_args       The original query_args array coming into the
3449
+		 *                                method.
3450
+		 * @since 4.2.0
3451
+		 */
3452
+		do_action(
3453
+			"AHEE__{$this->class_name}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3454
+			$query_args
3455
+		);
3456
+		// set redirect url.
3457
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3458
+		// otherwise we go with whatever is set as the _admin_base_url
3459
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3460
+		// calculate where we're going (if we have a "save and close" button pushed)
3461
+		if (
3462
+			$this->request->requestParamIsSet('save_and_close')
3463
+			&& $this->request->requestParamIsSet('save_and_close_referrer')
3464
+		) {
3465
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3466
+			$parsed_url = parse_url($this->request->getRequestParam('save_and_close_referrer', '', 'url'));
3467
+			// regenerate query args array from referrer URL
3468
+			parse_str($parsed_url['query'], $query_args);
3469
+			// correct page and action will be in the query args now
3470
+			$redirect_url = admin_url('admin.php');
3471
+		}
3472
+		// merge any default query_args set in _default_route_query_args property
3473
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3474
+			$args_to_merge = [];
3475
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3476
+				// is there a wp_referer array in our _default_route_query_args property?
3477
+				if ($query_param === 'wp_referer') {
3478
+					$query_value = (array) $query_value;
3479
+					foreach ($query_value as $reference => $value) {
3480
+						if (strpos($reference, 'nonce') !== false) {
3481
+							continue;
3482
+						}
3483
+						// finally we will override any arguments in the referer with
3484
+						// what might be set on the _default_route_query_args array.
3485
+						if (isset($this->_default_route_query_args[ $reference ])) {
3486
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3487
+						} else {
3488
+							$args_to_merge[ $reference ] = urlencode($value);
3489
+						}
3490
+					}
3491
+					continue;
3492
+				}
3493
+				$args_to_merge[ $query_param ] = $query_value;
3494
+			}
3495
+			// now let's merge these arguments but override with what was specifically sent in to the
3496
+			// redirect.
3497
+			$query_args = array_merge($args_to_merge, $query_args);
3498
+		}
3499
+		$this->_process_notices($query_args);
3500
+		// generate redirect url
3501
+		// if redirecting to anything other than the main page, add a nonce
3502
+		if (isset($query_args['action'])) {
3503
+			// manually generate wp_nonce and merge that with the query vars
3504
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3505
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3506
+		}
3507
+		// we're adding some hooks and filters in here for processing any things just before redirects
3508
+		// (example: an admin page has done an insert or update and we want to run something after that).
3509
+		do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args);
3510
+		$redirect_url = apply_filters(
3511
+			'FHEE_redirect_' . $this->class_name . $this->_req_action,
3512
+			EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3513
+			$query_args
3514
+		);
3515
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3516
+		if ($this->request->isAjax()) {
3517
+			$default_data                    = [
3518
+				'close'        => true,
3519
+				'redirect_url' => $redirect_url,
3520
+				'where'        => 'main',
3521
+				'what'         => 'append',
3522
+			];
3523
+			$this->_template_args['success'] = $success;
3524
+			$this->_template_args['data']    = ! empty($this->_template_args['data']) ? array_merge(
3525
+				$default_data,
3526
+				$this->_template_args['data']
3527
+			) : $default_data;
3528
+			$this->_return_json();
3529
+		}
3530
+		wp_safe_redirect($redirect_url);
3531
+		exit();
3532
+	}
3533
+
3534
+
3535
+	/**
3536
+	 * process any notices before redirecting (or returning ajax request)
3537
+	 * This method sets the $this->_template_args['notices'] attribute;
3538
+	 *
3539
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3540
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3541
+	 *                                  page_routes haven't been defined yet.
3542
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3543
+	 *                                  still save a transient for the notice.
3544
+	 * @return void
3545
+	 * @throws EE_Error
3546
+	 * @throws InvalidArgumentException
3547
+	 * @throws InvalidDataTypeException
3548
+	 * @throws InvalidInterfaceException
3549
+	 */
3550
+	protected function _process_notices($query_args = [], $skip_route_verify = false, $sticky_notices = true)
3551
+	{
3552
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3553
+		if ($this->request->isAjax()) {
3554
+			$notices = EE_Error::get_notices(false);
3555
+			if (empty($this->_template_args['success'])) {
3556
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3557
+			}
3558
+			if (empty($this->_template_args['errors'])) {
3559
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3560
+			}
3561
+			if (empty($this->_template_args['attention'])) {
3562
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3563
+			}
3564
+		}
3565
+		$this->_template_args['notices'] = EE_Error::get_notices();
3566
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3567
+		if (! $this->request->isAjax() || $sticky_notices) {
3568
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3569
+			$this->_add_transient(
3570
+				$route,
3571
+				$this->_template_args['notices'],
3572
+				true,
3573
+				$skip_route_verify
3574
+			);
3575
+		}
3576
+	}
3577
+
3578
+
3579
+	/**
3580
+	 * get_action_link_or_button
3581
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3582
+	 *
3583
+	 * @param string $action        use this to indicate which action the url is generated with.
3584
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3585
+	 *                              property.
3586
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3587
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button--primary'
3588
+	 * @param string $base_url      If this is not provided
3589
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3590
+	 *                              Otherwise this value will be used.
3591
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3592
+	 * @return string
3593
+	 * @throws InvalidArgumentException
3594
+	 * @throws InvalidInterfaceException
3595
+	 * @throws InvalidDataTypeException
3596
+	 * @throws EE_Error
3597
+	 */
3598
+	public function get_action_link_or_button(
3599
+		$action,
3600
+		$type = 'add',
3601
+		$extra_request = [],
3602
+		$class = 'button--primary',
3603
+		$base_url = '',
3604
+		$exclude_nonce = false
3605
+	) {
3606
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3607
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3608
+			throw new EE_Error(
3609
+				sprintf(
3610
+					esc_html__(
3611
+						'There is no page route for given action for the button.  This action was given: %s',
3612
+						'event_espresso'
3613
+					),
3614
+					$action
3615
+				)
3616
+			);
3617
+		}
3618
+		if (! isset($this->_labels['buttons'][ $type ])) {
3619
+			throw new EE_Error(
3620
+				sprintf(
3621
+					esc_html__(
3622
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3623
+						'event_espresso'
3624
+					),
3625
+					$type
3626
+				)
3627
+			);
3628
+		}
3629
+		// finally check user access for this button.
3630
+		$has_access = $this->check_user_access($action, true);
3631
+		if (! $has_access) {
3632
+			return '';
3633
+		}
3634
+		$_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
3635
+		$query_args = [
3636
+			'action' => $action,
3637
+		];
3638
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3639
+		if (! empty($extra_request)) {
3640
+			$query_args = array_merge($extra_request, $query_args);
3641
+		}
3642
+		$url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3643
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3644
+	}
3645
+
3646
+
3647
+	/**
3648
+	 * _per_page_screen_option
3649
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3650
+	 *
3651
+	 * @return void
3652
+	 * @throws InvalidArgumentException
3653
+	 * @throws InvalidInterfaceException
3654
+	 * @throws InvalidDataTypeException
3655
+	 */
3656
+	protected function _per_page_screen_option()
3657
+	{
3658
+		$option = 'per_page';
3659
+		$args   = [
3660
+			'label'   => apply_filters(
3661
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3662
+				$this->_admin_page_title,
3663
+				$this
3664
+			),
3665
+			'default' => (int) apply_filters(
3666
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3667
+				20
3668
+			),
3669
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3670
+		];
3671
+		// ONLY add the screen option if the user has access to it.
3672
+		if ($this->check_user_access($this->_current_view, true)) {
3673
+			add_screen_option($option, $args);
3674
+		}
3675
+	}
3676
+
3677
+
3678
+	/**
3679
+	 * set_per_page_screen_option
3680
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3681
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3682
+	 * admin_menu.
3683
+	 *
3684
+	 * @return void
3685
+	 */
3686
+	private function _set_per_page_screen_options()
3687
+	{
3688
+		if ($this->request->requestParamIsSet('wp_screen_options')) {
3689
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3690
+			if (! $user = wp_get_current_user()) {
3691
+				return;
3692
+			}
3693
+			$option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3694
+			if (! $option) {
3695
+				return;
3696
+			}
3697
+			$value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3698
+			$map_option = $option;
3699
+			$option     = str_replace('-', '_', $option);
3700
+			switch ($map_option) {
3701
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3702
+					$max_value = apply_filters(
3703
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3704
+						999,
3705
+						$this->_current_page,
3706
+						$this->_current_view
3707
+					);
3708
+					if ($value < 1) {
3709
+						return;
3710
+					}
3711
+					$value = min($value, $max_value);
3712
+					break;
3713
+				default:
3714
+					$value = apply_filters(
3715
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3716
+						false,
3717
+						$option,
3718
+						$value
3719
+					);
3720
+					if (false === $value) {
3721
+						return;
3722
+					}
3723
+					break;
3724
+			}
3725
+			update_user_meta($user->ID, $option, $value);
3726
+			wp_safe_redirect(remove_query_arg(['pagenum', 'apage', 'paged'], wp_get_referer()));
3727
+			exit;
3728
+		}
3729
+	}
3730
+
3731
+
3732
+	/**
3733
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3734
+	 *
3735
+	 * @param array $data array that will be assigned to template args.
3736
+	 */
3737
+	public function set_template_args($data)
3738
+	{
3739
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3740
+	}
3741
+
3742
+
3743
+	/**
3744
+	 * This makes available the WP transient system for temporarily moving data between routes
3745
+	 *
3746
+	 * @param string $route             the route that should receive the transient
3747
+	 * @param array  $data              the data that gets sent
3748
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3749
+	 *                                  normal route transient.
3750
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3751
+	 *                                  when we are adding a transient before page_routes have been defined.
3752
+	 * @return void
3753
+	 * @throws EE_Error
3754
+	 */
3755
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3756
+	{
3757
+		$user_id = get_current_user_id();
3758
+		if (! $skip_route_verify) {
3759
+			$this->_verify_route($route);
3760
+		}
3761
+		// now let's set the string for what kind of transient we're setting
3762
+		$transient = $notices
3763
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3764
+			: 'rte_tx_' . $route . '_' . $user_id;
3765
+		$data      = $notices ? ['notices' => $data] : $data;
3766
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3767
+		$existing = is_multisite() && is_network_admin()
3768
+			? get_site_transient($transient)
3769
+			: get_transient($transient);
3770
+		if ($existing) {
3771
+			$data = array_merge((array) $data, (array) $existing);
3772
+		}
3773
+		if (is_multisite() && is_network_admin()) {
3774
+			set_site_transient($transient, $data, 8);
3775
+		} else {
3776
+			set_transient($transient, $data, 8);
3777
+		}
3778
+	}
3779
+
3780
+
3781
+	/**
3782
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3783
+	 *
3784
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3785
+	 * @param string $route
3786
+	 * @return mixed data
3787
+	 */
3788
+	protected function _get_transient($notices = false, $route = '')
3789
+	{
3790
+		$user_id   = get_current_user_id();
3791
+		$route     = ! $route ? $this->_req_action : $route;
3792
+		$transient = $notices
3793
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3794
+			: 'rte_tx_' . $route . '_' . $user_id;
3795
+		$data      = is_multisite() && is_network_admin()
3796
+			? get_site_transient($transient)
3797
+			: get_transient($transient);
3798
+		// delete transient after retrieval (just in case it hasn't expired);
3799
+		if (is_multisite() && is_network_admin()) {
3800
+			delete_site_transient($transient);
3801
+		} else {
3802
+			delete_transient($transient);
3803
+		}
3804
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3805
+	}
3806
+
3807
+
3808
+	/**
3809
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3810
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3811
+	 * default route callback on the EE_Admin page you want it run.)
3812
+	 *
3813
+	 * @return void
3814
+	 */
3815
+	protected function _transient_garbage_collection()
3816
+	{
3817
+		global $wpdb;
3818
+		// retrieve all existing transients
3819
+		$query =
3820
+			"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3821
+		if ($results = $wpdb->get_results($query)) {
3822
+			foreach ($results as $result) {
3823
+				$transient = str_replace('_transient_', '', $result->option_name);
3824
+				get_transient($transient);
3825
+				if (is_multisite() && is_network_admin()) {
3826
+					get_site_transient($transient);
3827
+				}
3828
+			}
3829
+		}
3830
+	}
3831
+
3832
+
3833
+	/**
3834
+	 * get_view
3835
+	 *
3836
+	 * @return string content of _view property
3837
+	 */
3838
+	public function get_view()
3839
+	{
3840
+		return $this->_view;
3841
+	}
3842
+
3843
+
3844
+	/**
3845
+	 * getter for the protected $_views property
3846
+	 *
3847
+	 * @return array
3848
+	 */
3849
+	public function get_views()
3850
+	{
3851
+		return $this->_views;
3852
+	}
3853
+
3854
+
3855
+	/**
3856
+	 * get_current_page
3857
+	 *
3858
+	 * @return string _current_page property value
3859
+	 */
3860
+	public function get_current_page()
3861
+	{
3862
+		return $this->_current_page;
3863
+	}
3864
+
3865
+
3866
+	/**
3867
+	 * get_current_view
3868
+	 *
3869
+	 * @return string _current_view property value
3870
+	 */
3871
+	public function get_current_view()
3872
+	{
3873
+		return $this->_current_view;
3874
+	}
3875
+
3876
+
3877
+	/**
3878
+	 * get_current_screen
3879
+	 *
3880
+	 * @return object The current WP_Screen object
3881
+	 */
3882
+	public function get_current_screen()
3883
+	{
3884
+		return $this->_current_screen;
3885
+	}
3886
+
3887
+
3888
+	/**
3889
+	 * get_current_page_view_url
3890
+	 *
3891
+	 * @return string This returns the url for the current_page_view.
3892
+	 */
3893
+	public function get_current_page_view_url()
3894
+	{
3895
+		return $this->_current_page_view_url;
3896
+	}
3897
+
3898
+
3899
+	/**
3900
+	 * just returns the Request
3901
+	 *
3902
+	 * @return RequestInterface
3903
+	 */
3904
+	public function get_request()
3905
+	{
3906
+		return $this->request;
3907
+	}
3908
+
3909
+
3910
+	/**
3911
+	 * just returns the _req_data property
3912
+	 *
3913
+	 * @return array
3914
+	 */
3915
+	public function get_request_data()
3916
+	{
3917
+		return $this->request->requestParams();
3918
+	}
3919
+
3920
+
3921
+	/**
3922
+	 * returns the _req_data protected property
3923
+	 *
3924
+	 * @return string
3925
+	 */
3926
+	public function get_req_action()
3927
+	{
3928
+		return $this->_req_action;
3929
+	}
3930
+
3931
+
3932
+	/**
3933
+	 * @return bool  value of $_is_caf property
3934
+	 */
3935
+	public function is_caf()
3936
+	{
3937
+		return $this->_is_caf;
3938
+	}
3939
+
3940
+
3941
+	/**
3942
+	 * @return mixed
3943
+	 */
3944
+	public function default_espresso_metaboxes()
3945
+	{
3946
+		return $this->_default_espresso_metaboxes;
3947
+	}
3948
+
3949
+
3950
+	/**
3951
+	 * @return mixed
3952
+	 */
3953
+	public function admin_base_url()
3954
+	{
3955
+		return $this->_admin_base_url;
3956
+	}
3957
+
3958
+
3959
+	/**
3960
+	 * @return mixed
3961
+	 */
3962
+	public function wp_page_slug()
3963
+	{
3964
+		return $this->_wp_page_slug;
3965
+	}
3966
+
3967
+
3968
+	/**
3969
+	 * updates  espresso configuration settings
3970
+	 *
3971
+	 * @param string                   $tab
3972
+	 * @param EE_Config_Base|EE_Config $config
3973
+	 * @param string                   $file file where error occurred
3974
+	 * @param string                   $func function  where error occurred
3975
+	 * @param string                   $line line no where error occurred
3976
+	 * @return boolean
3977
+	 */
3978
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
3979
+	{
3980
+		// remove any options that are NOT going to be saved with the config settings.
3981
+		if (isset($config->core->ee_ueip_optin)) {
3982
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
3983
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
3984
+			update_option('ee_ueip_has_notified', true);
3985
+		}
3986
+		// and save it (note we're also doing the network save here)
3987
+		$net_saved    = ! is_main_site() || EE_Network_Config::instance()->update_config(false, false);
3988
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
3989
+		if ($config_saved && $net_saved) {
3990
+			EE_Error::add_success(sprintf(esc_html__('"%s" have been successfully updated.', 'event_espresso'), $tab));
3991
+			return true;
3992
+		}
3993
+		EE_Error::add_error(sprintf(esc_html__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
3994
+		return false;
3995
+	}
3996
+
3997
+
3998
+	/**
3999
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4000
+	 *
4001
+	 * @return array
4002
+	 */
4003
+	public function get_yes_no_values()
4004
+	{
4005
+		return $this->_yes_no_values;
4006
+	}
4007
+
4008
+
4009
+	/**
4010
+	 * @return string
4011
+	 * @throws ReflectionException
4012
+	 * @since $VID:$
4013
+	 */
4014
+	protected function _get_dir()
4015
+	{
4016
+		$reflector = new ReflectionClass($this->class_name);
4017
+		return dirname($reflector->getFileName());
4018
+	}
4019
+
4020
+
4021
+	/**
4022
+	 * A helper for getting a "next link".
4023
+	 *
4024
+	 * @param string $url   The url to link to
4025
+	 * @param string $class The class to use.
4026
+	 * @return string
4027
+	 */
4028
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4029
+	{
4030
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4031
+	}
4032
+
4033
+
4034
+	/**
4035
+	 * A helper for getting a "previous link".
4036
+	 *
4037
+	 * @param string $url   The url to link to
4038
+	 * @param string $class The class to use.
4039
+	 * @return string
4040
+	 */
4041
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4042
+	{
4043
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4044
+	}
4045
+
4046
+
4047
+
4048
+
4049
+
4050
+
4051
+
4052
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4053
+
4054
+
4055
+	/**
4056
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4057
+	 * 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
4058
+	 * _req_data array.
4059
+	 *
4060
+	 * @return bool success/fail
4061
+	 * @throws EE_Error
4062
+	 * @throws InvalidArgumentException
4063
+	 * @throws ReflectionException
4064
+	 * @throws InvalidDataTypeException
4065
+	 * @throws InvalidInterfaceException
4066
+	 */
4067
+	protected function _process_resend_registration()
4068
+	{
4069
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4070
+		do_action(
4071
+			'AHEE__EE_Admin_Page___process_resend_registration',
4072
+			$this->_template_args['success'],
4073
+			$this->request->requestParams()
4074
+		);
4075
+		return $this->_template_args['success'];
4076
+	}
4077
+
4078
+
4079
+	/**
4080
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4081
+	 *
4082
+	 * @param EE_Payment $payment
4083
+	 * @return bool success/fail
4084
+	 */
4085
+	protected function _process_payment_notification(EE_Payment $payment)
4086
+	{
4087
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4088
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4089
+		$this->_template_args['success'] = apply_filters(
4090
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4091
+			false,
4092
+			$payment
4093
+		);
4094
+		return $this->_template_args['success'];
4095
+	}
4096
+
4097
+
4098
+	/**
4099
+	 * @param EEM_Base      $entity_model
4100
+	 * @param string        $entity_PK_name name of the primary key field used as a request param, ie: id, ID, etc
4101
+	 * @param string        $action         one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4102
+	 * @param string        $delete_column  name of the field that denotes whether entity is trashed
4103
+	 * @param callable|null $callback       called after entity is trashed, restored, or deleted
4104
+	 * @return int|float
4105
+	 * @throws EE_Error
4106
+	 */
4107
+	protected function trashRestoreDeleteEntities(
4108
+		EEM_Base $entity_model,
4109
+		string $entity_PK_name,
4110
+		string $action = EE_Admin_List_Table::ACTION_DELETE,
4111
+		string $delete_column = '',
4112
+		callable $callback = null
4113
+	) {
4114
+		$entity_PK      = $entity_model->get_primary_key_field();
4115
+		$entity_PK_name = $entity_PK_name ?: $entity_PK->get_name();
4116
+		$entity_PK_type = $this->resolveEntityFieldDataType($entity_PK);
4117
+		// grab ID if deleting a single entity
4118
+		if ($this->request->requestParamIsSet($entity_PK_name)) {
4119
+			$ID = $this->request->getRequestParam($entity_PK_name, 0, $entity_PK_type);
4120
+			return $this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback) ? 1 : 0;
4121
+		}
4122
+		// or grab checkbox array if bulk deleting
4123
+		$checkboxes = $this->request->getRequestParam('checkbox', [], $entity_PK_type, true);
4124
+		if (empty($checkboxes)) {
4125
+			return 0;
4126
+		}
4127
+		$success = 0;
4128
+		$IDs     = array_keys($checkboxes);
4129
+		// cycle thru bulk action checkboxes
4130
+		foreach ($IDs as $ID) {
4131
+			// increment $success
4132
+			if ($this->trashRestoreDeleteEntity($entity_model, $ID, $action, $delete_column, $callback)) {
4133
+				$success++;
4134
+			}
4135
+		}
4136
+		$count = (int) count($checkboxes);
4137
+		// if multiple entities were deleted successfully, then $deleted will be full count of deletions,
4138
+		// otherwise it will be a fraction of ( actual deletions / total entities to be deleted )
4139
+		return $success === $count ? $count : $success / $count;
4140
+	}
4141
+
4142
+
4143
+	/**
4144
+	 * @param EE_Primary_Key_Field_Base $entity_PK
4145
+	 * @return string
4146
+	 * @throws EE_Error
4147
+	 * @since   $VID:$
4148
+	 */
4149
+	private function resolveEntityFieldDataType(EE_Primary_Key_Field_Base $entity_PK): string
4150
+	{
4151
+		$entity_PK_type = $entity_PK->getSchemaType();
4152
+		switch ($entity_PK_type) {
4153
+			case 'boolean':
4154
+				return 'bool';
4155
+			case 'integer':
4156
+				return 'int';
4157
+			case 'number':
4158
+				return 'float';
4159
+			case 'string':
4160
+				return 'string';
4161
+		}
4162
+		throw new RuntimeException(
4163
+			sprintf(
4164
+				esc_html__(
4165
+					'"%1$s" is an invalid schema type for the %2$s primary key.',
4166
+					'event_espresso'
4167
+				),
4168
+				$entity_PK_type,
4169
+				$entity_PK->get_name()
4170
+			)
4171
+		);
4172
+	}
4173
+
4174
+
4175
+	/**
4176
+	 * @param EEM_Base      $entity_model
4177
+	 * @param int|string    $entity_ID
4178
+	 * @param string        $action        one of the EE_Admin_List_Table::ACTION_* constants: delete, restore, trash
4179
+	 * @param string        $delete_column name of the field that denotes whether entity is trashed
4180
+	 * @param callable|null $callback      called after entity is trashed, restored, or deleted
4181
+	 * @return bool
4182
+	 */
4183
+	protected function trashRestoreDeleteEntity(
4184
+		EEM_Base $entity_model,
4185
+		$entity_ID,
4186
+		string $action,
4187
+		string $delete_column,
4188
+		?callable $callback = null
4189
+	): bool {
4190
+		$entity_ID = absint($entity_ID);
4191
+		if (! $entity_ID) {
4192
+			$this->trashRestoreDeleteError($action, $entity_model);
4193
+		}
4194
+		$result = 0;
4195
+		try {
4196
+			switch ($action) {
4197
+				case EE_Admin_List_Table::ACTION_DELETE:
4198
+					$result = (bool) $entity_model->delete_permanently_by_ID($entity_ID);
4199
+					break;
4200
+				case EE_Admin_List_Table::ACTION_RESTORE:
4201
+					$this->validateDeleteColumn($entity_model, $delete_column);
4202
+					$result = $entity_model->update_by_ID([$delete_column => 0], $entity_ID);
4203
+					break;
4204
+				case EE_Admin_List_Table::ACTION_TRASH:
4205
+					$this->validateDeleteColumn($entity_model, $delete_column);
4206
+					$result = $entity_model->update_by_ID([$delete_column => 1], $entity_ID);
4207
+					break;
4208
+			}
4209
+		} catch (Exception $exception) {
4210
+			$this->trashRestoreDeleteError($action, $entity_model, $exception);
4211
+		}
4212
+		if (is_callable($callback)) {
4213
+			call_user_func_array($callback, [$entity_model, $entity_ID, $action, $result, $delete_column]);
4214
+		}
4215
+		return $result;
4216
+	}
4217
+
4218
+
4219
+	/**
4220
+	 * @param EEM_Base $entity_model
4221
+	 * @param string   $delete_column
4222
+	 * @since $VID:$
4223
+	 */
4224
+	private function validateDeleteColumn(EEM_Base $entity_model, string $delete_column)
4225
+	{
4226
+		if (empty($delete_column)) {
4227
+			throw new DomainException(
4228
+				sprintf(
4229
+					esc_html__(
4230
+						'You need to specify the name of the "delete column" on the %2$s model, in order to trash or restore an entity.',
4231
+						'event_espresso'
4232
+					),
4233
+					$entity_model->get_this_model_name()
4234
+				)
4235
+			);
4236
+		}
4237
+		if (! $entity_model->has_field($delete_column)) {
4238
+			throw new DomainException(
4239
+				sprintf(
4240
+					esc_html__(
4241
+						'The %1$s field does not exist on the %2$s model.',
4242
+						'event_espresso'
4243
+					),
4244
+					$delete_column,
4245
+					$entity_model->get_this_model_name()
4246
+				)
4247
+			);
4248
+		}
4249
+	}
4250
+
4251
+
4252
+	/**
4253
+	 * @param EEM_Base       $entity_model
4254
+	 * @param Exception|null $exception
4255
+	 * @param string         $action
4256
+	 * @since $VID:$
4257
+	 */
4258
+	private function trashRestoreDeleteError(string $action, EEM_Base $entity_model, ?Exception $exception = null)
4259
+	{
4260
+		if ($exception instanceof Exception) {
4261
+			throw new RuntimeException(
4262
+				sprintf(
4263
+					esc_html__(
4264
+						'Could not %1$s the %2$s because the following error occurred: %3$s',
4265
+						'event_espresso'
4266
+					),
4267
+					$action,
4268
+					$entity_model->get_this_model_name(),
4269
+					$exception->getMessage()
4270
+				)
4271
+			);
4272
+		}
4273
+		throw new RuntimeException(
4274
+			sprintf(
4275
+				esc_html__(
4276
+					'Could not %1$s the %2$s because an invalid ID was received.',
4277
+					'event_espresso'
4278
+				),
4279
+				$action,
4280
+				$entity_model->get_this_model_name()
4281
+			)
4282
+		);
4283
+	}
4284 4284
 }
Please login to merge, or discard this patch.
Spacing   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
         $ee_menu_slugs = (array) $ee_menu_slugs;
629 629
         if (
630 630
             ! $this->request->isAjax()
631
-            && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))
631
+            && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))
632 632
         ) {
633 633
             return;
634 634
         }
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
             : $req_action;
649 649
 
650 650
         $this->_current_view = $this->_req_action;
651
-        $this->_req_nonce    = $this->_req_action . '_nonce';
651
+        $this->_req_nonce    = $this->_req_action.'_nonce';
652 652
         $this->_define_page_props();
653 653
         $this->_current_page_view_url = add_query_arg(
654 654
             ['page' => $this->_current_page, 'action' => $this->_current_view],
@@ -678,33 +678,33 @@  discard block
 block discarded – undo
678 678
         }
679 679
         // filter routes and page_config so addons can add their stuff. Filtering done per class
680 680
         $this->_page_routes = apply_filters(
681
-            'FHEE__' . $this->class_name . '__page_setup__page_routes',
681
+            'FHEE__'.$this->class_name.'__page_setup__page_routes',
682 682
             $this->_page_routes,
683 683
             $this
684 684
         );
685 685
         $this->_page_config = apply_filters(
686
-            'FHEE__' . $this->class_name . '__page_setup__page_config',
686
+            'FHEE__'.$this->class_name.'__page_setup__page_config',
687 687
             $this->_page_config,
688 688
             $this
689 689
         );
690 690
         if ($this->base_class_name !== '') {
691 691
             $this->_page_routes = apply_filters(
692
-                'FHEE__' . $this->base_class_name . '__page_setup__page_routes',
692
+                'FHEE__'.$this->base_class_name.'__page_setup__page_routes',
693 693
                 $this->_page_routes,
694 694
                 $this
695 695
             );
696 696
             $this->_page_config = apply_filters(
697
-                'FHEE__' . $this->base_class_name . '__page_setup__page_config',
697
+                'FHEE__'.$this->base_class_name.'__page_setup__page_config',
698 698
                 $this->_page_config,
699 699
                 $this
700 700
             );
701 701
         }
702 702
         // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
703 703
         // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
704
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
704
+        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) {
705 705
             add_action(
706 706
                 'AHEE__EE_Admin_Page__route_admin_request',
707
-                [$this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view],
707
+                [$this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view],
708 708
                 10,
709 709
                 2
710 710
             );
@@ -717,8 +717,8 @@  discard block
 block discarded – undo
717 717
             if ($this->_is_UI_request) {
718 718
                 // admin_init stuff - global, all views for this page class, specific view
719 719
                 add_action('admin_init', [$this, 'admin_init'], 10);
720
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
721
-                    add_action('admin_init', [$this, 'admin_init_' . $this->_current_view], 15);
720
+                if (method_exists($this, 'admin_init_'.$this->_current_view)) {
721
+                    add_action('admin_init', [$this, 'admin_init_'.$this->_current_view], 15);
722 722
                 }
723 723
             } else {
724 724
                 // hijack regular WP loading and route admin request immediately
@@ -737,12 +737,12 @@  discard block
 block discarded – undo
737 737
      */
738 738
     private function _do_other_page_hooks()
739 739
     {
740
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, []);
740
+        $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, []);
741 741
         foreach ($registered_pages as $page) {
742 742
             // now let's setup the file name and class that should be present
743 743
             $classname = str_replace('.class.php', '', $page);
744 744
             // autoloaders should take care of loading file
745
-            if (! class_exists($classname)) {
745
+            if ( ! class_exists($classname)) {
746 746
                 $error_msg[] = sprintf(
747 747
                     esc_html__(
748 748
                         'Something went wrong with loading the %s admin hooks page.',
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
                                    ),
760 760
                                    $page,
761 761
                                    '<br />',
762
-                                   '<strong>' . $classname . '</strong>'
762
+                                   '<strong>'.$classname.'</strong>'
763 763
                                );
764 764
                 throw new EE_Error(implode('||', $error_msg));
765 765
             }
@@ -801,13 +801,13 @@  discard block
 block discarded – undo
801 801
         // load admin_notices - global, page class, and view specific
802 802
         add_action('admin_notices', [$this, 'admin_notices_global'], 5);
803 803
         add_action('admin_notices', [$this, 'admin_notices'], 10);
804
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
805
-            add_action('admin_notices', [$this, 'admin_notices_' . $this->_current_view], 15);
804
+        if (method_exists($this, 'admin_notices_'.$this->_current_view)) {
805
+            add_action('admin_notices', [$this, 'admin_notices_'.$this->_current_view], 15);
806 806
         }
807 807
         // load network admin_notices - global, page class, and view specific
808 808
         add_action('network_admin_notices', [$this, 'network_admin_notices_global'], 5);
809
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
810
-            add_action('network_admin_notices', [$this, 'network_admin_notices_' . $this->_current_view]);
809
+        if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) {
810
+            add_action('network_admin_notices', [$this, 'network_admin_notices_'.$this->_current_view]);
811 811
         }
812 812
         // this will save any per_page screen options if they are present
813 813
         $this->_set_per_page_screen_options();
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
     protected function _verify_routes()
929 929
     {
930 930
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
931
-        if (! $this->_current_page && ! $this->request->isAjax()) {
931
+        if ( ! $this->_current_page && ! $this->request->isAjax()) {
932 932
             return false;
933 933
         }
934 934
         $this->_route = false;
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
                 $this->_admin_page_title
941 941
             );
942 942
             // developer error msg
943
-            $error_msg .= '||' . $error_msg
943
+            $error_msg .= '||'.$error_msg
944 944
                           . esc_html__(
945 945
                               ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
946 946
                               'event_espresso'
@@ -949,8 +949,8 @@  discard block
 block discarded – undo
949 949
         }
950 950
         // and that the requested page route exists
951 951
         if (array_key_exists($this->_req_action, $this->_page_routes)) {
952
-            $this->_route        = $this->_page_routes[ $this->_req_action ];
953
-            $this->_route_config = $this->_page_config[ $this->_req_action ] ?? [];
952
+            $this->_route        = $this->_page_routes[$this->_req_action];
953
+            $this->_route_config = $this->_page_config[$this->_req_action] ?? [];
954 954
         } else {
955 955
             // user error msg
956 956
             $error_msg = sprintf(
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
                 $this->_admin_page_title
962 962
             );
963 963
             // developer error msg
964
-            $error_msg .= '||' . $error_msg
964
+            $error_msg .= '||'.$error_msg
965 965
                           . sprintf(
966 966
                               esc_html__(
967 967
                                   ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
             throw new EE_Error($error_msg);
973 973
         }
974 974
         // and that a default route exists
975
-        if (! array_key_exists('default', $this->_page_routes)) {
975
+        if ( ! array_key_exists('default', $this->_page_routes)) {
976 976
             // user error msg
977 977
             $error_msg = sprintf(
978 978
                 esc_html__(
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
                 $this->_admin_page_title
983 983
             );
984 984
             // developer error msg
985
-            $error_msg .= '||' . $error_msg
985
+            $error_msg .= '||'.$error_msg
986 986
                           . esc_html__(
987 987
                               ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
988 988
                               'event_espresso'
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
             $this->_admin_page_title
1025 1025
         );
1026 1026
         // developer error msg
1027
-        $error_msg .= '||' . $error_msg
1027
+        $error_msg .= '||'.$error_msg
1028 1028
                       . sprintf(
1029 1029
                           esc_html__(
1030 1030
                               ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
     protected function _verify_nonce($nonce, $nonce_ref)
1053 1053
     {
1054 1054
         // verify nonce against expected value
1055
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
1055
+        if ( ! wp_verify_nonce($nonce, $nonce_ref)) {
1056 1056
             // these are not the droids you are looking for !!!
1057 1057
             $msg = sprintf(
1058 1058
                 esc_html__('%sNonce Fail.%s', 'event_espresso'),
@@ -1069,7 +1069,7 @@  discard block
 block discarded – undo
1069 1069
                     __CLASS__
1070 1070
                 );
1071 1071
             }
1072
-            if (! $this->request->isAjax()) {
1072
+            if ( ! $this->request->isAjax()) {
1073 1073
                 wp_die($msg);
1074 1074
             }
1075 1075
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
@@ -1093,7 +1093,7 @@  discard block
 block discarded – undo
1093 1093
      */
1094 1094
     protected function _route_admin_request()
1095 1095
     {
1096
-        if (! $this->_is_UI_request) {
1096
+        if ( ! $this->_is_UI_request) {
1097 1097
             $this->_verify_routes();
1098 1098
         }
1099 1099
         $nonce_check = ! isset($this->_route_config['require_nonce']) || $this->_route_config['require_nonce'];
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
         $error_msg = '';
1114 1114
         // action right before calling route
1115 1115
         // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1116
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1116
+        if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1117 1117
             do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1118 1118
         }
1119 1119
         // strip _wp_http_referer from the server REQUEST_URI
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
         );
1126 1126
         // set new value in both our Request object and the super global
1127 1127
         $this->request->setServerParam('REQUEST_URI', $request_uri, true);
1128
-        if (! empty($func)) {
1128
+        if ( ! empty($func)) {
1129 1129
             if (is_array($func)) {
1130 1130
                 [$class, $method] = $func;
1131 1131
             } elseif (strpos($func, '::') !== false) {
@@ -1134,7 +1134,7 @@  discard block
 block discarded – undo
1134 1134
                 $class  = $this;
1135 1135
                 $method = $func;
1136 1136
             }
1137
-            if (! (is_object($class) && $class === $this)) {
1137
+            if ( ! (is_object($class) && $class === $this)) {
1138 1138
                 // send along this admin page object for access by addons.
1139 1139
                 $args['admin_page_object'] = $this;
1140 1140
             }
@@ -1175,7 +1175,7 @@  discard block
 block discarded – undo
1175 1175
                     $method
1176 1176
                 );
1177 1177
             }
1178
-            if (! empty($error_msg)) {
1178
+            if ( ! empty($error_msg)) {
1179 1179
                 throw new EE_Error($error_msg);
1180 1180
             }
1181 1181
         }
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
                 if (strpos($key, 'nonce') !== false) {
1262 1262
                     continue;
1263 1263
                 }
1264
-                $args[ 'wp_referer[' . $key . ']' ] = is_string($value) ? htmlspecialchars($value) : $value;
1264
+                $args['wp_referer['.$key.']'] = is_string($value) ? htmlspecialchars($value) : $value;
1265 1265
             }
1266 1266
         }
1267 1267
         return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
@@ -1301,12 +1301,12 @@  discard block
 block discarded – undo
1301 1301
      */
1302 1302
     protected function _add_help_tabs()
1303 1303
     {
1304
-        if (isset($this->_page_config[ $this->_req_action ])) {
1305
-            $config = $this->_page_config[ $this->_req_action ];
1304
+        if (isset($this->_page_config[$this->_req_action])) {
1305
+            $config = $this->_page_config[$this->_req_action];
1306 1306
             // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1307 1307
             if (is_array($config) && isset($config['help_sidebar'])) {
1308 1308
                 // check that the callback given is valid
1309
-                if (! method_exists($this, $config['help_sidebar'])) {
1309
+                if ( ! method_exists($this, $config['help_sidebar'])) {
1310 1310
                     throw new EE_Error(
1311 1311
                         sprintf(
1312 1312
                             esc_html__(
@@ -1319,18 +1319,18 @@  discard block
 block discarded – undo
1319 1319
                     );
1320 1320
                 }
1321 1321
                 $content = apply_filters(
1322
-                    'FHEE__' . $this->class_name . '__add_help_tabs__help_sidebar',
1322
+                    'FHEE__'.$this->class_name.'__add_help_tabs__help_sidebar',
1323 1323
                     $this->{$config['help_sidebar']}()
1324 1324
                 );
1325 1325
                 $this->_current_screen->set_help_sidebar($content);
1326 1326
             }
1327
-            if (! isset($config['help_tabs'])) {
1327
+            if ( ! isset($config['help_tabs'])) {
1328 1328
                 return;
1329 1329
             } //no help tabs for this route
1330 1330
             foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1331 1331
                 // we're here so there ARE help tabs!
1332 1332
                 // make sure we've got what we need
1333
-                if (! isset($cfg['title'])) {
1333
+                if ( ! isset($cfg['title'])) {
1334 1334
                     throw new EE_Error(
1335 1335
                         esc_html__(
1336 1336
                             'The _page_config array is not set up properly for help tabs.  It is missing a title',
@@ -1338,7 +1338,7 @@  discard block
 block discarded – undo
1338 1338
                         )
1339 1339
                     );
1340 1340
                 }
1341
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1341
+                if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1342 1342
                     throw new EE_Error(
1343 1343
                         esc_html__(
1344 1344
                             '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',
@@ -1347,11 +1347,11 @@  discard block
 block discarded – undo
1347 1347
                     );
1348 1348
                 }
1349 1349
                 // first priority goes to content.
1350
-                if (! empty($cfg['content'])) {
1350
+                if ( ! empty($cfg['content'])) {
1351 1351
                     $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1352 1352
                     // second priority goes to filename
1353
-                } elseif (! empty($cfg['filename'])) {
1354
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1353
+                } elseif ( ! empty($cfg['filename'])) {
1354
+                    $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php';
1355 1355
                     // 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)
1356 1356
                     $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1357 1357
                                                              . basename($this->_get_dir())
@@ -1359,7 +1359,7 @@  discard block
 block discarded – undo
1359 1359
                                                              . $cfg['filename']
1360 1360
                                                              . '.help_tab.php' : $file_path;
1361 1361
                     // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1362
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1362
+                    if ( ! isset($cfg['callback']) && ! is_readable($file_path)) {
1363 1363
                         EE_Error::add_error(
1364 1364
                             sprintf(
1365 1365
                                 esc_html__(
@@ -1407,7 +1407,7 @@  discard block
 block discarded – undo
1407 1407
                     return;
1408 1408
                 }
1409 1409
                 // setup config array for help tab method
1410
-                $id  = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1410
+                $id  = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id;
1411 1411
                 $_ht = [
1412 1412
                     'id'       => $id,
1413 1413
                     'title'    => $cfg['title'],
@@ -1433,8 +1433,8 @@  discard block
 block discarded – undo
1433 1433
             $qtips = (array) $this->_route_config['qtips'];
1434 1434
             // load qtip loader
1435 1435
             $path = [
1436
-                $this->_get_dir() . '/qtips/',
1437
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1436
+                $this->_get_dir().'/qtips/',
1437
+                EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/',
1438 1438
             ];
1439 1439
             EEH_Qtip_Loader::instance()->register($qtips, $path);
1440 1440
         }
@@ -1456,7 +1456,7 @@  discard block
 block discarded – undo
1456 1456
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1457 1457
         $i = 0;
1458 1458
         foreach ($this->_page_config as $slug => $config) {
1459
-            if (! is_array($config) || empty($config['nav'])) {
1459
+            if ( ! is_array($config) || empty($config['nav'])) {
1460 1460
                 continue;
1461 1461
             }
1462 1462
             // no nav tab for this config
@@ -1465,12 +1465,12 @@  discard block
 block discarded – undo
1465 1465
                 // nav tab is only to appear when route requested.
1466 1466
                 continue;
1467 1467
             }
1468
-            if (! $this->check_user_access($slug, true)) {
1468
+            if ( ! $this->check_user_access($slug, true)) {
1469 1469
                 // no nav tab because current user does not have access.
1470 1470
                 continue;
1471 1471
             }
1472
-            $css_class                = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1473
-            $this->_nav_tabs[ $slug ] = [
1472
+            $css_class                = isset($config['css_class']) ? $config['css_class'].' ' : '';
1473
+            $this->_nav_tabs[$slug] = [
1474 1474
                 'url'       => isset($config['nav']['url'])
1475 1475
                     ? $config['nav']['url']
1476 1476
                     : EE_Admin_Page::add_query_args_and_nonce(
@@ -1482,14 +1482,14 @@  discard block
 block discarded – undo
1482 1482
                     : ucwords(
1483 1483
                         str_replace('_', ' ', $slug)
1484 1484
                     ),
1485
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1485
+                'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class,
1486 1486
                 'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1487 1487
             ];
1488 1488
             $i++;
1489 1489
         }
1490 1490
         // if $this->_nav_tabs is empty then lets set the default
1491 1491
         if (empty($this->_nav_tabs)) {
1492
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = [
1492
+            $this->_nav_tabs[$this->_default_nav_tab_name] = [
1493 1493
                 'url'       => $this->_admin_base_url,
1494 1494
                 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1495 1495
                 'css_class' => 'nav-tab-active',
@@ -1514,10 +1514,10 @@  discard block
 block discarded – undo
1514 1514
             foreach ($this->_route_config['labels'] as $label => $text) {
1515 1515
                 if (is_array($text)) {
1516 1516
                     foreach ($text as $sublabel => $subtext) {
1517
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1517
+                        $this->_labels[$label][$sublabel] = $subtext;
1518 1518
                     }
1519 1519
                 } else {
1520
-                    $this->_labels[ $label ] = $text;
1520
+                    $this->_labels[$label] = $text;
1521 1521
                 }
1522 1522
             }
1523 1523
         }
@@ -1539,10 +1539,10 @@  discard block
 block discarded – undo
1539 1539
     {
1540 1540
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1541 1541
         $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1542
-        $capability     = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1543
-                          && is_array($this->_page_routes[ $route_to_check ])
1544
-                          && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1545
-            ? $this->_page_routes[ $route_to_check ]['capability']
1542
+        $capability     = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check])
1543
+                          && is_array($this->_page_routes[$route_to_check])
1544
+                          && ! empty($this->_page_routes[$route_to_check]['capability'])
1545
+            ? $this->_page_routes[$route_to_check]['capability']
1546 1546
 			: null;
1547 1547
 
1548 1548
         if (empty($capability) && empty($route_to_check)) {
@@ -1596,14 +1596,14 @@  discard block
 block discarded – undo
1596 1596
         string $priority = 'default',
1597 1597
         ?array $callback_args = null
1598 1598
     ) {
1599
-        if (! is_callable($callback)) {
1599
+        if ( ! is_callable($callback)) {
1600 1600
             return;
1601 1601
         }
1602 1602
 
1603 1603
         add_meta_box($box_id, $title, $callback, $screen, $context, $priority, $callback_args);
1604 1604
         add_filter(
1605 1605
             "postbox_classes_{$this->_wp_page_slug}_{$box_id}",
1606
-            function ($classes) {
1606
+            function($classes) {
1607 1607
                 array_push($classes, 'ee-admin-container');
1608 1608
                 return $classes;
1609 1609
             }
@@ -1697,7 +1697,7 @@  discard block
 block discarded – undo
1697 1697
         ';
1698 1698
 
1699 1699
         // current set timezone for timezone js
1700
-        echo '<span id="current_timezone" class="hidden">' . esc_html(EEH_DTT_Helper::get_timezone()) . '</span>';
1700
+        echo '<span id="current_timezone" class="hidden">'.esc_html(EEH_DTT_Helper::get_timezone()).'</span>';
1701 1701
     }
1702 1702
 
1703 1703
 
@@ -1731,7 +1731,7 @@  discard block
 block discarded – undo
1731 1731
         // loop through the array and setup content
1732 1732
         foreach ($help_array as $trigger => $help) {
1733 1733
             // make sure the array is setup properly
1734
-            if (! isset($help['title'], $help['content'])) {
1734
+            if ( ! isset($help['title'], $help['content'])) {
1735 1735
                 throw new EE_Error(
1736 1736
                     esc_html__(
1737 1737
                         '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',
@@ -1745,8 +1745,8 @@  discard block
 block discarded – undo
1745 1745
                 'help_popup_title'   => $help['title'],
1746 1746
                 'help_popup_content' => $help['content'],
1747 1747
             ];
1748
-            $content       .= EEH_Template::display_template(
1749
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1748
+            $content .= EEH_Template::display_template(
1749
+                EE_ADMIN_TEMPLATE.'admin_help_popup.template.php',
1750 1750
                 $template_args,
1751 1751
                 true
1752 1752
             );
@@ -1768,15 +1768,15 @@  discard block
 block discarded – undo
1768 1768
     private function _get_help_content()
1769 1769
     {
1770 1770
         // what is the method we're looking for?
1771
-        $method_name = '_help_popup_content_' . $this->_req_action;
1771
+        $method_name = '_help_popup_content_'.$this->_req_action;
1772 1772
         // if method doesn't exist let's get out.
1773
-        if (! method_exists($this, $method_name)) {
1773
+        if ( ! method_exists($this, $method_name)) {
1774 1774
             return [];
1775 1775
         }
1776 1776
         // k we're good to go let's retrieve the help array
1777 1777
         $help_array = $this->{$method_name}();
1778 1778
         // make sure we've got an array!
1779
-        if (! is_array($help_array)) {
1779
+        if ( ! is_array($help_array)) {
1780 1780
             throw new EE_Error(
1781 1781
                 esc_html__(
1782 1782
                     'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
@@ -1808,8 +1808,8 @@  discard block
 block discarded – undo
1808 1808
         // 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
1809 1809
         $help_array   = $this->_get_help_content();
1810 1810
         $help_content = '';
1811
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1812
-            $help_array[ $trigger_id ] = [
1811
+        if (empty($help_array) || ! isset($help_array[$trigger_id])) {
1812
+            $help_array[$trigger_id] = [
1813 1813
                 'title'   => esc_html__('Missing Content', 'event_espresso'),
1814 1814
                 'content' => esc_html__(
1815 1815
                     '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.)',
@@ -1904,7 +1904,7 @@  discard block
 block discarded – undo
1904 1904
 
1905 1905
         add_filter(
1906 1906
             'admin_body_class',
1907
-            function ($classes) {
1907
+            function($classes) {
1908 1908
                 if (strpos($classes, 'espresso-admin') === false) {
1909 1909
                     $classes .= ' espresso-admin';
1910 1910
                 }
@@ -1995,12 +1995,12 @@  discard block
 block discarded – undo
1995 1995
     protected function _set_list_table()
1996 1996
     {
1997 1997
         // first is this a list_table view?
1998
-        if (! isset($this->_route_config['list_table'])) {
1998
+        if ( ! isset($this->_route_config['list_table'])) {
1999 1999
             return;
2000 2000
         } //not a list_table view so get out.
2001 2001
         // list table functions are per view specific (because some admin pages might have more than one list table!)
2002
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2003
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2002
+        $list_table_view = '_set_list_table_views_'.$this->_req_action;
2003
+        if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2004 2004
             // user error msg
2005 2005
             $error_msg = esc_html__(
2006 2006
                 'An error occurred. The requested list table views could not be found.',
@@ -2020,10 +2020,10 @@  discard block
 block discarded – undo
2020 2020
         }
2021 2021
         // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2022 2022
         $this->_views = apply_filters(
2023
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2023
+            'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action,
2024 2024
             $this->_views
2025 2025
         );
2026
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2026
+        $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views);
2027 2027
         $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2028 2028
         $this->_set_list_table_view();
2029 2029
         $this->_set_list_table_object();
@@ -2058,7 +2058,7 @@  discard block
 block discarded – undo
2058 2058
     protected function _set_list_table_object()
2059 2059
     {
2060 2060
         if (isset($this->_route_config['list_table'])) {
2061
-            if (! class_exists($this->_route_config['list_table'])) {
2061
+            if ( ! class_exists($this->_route_config['list_table'])) {
2062 2062
                 throw new EE_Error(
2063 2063
                     sprintf(
2064 2064
                         esc_html__(
@@ -2096,17 +2096,17 @@  discard block
 block discarded – undo
2096 2096
         foreach ($this->_views as $key => $view) {
2097 2097
             $query_args = [];
2098 2098
             // check for current view
2099
-            $this->_views[ $key ]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2099
+            $this->_views[$key]['class']               = $this->_view === $view['slug'] ? 'current' : '';
2100 2100
             $query_args['action']                        = $this->_req_action;
2101
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2101
+            $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce');
2102 2102
             $query_args['status']                        = $view['slug'];
2103 2103
             // merge any other arguments sent in.
2104
-            if (isset($extra_query_args[ $view['slug'] ])) {
2105
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2104
+            if (isset($extra_query_args[$view['slug']])) {
2105
+                foreach ($extra_query_args[$view['slug']] as $extra_query_arg) {
2106 2106
                     $query_args[] = $extra_query_arg;
2107 2107
                 }
2108 2108
             }
2109
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2109
+            $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2110 2110
         }
2111 2111
         return $this->_views;
2112 2112
     }
@@ -2137,14 +2137,14 @@  discard block
 block discarded – undo
2137 2137
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2138 2138
         foreach ($values as $value) {
2139 2139
             if ($value < $max_entries) {
2140
-                $selected                  = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2140
+                $selected = $value === $per_page ? ' selected="'.$per_page.'"' : '';
2141 2141
                 $entries_per_page_dropdown .= '
2142
-						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2142
+						<option value="' . $value.'"'.$selected.'>'.$value.'&nbsp;&nbsp;</option>';
2143 2143
             }
2144 2144
         }
2145
-        $selected                  = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2145
+        $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : '';
2146 2146
         $entries_per_page_dropdown .= '
2147
-						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2147
+						<option value="' . $max_entries.'"'.$selected.'>All&nbsp;&nbsp;</option>';
2148 2148
         $entries_per_page_dropdown .= '
2149 2149
 					</select>
2150 2150
 					entries
@@ -2168,7 +2168,7 @@  discard block
 block discarded – undo
2168 2168
             empty($this->_search_btn_label) ? $this->page_label
2169 2169
                 : $this->_search_btn_label
2170 2170
         );
2171
-        $this->_template_args['search']['callback']  = 'search_' . $this->page_slug;
2171
+        $this->_template_args['search']['callback'] = 'search_'.$this->page_slug;
2172 2172
     }
2173 2173
 
2174 2174
 
@@ -2256,7 +2256,7 @@  discard block
 block discarded – undo
2256 2256
             $total_columns                                       = ! empty($screen_columns)
2257 2257
                 ? $screen_columns
2258 2258
                 : $this->_route_config['columns'][1];
2259
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2259
+            $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns;
2260 2260
             $this->_template_args['current_page']                = $this->_wp_page_slug;
2261 2261
             $this->_template_args['screen']                      = $this->_current_screen;
2262 2262
             $this->_column_template_path                         = EE_ADMIN_TEMPLATE
@@ -2302,7 +2302,7 @@  discard block
 block discarded – undo
2302 2302
      */
2303 2303
     protected function _espresso_ratings_request()
2304 2304
     {
2305
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2305
+        if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2306 2306
             return;
2307 2307
         }
2308 2308
         $ratings_box_title = apply_filters(
@@ -2329,28 +2329,28 @@  discard block
 block discarded – undo
2329 2329
      */
2330 2330
     public function espresso_ratings_request()
2331 2331
     {
2332
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2332
+        EEH_Template::display_template(EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php');
2333 2333
     }
2334 2334
 
2335 2335
 
2336 2336
     public static function cached_rss_display($rss_id, $url)
2337 2337
     {
2338
-        $loading   = '<p class="widget-loading hide-if-no-js">'
2338
+        $loading = '<p class="widget-loading hide-if-no-js">'
2339 2339
                      . esc_html__('Loading&#8230;', 'event_espresso')
2340 2340
                      . '</p><p class="hide-if-js">'
2341 2341
                      . esc_html__('This widget requires JavaScript.', 'event_espresso')
2342 2342
                      . '</p>';
2343
-        $pre       = '<div class="espresso-rss-display">' . "\n\t";
2344
-        $pre       .= '<span id="' . esc_attr($rss_id) . '_url" class="hidden">' . esc_url_raw($url) . '</span>';
2345
-        $post      = '</div>' . "\n";
2346
-        $cache_key = 'ee_rss_' . md5($rss_id);
2343
+        $pre       = '<div class="espresso-rss-display">'."\n\t";
2344
+        $pre .= '<span id="'.esc_attr($rss_id).'_url" class="hidden">'.esc_url_raw($url).'</span>';
2345
+        $post      = '</div>'."\n";
2346
+        $cache_key = 'ee_rss_'.md5($rss_id);
2347 2347
         $output    = get_transient($cache_key);
2348 2348
         if ($output !== false) {
2349
-            echo $pre . $output . $post; // already escaped
2349
+            echo $pre.$output.$post; // already escaped
2350 2350
             return true;
2351 2351
         }
2352
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2353
-            echo $pre . $loading . $post; // already escaped
2352
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
2353
+            echo $pre.$loading.$post; // already escaped
2354 2354
             return false;
2355 2355
         }
2356 2356
         ob_start();
@@ -2417,19 +2417,19 @@  discard block
 block discarded – undo
2417 2417
     public function espresso_sponsors_post_box()
2418 2418
     {
2419 2419
         EEH_Template::display_template(
2420
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2420
+            EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php'
2421 2421
         );
2422 2422
     }
2423 2423
 
2424 2424
 
2425 2425
     private function _publish_post_box()
2426 2426
     {
2427
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2427
+        $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview';
2428 2428
         // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2429 2429
         // then we'll use that for the metabox label.
2430 2430
         // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2431
-        if (! empty($this->_labels['publishbox'])) {
2432
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2431
+        if ( ! empty($this->_labels['publishbox'])) {
2432
+            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action]
2433 2433
                 : $this->_labels['publishbox'];
2434 2434
         } else {
2435 2435
             $box_label = esc_html__('Publish', 'event_espresso');
@@ -2458,7 +2458,7 @@  discard block
 block discarded – undo
2458 2458
             ? $this->_template_args['publish_box_extra_content']
2459 2459
             : '';
2460 2460
         echo EEH_Template::display_template(
2461
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2461
+            EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php',
2462 2462
             $this->_template_args,
2463 2463
             true
2464 2464
         );
@@ -2546,18 +2546,18 @@  discard block
 block discarded – undo
2546 2546
             );
2547 2547
         }
2548 2548
         $this->_template_args['publish_delete_link'] = $delete_link;
2549
-        if (! empty($name) && ! empty($id)) {
2550
-            $hidden_field_arr[ $name ] = [
2549
+        if ( ! empty($name) && ! empty($id)) {
2550
+            $hidden_field_arr[$name] = [
2551 2551
                 'type'  => 'hidden',
2552 2552
                 'value' => $id,
2553 2553
             ];
2554
-            $hf                        = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2554
+            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2555 2555
         } else {
2556 2556
             $hf = '';
2557 2557
         }
2558 2558
         // add hidden field
2559 2559
         $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2560
-            ? $hf[ $name ]['field']
2560
+            ? $hf[$name]['field']
2561 2561
             : $hf;
2562 2562
     }
2563 2563
 
@@ -2659,7 +2659,7 @@  discard block
 block discarded – undo
2659 2659
         }
2660 2660
         // 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)
2661 2661
         $call_back_func = $create_func
2662
-            ? static function ($post, $metabox) {
2662
+            ? static function($post, $metabox) {
2663 2663
                 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2664 2664
                 echo EEH_Template::display_template(
2665 2665
                     $metabox['args']['template_path'],
@@ -2669,7 +2669,7 @@  discard block
 block discarded – undo
2669 2669
             }
2670 2670
             : $callback;
2671 2671
         $this->addMetaBox(
2672
-            str_replace('_', '-', $action) . '-mbox',
2672
+            str_replace('_', '-', $action).'-mbox',
2673 2673
             $title,
2674 2674
             $call_back_func,
2675 2675
             $this->_wp_page_slug,
@@ -2786,13 +2786,13 @@  discard block
 block discarded – undo
2786 2786
             'event-espresso_page_espresso_',
2787 2787
             '',
2788 2788
             $this->_wp_page_slug
2789
-        ) . ' ' . $this->_req_action . '-route';
2789
+        ).' '.$this->_req_action.'-route';
2790 2790
 
2791 2791
         $template_path = $sidebar
2792 2792
             ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2793
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2793
+            : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php';
2794 2794
         if ($this->request->isAjax()) {
2795
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2795
+            $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php';
2796 2796
         }
2797 2797
         $template_path = ! empty($this->_column_template_path) ? $this->_column_template_path : $template_path;
2798 2798
 
@@ -2826,11 +2826,11 @@  discard block
 block discarded – undo
2826 2826
     public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2827 2827
     {
2828 2828
         // let's generate a default preview action button if there isn't one already present.
2829
-        $this->_labels['buttons']['buy_now']           = esc_html__(
2829
+        $this->_labels['buttons']['buy_now'] = esc_html__(
2830 2830
             'Upgrade to Event Espresso 4 Right Now',
2831 2831
             'event_espresso'
2832 2832
         );
2833
-        $buy_now_url                                   = add_query_arg(
2833
+        $buy_now_url = add_query_arg(
2834 2834
             [
2835 2835
                 'ee_ver'       => 'ee4',
2836 2836
                 'utm_source'   => 'ee4_plugin_admin',
@@ -2850,8 +2850,8 @@  discard block
 block discarded – undo
2850 2850
                 true
2851 2851
             )
2852 2852
             : $this->_template_args['preview_action_button'];
2853
-        $this->_template_args['admin_page_content']    = EEH_Template::display_template(
2854
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2853
+        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2854
+            EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php',
2855 2855
             $this->_template_args,
2856 2856
             true
2857 2857
         );
@@ -2909,7 +2909,7 @@  discard block
 block discarded – undo
2909 2909
         // setup search attributes
2910 2910
         $this->_set_search_attributes();
2911 2911
         $this->_template_args['current_page']     = $this->_wp_page_slug;
2912
-        $template_path                            = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2912
+        $template_path                            = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php';
2913 2913
         $this->_template_args['table_url']        = $this->request->isAjax()
2914 2914
             ? add_query_arg(['noheader' => 'true', 'route' => $this->_req_action], $this->_admin_base_url)
2915 2915
             : add_query_arg(['route' => $this->_req_action], $this->_admin_base_url);
@@ -2917,10 +2917,10 @@  discard block
 block discarded – undo
2917 2917
         $this->_template_args['current_route']    = $this->_req_action;
2918 2918
         $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2919 2919
         $ajax_sorting_callback                    = $this->_list_table_object->get_ajax_sorting_callback();
2920
-        if (! empty($ajax_sorting_callback)) {
2920
+        if ( ! empty($ajax_sorting_callback)) {
2921 2921
             $sortable_list_table_form_fields = wp_nonce_field(
2922
-                $ajax_sorting_callback . '_nonce',
2923
-                $ajax_sorting_callback . '_nonce',
2922
+                $ajax_sorting_callback.'_nonce',
2923
+                $ajax_sorting_callback.'_nonce',
2924 2924
                 false,
2925 2925
                 false
2926 2926
             );
@@ -2937,18 +2937,18 @@  discard block
 block discarded – undo
2937 2937
 
2938 2938
         $hidden_form_fields = $this->_template_args['list_table_hidden_fields'] ?? '';
2939 2939
 
2940
-        $nonce_ref          = $this->_req_action . '_nonce';
2940
+        $nonce_ref          = $this->_req_action.'_nonce';
2941 2941
         $hidden_form_fields .= '
2942
-            <input type="hidden" name="' . $nonce_ref . '" value="' . wp_create_nonce($nonce_ref) . '">';
2942
+            <input type="hidden" name="' . $nonce_ref.'" value="'.wp_create_nonce($nonce_ref).'">';
2943 2943
 
2944
-        $this->_template_args['list_table_hidden_fields']        = $hidden_form_fields;
2944
+        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
2945 2945
         // display message about search results?
2946 2946
         $search = $this->request->getRequestParam('s');
2947 2947
         $this->_template_args['before_list_table'] .= ! empty($search)
2948
-            ? '<p class="ee-search-results">' . sprintf(
2948
+            ? '<p class="ee-search-results">'.sprintf(
2949 2949
                 esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
2950 2950
                 trim($search, '%')
2951
-            ) . '</p>'
2951
+            ).'</p>'
2952 2952
             : '';
2953 2953
         // filter before_list_table template arg
2954 2954
         $this->_template_args['before_list_table'] = apply_filters(
@@ -2982,7 +2982,7 @@  discard block
 block discarded – undo
2982 2982
         // convert to array and filter again
2983 2983
         // arrays are easier to inject new items in a specific location,
2984 2984
         // but would not be backwards compatible, so we have to add a new filter
2985
-        $this->_template_args['after_list_table']   = implode(
2985
+        $this->_template_args['after_list_table'] = implode(
2986 2986
             " \n",
2987 2987
             (array) apply_filters(
2988 2988
                 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
@@ -3037,7 +3037,7 @@  discard block
 block discarded – undo
3037 3037
             $this->page_slug
3038 3038
         );
3039 3039
         return EEH_Template::display_template(
3040
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3040
+            EE_ADMIN_TEMPLATE.'admin_details_legend.template.php',
3041 3041
             $this->_template_args,
3042 3042
             true
3043 3043
         );
@@ -3153,16 +3153,16 @@  discard block
 block discarded – undo
3153 3153
             $this->_template_args['before_admin_page_content'] ?? ''
3154 3154
         );
3155 3155
 
3156
-        $this->_template_args['after_admin_page_content']  = apply_filters(
3156
+        $this->_template_args['after_admin_page_content'] = apply_filters(
3157 3157
             "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3158 3158
             $this->_template_args['after_admin_page_content'] ?? ''
3159 3159
         );
3160
-        $this->_template_args['after_admin_page_content']  .= $this->_set_help_popup_content();
3160
+        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3161 3161
 
3162 3162
         if ($this->request->isAjax()) {
3163 3163
             $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3164 3164
                 // $template_path,
3165
-                EE_ADMIN_TEMPLATE . 'admin_wrapper_ajax.template.php',
3165
+                EE_ADMIN_TEMPLATE.'admin_wrapper_ajax.template.php',
3166 3166
                 $this->_template_args,
3167 3167
                 true
3168 3168
             );
@@ -3171,7 +3171,7 @@  discard block
 block discarded – undo
3171 3171
         // load settings page wrapper template
3172 3172
         $template_path = $about
3173 3173
             ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3174
-            : EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php';
3174
+            : EE_ADMIN_TEMPLATE.'admin_wrapper.template.php';
3175 3175
 
3176 3176
         EEH_Template::display_template($template_path, $this->_template_args);
3177 3177
     }
@@ -3255,12 +3255,12 @@  discard block
 block discarded – undo
3255 3255
         $default_names = ['save', 'save_and_close'];
3256 3256
         $buttons = '';
3257 3257
         foreach ($button_text as $key => $button) {
3258
-            $ref     = $default_names[ $key ];
3259
-            $name    = ! empty($actions) ? $actions[ $key ] : $ref;
3260
-            $buttons .= '<input type="submit" class="button button--primary ' . $ref . '" '
3261
-                        . 'value="' . $button . '" name="' . $name . '" '
3262
-                        . 'id="' . $this->_current_view . '_' . $ref . '" />';
3263
-            if (! $both) {
3258
+            $ref     = $default_names[$key];
3259
+            $name    = ! empty($actions) ? $actions[$key] : $ref;
3260
+            $buttons .= '<input type="submit" class="button button--primary '.$ref.'" '
3261
+                        . 'value="'.$button.'" name="'.$name.'" '
3262
+                        . 'id="'.$this->_current_view.'_'.$ref.'" />';
3263
+            if ( ! $both) {
3264 3264
                 break;
3265 3265
             }
3266 3266
         }
@@ -3300,13 +3300,13 @@  discard block
 block discarded – undo
3300 3300
                 'An error occurred. No action was set for this page\'s form.',
3301 3301
                 'event_espresso'
3302 3302
             );
3303
-            $dev_msg  = $user_msg . "\n"
3303
+            $dev_msg = $user_msg."\n"
3304 3304
                         . sprintf(
3305 3305
                             esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3306 3306
                             __FUNCTION__,
3307 3307
                             __CLASS__
3308 3308
                         );
3309
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3309
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
3310 3310
         }
3311 3311
         // open form
3312 3312
         $action = $this->_admin_base_url;
@@ -3314,9 +3314,9 @@  discard block
 block discarded – undo
3314 3314
             <form name='form' method='post' action='{$action}' id='{$route}_event_form' class='ee-admin-page-form' >
3315 3315
             ";
3316 3316
         // add nonce
3317
-        $nonce                                             =
3318
-            wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3319
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3317
+        $nonce =
3318
+            wp_nonce_field($route.'_nonce', $route.'_nonce', false, false);
3319
+        $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce;
3320 3320
         // add REQUIRED form action
3321 3321
         $hidden_fields = [
3322 3322
             'action' => ['type' => 'hidden', 'value' => $route],
@@ -3329,7 +3329,7 @@  discard block
 block discarded – undo
3329 3329
         $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3330 3330
         // add fields to form
3331 3331
         foreach ((array) $form_fields as $form_field) {
3332
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3332
+            $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field'];
3333 3333
         }
3334 3334
         // close form
3335 3335
         $this->_template_args['after_admin_page_content'] = '</form>';
@@ -3412,12 +3412,12 @@  discard block
 block discarded – undo
3412 3412
         bool $override_overwrite = false
3413 3413
     ) {
3414 3414
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3415
-        $notices      = EE_Error::get_notices(false);
3415
+        $notices = EE_Error::get_notices(false);
3416 3416
         // overwrite default success messages //BUT ONLY if overwrite not overridden
3417
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3417
+        if ( ! $override_overwrite || ! empty($notices['errors'])) {
3418 3418
             EE_Error::overwrite_success();
3419 3419
         }
3420
-        if (! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3420
+        if ( ! $override_overwrite && ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3421 3421
             // how many records affected ? more than one record ? or just one ?
3422 3422
             EE_Error::add_success(
3423 3423
                 sprintf(
@@ -3438,7 +3438,7 @@  discard block
 block discarded – undo
3438 3438
             );
3439 3439
         }
3440 3440
         // check that $query_args isn't something crazy
3441
-        if (! is_array($query_args)) {
3441
+        if ( ! is_array($query_args)) {
3442 3442
             $query_args = [];
3443 3443
         }
3444 3444
         /**
@@ -3470,7 +3470,7 @@  discard block
 block discarded – undo
3470 3470
             $redirect_url = admin_url('admin.php');
3471 3471
         }
3472 3472
         // merge any default query_args set in _default_route_query_args property
3473
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3473
+        if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3474 3474
             $args_to_merge = [];
3475 3475
             foreach ($this->_default_route_query_args as $query_param => $query_value) {
3476 3476
                 // is there a wp_referer array in our _default_route_query_args property?
@@ -3482,15 +3482,15 @@  discard block
 block discarded – undo
3482 3482
                         }
3483 3483
                         // finally we will override any arguments in the referer with
3484 3484
                         // what might be set on the _default_route_query_args array.
3485
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3486
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3485
+                        if (isset($this->_default_route_query_args[$reference])) {
3486
+                            $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
3487 3487
                         } else {
3488
-                            $args_to_merge[ $reference ] = urlencode($value);
3488
+                            $args_to_merge[$reference] = urlencode($value);
3489 3489
                         }
3490 3490
                     }
3491 3491
                     continue;
3492 3492
                 }
3493
-                $args_to_merge[ $query_param ] = $query_value;
3493
+                $args_to_merge[$query_param] = $query_value;
3494 3494
             }
3495 3495
             // now let's merge these arguments but override with what was specifically sent in to the
3496 3496
             // redirect.
@@ -3502,19 +3502,19 @@  discard block
 block discarded – undo
3502 3502
         if (isset($query_args['action'])) {
3503 3503
             // manually generate wp_nonce and merge that with the query vars
3504 3504
             // becuz the wp_nonce_url function wrecks havoc on some vars
3505
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3505
+            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce');
3506 3506
         }
3507 3507
         // we're adding some hooks and filters in here for processing any things just before redirects
3508 3508
         // (example: an admin page has done an insert or update and we want to run something after that).
3509
-        do_action('AHEE_redirect_' . $this->class_name . $this->_req_action, $query_args);
3509
+        do_action('AHEE_redirect_'.$this->class_name.$this->_req_action, $query_args);
3510 3510
         $redirect_url = apply_filters(
3511
-            'FHEE_redirect_' . $this->class_name . $this->_req_action,
3511
+            'FHEE_redirect_'.$this->class_name.$this->_req_action,
3512 3512
             EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3513 3513
             $query_args
3514 3514
         );
3515 3515
         // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3516 3516
         if ($this->request->isAjax()) {
3517
-            $default_data                    = [
3517
+            $default_data = [
3518 3518
                 'close'        => true,
3519 3519
                 'redirect_url' => $redirect_url,
3520 3520
                 'where'        => 'main',
@@ -3564,7 +3564,7 @@  discard block
 block discarded – undo
3564 3564
         }
3565 3565
         $this->_template_args['notices'] = EE_Error::get_notices();
3566 3566
         // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3567
-        if (! $this->request->isAjax() || $sticky_notices) {
3567
+        if ( ! $this->request->isAjax() || $sticky_notices) {
3568 3568
             $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3569 3569
             $this->_add_transient(
3570 3570
                 $route,
@@ -3604,7 +3604,7 @@  discard block
 block discarded – undo
3604 3604
         $exclude_nonce = false
3605 3605
     ) {
3606 3606
         // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3607
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3607
+        if (empty($base_url) && ! isset($this->_page_routes[$action])) {
3608 3608
             throw new EE_Error(
3609 3609
                 sprintf(
3610 3610
                     esc_html__(
@@ -3615,7 +3615,7 @@  discard block
 block discarded – undo
3615 3615
                 )
3616 3616
             );
3617 3617
         }
3618
-        if (! isset($this->_labels['buttons'][ $type ])) {
3618
+        if ( ! isset($this->_labels['buttons'][$type])) {
3619 3619
             throw new EE_Error(
3620 3620
                 sprintf(
3621 3621
                     esc_html__(
@@ -3628,7 +3628,7 @@  discard block
 block discarded – undo
3628 3628
         }
3629 3629
         // finally check user access for this button.
3630 3630
         $has_access = $this->check_user_access($action, true);
3631
-        if (! $has_access) {
3631
+        if ( ! $has_access) {
3632 3632
             return '';
3633 3633
         }
3634 3634
         $_base_url  = ! $base_url ? $this->_admin_base_url : $base_url;
@@ -3636,11 +3636,11 @@  discard block
 block discarded – undo
3636 3636
             'action' => $action,
3637 3637
         ];
3638 3638
         // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3639
-        if (! empty($extra_request)) {
3639
+        if ( ! empty($extra_request)) {
3640 3640
             $query_args = array_merge($extra_request, $query_args);
3641 3641
         }
3642 3642
         $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3643
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3643
+        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class);
3644 3644
     }
3645 3645
 
3646 3646
 
@@ -3666,7 +3666,7 @@  discard block
 block discarded – undo
3666 3666
                 'FHEE__EE_Admin_Page___per_page_screen_options__default',
3667 3667
                 20
3668 3668
             ),
3669
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3669
+            'option'  => $this->_current_page.'_'.$this->_current_view.'_per_page',
3670 3670
         ];
3671 3671
         // ONLY add the screen option if the user has access to it.
3672 3672
         if ($this->check_user_access($this->_current_view, true)) {
@@ -3687,18 +3687,18 @@  discard block
 block discarded – undo
3687 3687
     {
3688 3688
         if ($this->request->requestParamIsSet('wp_screen_options')) {
3689 3689
             check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3690
-            if (! $user = wp_get_current_user()) {
3690
+            if ( ! $user = wp_get_current_user()) {
3691 3691
                 return;
3692 3692
             }
3693 3693
             $option = $this->request->getRequestParam('wp_screen_options[option]', '', 'key');
3694
-            if (! $option) {
3694
+            if ( ! $option) {
3695 3695
                 return;
3696 3696
             }
3697
-            $value  = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3697
+            $value = $this->request->getRequestParam('wp_screen_options[value]', 0, 'int');
3698 3698
             $map_option = $option;
3699 3699
             $option     = str_replace('-', '_', $option);
3700 3700
             switch ($map_option) {
3701
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3701
+                case $this->_current_page.'_'.$this->_current_view.'_per_page':
3702 3702
                     $max_value = apply_filters(
3703 3703
                         'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3704 3704
                         999,
@@ -3755,13 +3755,13 @@  discard block
 block discarded – undo
3755 3755
     protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3756 3756
     {
3757 3757
         $user_id = get_current_user_id();
3758
-        if (! $skip_route_verify) {
3758
+        if ( ! $skip_route_verify) {
3759 3759
             $this->_verify_route($route);
3760 3760
         }
3761 3761
         // now let's set the string for what kind of transient we're setting
3762 3762
         $transient = $notices
3763
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3764
-            : 'rte_tx_' . $route . '_' . $user_id;
3763
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3764
+            : 'rte_tx_'.$route.'_'.$user_id;
3765 3765
         $data      = $notices ? ['notices' => $data] : $data;
3766 3766
         // is there already a transient for this route?  If there is then let's ADD to that transient
3767 3767
         $existing = is_multisite() && is_network_admin()
@@ -3790,8 +3790,8 @@  discard block
 block discarded – undo
3790 3790
         $user_id   = get_current_user_id();
3791 3791
         $route     = ! $route ? $this->_req_action : $route;
3792 3792
         $transient = $notices
3793
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3794
-            : 'rte_tx_' . $route . '_' . $user_id;
3793
+            ? 'ee_rte_n_tx_'.$route.'_'.$user_id
3794
+            : 'rte_tx_'.$route.'_'.$user_id;
3795 3795
         $data      = is_multisite() && is_network_admin()
3796 3796
             ? get_site_transient($transient)
3797 3797
             : get_transient($transient);
@@ -4027,7 +4027,7 @@  discard block
 block discarded – undo
4027 4027
      */
4028 4028
     protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4029 4029
     {
4030
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4030
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
4031 4031
     }
4032 4032
 
4033 4033
 
@@ -4040,7 +4040,7 @@  discard block
 block discarded – undo
4040 4040
      */
4041 4041
     protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4042 4042
     {
4043
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4043
+        return '<a class="'.$class.'" href="'.$url.'"></a>';
4044 4044
     }
4045 4045
 
4046 4046
 
@@ -4188,7 +4188,7 @@  discard block
 block discarded – undo
4188 4188
         ?callable $callback = null
4189 4189
     ): bool {
4190 4190
         $entity_ID = absint($entity_ID);
4191
-        if (! $entity_ID) {
4191
+        if ( ! $entity_ID) {
4192 4192
             $this->trashRestoreDeleteError($action, $entity_model);
4193 4193
         }
4194 4194
         $result = 0;
@@ -4234,7 +4234,7 @@  discard block
 block discarded – undo
4234 4234
                 )
4235 4235
             );
4236 4236
         }
4237
-        if (! $entity_model->has_field($delete_column)) {
4237
+        if ( ! $entity_model->has_field($delete_column)) {
4238 4238
             throw new DomainException(
4239 4239
                 sprintf(
4240 4240
                     esc_html__(
Please login to merge, or discard this patch.
core/services/json/JsonDataHandler.php 1 patch
Indentation   +331 added lines, -331 removed lines patch added patch discarded remove patch
@@ -14,212 +14,212 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class JsonDataHandler
16 16
 {
17
-    const DATA_TYPE_ARRAY     = 'array';
18
-
19
-    const DATA_TYPE_OBJECT    = 'object';
20
-
21
-    const DATA_TYPE_USE_FLAGS = 'flags';
22
-
23
-    const NO_ERROR_MSG        = 'No error';
24
-
25
-    /**
26
-     * @var string|null
27
-     */
28
-    private $data_type = null;
29
-
30
-    /**
31
-     * @var array|stdClass|null
32
-     */
33
-    private $decoded_data = null;
34
-
35
-    /**
36
-     * JSON_BIGINT_AS_STRING,
37
-     * JSON_INVALID_UTF8_IGNORE,
38
-     * JSON_INVALID_UTF8_SUBSTITUTE,
39
-     * JSON_OBJECT_AS_ARRAY,
40
-     * JSON_THROW_ON_ERROR
41
-     *
42
-     * @var int
43
-     */
44
-    private $decode_flags = 0;
45
-
46
-    /**
47
-     * @var int
48
-     */
49
-    private $depth = 512;
50
-
51
-    /**
52
-     * @var string
53
-     */
54
-    private $encoded_data = '';
55
-
56
-    /**
57
-     * JSON_FORCE_OBJECT,
58
-     * JSON_HEX_QUOT,
59
-     * JSON_HEX_TAG,
60
-     * JSON_HEX_AMP,
61
-     * JSON_HEX_APOS,
62
-     * JSON_INVALID_UTF8_IGNORE,
63
-     * JSON_INVALID_UTF8_SUBSTITUTE,
64
-     * JSON_NUMERIC_CHECK,
65
-     * JSON_PARTIAL_OUTPUT_ON_ERROR,
66
-     * JSON_PRESERVE_ZERO_FRACTION,
67
-     * JSON_PRETTY_PRINT,
68
-     * JSON_UNESCAPED_LINE_TERMINATORS,
69
-     * JSON_UNESCAPED_SLASHES,
70
-     * JSON_UNESCAPED_UNICODE,
71
-     * JSON_THROW_ON_ERROR.
72
-     *
73
-     * @var int
74
-     */
75
-    private $encode_flags = 0;
76
-
77
-    /**
78
-     * @var int
79
-     */
80
-    private $last_error_code = JSON_ERROR_NONE;
81
-
82
-    /**
83
-     * @var string
84
-     */
85
-    private $last_error_msg = JsonDataHandler::NO_ERROR_MSG;
86
-
87
-
88
-    /**
89
-     * JsonDataHandler constructor.
90
-     */
91
-    public function __construct()
92
-    {
93
-        if (! defined('JSON_INVALID_UTF8_IGNORE')) {
94
-            define('JSON_INVALID_UTF8_IGNORE', 1048576);
95
-        }
96
-        if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
97
-            define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152);
98
-        }
99
-        if (! defined('JSON_THROW_ON_ERROR')) {
100
-            define('JSON_THROW_ON_ERROR', 4194304);
101
-        }
102
-    }
103
-
104
-
105
-    /**
106
-     * set $data_type, $decode_flags, $encode_flags, and depth all in one shot
107
-     *
108
-     * @param string $data_type
109
-     * @param int    $decode_flags
110
-     * @param int    $encode_flags
111
-     * @param int    $depth
112
-     */
113
-    public function configure(
114
-        string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS,
115
-        int $decode_flags = 0,
116
-        int $encode_flags = 0,
117
-        int $depth = 512
118
-    ) {
119
-        $this->setDataType($data_type);
120
-        $this->setDecodeFlags($decode_flags);
121
-        $this->setDepth($depth);
122
-        $this->setEncodeFlags($encode_flags);
123
-    }
124
-
125
-
126
-    /**
127
-     * @param string $data_type
128
-     */
129
-    public function setDataType(string $data_type): void
130
-    {
131
-        $this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY
132
-                           || $data_type === JsonDataHandler::DATA_TYPE_OBJECT
133
-                           || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS
134
-            ? $data_type
135
-            : JsonDataHandler::DATA_TYPE_USE_FLAGS;
136
-    }
137
-
138
-
139
-    /**
140
-     * One or more Bitmask values:
141
-     * JSON_BIGINT_AS_STRING,
142
-     * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
143
-     * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
144
-     * JSON_OBJECT_AS_ARRAY,
145
-     * JSON_THROW_ON_ERROR              PHP >= 7.3
146
-     *
147
-     * pass multiple values separated with |
148
-     * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY
149
-     *
150
-     * @param int $decode_flags
151
-     */
152
-    public function setDecodeFlags(int $decode_flags): void
153
-    {
154
-        $this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING
155
-                              || $decode_flags === JSON_OBJECT_AS_ARRAY
156
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
157
-                              || $decode_flags === JSON_INVALID_UTF8_IGNORE
158
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
159
-                              || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE
160
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
161
-                              || $decode_flags === JSON_THROW_ON_ERROR
162
-            ? $decode_flags
163
-            : 0;
164
-    }
165
-
166
-
167
-    /**
168
-     * @param int $depth
169
-     */
170
-    public function setDepth(int $depth): void
171
-    {
172
-        $depth       = absint($depth);
173
-        $this->depth = $depth ?: 512;
174
-    }
175
-
176
-
177
-    /**
178
-     * One or more Bitmask values:
179
-     * JSON_FORCE_OBJECT,
180
-     * JSON_HEX_QUOT,
181
-     * JSON_HEX_TAG,
182
-     * JSON_HEX_AMP,
183
-     * JSON_HEX_APOS,
184
-     * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
185
-     * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
186
-     * JSON_NUMERIC_CHECK,
187
-     * JSON_PARTIAL_OUTPUT_ON_ERROR,
188
-     * JSON_PRESERVE_ZERO_FRACTION,
189
-     * JSON_PRETTY_PRINT,
190
-     * JSON_UNESCAPED_LINE_TERMINATORS,
191
-     * JSON_UNESCAPED_SLASHES,
192
-     * JSON_UNESCAPED_UNICODE,
193
-     * JSON_THROW_ON_ERROR.             PHP >= 7.3
194
-     *
195
-     * pass multiple values separated with |
196
-     * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR
197
-     *
198
-     * @param int $encode_flags
199
-     */
200
-    public function setEncodeFlags(int $encode_flags): void
201
-    {
202
-        $this->encode_flags = $encode_flags === JSON_FORCE_OBJECT
203
-                              || $encode_flags === JSON_HEX_QUOT
204
-                              || $encode_flags === JSON_HEX_TAG
205
-                              || $encode_flags === JSON_HEX_AMP
206
-                              || $encode_flags === JSON_HEX_APOS
207
-                              || $encode_flags === JSON_NUMERIC_CHECK
208
-                              || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR
209
-                              || $encode_flags === JSON_PRESERVE_ZERO_FRACTION
210
-                              || $encode_flags === JSON_PRETTY_PRINT
211
-                              || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS
212
-                              || $encode_flags === JSON_UNESCAPED_SLASHES
213
-                              || $encode_flags === JSON_UNESCAPED_UNICODE
214
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
215
-                              || $encode_flags === JSON_INVALID_UTF8_IGNORE
216
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
217
-                              || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE
218
-                              // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
219
-                              || $encode_flags === JSON_THROW_ON_ERROR
220
-            ? $encode_flags
221
-            : 0;
222
-    }
17
+	const DATA_TYPE_ARRAY     = 'array';
18
+
19
+	const DATA_TYPE_OBJECT    = 'object';
20
+
21
+	const DATA_TYPE_USE_FLAGS = 'flags';
22
+
23
+	const NO_ERROR_MSG        = 'No error';
24
+
25
+	/**
26
+	 * @var string|null
27
+	 */
28
+	private $data_type = null;
29
+
30
+	/**
31
+	 * @var array|stdClass|null
32
+	 */
33
+	private $decoded_data = null;
34
+
35
+	/**
36
+	 * JSON_BIGINT_AS_STRING,
37
+	 * JSON_INVALID_UTF8_IGNORE,
38
+	 * JSON_INVALID_UTF8_SUBSTITUTE,
39
+	 * JSON_OBJECT_AS_ARRAY,
40
+	 * JSON_THROW_ON_ERROR
41
+	 *
42
+	 * @var int
43
+	 */
44
+	private $decode_flags = 0;
45
+
46
+	/**
47
+	 * @var int
48
+	 */
49
+	private $depth = 512;
50
+
51
+	/**
52
+	 * @var string
53
+	 */
54
+	private $encoded_data = '';
55
+
56
+	/**
57
+	 * JSON_FORCE_OBJECT,
58
+	 * JSON_HEX_QUOT,
59
+	 * JSON_HEX_TAG,
60
+	 * JSON_HEX_AMP,
61
+	 * JSON_HEX_APOS,
62
+	 * JSON_INVALID_UTF8_IGNORE,
63
+	 * JSON_INVALID_UTF8_SUBSTITUTE,
64
+	 * JSON_NUMERIC_CHECK,
65
+	 * JSON_PARTIAL_OUTPUT_ON_ERROR,
66
+	 * JSON_PRESERVE_ZERO_FRACTION,
67
+	 * JSON_PRETTY_PRINT,
68
+	 * JSON_UNESCAPED_LINE_TERMINATORS,
69
+	 * JSON_UNESCAPED_SLASHES,
70
+	 * JSON_UNESCAPED_UNICODE,
71
+	 * JSON_THROW_ON_ERROR.
72
+	 *
73
+	 * @var int
74
+	 */
75
+	private $encode_flags = 0;
76
+
77
+	/**
78
+	 * @var int
79
+	 */
80
+	private $last_error_code = JSON_ERROR_NONE;
81
+
82
+	/**
83
+	 * @var string
84
+	 */
85
+	private $last_error_msg = JsonDataHandler::NO_ERROR_MSG;
86
+
87
+
88
+	/**
89
+	 * JsonDataHandler constructor.
90
+	 */
91
+	public function __construct()
92
+	{
93
+		if (! defined('JSON_INVALID_UTF8_IGNORE')) {
94
+			define('JSON_INVALID_UTF8_IGNORE', 1048576);
95
+		}
96
+		if (! defined('JSON_INVALID_UTF8_SUBSTITUTE')) {
97
+			define('JSON_INVALID_UTF8_SUBSTITUTE', 2097152);
98
+		}
99
+		if (! defined('JSON_THROW_ON_ERROR')) {
100
+			define('JSON_THROW_ON_ERROR', 4194304);
101
+		}
102
+	}
103
+
104
+
105
+	/**
106
+	 * set $data_type, $decode_flags, $encode_flags, and depth all in one shot
107
+	 *
108
+	 * @param string $data_type
109
+	 * @param int    $decode_flags
110
+	 * @param int    $encode_flags
111
+	 * @param int    $depth
112
+	 */
113
+	public function configure(
114
+		string $data_type = JsonDataHandler::DATA_TYPE_USE_FLAGS,
115
+		int $decode_flags = 0,
116
+		int $encode_flags = 0,
117
+		int $depth = 512
118
+	) {
119
+		$this->setDataType($data_type);
120
+		$this->setDecodeFlags($decode_flags);
121
+		$this->setDepth($depth);
122
+		$this->setEncodeFlags($encode_flags);
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param string $data_type
128
+	 */
129
+	public function setDataType(string $data_type): void
130
+	{
131
+		$this->data_type = $data_type === JsonDataHandler::DATA_TYPE_ARRAY
132
+						   || $data_type === JsonDataHandler::DATA_TYPE_OBJECT
133
+						   || $data_type === JsonDataHandler::DATA_TYPE_USE_FLAGS
134
+			? $data_type
135
+			: JsonDataHandler::DATA_TYPE_USE_FLAGS;
136
+	}
137
+
138
+
139
+	/**
140
+	 * One or more Bitmask values:
141
+	 * JSON_BIGINT_AS_STRING,
142
+	 * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
143
+	 * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
144
+	 * JSON_OBJECT_AS_ARRAY,
145
+	 * JSON_THROW_ON_ERROR              PHP >= 7.3
146
+	 *
147
+	 * pass multiple values separated with |
148
+	 * ex: JSON_BIGINT_AS_STRING | JSON_INVALID_UTF8_IGNORE | JSON_OBJECT_AS_ARRAY
149
+	 *
150
+	 * @param int $decode_flags
151
+	 */
152
+	public function setDecodeFlags(int $decode_flags): void
153
+	{
154
+		$this->decode_flags = $decode_flags === JSON_BIGINT_AS_STRING
155
+							  || $decode_flags === JSON_OBJECT_AS_ARRAY
156
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
157
+							  || $decode_flags === JSON_INVALID_UTF8_IGNORE
158
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
159
+							  || $decode_flags === JSON_INVALID_UTF8_SUBSTITUTE
160
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
161
+							  || $decode_flags === JSON_THROW_ON_ERROR
162
+			? $decode_flags
163
+			: 0;
164
+	}
165
+
166
+
167
+	/**
168
+	 * @param int $depth
169
+	 */
170
+	public function setDepth(int $depth): void
171
+	{
172
+		$depth       = absint($depth);
173
+		$this->depth = $depth ?: 512;
174
+	}
175
+
176
+
177
+	/**
178
+	 * One or more Bitmask values:
179
+	 * JSON_FORCE_OBJECT,
180
+	 * JSON_HEX_QUOT,
181
+	 * JSON_HEX_TAG,
182
+	 * JSON_HEX_AMP,
183
+	 * JSON_HEX_APOS,
184
+	 * JSON_INVALID_UTF8_IGNORE,        PHP >= 7.2
185
+	 * JSON_INVALID_UTF8_SUBSTITUTE,    PHP >= 7.2
186
+	 * JSON_NUMERIC_CHECK,
187
+	 * JSON_PARTIAL_OUTPUT_ON_ERROR,
188
+	 * JSON_PRESERVE_ZERO_FRACTION,
189
+	 * JSON_PRETTY_PRINT,
190
+	 * JSON_UNESCAPED_LINE_TERMINATORS,
191
+	 * JSON_UNESCAPED_SLASHES,
192
+	 * JSON_UNESCAPED_UNICODE,
193
+	 * JSON_THROW_ON_ERROR.             PHP >= 7.3
194
+	 *
195
+	 * pass multiple values separated with |
196
+	 * ex: JSON_FORCE_OBJECT | JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR
197
+	 *
198
+	 * @param int $encode_flags
199
+	 */
200
+	public function setEncodeFlags(int $encode_flags): void
201
+	{
202
+		$this->encode_flags = $encode_flags === JSON_FORCE_OBJECT
203
+							  || $encode_flags === JSON_HEX_QUOT
204
+							  || $encode_flags === JSON_HEX_TAG
205
+							  || $encode_flags === JSON_HEX_AMP
206
+							  || $encode_flags === JSON_HEX_APOS
207
+							  || $encode_flags === JSON_NUMERIC_CHECK
208
+							  || $encode_flags === JSON_PARTIAL_OUTPUT_ON_ERROR
209
+							  || $encode_flags === JSON_PRESERVE_ZERO_FRACTION
210
+							  || $encode_flags === JSON_PRETTY_PRINT
211
+							  || $encode_flags === JSON_UNESCAPED_LINE_TERMINATORS
212
+							  || $encode_flags === JSON_UNESCAPED_SLASHES
213
+							  || $encode_flags === JSON_UNESCAPED_UNICODE
214
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_ignoreFound
215
+							  || $encode_flags === JSON_INVALID_UTF8_IGNORE
216
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_invalid_utf8_substituteFound
217
+							  || $encode_flags === JSON_INVALID_UTF8_SUBSTITUTE
218
+							  // phpcs:ignore PHPCompatibility.Constants.NewConstants.json_throw_on_errorFound
219
+							  || $encode_flags === JSON_THROW_ON_ERROR
220
+			? $encode_flags
221
+			: 0;
222
+	}
223 223
 
224 224
 
225 225
 	/**
@@ -231,129 +231,129 @@  discard block
 block discarded – undo
231 231
 	}
232 232
 
233 233
 
234
-    /**
235
-     * @return bool|null
236
-     */
237
-    private function asAssociative(): ?bool
238
-    {
239
-        switch ($this->data_type) {
240
-            case JsonDataHandler::DATA_TYPE_ARRAY:
241
-                return true;
242
-            case JsonDataHandler::DATA_TYPE_OBJECT:
243
-                return false;
244
-            case JsonDataHandler::DATA_TYPE_USE_FLAGS:
245
-                return null;
246
-        }
247
-        return null;
248
-    }
249
-
250
-
251
-    /**
252
-     * @param array|string $json
253
-     * @return array|mixed|stdClass
254
-     */
255
-    public function decodeJson($json)
256
-    {
257
-        $this->resetErrors();
258
-        if ($this->isJson($json)) {
259
-            $this->decoded_data    = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags);
260
-            $this->last_error_code = json_last_error();
261
-            $this->last_error_msg  = json_last_error_msg();
262
-        } else {
263
-            $this->decoded_data    = $json;
264
-            $this->last_error_code = JSON_ERROR_NONE;
265
-            $this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
266
-        }
267
-        return $this->decoded_data;
268
-    }
269
-
270
-
271
-    /**
272
-     * @param $data
273
-     * @return string
274
-     */
275
-    public function encodeData($data): string
276
-    {
277
-        $this->resetErrors();
278
-        if ($this->isJson($data)) {
279
-            $this->encoded_data = $data;
280
-            $this->last_error_code = JSON_ERROR_NONE;
281
-            $this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
282
-        } else {
283
-            $this->encoded_data = json_encode($data, $this->encode_flags, $this->depth);
284
-            $this->last_error_code = json_last_error();
285
-            $this->last_error_msg  = json_last_error_msg();
286
-        }
287
-        return $this->encoded_data ?: '{}';
288
-    }
289
-
290
-
291
-    /**
292
-     * @return array|stdClass
293
-     */
294
-    public function getDecodedData()
295
-    {
296
-        return $this->decoded_data;
297
-    }
298
-
299
-
300
-    /**
301
-     * @return string
302
-     */
303
-    public function getEncodedData(): string
304
-    {
305
-        return $this->encoded_data;
306
-    }
307
-
308
-
309
-    /**
310
-     * @param bool $reset
311
-     * @return int
312
-     */
313
-    public function getLastErrorCode(bool $reset = false): int
314
-    {
315
-        $last_error = $this->last_error_code;
316
-        if ($reset) {
317
-            $this->resetErrors();
318
-        }
319
-        return $last_error;
320
-    }
321
-
322
-
323
-    /**
324
-     * @param bool $reset
325
-     * @return string
326
-     */
327
-    public function getLastErrorMessage(bool $reset = false): string
328
-    {
329
-        $last_error = $this->last_error_msg;
330
-        if ($reset) {
331
-            $this->resetErrors();
332
-        }
333
-        return $last_error;
334
-    }
335
-
336
-
337
-    /**
338
-     * @param array|string $maybe_json
339
-     * @return bool
340
-     */
341
-    public function isJson($maybe_json): bool
342
-    {
343
-        if (! is_string($maybe_json)) {
344
-            return false;
345
-        }
346
-        $decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags);
347
-        return json_last_error() === JSON_ERROR_NONE && ! ($decoded === null && ! empty($maybe_json));
348
-    }
349
-
350
-
351
-    /**
352
-     * @since $VID:$
353
-     */
354
-    public function resetErrors()
355
-    {
356
-        $this->last_error_code = JSON_ERROR_NONE;
357
-        $this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
358
-    }
234
+	/**
235
+	 * @return bool|null
236
+	 */
237
+	private function asAssociative(): ?bool
238
+	{
239
+		switch ($this->data_type) {
240
+			case JsonDataHandler::DATA_TYPE_ARRAY:
241
+				return true;
242
+			case JsonDataHandler::DATA_TYPE_OBJECT:
243
+				return false;
244
+			case JsonDataHandler::DATA_TYPE_USE_FLAGS:
245
+				return null;
246
+		}
247
+		return null;
248
+	}
249
+
250
+
251
+	/**
252
+	 * @param array|string $json
253
+	 * @return array|mixed|stdClass
254
+	 */
255
+	public function decodeJson($json)
256
+	{
257
+		$this->resetErrors();
258
+		if ($this->isJson($json)) {
259
+			$this->decoded_data    = json_decode($json, $this->asAssociative(), $this->depth, $this->decode_flags);
260
+			$this->last_error_code = json_last_error();
261
+			$this->last_error_msg  = json_last_error_msg();
262
+		} else {
263
+			$this->decoded_data    = $json;
264
+			$this->last_error_code = JSON_ERROR_NONE;
265
+			$this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
266
+		}
267
+		return $this->decoded_data;
268
+	}
269
+
270
+
271
+	/**
272
+	 * @param $data
273
+	 * @return string
274
+	 */
275
+	public function encodeData($data): string
276
+	{
277
+		$this->resetErrors();
278
+		if ($this->isJson($data)) {
279
+			$this->encoded_data = $data;
280
+			$this->last_error_code = JSON_ERROR_NONE;
281
+			$this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
282
+		} else {
283
+			$this->encoded_data = json_encode($data, $this->encode_flags, $this->depth);
284
+			$this->last_error_code = json_last_error();
285
+			$this->last_error_msg  = json_last_error_msg();
286
+		}
287
+		return $this->encoded_data ?: '{}';
288
+	}
289
+
290
+
291
+	/**
292
+	 * @return array|stdClass
293
+	 */
294
+	public function getDecodedData()
295
+	{
296
+		return $this->decoded_data;
297
+	}
298
+
299
+
300
+	/**
301
+	 * @return string
302
+	 */
303
+	public function getEncodedData(): string
304
+	{
305
+		return $this->encoded_data;
306
+	}
307
+
308
+
309
+	/**
310
+	 * @param bool $reset
311
+	 * @return int
312
+	 */
313
+	public function getLastErrorCode(bool $reset = false): int
314
+	{
315
+		$last_error = $this->last_error_code;
316
+		if ($reset) {
317
+			$this->resetErrors();
318
+		}
319
+		return $last_error;
320
+	}
321
+
322
+
323
+	/**
324
+	 * @param bool $reset
325
+	 * @return string
326
+	 */
327
+	public function getLastErrorMessage(bool $reset = false): string
328
+	{
329
+		$last_error = $this->last_error_msg;
330
+		if ($reset) {
331
+			$this->resetErrors();
332
+		}
333
+		return $last_error;
334
+	}
335
+
336
+
337
+	/**
338
+	 * @param array|string $maybe_json
339
+	 * @return bool
340
+	 */
341
+	public function isJson($maybe_json): bool
342
+	{
343
+		if (! is_string($maybe_json)) {
344
+			return false;
345
+		}
346
+		$decoded = json_decode($maybe_json, $this->asAssociative(), $this->depth, $this->decode_flags);
347
+		return json_last_error() === JSON_ERROR_NONE && ! ($decoded === null && ! empty($maybe_json));
348
+	}
349
+
350
+
351
+	/**
352
+	 * @since $VID:$
353
+	 */
354
+	public function resetErrors()
355
+	{
356
+		$this->last_error_code = JSON_ERROR_NONE;
357
+		$this->last_error_msg  = JsonDataHandler::NO_ERROR_MSG;
358
+	}
359 359
 }
Please login to merge, or discard this patch.
core/services/json/JsonDataWordpressOption.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -15,15 +15,15 @@  discard block
 block discarded – undo
15 15
  */
16 16
 abstract class JsonDataWordpressOption extends WordPressOption
17 17
 {
18
-    /**
18
+	/**
19 19
 	 * @var array|mixed|stdClass
20 20
 	 */
21
-    private $options = [];
21
+	private $options = [];
22 22
 
23
-    /**
24
-     * @var JsonDataHandler|null
25
-     */
26
-    private ?JsonDataHandler $json_data_handler;
23
+	/**
24
+	 * @var JsonDataHandler|null
25
+	 */
26
+	private ?JsonDataHandler $json_data_handler;
27 27
 
28 28
 
29 29
 	/**
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
 		$default_value,
41 41
 		bool $autoload = false
42 42
 	) {
43
-        $this->json_data_handler = $json_data_handler;
43
+		$this->json_data_handler = $json_data_handler;
44 44
 		if (! $this->json_data_handler->dataType()) {
45 45
 			$this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
46 46
 		}
47
-        parent::__construct($option_name, $default_value, $autoload);
48
-    }
47
+		parent::__construct($option_name, $default_value, $autoload);
48
+	}
49 49
 
50 50
 
51 51
 	/**
@@ -53,59 +53,59 @@  discard block
 block discarded – undo
53 53
 	 * @return int
54 54
 	 */
55 55
 	public function updateOption($value): int
56
-    {
57
-        if (parent::updateOption($this->json_data_handler->encodeData($value))) {
58
-            $this->options = $value;
56
+	{
57
+		if (parent::updateOption($this->json_data_handler->encodeData($value))) {
58
+			$this->options = $value;
59 59
 			return WordPressOption::UPDATE_SUCCESS;
60 60
 		}
61 61
 		return WordPressOption::UPDATE_ERROR;
62
-    }
63
-
64
-
65
-    /**
66
-     * @param string $property
67
-     * @param mixed  $value
68
-     * @return void
69
-     */
70
-    public function addProperty(string $property, $value)
71
-    {
72
-        $options = $this->getAll();
73
-        $options->{$property} = $value;
74
-        $this->updateOption($options);
75
-    }
76
-
77
-
78
-    /**
79
-     * @param string $property
80
-     * @return mixed
81
-     */
82
-    public function getProperty(string $property)
83
-    {
84
-        $options = $this->getAll();
85
-        return property_exists($options, $property) ? $options->{$property} : null;
86
-    }
87
-
88
-
89
-    /**
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param string $property
67
+	 * @param mixed  $value
68
+	 * @return void
69
+	 */
70
+	public function addProperty(string $property, $value)
71
+	{
72
+		$options = $this->getAll();
73
+		$options->{$property} = $value;
74
+		$this->updateOption($options);
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param string $property
80
+	 * @return mixed
81
+	 */
82
+	public function getProperty(string $property)
83
+	{
84
+		$options = $this->getAll();
85
+		return property_exists($options, $property) ? $options->{$property} : null;
86
+	}
87
+
88
+
89
+	/**
90 90
 	 * @return array|mixed|stdClass
91
-     */
92
-    public function getAll()
91
+	 */
92
+	public function getAll()
93 93
 	{
94
-        if (empty($this->options)) {
94
+		if (empty($this->options)) {
95 95
 			$this->options = $this->json_data_handler->decodeJson($this->loadOption());
96
-        }
97
-        return $this->options;
98
-    }
99
-
100
-
101
-    /**
102
-     * @param string $property
103
-     * @return void
104
-     */
105
-    public function removeProperty(string $property)
106
-    {
107
-        $options = $this->getAll();
108
-        unset($options->{$property});
109
-        $this->updateOption($options);
110
-    }
96
+		}
97
+		return $this->options;
98
+	}
99
+
100
+
101
+	/**
102
+	 * @param string $property
103
+	 * @return void
104
+	 */
105
+	public function removeProperty(string $property)
106
+	{
107
+		$options = $this->getAll();
108
+		unset($options->{$property});
109
+		$this->updateOption($options);
110
+	}
111 111
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
 		bool $autoload = false
42 42
 	) {
43 43
         $this->json_data_handler = $json_data_handler;
44
-		if (! $this->json_data_handler->dataType()) {
44
+		if ( ! $this->json_data_handler->dataType()) {
45 45
 			$this->json_data_handler->configure(JsonDataHandler::DATA_TYPE_OBJECT);
46 46
 		}
47 47
         parent::__construct($option_name, $default_value, $autoload);
Please login to merge, or discard this patch.
core/domain/services/admin/notices/status_change/StatusChangeNotice.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -16,112 +16,112 @@
 block discarded – undo
16 16
  */
17 17
 class StatusChangeNotice extends WordPressOption
18 18
 {
19
-    public function __construct()
20
-    {
21
-        parent::__construct('ee_hide_status_change_notices_for_users', [], false);
22
-    }
19
+	public function __construct()
20
+	{
21
+		parent::__construct('ee_hide_status_change_notices_for_users', [], false);
22
+	}
23 23
 
24 24
 
25
-    public static function loadAssets()
26
-    {
27
-        wp_enqueue_style(
28
-            'status_change_notice',
29
-            EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.css',
30
-            ['espresso_menu'],
31
-            EVENT_ESPRESSO_VERSION
32
-        );
33
-        wp_enqueue_script(
34
-            'status_change_notice',
35
-            EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.js',
36
-            ['jquery'],
37
-            EVENT_ESPRESSO_VERSION,
38
-            true
39
-        );
40
-        wp_localize_script(
41
-            'status_change_notice',
42
-            'eeStatusChangeNotice',
43
-            [
44
-                'failed_request_msg' => wp_strip_all_tags(
45
-                    __(
46
-                        'Request failed. The server returned status code: ',
47
-                        'event_espresso'
48
-                    )
49
-                ),
50
-                'unknown_error_msg' => wp_strip_all_tags(
51
-                    __(
52
-                        'Oops... an unknown error has occurred on the server and this notice could not be dismissed.',
53
-                        'event_espresso'
54
-                    )
55
-                ),
56
-            ]
57
-        );
58
-    }
25
+	public static function loadAssets()
26
+	{
27
+		wp_enqueue_style(
28
+			'status_change_notice',
29
+			EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.css',
30
+			['espresso_menu'],
31
+			EVENT_ESPRESSO_VERSION
32
+		);
33
+		wp_enqueue_script(
34
+			'status_change_notice',
35
+			EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.js',
36
+			['jquery'],
37
+			EVENT_ESPRESSO_VERSION,
38
+			true
39
+		);
40
+		wp_localize_script(
41
+			'status_change_notice',
42
+			'eeStatusChangeNotice',
43
+			[
44
+				'failed_request_msg' => wp_strip_all_tags(
45
+					__(
46
+						'Request failed. The server returned status code: ',
47
+						'event_espresso'
48
+					)
49
+				),
50
+				'unknown_error_msg' => wp_strip_all_tags(
51
+					__(
52
+						'Oops... an unknown error has occurred on the server and this notice could not be dismissed.',
53
+						'event_espresso'
54
+					)
55
+				),
56
+			]
57
+		);
58
+	}
59 59
 
60 60
 
61
-    public function display(string $context, string $page_slug): string
62
-    {
63
-        return $this->isNotDismissed()
64
-            ? EEH_Template::display_template(
65
-                __DIR__ . '/status_change_notice.template.php',
66
-                [
61
+	public function display(string $context, string $page_slug): string
62
+	{
63
+		return $this->isNotDismissed()
64
+			? EEH_Template::display_template(
65
+				__DIR__ . '/status_change_notice.template.php',
66
+				[
67 67
 					'context'   => $context,
68 68
 					'page_slug' => ! empty($page_slug) ? "$page_slug-page" : '',
69
-                ],
70
-                true
71
-            )
72
-            : '';
73
-    }
69
+				],
70
+				true
71
+			)
72
+			: '';
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * @return int
78
-     * @throws RuntimeException
79
-     */
80
-    public function dismiss(): int
81
-    {
82
-        $user      = $this->getCurrentUser();
83
-        $dismissed = (array) $this->loadOption();
84
-        if (! in_array($user, $dismissed)) {
85
-            $dismissed[] = $user;
86
-        }
87
-        return $this->updateOption($dismissed);
88
-    }
76
+	/**
77
+	 * @return int
78
+	 * @throws RuntimeException
79
+	 */
80
+	public function dismiss(): int
81
+	{
82
+		$user      = $this->getCurrentUser();
83
+		$dismissed = (array) $this->loadOption();
84
+		if (! in_array($user, $dismissed)) {
85
+			$dismissed[] = $user;
86
+		}
87
+		return $this->updateOption($dismissed);
88
+	}
89 89
 
90 90
 
91
-    /**
92
-     * @return bool
93
-     * @throws RuntimeException
94
-     */
95
-    public function isDismissed(): bool
96
-    {
97
-        $user      = $this->getCurrentUser();
98
-        $dismissed = (array) $this->loadOption();
99
-        return in_array($user, $dismissed);
100
-    }
91
+	/**
92
+	 * @return bool
93
+	 * @throws RuntimeException
94
+	 */
95
+	public function isDismissed(): bool
96
+	{
97
+		$user      = $this->getCurrentUser();
98
+		$dismissed = (array) $this->loadOption();
99
+		return in_array($user, $dismissed);
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     * @return bool
105
-     * @throws RuntimeException
106
-     */
107
-    public function isNotDismissed(): bool
108
-    {
109
-        return ! $this->isDismissed();
110
-    }
103
+	/**
104
+	 * @return bool
105
+	 * @throws RuntimeException
106
+	 */
107
+	public function isNotDismissed(): bool
108
+	{
109
+		return ! $this->isDismissed();
110
+	}
111 111
 
112 112
 
113
-    /**
114
-     * @return string
115
-     * @throws RuntimeException
116
-     */
117
-    private function getCurrentUser(): string
118
-    {
119
-        $user = wp_get_current_user();
120
-        if (! $user instanceof WP_User || ! $user->exists()) {
121
-            throw new RuntimeException(
122
-                esc_html__('A valid WP User could not be retrieved.', 'event_espresso')
123
-            );
124
-        }
125
-        return $user->user_login;
126
-    }
113
+	/**
114
+	 * @return string
115
+	 * @throws RuntimeException
116
+	 */
117
+	private function getCurrentUser(): string
118
+	{
119
+		$user = wp_get_current_user();
120
+		if (! $user instanceof WP_User || ! $user->exists()) {
121
+			throw new RuntimeException(
122
+				esc_html__('A valid WP User could not be retrieved.', 'event_espresso')
123
+			);
124
+		}
125
+		return $user->user_login;
126
+	}
127 127
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
     {
27 27
         wp_enqueue_style(
28 28
             'status_change_notice',
29
-            EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.css',
29
+            EE_PLUGIN_DIR_URL.'core/domain/services/admin/notices/status_change/status_change_notice.css',
30 30
             ['espresso_menu'],
31 31
             EVENT_ESPRESSO_VERSION
32 32
         );
33 33
         wp_enqueue_script(
34 34
             'status_change_notice',
35
-            EE_PLUGIN_DIR_URL . 'core/domain/services/admin/notices/status_change/status_change_notice.js',
35
+            EE_PLUGIN_DIR_URL.'core/domain/services/admin/notices/status_change/status_change_notice.js',
36 36
             ['jquery'],
37 37
             EVENT_ESPRESSO_VERSION,
38 38
             true
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     {
63 63
         return $this->isNotDismissed()
64 64
             ? EEH_Template::display_template(
65
-                __DIR__ . '/status_change_notice.template.php',
65
+                __DIR__.'/status_change_notice.template.php',
66 66
                 [
67 67
 					'context'   => $context,
68 68
 					'page_slug' => ! empty($page_slug) ? "$page_slug-page" : '',
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     {
82 82
         $user      = $this->getCurrentUser();
83 83
         $dismissed = (array) $this->loadOption();
84
-        if (! in_array($user, $dismissed)) {
84
+        if ( ! in_array($user, $dismissed)) {
85 85
             $dismissed[] = $user;
86 86
         }
87 87
         return $this->updateOption($dismissed);
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
     private function getCurrentUser(): string
118 118
     {
119 119
         $user = wp_get_current_user();
120
-        if (! $user instanceof WP_User || ! $user->exists()) {
120
+        if ( ! $user instanceof WP_User || ! $user->exists()) {
121 121
             throw new RuntimeException(
122 122
                 esc_html__('A valid WP User could not be retrieved.', 'event_espresso')
123 123
             );
Please login to merge, or discard this patch.