Completed
Branch dev (1631a7)
by
unknown
32:18 queued 25:00
created
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2924 added lines, -2924 removed lines patch added patch discarded remove patch
@@ -16,2931 +16,2931 @@
 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
+					'icon' => 'dashicons-list-view',
270
+					'order' => 10,
271
+				],
272
+				'list_table'    => 'Events_Admin_List_Table',
273
+				'help_tabs'     => [
274
+					'events_overview_help_tab'                       => [
275
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
276
+						'filename' => 'events_overview',
277
+					],
278
+					'events_overview_table_column_headings_help_tab' => [
279
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
280
+						'filename' => 'events_overview_table_column_headings',
281
+					],
282
+					'events_overview_filters_help_tab'               => [
283
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
284
+						'filename' => 'events_overview_filters',
285
+					],
286
+					'events_overview_view_help_tab'                  => [
287
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
288
+						'filename' => 'events_overview_views',
289
+					],
290
+					'events_overview_other_help_tab'                 => [
291
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
292
+						'filename' => 'events_overview_other',
293
+					],
294
+				],
295
+				'require_nonce' => false,
296
+			],
297
+			'create_new'             => [
298
+				'nav'           => [
299
+					'label'      => esc_html__('Add New Event', 'event_espresso'),
300
+					'icon' => 'dashicons-plus-alt',
301
+					'order'      => 15,
302
+					'persistent' => false,
303
+				],
304
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
305
+				'help_tabs'     => [
306
+					'event_editor_help_tab'                            => [
307
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
308
+						'filename' => 'event_editor',
309
+					],
310
+					'event_editor_title_richtexteditor_help_tab'       => [
311
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
312
+						'filename' => 'event_editor_title_richtexteditor',
313
+					],
314
+					'event_editor_venue_details_help_tab'              => [
315
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
316
+						'filename' => 'event_editor_venue_details',
317
+					],
318
+					'event_editor_event_datetimes_help_tab'            => [
319
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
320
+						'filename' => 'event_editor_event_datetimes',
321
+					],
322
+					'event_editor_event_tickets_help_tab'              => [
323
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
324
+						'filename' => 'event_editor_event_tickets',
325
+					],
326
+					'event_editor_event_registration_options_help_tab' => [
327
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
328
+						'filename' => 'event_editor_event_registration_options',
329
+					],
330
+					'event_editor_tags_categories_help_tab'            => [
331
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
332
+						'filename' => 'event_editor_tags_categories',
333
+					],
334
+					'event_editor_questions_registrants_help_tab'      => [
335
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
336
+						'filename' => 'event_editor_questions_registrants',
337
+					],
338
+					'event_editor_save_new_event_help_tab'             => [
339
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
340
+						'filename' => 'event_editor_save_new_event',
341
+					],
342
+					'event_editor_other_help_tab'                      => [
343
+						'title'    => esc_html__('Event Other', 'event_espresso'),
344
+						'filename' => 'event_editor_other',
345
+					],
346
+				],
347
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
348
+				'require_nonce' => false,
349
+			],
350
+			'edit'                   => [
351
+				'nav'           => [
352
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
353
+					'icon' => 'dashicons-edit',
354
+					'order'      => 15,
355
+					'persistent' => false,
356
+					'url'        => $post_id
357
+						? EE_Admin_Page::add_query_args_and_nonce(
358
+							['post' => $post_id, 'action' => 'edit'],
359
+							$this->_current_page_view_url
360
+						)
361
+						: $this->_admin_base_url,
362
+				],
363
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
364
+				'help_tabs'     => [
365
+					'event_editor_help_tab'                            => [
366
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
367
+						'filename' => 'event_editor',
368
+					],
369
+					'event_editor_title_richtexteditor_help_tab'       => [
370
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
371
+						'filename' => 'event_editor_title_richtexteditor',
372
+					],
373
+					'event_editor_venue_details_help_tab'              => [
374
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
375
+						'filename' => 'event_editor_venue_details',
376
+					],
377
+					'event_editor_event_datetimes_help_tab'            => [
378
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
379
+						'filename' => 'event_editor_event_datetimes',
380
+					],
381
+					'event_editor_event_tickets_help_tab'              => [
382
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
383
+						'filename' => 'event_editor_event_tickets',
384
+					],
385
+					'event_editor_event_registration_options_help_tab' => [
386
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
387
+						'filename' => 'event_editor_event_registration_options',
388
+					],
389
+					'event_editor_tags_categories_help_tab'            => [
390
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
391
+						'filename' => 'event_editor_tags_categories',
392
+					],
393
+					'event_editor_questions_registrants_help_tab'      => [
394
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
395
+						'filename' => 'event_editor_questions_registrants',
396
+					],
397
+					'event_editor_save_new_event_help_tab'             => [
398
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
399
+						'filename' => 'event_editor_save_new_event',
400
+					],
401
+					'event_editor_other_help_tab'                      => [
402
+						'title'    => esc_html__('Event Other', 'event_espresso'),
403
+						'filename' => 'event_editor_other',
404
+					],
405
+				],
406
+				'require_nonce' => false,
407
+			],
408
+			'default_event_settings' => [
409
+				'nav'           => [
410
+					'label' => esc_html__('Default Settings', 'event_espresso'),
411
+					'icon' => 'dashicons-admin-generic',
412
+					'order' => 40,
413
+				],
414
+				'metaboxes'     => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes),
415
+				'labels'        => [
416
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
417
+				],
418
+				'help_tabs'     => [
419
+					'default_settings_help_tab'        => [
420
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
421
+						'filename' => 'events_default_settings',
422
+					],
423
+					'default_settings_status_help_tab' => [
424
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
425
+						'filename' => 'events_default_settings_status',
426
+					],
427
+					'default_maximum_tickets_help_tab' => [
428
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
429
+						'filename' => 'events_default_settings_max_tickets',
430
+					],
431
+				],
432
+				'require_nonce' => false,
433
+			],
434
+			// template settings
435
+			'template_settings'      => [
436
+				'nav'           => [
437
+					'label' => esc_html__('Templates', 'event_espresso'),
438
+					'icon' => 'dashicons-layout',
439
+					'order' => 30,
440
+				],
441
+				'metaboxes'     => $this->_default_espresso_metaboxes,
442
+				'help_tabs'     => [
443
+					'general_settings_templates_help_tab' => [
444
+						'title'    => esc_html__('Templates', 'event_espresso'),
445
+						'filename' => 'general_settings_templates',
446
+					],
447
+				],
448
+				'require_nonce' => false,
449
+			],
450
+			// event category stuff
451
+			'add_category'           => [
452
+				'nav'           => [
453
+					'label'      => esc_html__('Add Category', 'event_espresso'),
454
+					'icon' => 'dashicons-plus-alt',
455
+					'order'      => 25,
456
+					'persistent' => false,
457
+				],
458
+				'help_tabs'     => [
459
+					'add_category_help_tab' => [
460
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
461
+						'filename' => 'events_add_category',
462
+					],
463
+				],
464
+				'metaboxes'     => ['_publish_post_box'],
465
+				'require_nonce' => false,
466
+			],
467
+			'edit_category'          => [
468
+				'nav'           => [
469
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
470
+					'icon' => 'dashicons-edit',
471
+					'order'      => 25,
472
+					'persistent' => false,
473
+					'url'        => $EVT_CAT_ID
474
+						? add_query_arg(
475
+							['EVT_CAT_ID' => $EVT_CAT_ID],
476
+							$this->_current_page_view_url
477
+						)
478
+						: $this->_admin_base_url,
479
+				],
480
+				'help_tabs'     => [
481
+					'edit_category_help_tab' => [
482
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
483
+						'filename' => 'events_edit_category',
484
+					],
485
+				],
486
+				'metaboxes'     => ['_publish_post_box'],
487
+				'require_nonce' => false,
488
+			],
489
+			'category_list'          => [
490
+				'nav'           => [
491
+					'label' => esc_html__('Categories', 'event_espresso'),
492
+					'icon' => 'dashicons-networking',
493
+					'order' => 20,
494
+				],
495
+				'list_table'    => 'Event_Categories_Admin_List_Table',
496
+				'help_tabs'     => [
497
+					'events_categories_help_tab'                       => [
498
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
499
+						'filename' => 'events_categories',
500
+					],
501
+					'events_categories_table_column_headings_help_tab' => [
502
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
503
+						'filename' => 'events_categories_table_column_headings',
504
+					],
505
+					'events_categories_view_help_tab'                  => [
506
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
507
+						'filename' => 'events_categories_views',
508
+					],
509
+					'events_categories_other_help_tab'                 => [
510
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
511
+						'filename' => 'events_categories_other',
512
+					],
513
+				],
514
+				'metaboxes'     => $this->_default_espresso_metaboxes,
515
+				'require_nonce' => false,
516
+			],
517
+			'preview_deletion'       => [
518
+				'nav'           => [
519
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
520
+					'icon' => 'dashicons-remove',
521
+					'order'      => 15,
522
+					'persistent' => false,
523
+					'url'        => '',
524
+				],
525
+				'require_nonce' => false,
526
+			],
527
+		];
528
+	}
529
+
530
+
531
+	/**
532
+	 * Used to register any global screen options if necessary for every route in this admin page group.
533
+	 */
534
+	protected function _add_screen_options()
535
+	{
536
+	}
537
+
538
+
539
+	/**
540
+	 * Implementing the screen options for the 'default' route.
541
+	 *
542
+	 * @throws InvalidArgumentException
543
+	 * @throws InvalidDataTypeException
544
+	 * @throws InvalidInterfaceException
545
+	 */
546
+	protected function _add_screen_options_default()
547
+	{
548
+		$this->_per_page_screen_option();
549
+	}
550
+
551
+
552
+	/**
553
+	 * Implementing screen options for the category list route.
554
+	 *
555
+	 * @throws InvalidArgumentException
556
+	 * @throws InvalidDataTypeException
557
+	 * @throws InvalidInterfaceException
558
+	 */
559
+	protected function _add_screen_options_category_list()
560
+	{
561
+		$page_title              = $this->_admin_page_title;
562
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
563
+		$this->_per_page_screen_option();
564
+		$this->_admin_page_title = $page_title;
565
+	}
566
+
567
+
568
+	/**
569
+	 * Used to register any global feature pointers for the admin page group.
570
+	 */
571
+	protected function _add_feature_pointers()
572
+	{
573
+	}
574
+
575
+
576
+	/**
577
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
578
+	 */
579
+	public function load_scripts_styles()
580
+	{
581
+		wp_register_style(
582
+			'events-admin-css',
583
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
584
+			[],
585
+			EVENT_ESPRESSO_VERSION
586
+		);
587
+		wp_register_style(
588
+			'ee-cat-admin',
589
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
590
+			[],
591
+			EVENT_ESPRESSO_VERSION
592
+		);
593
+		wp_enqueue_style('events-admin-css');
594
+		wp_enqueue_style('ee-cat-admin');
595
+		// scripts
596
+		wp_register_script(
597
+			'event_editor_js',
598
+			EVENTS_ASSETS_URL . 'event_editor.js',
599
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
600
+			EVENT_ESPRESSO_VERSION,
601
+			true
602
+		);
603
+	}
604
+
605
+
606
+	/**
607
+	 * Enqueuing scripts and styles specific to this view
608
+	 */
609
+	public function load_scripts_styles_create_new()
610
+	{
611
+		$this->load_scripts_styles_edit();
612
+	}
613
+
614
+
615
+	/**
616
+	 * Enqueuing scripts and styles specific to this view
617
+	 */
618
+	public function load_scripts_styles_edit()
619
+	{
620
+		// styles
621
+		wp_enqueue_style('espresso-ui-theme');
622
+		wp_register_style(
623
+			'event-editor-css',
624
+			EVENTS_ASSETS_URL . 'event-editor.css',
625
+			['ee-admin-css'],
626
+			EVENT_ESPRESSO_VERSION
627
+		);
628
+		wp_enqueue_style('event-editor-css');
629
+		// scripts
630
+		if (! $this->admin_config->useAdvancedEditor()) {
631
+			wp_register_script(
632
+				'event-datetime-metabox',
633
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
634
+				['event_editor_js', 'ee-datepicker'],
635
+				EVENT_ESPRESSO_VERSION
636
+			);
637
+			wp_enqueue_script('event-datetime-metabox');
638
+		}
639
+	}
640
+
641
+
642
+	/**
643
+	 * Populating the _views property for the category list table view.
644
+	 */
645
+	protected function _set_list_table_views_category_list()
646
+	{
647
+		$this->_views = [
648
+			'all' => [
649
+				'slug'        => 'all',
650
+				'label'       => esc_html__('All', 'event_espresso'),
651
+				'count'       => 0,
652
+				'bulk_action' => [
653
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
654
+				],
655
+			],
656
+		];
657
+	}
658
+
659
+
660
+	/**
661
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
662
+	 */
663
+	public function admin_init()
664
+	{
665
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
666
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
667
+			'event_espresso'
668
+		);
669
+	}
670
+
671
+
672
+	/**
673
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
674
+	 * group.
675
+	 */
676
+	public function admin_notices()
677
+	{
678
+	}
679
+
680
+
681
+	/**
682
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
683
+	 * this admin page group.
684
+	 */
685
+	public function admin_footer_scripts()
686
+	{
687
+	}
688
+
689
+
690
+	/**
691
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
692
+	 * warning (via EE_Error::add_error());
693
+	 *
694
+	 * @param EE_Event $event Event object
695
+	 * @param string   $req_type
696
+	 * @return void
697
+	 * @throws EE_Error
698
+	 * @throws ReflectionException
699
+	 */
700
+	public function verify_event_edit($event = null, $req_type = '')
701
+	{
702
+		// don't need to do this when processing
703
+		if (! empty($req_type)) {
704
+			return;
705
+		}
706
+		// no event?
707
+		if (! $event instanceof EE_Event) {
708
+			$event = $this->_cpt_model_obj;
709
+		}
710
+		// STILL no event?
711
+		if (! $event instanceof EE_Event) {
712
+			return;
713
+		}
714
+		$orig_status = $event->status();
715
+		// first check if event is active.
716
+		if (
717
+			$orig_status === EEM_Event::cancelled
718
+			|| $orig_status === EEM_Event::postponed
719
+			|| $event->is_expired()
720
+			|| $event->is_inactive()
721
+		) {
722
+			return;
723
+		}
724
+		// made it here so it IS active... next check that any of the tickets are sold.
725
+		if ($event->is_sold_out(true)) {
726
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
727
+				EE_Error::add_attention(
728
+					sprintf(
729
+						esc_html__(
730
+							'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.',
731
+							'event_espresso'
732
+						),
733
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
734
+					)
735
+				);
736
+			}
737
+			return;
738
+		}
739
+		if ($orig_status === EEM_Event::sold_out) {
740
+			EE_Error::add_attention(
741
+				sprintf(
742
+					esc_html__(
743
+						'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.',
744
+						'event_espresso'
745
+					),
746
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
747
+				)
748
+			);
749
+		}
750
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
751
+		if (! $event->tickets_on_sale()) {
752
+			return;
753
+		}
754
+		// made it here so show warning
755
+		$this->_edit_event_warning();
756
+	}
757
+
758
+
759
+	/**
760
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
761
+	 * When needed, hook this into a EE_Error::add_error() notice.
762
+	 *
763
+	 * @access protected
764
+	 * @return void
765
+	 */
766
+	protected function _edit_event_warning()
767
+	{
768
+		// we don't want to add warnings during these requests
769
+		if ($this->request->getRequestParam('action') === 'editpost') {
770
+			return;
771
+		}
772
+		EE_Error::add_attention(
773
+			sprintf(
774
+				esc_html__(
775
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
776
+					'event_espresso'
777
+				),
778
+				'<a class="espresso-help-tab-lnk ee-help-tab-link">',
779
+				'</a>'
780
+			)
781
+		);
782
+	}
783
+
784
+
785
+	/**
786
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
787
+	 * Otherwise, do the normal logic
788
+	 *
789
+	 * @return void
790
+	 * @throws EE_Error
791
+	 * @throws InvalidArgumentException
792
+	 * @throws InvalidDataTypeException
793
+	 * @throws InvalidInterfaceException
794
+	 */
795
+	protected function _create_new_cpt_item()
796
+	{
797
+		$has_timezone_string = get_option('timezone_string');
798
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
799
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
800
+			EE_Error::add_attention(
801
+				sprintf(
802
+					esc_html__(
803
+						'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',
804
+						'event_espresso'
805
+					),
806
+					'<br>',
807
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
808
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
809
+					. '</select>',
810
+					'<button class="button button--secondary timezone-submit">',
811
+					'</button><span class="spinner"></span>'
812
+				),
813
+				__FILE__,
814
+				__FUNCTION__,
815
+				__LINE__
816
+			);
817
+		}
818
+		parent::_create_new_cpt_item();
819
+	}
820
+
821
+
822
+	/**
823
+	 * Sets the _views property for the default route in this admin page group.
824
+	 */
825
+	protected function _set_list_table_views_default()
826
+	{
827
+		$this->_views = [
828
+			'all'   => [
829
+				'slug'        => 'all',
830
+				'label'       => esc_html__('View All Events', 'event_espresso'),
831
+				'count'       => 0,
832
+				'bulk_action' => [
833
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
834
+				],
835
+			],
836
+			'draft' => [
837
+				'slug'        => 'draft',
838
+				'label'       => esc_html__('Draft', 'event_espresso'),
839
+				'count'       => 0,
840
+				'bulk_action' => [
841
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
842
+				],
843
+			],
844
+		];
845
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
846
+			$this->_views['trash'] = [
847
+				'slug'        => 'trash',
848
+				'label'       => esc_html__('Trash', 'event_espresso'),
849
+				'count'       => 0,
850
+				'bulk_action' => [
851
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
852
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
853
+				],
854
+			];
855
+		}
856
+	}
857
+
858
+
859
+	/**
860
+	 * Provides the legend item array for the default list table view.
861
+	 *
862
+	 * @return array
863
+	 * @throws EE_Error
864
+	 * @throws EE_Error
865
+	 */
866
+	protected function _event_legend_items()
867
+	{
868
+		$items    = [
869
+			'view_details'   => [
870
+				'class' => 'dashicons dashicons-visibility',
871
+				'desc'  => esc_html__('View Event', 'event_espresso'),
872
+			],
873
+			'edit_event'     => [
874
+				'class' => 'dashicons dashicons-calendar-alt',
875
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
876
+			],
877
+			'view_attendees' => [
878
+				'class' => 'dashicons dashicons-groups',
879
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
880
+			],
881
+		];
882
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
883
+		$statuses = [
884
+			'sold_out_status'  => [
885
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
886
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
887
+			],
888
+			'active_status'    => [
889
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
890
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
891
+			],
892
+			'upcoming_status'  => [
893
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
894
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
895
+			],
896
+			'postponed_status' => [
897
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
898
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
899
+			],
900
+			'cancelled_status' => [
901
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
902
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
903
+			],
904
+			'expired_status'   => [
905
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
906
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
907
+			],
908
+			'inactive_status'  => [
909
+				'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
910
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
911
+			],
912
+		];
913
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
914
+		return array_merge($items, $statuses);
915
+	}
916
+
917
+
918
+	/**
919
+	 * @return EEM_Event
920
+	 * @throws EE_Error
921
+	 * @throws InvalidArgumentException
922
+	 * @throws InvalidDataTypeException
923
+	 * @throws InvalidInterfaceException
924
+	 * @throws ReflectionException
925
+	 */
926
+	private function _event_model()
927
+	{
928
+		if (! $this->_event_model instanceof EEM_Event) {
929
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
930
+		}
931
+		return $this->_event_model;
932
+	}
933
+
934
+
935
+	/**
936
+	 * Adds extra buttons to the WP CPT permalink field row.
937
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
938
+	 *
939
+	 * @param string $return    the current html
940
+	 * @param int    $id        the post id for the page
941
+	 * @param string $new_title What the title is
942
+	 * @param string $new_slug  what the slug is
943
+	 * @return string            The new html string for the permalink area
944
+	 */
945
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
946
+	{
947
+		// make sure this is only when editing
948
+		if (! empty($id)) {
949
+			$post = get_post($id);
950
+			$return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
951
+					   . esc_html__('Shortcode', 'event_espresso')
952
+					   . '</a> ';
953
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
954
+					   . $post->ID
955
+					   . ']">';
956
+		}
957
+		return $return;
958
+	}
959
+
960
+
961
+	/**
962
+	 * _events_overview_list_table
963
+	 * This contains the logic for showing the events_overview list
964
+	 *
965
+	 * @access protected
966
+	 * @return void
967
+	 * @throws DomainException
968
+	 * @throws EE_Error
969
+	 * @throws InvalidArgumentException
970
+	 * @throws InvalidDataTypeException
971
+	 * @throws InvalidInterfaceException
972
+	 */
973
+	protected function _events_overview_list_table()
974
+	{
975
+		$after_list_table                           = [];
976
+		$links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
977
+		$links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
978
+		$links_html .= EEH_HTML::div(
979
+			EEH_Template::get_button_or_link(
980
+				get_post_type_archive_link('espresso_events'),
981
+				esc_html__('View Event Archive Page', 'event_espresso'),
982
+				'button button--small button--secondary'
983
+			),
984
+			'',
985
+			'ee-admin-button-row ee-admin-button-row--align-start'
986
+		);
987
+		$links_html .= EEH_HTML::divx();
988
+
989
+		$after_list_table['view_event_list_button'] = $links_html;
990
+
991
+		$after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
992
+		$this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
993
+			'create_new',
994
+			'add',
995
+			[],
996
+			'add-new-h2'
997
+		);
998
+
999
+		$this->_template_args['after_list_table']   = array_merge(
1000
+			(array) $this->_template_args['after_list_table'],
1001
+			$after_list_table
1002
+		);
1003
+		$this->display_admin_list_table_page_with_no_sidebar();
1004
+	}
1005
+
1006
+
1007
+	/**
1008
+	 * this allows for extra misc actions in the default WP publish box
1009
+	 *
1010
+	 * @return void
1011
+	 * @throws DomainException
1012
+	 * @throws EE_Error
1013
+	 * @throws InvalidArgumentException
1014
+	 * @throws InvalidDataTypeException
1015
+	 * @throws InvalidInterfaceException
1016
+	 * @throws ReflectionException
1017
+	 */
1018
+	public function extra_misc_actions_publish_box()
1019
+	{
1020
+		$this->_generate_publish_box_extra_content();
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1026
+	 * saved.
1027
+	 * Typically you would use this to save any additional data.
1028
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1029
+	 * ALSO very important.  When a post transitions from scheduled to published,
1030
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1031
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1032
+	 *
1033
+	 * @access protected
1034
+	 * @abstract
1035
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1036
+	 * @param WP_Post $post    The post object of the cpt that was saved.
1037
+	 * @return void
1038
+	 * @throws EE_Error
1039
+	 * @throws InvalidArgumentException
1040
+	 * @throws InvalidDataTypeException
1041
+	 * @throws InvalidInterfaceException
1042
+	 * @throws ReflectionException
1043
+	 */
1044
+	protected function _insert_update_cpt_item($post_id, $post)
1045
+	{
1046
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1047
+			// get out we're not processing an event save.
1048
+			return;
1049
+		}
1050
+		$event_values = [
1051
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1052
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1053
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1054
+		];
1055
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1056
+		if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1057
+			$event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1058
+				'display_ticket_selector',
1059
+				false,
1060
+				'bool'
1061
+			);
1062
+			$event_values['EVT_additional_limit']            = min(
1063
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1064
+				$this->request->getRequestParam(
1065
+					'additional_limit',
1066
+					EEM_Event::get_default_additional_limit(),
1067
+					'int'
1068
+				)
1069
+			);
1070
+			$event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1071
+				'EVT_default_registration_status',
1072
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1073
+			);
1074
+
1075
+			$event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1076
+			$event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1077
+			$event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1078
+		} elseif ($post instanceof WP_Post) {
1079
+			$event_values['EVT_name'] = $post->post_title;
1080
+			$event_values['EVT_desc'] = $post->post_content;
1081
+		}
1082
+		// update event
1083
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1084
+		// get event_object for other metaboxes...
1085
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1086
+		// i have to setup where conditions to override the filters in the model
1087
+		// that filter out auto-draft and inherit statuses so we GET the inherit id!
1088
+		/** @var EE_Event $event */
1089
+		$event = $this->_event_model()->get_one(
1090
+			[
1091
+				[
1092
+					$this->_event_model()->primary_key_name() => $post_id,
1093
+					'OR'                                      => [
1094
+						'status'   => $post->post_status,
1095
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1096
+						// but the returned object here has a status of "publish", so use the original post status as well
1097
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1098
+					],
1099
+				],
1100
+			]
1101
+		);
1102
+
1103
+		// the following are default callbacks for event attachment updates
1104
+		// that can be overridden by caffeinated functionality and/or addons.
1105
+		$event_update_callbacks = [];
1106
+		if (! $this->admin_config->useAdvancedEditor()) {
1107
+			$event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1108
+			$event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1109
+		}
1110
+		$event_update_callbacks = apply_filters(
1111
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1112
+			$event_update_callbacks
1113
+		);
1114
+
1115
+		$att_success = true;
1116
+		foreach ($event_update_callbacks as $e_callback) {
1117
+			$_success = is_callable($e_callback)
1118
+				? $e_callback($event, $this->request->requestParams())
1119
+				: false;
1120
+			// if ANY of these updates fail then we want the appropriate global error message
1121
+			$att_success = $_success !== false ? $att_success : false;
1122
+		}
1123
+		// any errors?
1124
+		if ($success && $att_success === false) {
1125
+			EE_Error::add_error(
1126
+				esc_html__(
1127
+					'Event Details saved successfully but something went wrong with saving attachments.',
1128
+					'event_espresso'
1129
+				),
1130
+				__FILE__,
1131
+				__FUNCTION__,
1132
+				__LINE__
1133
+			);
1134
+		} elseif ($success === false) {
1135
+			EE_Error::add_error(
1136
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1137
+				__FILE__,
1138
+				__FUNCTION__,
1139
+				__LINE__
1140
+			);
1141
+		}
1142
+	}
1143
+
1144
+
1145
+	/**
1146
+	 * @param int $post_id
1147
+	 * @param int $revision_id
1148
+	 * @throws EE_Error
1149
+	 * @throws EE_Error
1150
+	 * @throws ReflectionException
1151
+	 * @see parent::restore_item()
1152
+	 */
1153
+	protected function _restore_cpt_item($post_id, $revision_id)
1154
+	{
1155
+		// copy existing event meta to new post
1156
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1157
+		if ($post_evt instanceof EE_Event) {
1158
+			// meta revision restore
1159
+			$post_evt->restore_revision($revision_id);
1160
+			// related objs restore
1161
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1162
+		}
1163
+	}
1164
+
1165
+
1166
+	/**
1167
+	 * Attach the venue to the Event
1168
+	 *
1169
+	 * @param EE_Event $event Event Object to add the venue to
1170
+	 * @param array    $data  The request data from the form
1171
+	 * @return bool           Success or fail.
1172
+	 * @throws EE_Error
1173
+	 * @throws ReflectionException
1174
+	 */
1175
+	protected function _default_venue_update(EE_Event $event, $data)
1176
+	{
1177
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1178
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1179
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1180
+		// very important.  If we don't have a venue name...
1181
+		// then we'll get out because not necessary to create empty venue
1182
+		if (empty($data['venue_title'])) {
1183
+			return false;
1184
+		}
1185
+		$venue_array = [
1186
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1187
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1188
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1189
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1190
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1191
+				? $data['venue_short_description']
1192
+				: null,
1193
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1194
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1195
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1196
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1197
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1198
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1199
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1200
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1201
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1202
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1203
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1204
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1205
+			'status'              => 'publish',
1206
+		];
1207
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1208
+		if (! empty($venue_id)) {
1209
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1210
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1211
+			// we've gotta make sure that the venue is always attached to a revision..
1212
+			// add_relation_to should take care of making sure that the relation is already present.
1213
+			$event->_add_relation_to($venue_id, 'Venue');
1214
+			return $rows_affected > 0;
1215
+		}
1216
+		// we insert the venue
1217
+		$venue_id = $venue_model->insert($venue_array);
1218
+		$event->_add_relation_to($venue_id, 'Venue');
1219
+		return ! empty($venue_id);
1220
+		// when we have the ancestor come in it's already been handled by the revision save.
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1226
+	 *
1227
+	 * @param EE_Event $event The Event object we're attaching data to
1228
+	 * @param array    $data  The request data from the form
1229
+	 * @return array
1230
+	 * @throws EE_Error
1231
+	 * @throws ReflectionException
1232
+	 * @throws Exception
1233
+	 */
1234
+	protected function _default_tickets_update(EE_Event $event, $data)
1235
+	{
1236
+		if ($this->admin_config->useAdvancedEditor()) {
1237
+			return [];
1238
+		}
1239
+		$datetime       = null;
1240
+		$saved_tickets  = [];
1241
+		$event_timezone = $event->get_timezone();
1242
+		$date_formats   = ['Y-m-d', 'h:i a'];
1243
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1244
+			// trim all values to ensure any excess whitespace is removed.
1245
+			$datetime_data                = array_map('trim', $datetime_data);
1246
+			$datetime_data['DTT_EVT_end'] =
1247
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1248
+					? $datetime_data['DTT_EVT_end']
1249
+					: $datetime_data['DTT_EVT_start'];
1250
+			$datetime_values              = [
1251
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1252
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1253
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1254
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1255
+				'DTT_order'     => $row,
1256
+			];
1257
+			// if we have an id then let's get existing object first and then set the new values.
1258
+			//  Otherwise we instantiate a new object for save.
1259
+			if (! empty($datetime_data['DTT_ID'])) {
1260
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1261
+				if (! $datetime instanceof EE_Datetime) {
1262
+					throw new RuntimeException(
1263
+						sprintf(
1264
+							esc_html__(
1265
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1266
+								'event_espresso'
1267
+							),
1268
+							$datetime_data['DTT_ID']
1269
+						)
1270
+					);
1271
+				}
1272
+				$datetime->set_date_format($date_formats[0]);
1273
+				$datetime->set_time_format($date_formats[1]);
1274
+				foreach ($datetime_values as $field => $value) {
1275
+					$datetime->set($field, $value);
1276
+				}
1277
+			} else {
1278
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1279
+			}
1280
+			if (! $datetime instanceof EE_Datetime) {
1281
+				throw new RuntimeException(
1282
+					sprintf(
1283
+						esc_html__(
1284
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1285
+							'event_espresso'
1286
+						),
1287
+						print_r($datetime_values, true)
1288
+					)
1289
+				);
1290
+			}
1291
+			// before going any further make sure our dates are setup correctly
1292
+			// so that the end date is always equal or greater than the start date.
1293
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1294
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1295
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1296
+			}
1297
+			$datetime->save();
1298
+			$event->_add_relation_to($datetime, 'Datetime');
1299
+		}
1300
+		// no datetimes get deleted so we don't do any of that logic here.
1301
+		// update tickets next
1302
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1303
+
1304
+		// set up some default start and end dates in case those are not present in the incoming data
1305
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1306
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1307
+		// use the start date of the first datetime for the end date
1308
+		$first_datetime   = $event->first_datetime();
1309
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1310
+
1311
+		// now process the incoming data
1312
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1313
+			$update_prices = false;
1314
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1315
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1316
+				: 0;
1317
+			// trim inputs to ensure any excess whitespace is removed.
1318
+			$ticket_data   = array_map('trim', $ticket_data);
1319
+			$ticket_values = [
1320
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1321
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1322
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1323
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1324
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1325
+					? $ticket_data['TKT_start_date']
1326
+					: $default_start_date,
1327
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1328
+					? $ticket_data['TKT_end_date']
1329
+					: $default_end_date,
1330
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1331
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1332
+					? $ticket_data['TKT_qty']
1333
+					: EE_INF,
1334
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1335
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1336
+					? $ticket_data['TKT_uses']
1337
+					: EE_INF,
1338
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1339
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1340
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1341
+				'TKT_price'       => $ticket_price,
1342
+				'TKT_row'         => $row,
1343
+			];
1344
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1345
+			// which means in turn that the prices will become new prices as well.
1346
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1347
+				$ticket_values['TKT_ID']         = 0;
1348
+				$ticket_values['TKT_is_default'] = 0;
1349
+				$update_prices                   = true;
1350
+			}
1351
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1352
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1353
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1354
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1355
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1356
+			if (! empty($ticket_data['TKT_ID'])) {
1357
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1358
+				if (! $existing_ticket instanceof EE_Ticket) {
1359
+					throw new RuntimeException(
1360
+						sprintf(
1361
+							esc_html__(
1362
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1363
+								'event_espresso'
1364
+							),
1365
+							$ticket_data['TKT_ID']
1366
+						)
1367
+					);
1368
+				}
1369
+				$ticket_sold = $existing_ticket->count_related(
1370
+					'Registration',
1371
+					[
1372
+							[
1373
+								'STS_ID' => [
1374
+									'NOT IN',
1375
+									[EEM_Registration::status_id_incomplete],
1376
+								],
1377
+							],
1378
+						]
1379
+				) > 0;
1380
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1381
+				// if they are different then we create a new ticket (if $ticket_sold)
1382
+				// if they aren't different then we go ahead and modify existing ticket.
1383
+				$create_new_ticket = $ticket_sold
1384
+									 && $ticket_price !== $existing_ticket->price()
1385
+									 && ! $existing_ticket->deleted();
1386
+				$existing_ticket->set_date_format($date_formats[0]);
1387
+				$existing_ticket->set_time_format($date_formats[1]);
1388
+				// set new values
1389
+				foreach ($ticket_values as $field => $value) {
1390
+					if ($field == 'TKT_qty') {
1391
+						$existing_ticket->set_qty($value);
1392
+					} elseif ($field == 'TKT_price') {
1393
+						$existing_ticket->set('TKT_price', $ticket_price);
1394
+					} else {
1395
+						$existing_ticket->set($field, $value);
1396
+					}
1397
+				}
1398
+				$ticket = $existing_ticket;
1399
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1400
+				//  Otherwise we have to create a new ticket.
1401
+				if ($create_new_ticket) {
1402
+					// archive the old ticket first
1403
+					$existing_ticket->set('TKT_deleted', 1);
1404
+					$existing_ticket->save();
1405
+					// make sure this ticket is still recorded in our $saved_tickets
1406
+					// so we don't run it through the regular trash routine.
1407
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1408
+					// create new ticket that's a copy of the existing except,
1409
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1410
+					$new_ticket = clone $existing_ticket;
1411
+					$new_ticket->set('TKT_ID', 0);
1412
+					$new_ticket->set('TKT_deleted', 0);
1413
+					$new_ticket->set('TKT_sold', 0);
1414
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1415
+					$update_prices = true;
1416
+					$ticket        = $new_ticket;
1417
+				}
1418
+			} else {
1419
+				// no TKT_id so a new ticket
1420
+				$ticket_values['TKT_price'] = $ticket_price;
1421
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1422
+				$update_prices              = true;
1423
+			}
1424
+			if (! $ticket instanceof EE_Ticket) {
1425
+				throw new RuntimeException(
1426
+					sprintf(
1427
+						esc_html__(
1428
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1429
+							'event_espresso'
1430
+						),
1431
+						print_r($ticket_values, true)
1432
+					)
1433
+				);
1434
+			}
1435
+			// cap ticket qty by datetime reg limits
1436
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1437
+			// update ticket.
1438
+			$ticket->save();
1439
+			// before going any further make sure our dates are setup correctly
1440
+			// so that the end date is always equal or greater than the start date.
1441
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1442
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1443
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1444
+				$ticket->save();
1445
+			}
1446
+			// initially let's add the ticket to the datetime
1447
+			$datetime->_add_relation_to($ticket, 'Ticket');
1448
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1449
+			// add prices to ticket
1450
+			$prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1451
+				? $data['edit_prices'][ $row ]
1452
+				: [];
1453
+			$this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1454
+		}
1455
+		// however now we need to handle permanently deleting tickets via the ui.
1456
+		// Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1457
+		// However, it does allow for deleting tickets that have no tickets sold,
1458
+		// in which case we want to get rid of permanently because there is no need to save in db.
1459
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1460
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1461
+		foreach ($tickets_removed as $id) {
1462
+			$id = absint($id);
1463
+			// get the ticket for this id
1464
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1465
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1466
+				continue;
1467
+			}
1468
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1469
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1470
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1471
+			foreach ($related_datetimes as $related_datetime) {
1472
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1473
+			}
1474
+			// need to do the same for prices (except these prices can also be deleted because again,
1475
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1476
+			$ticket_to_remove->delete_related_permanently('Price');
1477
+			// finally let's delete this ticket
1478
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1479
+			$ticket_to_remove->delete_permanently();
1480
+		}
1481
+		return [$datetime, $saved_tickets];
1482
+	}
1483
+
1484
+
1485
+	/**
1486
+	 * This attaches a list of given prices to a ticket.
1487
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1488
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1489
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1490
+	 *
1491
+	 * @access  private
1492
+	 * @param array     $prices_data Array of prices from the form.
1493
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1494
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1495
+	 * @return  void
1496
+	 * @throws EE_Error
1497
+	 * @throws ReflectionException
1498
+	 */
1499
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1500
+	{
1501
+		$timezone = $ticket->get_timezone();
1502
+		foreach ($prices_data as $row => $price_data) {
1503
+			$price_values = [
1504
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1505
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1506
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1507
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1508
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1509
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1510
+				'PRC_order'      => $row,
1511
+			];
1512
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1513
+				$price_values['PRC_ID'] = 0;
1514
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1515
+			} else {
1516
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1517
+				// update this price with new values
1518
+				foreach ($price_values as $field => $new_price) {
1519
+					$price->set($field, $new_price);
1520
+				}
1521
+			}
1522
+			if (! $price instanceof EE_Price) {
1523
+				throw new RuntimeException(
1524
+					sprintf(
1525
+						esc_html__(
1526
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1527
+							'event_espresso'
1528
+						),
1529
+						print_r($price_values, true)
1530
+					)
1531
+				);
1532
+			}
1533
+			$price->save();
1534
+			$ticket->_add_relation_to($price, 'Price');
1535
+		}
1536
+	}
1537
+
1538
+
1539
+	/**
1540
+	 * Add in our autosave ajax handlers
1541
+	 *
1542
+	 */
1543
+	protected function _ee_autosave_create_new()
1544
+	{
1545
+	}
1546
+
1547
+
1548
+	/**
1549
+	 * More autosave handlers.
1550
+	 */
1551
+	protected function _ee_autosave_edit()
1552
+	{
1553
+	}
1554
+
1555
+
1556
+	/**
1557
+	 * @throws EE_Error
1558
+	 * @throws ReflectionException
1559
+	 */
1560
+	private function _generate_publish_box_extra_content()
1561
+	{
1562
+		// load formatter helper
1563
+		// args for getting related registrations
1564
+		$approved_query_args        = [
1565
+			[
1566
+				'REG_deleted' => 0,
1567
+				'STS_ID'      => EEM_Registration::status_id_approved,
1568
+			],
1569
+		];
1570
+		$not_approved_query_args    = [
1571
+			[
1572
+				'REG_deleted' => 0,
1573
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1574
+			],
1575
+		];
1576
+		$pending_payment_query_args = [
1577
+			[
1578
+				'REG_deleted' => 0,
1579
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1580
+			],
1581
+		];
1582
+		// publish box
1583
+		$publish_box_extra_args = [
1584
+			'view_approved_reg_url'        => add_query_arg(
1585
+				[
1586
+					'action'      => 'default',
1587
+					'event_id'    => $this->_cpt_model_obj->ID(),
1588
+					'_reg_status' => EEM_Registration::status_id_approved,
1589
+				],
1590
+				REG_ADMIN_URL
1591
+			),
1592
+			'view_not_approved_reg_url'    => add_query_arg(
1593
+				[
1594
+					'action'      => 'default',
1595
+					'event_id'    => $this->_cpt_model_obj->ID(),
1596
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1597
+				],
1598
+				REG_ADMIN_URL
1599
+			),
1600
+			'view_pending_payment_reg_url' => add_query_arg(
1601
+				[
1602
+					'action'      => 'default',
1603
+					'event_id'    => $this->_cpt_model_obj->ID(),
1604
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1605
+				],
1606
+				REG_ADMIN_URL
1607
+			),
1608
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1609
+				'Registration',
1610
+				$approved_query_args
1611
+			),
1612
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1613
+				'Registration',
1614
+				$not_approved_query_args
1615
+			),
1616
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1617
+				'Registration',
1618
+				$pending_payment_query_args
1619
+			),
1620
+			'misc_pub_section_class'       => apply_filters(
1621
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1622
+				'misc-pub-section'
1623
+			),
1624
+		];
1625
+		ob_start();
1626
+		do_action(
1627
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1628
+			$this->_cpt_model_obj
1629
+		);
1630
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1631
+		// load template
1632
+		EEH_Template::display_template(
1633
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1634
+			$publish_box_extra_args
1635
+		);
1636
+	}
1637
+
1638
+
1639
+	/**
1640
+	 * @return EE_Event
1641
+	 */
1642
+	public function get_event_object()
1643
+	{
1644
+		return $this->_cpt_model_obj;
1645
+	}
1646
+
1647
+
1648
+
1649
+
1650
+	/** METABOXES * */
1651
+	/**
1652
+	 * _register_event_editor_meta_boxes
1653
+	 * add all metaboxes related to the event_editor
1654
+	 *
1655
+	 * @return void
1656
+	 * @throws EE_Error
1657
+	 * @throws ReflectionException
1658
+	 */
1659
+	protected function _register_event_editor_meta_boxes()
1660
+	{
1661
+		$this->verify_cpt_object();
1662
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1663
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1664
+		if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1665
+			$this->addMetaBox(
1666
+				'espresso_event_editor_event_options',
1667
+				esc_html__('Event Registration Options', 'event_espresso'),
1668
+				[$this, 'registration_options_meta_box'],
1669
+				$this->page_slug,
1670
+				'side'
1671
+			);
1672
+		}
1673
+		if (! $use_advanced_editor) {
1674
+			$this->addMetaBox(
1675
+				'espresso_event_editor_tickets',
1676
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1677
+				[$this, 'ticket_metabox'],
1678
+				$this->page_slug,
1679
+				'normal',
1680
+				'high'
1681
+			);
1682
+		} elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1683
+			add_action(
1684
+				'add_meta_boxes_espresso_events',
1685
+				function () {
1686
+					global $current_screen;
1687
+					remove_meta_box('authordiv', $current_screen, 'normal');
1688
+				},
1689
+				99
1690
+			);
1691
+		}
1692
+		// NOTE: if you're looking for other metaboxes in here,
1693
+		// where a metabox has a related management page in the admin
1694
+		// you will find it setup in the related management page's "_Hooks" file.
1695
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1696
+	}
1697
+
1698
+
1699
+	/**
1700
+	 * @throws DomainException
1701
+	 * @throws EE_Error
1702
+	 * @throws ReflectionException
1703
+	 */
1704
+	public function ticket_metabox()
1705
+	{
1706
+		$existing_datetime_ids = $existing_ticket_ids = [];
1707
+		// defaults for template args
1708
+		$template_args = [
1709
+			'existing_datetime_ids'    => '',
1710
+			'event_datetime_help_link' => '',
1711
+			'ticket_options_help_link' => '',
1712
+			'time'                     => null,
1713
+			'ticket_rows'              => '',
1714
+			'existing_ticket_ids'      => '',
1715
+			'total_ticket_rows'        => 1,
1716
+			'ticket_js_structure'      => '',
1717
+			'trash_icon'               => 'dashicons dashicons-lock',
1718
+			'disabled'                 => '',
1719
+		];
1720
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1721
+		/**
1722
+		 * 1. Start with retrieving Datetimes
1723
+		 * 2. Fore each datetime get related tickets
1724
+		 * 3. For each ticket get related prices
1725
+		 */
1726
+		/** @var EEM_Datetime $datetime_model */
1727
+		$datetime_model = EE_Registry::instance()->load_model('Datetime');
1728
+		/** @var EEM_Ticket $datetime_model */
1729
+		$ticket_model = EE_Registry::instance()->load_model('Ticket');
1730
+		$times        = $datetime_model->get_all_event_dates($event_id);
1731
+		/** @type EE_Datetime $first_datetime */
1732
+		$first_datetime = reset($times);
1733
+		// do we get related tickets?
1734
+		if (
1735
+			$first_datetime instanceof EE_Datetime
1736
+			&& $first_datetime->ID() !== 0
1737
+		) {
1738
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1739
+			$template_args['time']   = $first_datetime;
1740
+			$related_tickets         = $first_datetime->tickets(
1741
+				[
1742
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1743
+					'default_where_conditions' => 'none',
1744
+				]
1745
+			);
1746
+			if (! empty($related_tickets)) {
1747
+				$template_args['total_ticket_rows'] = count($related_tickets);
1748
+				$row                                = 0;
1749
+				foreach ($related_tickets as $ticket) {
1750
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1751
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1752
+					$row++;
1753
+				}
1754
+			} else {
1755
+				$template_args['total_ticket_rows'] = 1;
1756
+				/** @type EE_Ticket $ticket */
1757
+				$ticket                       = $ticket_model->create_default_object();
1758
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1759
+			}
1760
+		} else {
1761
+			$template_args['time'] = $times[0];
1762
+			/** @type EE_Ticket[] $tickets */
1763
+			$tickets                      = $ticket_model->get_all_default_tickets();
1764
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1765
+			// NOTE: we're just sending the first default row
1766
+			// (decaf can't manage default tickets so this should be sufficient);
1767
+		}
1768
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1769
+			'event_editor_event_datetimes_help_tab'
1770
+		);
1771
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1772
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1773
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1774
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1775
+			$ticket_model->create_default_object(),
1776
+			true
1777
+		);
1778
+		$template                                  = apply_filters(
1779
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1780
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1781
+		);
1782
+		EEH_Template::display_template($template, $template_args);
1783
+	}
1784
+
1785
+
1786
+	/**
1787
+	 * Setup an individual ticket form for the decaf event editor page
1788
+	 *
1789
+	 * @access private
1790
+	 * @param EE_Ticket $ticket   the ticket object
1791
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1792
+	 * @param int       $row
1793
+	 * @return string generated html for the ticket row.
1794
+	 * @throws EE_Error
1795
+	 * @throws ReflectionException
1796
+	 */
1797
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1798
+	{
1799
+		$template_args = [
1800
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1801
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1802
+				: '',
1803
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1804
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1805
+			'TKT_name'            => $ticket->get('TKT_name'),
1806
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1807
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1808
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1809
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1810
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1811
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1812
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1813
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1814
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1815
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1816
+				: ' disabled=disabled',
1817
+		];
1818
+		$price         = $ticket->ID() !== 0
1819
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1820
+			: null;
1821
+		$price         = $price instanceof EE_Price
1822
+			? $price
1823
+			: EEM_Price::instance()->create_default_object();
1824
+		$price_args    = [
1825
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1826
+			'PRC_amount'            => $price->get('PRC_amount'),
1827
+			'PRT_ID'                => $price->get('PRT_ID'),
1828
+			'PRC_ID'                => $price->get('PRC_ID'),
1829
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1830
+		];
1831
+		// make sure we have default start and end dates if skeleton
1832
+		// handle rows that should NOT be empty
1833
+		if (empty($template_args['TKT_start_date'])) {
1834
+			// if empty then the start date will be now.
1835
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1836
+		}
1837
+		if (empty($template_args['TKT_end_date'])) {
1838
+			// get the earliest datetime (if present);
1839
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1840
+				? $this->_cpt_model_obj->get_first_related(
1841
+					'Datetime',
1842
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1843
+				)
1844
+				: null;
1845
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1846
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1847
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1848
+		}
1849
+		$template_args = array_merge($template_args, $price_args);
1850
+		$template      = apply_filters(
1851
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1852
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1853
+			$ticket
1854
+		);
1855
+		return EEH_Template::display_template($template, $template_args, true);
1856
+	}
1857
+
1858
+
1859
+	/**
1860
+	 * @throws EE_Error
1861
+	 * @throws ReflectionException
1862
+	 */
1863
+	public function registration_options_meta_box()
1864
+	{
1865
+		$yes_no_values             = [
1866
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1867
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1868
+		];
1869
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1870
+			[
1871
+				EEM_Registration::status_id_cancelled,
1872
+				EEM_Registration::status_id_declined,
1873
+				EEM_Registration::status_id_incomplete,
1874
+			],
1875
+			true
1876
+		);
1877
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1878
+		$template_args['_event']                          = $this->_cpt_model_obj;
1879
+		$template_args['event']                           = $this->_cpt_model_obj;
1880
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1881
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1882
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1883
+			'default_reg_status',
1884
+			$default_reg_status_values,
1885
+			$this->_cpt_model_obj->default_registration_status()
1886
+		);
1887
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1888
+			'display_desc',
1889
+			$yes_no_values,
1890
+			$this->_cpt_model_obj->display_description()
1891
+		);
1892
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1893
+			'display_ticket_selector',
1894
+			$yes_no_values,
1895
+			$this->_cpt_model_obj->display_ticket_selector(),
1896
+			'',
1897
+			'',
1898
+			false
1899
+		);
1900
+		$template_args['additional_registration_options'] = apply_filters(
1901
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1902
+			'',
1903
+			$template_args,
1904
+			$yes_no_values,
1905
+			$default_reg_status_values
1906
+		);
1907
+		EEH_Template::display_template(
1908
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1909
+			$template_args
1910
+		);
1911
+	}
1912
+
1913
+
1914
+	/**
1915
+	 * _get_events()
1916
+	 * This method simply returns all the events (for the given _view and paging)
1917
+	 *
1918
+	 * @access public
1919
+	 * @param int  $per_page     count of items per page (20 default);
1920
+	 * @param int  $current_page what is the current page being viewed.
1921
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1922
+	 *                           If FALSE then we return an array of event objects
1923
+	 *                           that match the given _view and paging parameters.
1924
+	 * @return array|int         an array of event objects or a count of them.
1925
+	 * @throws Exception
1926
+	 */
1927
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1928
+	{
1929
+		$EEM_Event   = $this->_event_model();
1930
+		$offset      = ($current_page - 1) * $per_page;
1931
+		$limit       = $count ? null : $offset . ',' . $per_page;
1932
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1933
+		$order       = $this->request->getRequestParam('order', 'DESC');
1934
+		$month_range = $this->request->getRequestParam('month_range');
1935
+		if ($month_range) {
1936
+			$pieces = explode(' ', $month_range, 3);
1937
+			// simulate the FIRST day of the month, that fixes issues for months like February
1938
+			// where PHP doesn't know what to assume for date.
1939
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1940
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1941
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1942
+		}
1943
+		$where  = [];
1944
+		$status = $this->request->getRequestParam('status');
1945
+		// determine what post_status our condition will have for the query.
1946
+		switch ($status) {
1947
+			case 'month':
1948
+			case 'today':
1949
+			case null:
1950
+			case 'all':
1951
+				break;
1952
+			case 'draft':
1953
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1954
+				break;
1955
+			default:
1956
+				$where['status'] = $status;
1957
+		}
1958
+		// categories? The default for all categories is -1
1959
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1960
+		if ($category !== -1) {
1961
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1962
+			$where['Term_Taxonomy.term_id']  = $category;
1963
+		}
1964
+		// date where conditions
1965
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1966
+		if ($month_range) {
1967
+			$DateTime = new DateTime(
1968
+				$year_r . '-' . $month_r . '-01 00:00:00',
1969
+				new DateTimeZone('UTC')
1970
+			);
1971
+			$start    = $DateTime->getTimestamp();
1972
+			// set the datetime to be the end of the month
1973
+			$DateTime->setDate(
1974
+				$year_r,
1975
+				$month_r,
1976
+				$DateTime->format('t')
1977
+			)->setTime(23, 59, 59);
1978
+			$end                             = $DateTime->getTimestamp();
1979
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1980
+		} elseif ($status === 'today') {
1981
+			$DateTime                        =
1982
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1983
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1984
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1985
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986
+		} elseif ($status === 'month') {
1987
+			$now                             = date('Y-m-01');
1988
+			$DateTime                        =
1989
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1990
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1991
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1992
+														->setTime(23, 59, 59)
1993
+														->format(implode(' ', $start_formats));
1994
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1995
+		}
1996
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1997
+			$where['EVT_wp_user'] = get_current_user_id();
1998
+		} else {
1999
+			if (! isset($where['status'])) {
2000
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
2001
+					$where['OR'] = [
2002
+						'status*restrict_private' => ['!=', 'private'],
2003
+						'AND'                     => [
2004
+							'status*inclusive' => ['=', 'private'],
2005
+							'EVT_wp_user'      => get_current_user_id(),
2006
+						],
2007
+					];
2008
+				}
2009
+			}
2010
+		}
2011
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
2012
+		if (
2013
+			$wp_user
2014
+			&& $wp_user !== get_current_user_id()
2015
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2016
+		) {
2017
+			$where['EVT_wp_user'] = $wp_user;
2018
+		}
2019
+		// search query handling
2020
+		$search_term = $this->request->getRequestParam('s');
2021
+		if ($search_term) {
2022
+			$search_term = '%' . $search_term . '%';
2023
+			$where['OR'] = [
2024
+				'EVT_name'       => ['LIKE', $search_term],
2025
+				'EVT_desc'       => ['LIKE', $search_term],
2026
+				'EVT_short_desc' => ['LIKE', $search_term],
2027
+			];
2028
+		}
2029
+		// filter events by venue.
2030
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
2031
+		if ($venue) {
2032
+			$where['Venue.VNU_ID'] = $venue;
2033
+		}
2034
+		$request_params = $this->request->requestParams();
2035
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2036
+		$query_params   = apply_filters(
2037
+			'FHEE__Events_Admin_Page__get_events__query_params',
2038
+			[
2039
+				$where,
2040
+				'limit'    => $limit,
2041
+				'order_by' => $orderby,
2042
+				'order'    => $order,
2043
+				'group_by' => 'EVT_ID',
2044
+			],
2045
+			$request_params
2046
+		);
2047
+
2048
+		// let's first check if we have special requests coming in.
2049
+		$active_status = $this->request->getRequestParam('active_status');
2050
+		if ($active_status) {
2051
+			switch ($active_status) {
2052
+				case 'upcoming':
2053
+					return $EEM_Event->get_upcoming_events($query_params, $count);
2054
+				case 'expired':
2055
+					return $EEM_Event->get_expired_events($query_params, $count);
2056
+				case 'active':
2057
+					return $EEM_Event->get_active_events($query_params, $count);
2058
+				case 'inactive':
2059
+					return $EEM_Event->get_inactive_events($query_params, $count);
2060
+			}
2061
+		}
2062
+
2063
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2064
+	}
2065
+
2066
+
2067
+	/**
2068
+	 * handling for WordPress CPT actions (trash, restore, delete)
2069
+	 *
2070
+	 * @param string $post_id
2071
+	 * @throws EE_Error
2072
+	 * @throws ReflectionException
2073
+	 */
2074
+	public function trash_cpt_item($post_id)
2075
+	{
2076
+		$this->request->setRequestParam('EVT_ID', $post_id);
2077
+		$this->_trash_or_restore_event('trash', false);
2078
+	}
2079
+
2080
+
2081
+	/**
2082
+	 * @param string $post_id
2083
+	 * @throws EE_Error
2084
+	 * @throws ReflectionException
2085
+	 */
2086
+	public function restore_cpt_item($post_id)
2087
+	{
2088
+		$this->request->setRequestParam('EVT_ID', $post_id);
2089
+		$this->_trash_or_restore_event('draft', false);
2090
+	}
2091
+
2092
+
2093
+	/**
2094
+	 * @param string $post_id
2095
+	 * @throws EE_Error
2096
+	 * @throws EE_Error
2097
+	 */
2098
+	public function delete_cpt_item($post_id)
2099
+	{
2100
+		throw new EE_Error(
2101
+			esc_html__(
2102
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2103
+				'event_espresso'
2104
+			)
2105
+		);
2106
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2107
+		// $this->_delete_event();
2108
+	}
2109
+
2110
+
2111
+	/**
2112
+	 * _trash_or_restore_event
2113
+	 *
2114
+	 * @access protected
2115
+	 * @param string $event_status
2116
+	 * @param bool   $redirect_after
2117
+	 * @throws EE_Error
2118
+	 * @throws EE_Error
2119
+	 * @throws ReflectionException
2120
+	 */
2121
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2122
+	{
2123
+		// determine the event id and set to array.
2124
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2125
+		// loop thru events
2126
+		if ($EVT_ID) {
2127
+			// clean status
2128
+			$event_status = sanitize_key($event_status);
2129
+			// grab status
2130
+			if (! empty($event_status)) {
2131
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2132
+			} else {
2133
+				$success = false;
2134
+				$msg     = esc_html__(
2135
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2136
+					'event_espresso'
2137
+				);
2138
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2139
+			}
2140
+		} else {
2141
+			$success = false;
2142
+			$msg     = esc_html__(
2143
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2144
+				'event_espresso'
2145
+			);
2146
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2147
+		}
2148
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2149
+		if ($redirect_after) {
2150
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2151
+		}
2152
+	}
2153
+
2154
+
2155
+	/**
2156
+	 * _trash_or_restore_events
2157
+	 *
2158
+	 * @access protected
2159
+	 * @param string $event_status
2160
+	 * @return void
2161
+	 * @throws EE_Error
2162
+	 * @throws EE_Error
2163
+	 * @throws ReflectionException
2164
+	 */
2165
+	protected function _trash_or_restore_events($event_status = 'trash')
2166
+	{
2167
+		// clean status
2168
+		$event_status = sanitize_key($event_status);
2169
+		// grab status
2170
+		if (! empty($event_status)) {
2171
+			$success = true;
2172
+			// determine the event id and set to array.
2173
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2174
+			// loop thru events
2175
+			foreach ($EVT_IDs as $EVT_ID) {
2176
+				if ($EVT_ID = absint($EVT_ID)) {
2177
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2178
+					$success = $results !== false ? $success : false;
2179
+				} else {
2180
+					$msg = sprintf(
2181
+						esc_html__(
2182
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2183
+							'event_espresso'
2184
+						),
2185
+						$EVT_ID
2186
+					);
2187
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2188
+					$success = false;
2189
+				}
2190
+			}
2191
+		} else {
2192
+			$success = false;
2193
+			$msg     = esc_html__(
2194
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2195
+				'event_espresso'
2196
+			);
2197
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2198
+		}
2199
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2200
+		$success = $success ? 2 : false;
2201
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2202
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2203
+	}
2204
+
2205
+
2206
+	/**
2207
+	 * @param int    $EVT_ID
2208
+	 * @param string $event_status
2209
+	 * @return bool
2210
+	 * @throws EE_Error
2211
+	 * @throws ReflectionException
2212
+	 */
2213
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2214
+	{
2215
+		// grab event id
2216
+		if (! $EVT_ID) {
2217
+			$msg = esc_html__(
2218
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2219
+				'event_espresso'
2220
+			);
2221
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2222
+			return false;
2223
+		}
2224
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2225
+		// clean status
2226
+		$event_status = sanitize_key($event_status);
2227
+		// grab status
2228
+		if (empty($event_status)) {
2229
+			$msg = esc_html__(
2230
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2231
+				'event_espresso'
2232
+			);
2233
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2234
+			return false;
2235
+		}
2236
+		// was event trashed or restored ?
2237
+		switch ($event_status) {
2238
+			case 'draft':
2239
+				$action = 'restored from the trash';
2240
+				$hook   = 'AHEE_event_restored_from_trash';
2241
+				break;
2242
+			case 'trash':
2243
+				$action = 'moved to the trash';
2244
+				$hook   = 'AHEE_event_moved_to_trash';
2245
+				break;
2246
+			default:
2247
+				$action = 'updated';
2248
+				$hook   = false;
2249
+		}
2250
+		// use class to change status
2251
+		$this->_cpt_model_obj->set_status($event_status);
2252
+		$success = $this->_cpt_model_obj->save();
2253
+		if (! $success) {
2254
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2255
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2256
+			return false;
2257
+		}
2258
+		if ($hook) {
2259
+			do_action($hook);
2260
+		}
2261
+		return true;
2262
+	}
2263
+
2264
+
2265
+	/**
2266
+	 * @param array $event_ids
2267
+	 * @return array
2268
+	 * @since   4.10.23.p
2269
+	 */
2270
+	private function cleanEventIds(array $event_ids)
2271
+	{
2272
+		return array_map('absint', $event_ids);
2273
+	}
2274
+
2275
+
2276
+	/**
2277
+	 * @return array
2278
+	 * @since   4.10.23.p
2279
+	 */
2280
+	private function getEventIdsFromRequest()
2281
+	{
2282
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2283
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2284
+		} else {
2285
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2286
+		}
2287
+	}
2288
+
2289
+
2290
+	/**
2291
+	 * @param bool $preview_delete
2292
+	 * @throws EE_Error
2293
+	 */
2294
+	protected function _delete_event($preview_delete = true)
2295
+	{
2296
+		$this->_delete_events($preview_delete);
2297
+	}
2298
+
2299
+
2300
+	/**
2301
+	 * Gets the tree traversal batch persister.
2302
+	 *
2303
+	 * @return NodeGroupDao
2304
+	 * @throws InvalidArgumentException
2305
+	 * @throws InvalidDataTypeException
2306
+	 * @throws InvalidInterfaceException
2307
+	 * @since 4.10.12.p
2308
+	 */
2309
+	protected function getModelObjNodeGroupPersister()
2310
+	{
2311
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2312
+			$this->model_obj_node_group_persister =
2313
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2314
+		}
2315
+		return $this->model_obj_node_group_persister;
2316
+	}
2317
+
2318
+
2319
+	/**
2320
+	 * @param bool $preview_delete
2321
+	 * @return void
2322
+	 * @throws EE_Error
2323
+	 */
2324
+	protected function _delete_events($preview_delete = true)
2325
+	{
2326
+		$event_ids = $this->getEventIdsFromRequest();
2327
+		if ($preview_delete) {
2328
+			$this->generateDeletionPreview($event_ids);
2329
+		} else {
2330
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2331
+		}
2332
+	}
2333
+
2334
+
2335
+	/**
2336
+	 * @param array $event_ids
2337
+	 */
2338
+	protected function generateDeletionPreview(array $event_ids)
2339
+	{
2340
+		$event_ids = $this->cleanEventIds($event_ids);
2341
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2342
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2343
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2344
+			[
2345
+				'action'            => 'preview_deletion',
2346
+				'deletion_job_code' => $deletion_job_code,
2347
+			],
2348
+			$this->_admin_base_url
2349
+		);
2350
+		EEH_URL::safeRedirectAndExit(
2351
+			EE_Admin_Page::add_query_args_and_nonce(
2352
+				[
2353
+					'page'              => EED_Batch::PAGE_SLUG,
2354
+					'batch'             => EED_Batch::batch_job,
2355
+					'EVT_IDs'           => $event_ids,
2356
+					'deletion_job_code' => $deletion_job_code,
2357
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2358
+					'return_url'        => urlencode($return_url),
2359
+				],
2360
+				admin_url()
2361
+			)
2362
+		);
2363
+	}
2364
+
2365
+
2366
+	/**
2367
+	 * Checks for a POST submission
2368
+	 *
2369
+	 * @since 4.10.12.p
2370
+	 */
2371
+	protected function confirmDeletion()
2372
+	{
2373
+		$deletion_redirect_logic =
2374
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2375
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2376
+	}
2377
+
2378
+
2379
+	/**
2380
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2381
+	 *
2382
+	 * @throws EE_Error
2383
+	 * @since 4.10.12.p
2384
+	 */
2385
+	protected function previewDeletion()
2386
+	{
2387
+		$preview_deletion_logic =
2388
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2389
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2390
+		$this->display_admin_page_with_no_sidebar();
2391
+	}
2392
+
2393
+
2394
+	/**
2395
+	 * get total number of events
2396
+	 *
2397
+	 * @access public
2398
+	 * @return int
2399
+	 * @throws EE_Error
2400
+	 * @throws EE_Error
2401
+	 */
2402
+	public function total_events()
2403
+	{
2404
+		return EEM_Event::instance()->count(
2405
+			['caps' => 'read_admin'],
2406
+			'EVT_ID',
2407
+			true
2408
+		);
2409
+	}
2410
+
2411
+
2412
+	/**
2413
+	 * get total number of draft events
2414
+	 *
2415
+	 * @access public
2416
+	 * @return int
2417
+	 * @throws EE_Error
2418
+	 * @throws EE_Error
2419
+	 */
2420
+	public function total_events_draft()
2421
+	{
2422
+		return EEM_Event::instance()->count(
2423
+			[
2424
+				['status' => ['IN', ['draft', 'auto-draft']]],
2425
+				'caps' => 'read_admin',
2426
+			],
2427
+			'EVT_ID',
2428
+			true
2429
+		);
2430
+	}
2431
+
2432
+
2433
+	/**
2434
+	 * get total number of trashed events
2435
+	 *
2436
+	 * @access public
2437
+	 * @return int
2438
+	 * @throws EE_Error
2439
+	 * @throws EE_Error
2440
+	 */
2441
+	public function total_trashed_events()
2442
+	{
2443
+		return EEM_Event::instance()->count(
2444
+			[
2445
+				['status' => 'trash'],
2446
+				'caps' => 'read_admin',
2447
+			],
2448
+			'EVT_ID',
2449
+			true
2450
+		);
2451
+	}
2452
+
2453
+
2454
+	/**
2455
+	 *    _default_event_settings
2456
+	 *    This generates the Default Settings Tab
2457
+	 *
2458
+	 * @return void
2459
+	 * @throws DomainException
2460
+	 * @throws EE_Error
2461
+	 * @throws InvalidArgumentException
2462
+	 * @throws InvalidDataTypeException
2463
+	 * @throws InvalidInterfaceException
2464
+	 */
2465
+	protected function _default_event_settings()
2466
+	{
2467
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2468
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2469
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
2470
+			$this->_default_event_settings_form()->get_html(),
2471
+			'',
2472
+			'padding'
2473
+		);
2474
+		$this->display_admin_page_with_sidebar();
2475
+	}
2476
+
2477
+
2478
+	/**
2479
+	 * Return the form for event settings.
2480
+	 *
2481
+	 * @return EE_Form_Section_Proper
2482
+	 * @throws EE_Error
2483
+	 */
2484
+	protected function _default_event_settings_form()
2485
+	{
2486
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2487
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2488
+		// exclude
2489
+			[
2490
+				EEM_Registration::status_id_cancelled,
2491
+				EEM_Registration::status_id_declined,
2492
+				EEM_Registration::status_id_incomplete,
2493
+				EEM_Registration::status_id_wait_list,
2494
+			],
2495
+			true
2496
+		);
2497
+		// setup Advanced Editor ???
2498
+		if (
2499
+			$this->raw_req_action === 'default_event_settings'
2500
+			|| $this->raw_req_action === 'update_default_event_settings'
2501
+		) {
2502
+			$this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class);
2503
+		}
2504
+		return new EE_Form_Section_Proper(
2505
+			[
2506
+				'name'            => 'update_default_event_settings',
2507
+				'html_id'         => 'update_default_event_settings',
2508
+				'html_class'      => 'form-table',
2509
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2510
+				'subsections'     => apply_filters(
2511
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2512
+					[
2513
+						'defaults_section_header' => new EE_Form_Section_HTML(
2514
+							EEH_HTML::h2(
2515
+								esc_html__('Default Settings', 'event_espresso'),
2516
+								'',
2517
+								'ee-admin-settings-hdr'
2518
+							)
2519
+						),
2520
+						'default_reg_status'  => new EE_Select_Input(
2521
+							$registration_stati_for_selection,
2522
+							[
2523
+								'default'         => isset($registration_config->default_STS_ID)
2524
+													 && array_key_exists(
2525
+														 $registration_config->default_STS_ID,
2526
+														 $registration_stati_for_selection
2527
+													 )
2528
+									? sanitize_text_field($registration_config->default_STS_ID)
2529
+									: EEM_Registration::status_id_pending_payment,
2530
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2531
+													 . EEH_Template::get_help_tab_link(
2532
+														 'default_settings_status_help_tab'
2533
+													 ),
2534
+								'html_help_text'  => esc_html__(
2535
+									'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.',
2536
+									'event_espresso'
2537
+								),
2538
+							]
2539
+						),
2540
+						'default_max_tickets' => new EE_Integer_Input(
2541
+							[
2542
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2543
+									? $registration_config->default_maximum_number_of_tickets
2544
+									: EEM_Event::get_default_additional_limit(),
2545
+								'html_label_text' => esc_html__(
2546
+									'Default Maximum Tickets Allowed Per Order:',
2547
+									'event_espresso'
2548
+								)
2549
+													 . EEH_Template::get_help_tab_link(
2550
+														 'default_maximum_tickets_help_tab"'
2551
+													 ),
2552
+								'html_help_text'  => esc_html__(
2553
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2554
+									'event_espresso'
2555
+								),
2556
+							]
2557
+						),
2558
+					]
2559
+				),
2560
+			]
2561
+		);
2562
+	}
2563
+
2564
+
2565
+	/**
2566
+	 * @return void
2567
+	 * @throws EE_Error
2568
+	 * @throws InvalidArgumentException
2569
+	 * @throws InvalidDataTypeException
2570
+	 * @throws InvalidInterfaceException
2571
+	 */
2572
+	protected function _update_default_event_settings()
2573
+	{
2574
+		$form = $this->_default_event_settings_form();
2575
+		if ($form->was_submitted()) {
2576
+			$form->receive_form_submission();
2577
+			if ($form->is_valid()) {
2578
+				$registration_config = EE_Registry::instance()->CFG->registration;
2579
+				$valid_data          = $form->valid_data();
2580
+				if (isset($valid_data['default_reg_status'])) {
2581
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2582
+				}
2583
+				if (isset($valid_data['default_max_tickets'])) {
2584
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2585
+				}
2586
+				do_action(
2587
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2588
+					$valid_data,
2589
+					EE_Registry::instance()->CFG,
2590
+					$this
2591
+				);
2592
+				// update because data was valid!
2593
+				EE_Registry::instance()->CFG->update_espresso_config();
2594
+				EE_Error::overwrite_success();
2595
+				EE_Error::add_success(
2596
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2597
+				);
2598
+			}
2599
+		}
2600
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2601
+	}
2602
+
2603
+
2604
+	/*************        Templates        *************
21 2605
      *
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
-                    'icon' => 'dashicons-list-view',
270
-                    'order' => 10,
271
-                ],
272
-                'list_table'    => 'Events_Admin_List_Table',
273
-                'help_tabs'     => [
274
-                    'events_overview_help_tab'                       => [
275
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
276
-                        'filename' => 'events_overview',
277
-                    ],
278
-                    'events_overview_table_column_headings_help_tab' => [
279
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
280
-                        'filename' => 'events_overview_table_column_headings',
281
-                    ],
282
-                    'events_overview_filters_help_tab'               => [
283
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
284
-                        'filename' => 'events_overview_filters',
285
-                    ],
286
-                    'events_overview_view_help_tab'                  => [
287
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
288
-                        'filename' => 'events_overview_views',
289
-                    ],
290
-                    'events_overview_other_help_tab'                 => [
291
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
292
-                        'filename' => 'events_overview_other',
293
-                    ],
294
-                ],
295
-                'require_nonce' => false,
296
-            ],
297
-            'create_new'             => [
298
-                'nav'           => [
299
-                    'label'      => esc_html__('Add New Event', 'event_espresso'),
300
-                    'icon' => 'dashicons-plus-alt',
301
-                    'order'      => 15,
302
-                    'persistent' => false,
303
-                ],
304
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
305
-                'help_tabs'     => [
306
-                    'event_editor_help_tab'                            => [
307
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
308
-                        'filename' => 'event_editor',
309
-                    ],
310
-                    'event_editor_title_richtexteditor_help_tab'       => [
311
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
312
-                        'filename' => 'event_editor_title_richtexteditor',
313
-                    ],
314
-                    'event_editor_venue_details_help_tab'              => [
315
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
316
-                        'filename' => 'event_editor_venue_details',
317
-                    ],
318
-                    'event_editor_event_datetimes_help_tab'            => [
319
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
320
-                        'filename' => 'event_editor_event_datetimes',
321
-                    ],
322
-                    'event_editor_event_tickets_help_tab'              => [
323
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
324
-                        'filename' => 'event_editor_event_tickets',
325
-                    ],
326
-                    'event_editor_event_registration_options_help_tab' => [
327
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
328
-                        'filename' => 'event_editor_event_registration_options',
329
-                    ],
330
-                    'event_editor_tags_categories_help_tab'            => [
331
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
332
-                        'filename' => 'event_editor_tags_categories',
333
-                    ],
334
-                    'event_editor_questions_registrants_help_tab'      => [
335
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
336
-                        'filename' => 'event_editor_questions_registrants',
337
-                    ],
338
-                    'event_editor_save_new_event_help_tab'             => [
339
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
340
-                        'filename' => 'event_editor_save_new_event',
341
-                    ],
342
-                    'event_editor_other_help_tab'                      => [
343
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
344
-                        'filename' => 'event_editor_other',
345
-                    ],
346
-                ],
347
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
348
-                'require_nonce' => false,
349
-            ],
350
-            'edit'                   => [
351
-                'nav'           => [
352
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
353
-                    'icon' => 'dashicons-edit',
354
-                    'order'      => 15,
355
-                    'persistent' => false,
356
-                    'url'        => $post_id
357
-                        ? EE_Admin_Page::add_query_args_and_nonce(
358
-                            ['post' => $post_id, 'action' => 'edit'],
359
-                            $this->_current_page_view_url
360
-                        )
361
-                        : $this->_admin_base_url,
362
-                ],
363
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
364
-                'help_tabs'     => [
365
-                    'event_editor_help_tab'                            => [
366
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
367
-                        'filename' => 'event_editor',
368
-                    ],
369
-                    'event_editor_title_richtexteditor_help_tab'       => [
370
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
371
-                        'filename' => 'event_editor_title_richtexteditor',
372
-                    ],
373
-                    'event_editor_venue_details_help_tab'              => [
374
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
375
-                        'filename' => 'event_editor_venue_details',
376
-                    ],
377
-                    'event_editor_event_datetimes_help_tab'            => [
378
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
379
-                        'filename' => 'event_editor_event_datetimes',
380
-                    ],
381
-                    'event_editor_event_tickets_help_tab'              => [
382
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
383
-                        'filename' => 'event_editor_event_tickets',
384
-                    ],
385
-                    'event_editor_event_registration_options_help_tab' => [
386
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
387
-                        'filename' => 'event_editor_event_registration_options',
388
-                    ],
389
-                    'event_editor_tags_categories_help_tab'            => [
390
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
391
-                        'filename' => 'event_editor_tags_categories',
392
-                    ],
393
-                    'event_editor_questions_registrants_help_tab'      => [
394
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
395
-                        'filename' => 'event_editor_questions_registrants',
396
-                    ],
397
-                    'event_editor_save_new_event_help_tab'             => [
398
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
399
-                        'filename' => 'event_editor_save_new_event',
400
-                    ],
401
-                    'event_editor_other_help_tab'                      => [
402
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
403
-                        'filename' => 'event_editor_other',
404
-                    ],
405
-                ],
406
-                'require_nonce' => false,
407
-            ],
408
-            'default_event_settings' => [
409
-                'nav'           => [
410
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
411
-                    'icon' => 'dashicons-admin-generic',
412
-                    'order' => 40,
413
-                ],
414
-                'metaboxes'     => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes),
415
-                'labels'        => [
416
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
417
-                ],
418
-                'help_tabs'     => [
419
-                    'default_settings_help_tab'        => [
420
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
421
-                        'filename' => 'events_default_settings',
422
-                    ],
423
-                    'default_settings_status_help_tab' => [
424
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
425
-                        'filename' => 'events_default_settings_status',
426
-                    ],
427
-                    'default_maximum_tickets_help_tab' => [
428
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
429
-                        'filename' => 'events_default_settings_max_tickets',
430
-                    ],
431
-                ],
432
-                'require_nonce' => false,
433
-            ],
434
-            // template settings
435
-            'template_settings'      => [
436
-                'nav'           => [
437
-                    'label' => esc_html__('Templates', 'event_espresso'),
438
-                    'icon' => 'dashicons-layout',
439
-                    'order' => 30,
440
-                ],
441
-                'metaboxes'     => $this->_default_espresso_metaboxes,
442
-                'help_tabs'     => [
443
-                    'general_settings_templates_help_tab' => [
444
-                        'title'    => esc_html__('Templates', 'event_espresso'),
445
-                        'filename' => 'general_settings_templates',
446
-                    ],
447
-                ],
448
-                'require_nonce' => false,
449
-            ],
450
-            // event category stuff
451
-            'add_category'           => [
452
-                'nav'           => [
453
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
454
-                    'icon' => 'dashicons-plus-alt',
455
-                    'order'      => 25,
456
-                    'persistent' => false,
457
-                ],
458
-                'help_tabs'     => [
459
-                    'add_category_help_tab' => [
460
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
461
-                        'filename' => 'events_add_category',
462
-                    ],
463
-                ],
464
-                'metaboxes'     => ['_publish_post_box'],
465
-                'require_nonce' => false,
466
-            ],
467
-            'edit_category'          => [
468
-                'nav'           => [
469
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
470
-                    'icon' => 'dashicons-edit',
471
-                    'order'      => 25,
472
-                    'persistent' => false,
473
-                    'url'        => $EVT_CAT_ID
474
-                        ? add_query_arg(
475
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
476
-                            $this->_current_page_view_url
477
-                        )
478
-                        : $this->_admin_base_url,
479
-                ],
480
-                'help_tabs'     => [
481
-                    'edit_category_help_tab' => [
482
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
483
-                        'filename' => 'events_edit_category',
484
-                    ],
485
-                ],
486
-                'metaboxes'     => ['_publish_post_box'],
487
-                'require_nonce' => false,
488
-            ],
489
-            'category_list'          => [
490
-                'nav'           => [
491
-                    'label' => esc_html__('Categories', 'event_espresso'),
492
-                    'icon' => 'dashicons-networking',
493
-                    'order' => 20,
494
-                ],
495
-                'list_table'    => 'Event_Categories_Admin_List_Table',
496
-                'help_tabs'     => [
497
-                    'events_categories_help_tab'                       => [
498
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
499
-                        'filename' => 'events_categories',
500
-                    ],
501
-                    'events_categories_table_column_headings_help_tab' => [
502
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
503
-                        'filename' => 'events_categories_table_column_headings',
504
-                    ],
505
-                    'events_categories_view_help_tab'                  => [
506
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
507
-                        'filename' => 'events_categories_views',
508
-                    ],
509
-                    'events_categories_other_help_tab'                 => [
510
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
511
-                        'filename' => 'events_categories_other',
512
-                    ],
513
-                ],
514
-                'metaboxes'     => $this->_default_espresso_metaboxes,
515
-                'require_nonce' => false,
516
-            ],
517
-            'preview_deletion'       => [
518
-                'nav'           => [
519
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
520
-                    'icon' => 'dashicons-remove',
521
-                    'order'      => 15,
522
-                    'persistent' => false,
523
-                    'url'        => '',
524
-                ],
525
-                'require_nonce' => false,
526
-            ],
527
-        ];
528
-    }
529
-
530
-
531
-    /**
532
-     * Used to register any global screen options if necessary for every route in this admin page group.
533
-     */
534
-    protected function _add_screen_options()
535
-    {
536
-    }
537
-
538
-
539
-    /**
540
-     * Implementing the screen options for the 'default' route.
541
-     *
542
-     * @throws InvalidArgumentException
543
-     * @throws InvalidDataTypeException
544
-     * @throws InvalidInterfaceException
545
-     */
546
-    protected function _add_screen_options_default()
547
-    {
548
-        $this->_per_page_screen_option();
549
-    }
550
-
551
-
552
-    /**
553
-     * Implementing screen options for the category list route.
554
-     *
555
-     * @throws InvalidArgumentException
556
-     * @throws InvalidDataTypeException
557
-     * @throws InvalidInterfaceException
558
-     */
559
-    protected function _add_screen_options_category_list()
560
-    {
561
-        $page_title              = $this->_admin_page_title;
562
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
563
-        $this->_per_page_screen_option();
564
-        $this->_admin_page_title = $page_title;
565
-    }
566
-
567
-
568
-    /**
569
-     * Used to register any global feature pointers for the admin page group.
570
-     */
571
-    protected function _add_feature_pointers()
572
-    {
573
-    }
574
-
575
-
576
-    /**
577
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
578
-     */
579
-    public function load_scripts_styles()
580
-    {
581
-        wp_register_style(
582
-            'events-admin-css',
583
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
584
-            [],
585
-            EVENT_ESPRESSO_VERSION
586
-        );
587
-        wp_register_style(
588
-            'ee-cat-admin',
589
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
590
-            [],
591
-            EVENT_ESPRESSO_VERSION
592
-        );
593
-        wp_enqueue_style('events-admin-css');
594
-        wp_enqueue_style('ee-cat-admin');
595
-        // scripts
596
-        wp_register_script(
597
-            'event_editor_js',
598
-            EVENTS_ASSETS_URL . 'event_editor.js',
599
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
600
-            EVENT_ESPRESSO_VERSION,
601
-            true
602
-        );
603
-    }
604
-
605
-
606
-    /**
607
-     * Enqueuing scripts and styles specific to this view
608
-     */
609
-    public function load_scripts_styles_create_new()
610
-    {
611
-        $this->load_scripts_styles_edit();
612
-    }
613
-
614
-
615
-    /**
616
-     * Enqueuing scripts and styles specific to this view
617
-     */
618
-    public function load_scripts_styles_edit()
619
-    {
620
-        // styles
621
-        wp_enqueue_style('espresso-ui-theme');
622
-        wp_register_style(
623
-            'event-editor-css',
624
-            EVENTS_ASSETS_URL . 'event-editor.css',
625
-            ['ee-admin-css'],
626
-            EVENT_ESPRESSO_VERSION
627
-        );
628
-        wp_enqueue_style('event-editor-css');
629
-        // scripts
630
-        if (! $this->admin_config->useAdvancedEditor()) {
631
-            wp_register_script(
632
-                'event-datetime-metabox',
633
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
634
-                ['event_editor_js', 'ee-datepicker'],
635
-                EVENT_ESPRESSO_VERSION
636
-            );
637
-            wp_enqueue_script('event-datetime-metabox');
638
-        }
639
-    }
640
-
641
-
642
-    /**
643
-     * Populating the _views property for the category list table view.
644
-     */
645
-    protected function _set_list_table_views_category_list()
646
-    {
647
-        $this->_views = [
648
-            'all' => [
649
-                'slug'        => 'all',
650
-                'label'       => esc_html__('All', 'event_espresso'),
651
-                'count'       => 0,
652
-                'bulk_action' => [
653
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
654
-                ],
655
-            ],
656
-        ];
657
-    }
658
-
659
-
660
-    /**
661
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
662
-     */
663
-    public function admin_init()
664
-    {
665
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
666
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
667
-            'event_espresso'
668
-        );
669
-    }
670
-
671
-
672
-    /**
673
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
674
-     * group.
675
-     */
676
-    public function admin_notices()
677
-    {
678
-    }
679
-
680
-
681
-    /**
682
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
683
-     * this admin page group.
684
-     */
685
-    public function admin_footer_scripts()
686
-    {
687
-    }
688
-
689
-
690
-    /**
691
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
692
-     * warning (via EE_Error::add_error());
693
-     *
694
-     * @param EE_Event $event Event object
695
-     * @param string   $req_type
696
-     * @return void
697
-     * @throws EE_Error
698
-     * @throws ReflectionException
699
-     */
700
-    public function verify_event_edit($event = null, $req_type = '')
701
-    {
702
-        // don't need to do this when processing
703
-        if (! empty($req_type)) {
704
-            return;
705
-        }
706
-        // no event?
707
-        if (! $event instanceof EE_Event) {
708
-            $event = $this->_cpt_model_obj;
709
-        }
710
-        // STILL no event?
711
-        if (! $event instanceof EE_Event) {
712
-            return;
713
-        }
714
-        $orig_status = $event->status();
715
-        // first check if event is active.
716
-        if (
717
-            $orig_status === EEM_Event::cancelled
718
-            || $orig_status === EEM_Event::postponed
719
-            || $event->is_expired()
720
-            || $event->is_inactive()
721
-        ) {
722
-            return;
723
-        }
724
-        // made it here so it IS active... next check that any of the tickets are sold.
725
-        if ($event->is_sold_out(true)) {
726
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
727
-                EE_Error::add_attention(
728
-                    sprintf(
729
-                        esc_html__(
730
-                            '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.',
731
-                            'event_espresso'
732
-                        ),
733
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
734
-                    )
735
-                );
736
-            }
737
-            return;
738
-        }
739
-        if ($orig_status === EEM_Event::sold_out) {
740
-            EE_Error::add_attention(
741
-                sprintf(
742
-                    esc_html__(
743
-                        '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.',
744
-                        'event_espresso'
745
-                    ),
746
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
747
-                )
748
-            );
749
-        }
750
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
751
-        if (! $event->tickets_on_sale()) {
752
-            return;
753
-        }
754
-        // made it here so show warning
755
-        $this->_edit_event_warning();
756
-    }
757
-
758
-
759
-    /**
760
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
761
-     * When needed, hook this into a EE_Error::add_error() notice.
762
-     *
763
-     * @access protected
764
-     * @return void
765
-     */
766
-    protected function _edit_event_warning()
767
-    {
768
-        // we don't want to add warnings during these requests
769
-        if ($this->request->getRequestParam('action') === 'editpost') {
770
-            return;
771
-        }
772
-        EE_Error::add_attention(
773
-            sprintf(
774
-                esc_html__(
775
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
776
-                    'event_espresso'
777
-                ),
778
-                '<a class="espresso-help-tab-lnk ee-help-tab-link">',
779
-                '</a>'
780
-            )
781
-        );
782
-    }
783
-
784
-
785
-    /**
786
-     * When a user is creating a new event, notify them if they haven't set their timezone.
787
-     * Otherwise, do the normal logic
788
-     *
789
-     * @return void
790
-     * @throws EE_Error
791
-     * @throws InvalidArgumentException
792
-     * @throws InvalidDataTypeException
793
-     * @throws InvalidInterfaceException
794
-     */
795
-    protected function _create_new_cpt_item()
796
-    {
797
-        $has_timezone_string = get_option('timezone_string');
798
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
799
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
800
-            EE_Error::add_attention(
801
-                sprintf(
802
-                    esc_html__(
803
-                        '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',
804
-                        'event_espresso'
805
-                    ),
806
-                    '<br>',
807
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
808
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
809
-                    . '</select>',
810
-                    '<button class="button button--secondary timezone-submit">',
811
-                    '</button><span class="spinner"></span>'
812
-                ),
813
-                __FILE__,
814
-                __FUNCTION__,
815
-                __LINE__
816
-            );
817
-        }
818
-        parent::_create_new_cpt_item();
819
-    }
820
-
821
-
822
-    /**
823
-     * Sets the _views property for the default route in this admin page group.
824
-     */
825
-    protected function _set_list_table_views_default()
826
-    {
827
-        $this->_views = [
828
-            'all'   => [
829
-                'slug'        => 'all',
830
-                'label'       => esc_html__('View All Events', 'event_espresso'),
831
-                'count'       => 0,
832
-                'bulk_action' => [
833
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
834
-                ],
835
-            ],
836
-            'draft' => [
837
-                'slug'        => 'draft',
838
-                'label'       => esc_html__('Draft', 'event_espresso'),
839
-                'count'       => 0,
840
-                'bulk_action' => [
841
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
842
-                ],
843
-            ],
844
-        ];
845
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
846
-            $this->_views['trash'] = [
847
-                'slug'        => 'trash',
848
-                'label'       => esc_html__('Trash', 'event_espresso'),
849
-                'count'       => 0,
850
-                'bulk_action' => [
851
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
852
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
853
-                ],
854
-            ];
855
-        }
856
-    }
857
-
858
-
859
-    /**
860
-     * Provides the legend item array for the default list table view.
861
-     *
862
-     * @return array
863
-     * @throws EE_Error
864
-     * @throws EE_Error
865
-     */
866
-    protected function _event_legend_items()
867
-    {
868
-        $items    = [
869
-            'view_details'   => [
870
-                'class' => 'dashicons dashicons-visibility',
871
-                'desc'  => esc_html__('View Event', 'event_espresso'),
872
-            ],
873
-            'edit_event'     => [
874
-                'class' => 'dashicons dashicons-calendar-alt',
875
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
876
-            ],
877
-            'view_attendees' => [
878
-                'class' => 'dashicons dashicons-groups',
879
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
880
-            ],
881
-        ];
882
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
883
-        $statuses = [
884
-            'sold_out_status'  => [
885
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
886
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
887
-            ],
888
-            'active_status'    => [
889
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
890
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
891
-            ],
892
-            'upcoming_status'  => [
893
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
894
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
895
-            ],
896
-            'postponed_status' => [
897
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
898
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
899
-            ],
900
-            'cancelled_status' => [
901
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
902
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
903
-            ],
904
-            'expired_status'   => [
905
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
906
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
907
-            ],
908
-            'inactive_status'  => [
909
-                'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
910
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
911
-            ],
912
-        ];
913
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
914
-        return array_merge($items, $statuses);
915
-    }
916
-
917
-
918
-    /**
919
-     * @return EEM_Event
920
-     * @throws EE_Error
921
-     * @throws InvalidArgumentException
922
-     * @throws InvalidDataTypeException
923
-     * @throws InvalidInterfaceException
924
-     * @throws ReflectionException
925
-     */
926
-    private function _event_model()
927
-    {
928
-        if (! $this->_event_model instanceof EEM_Event) {
929
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
930
-        }
931
-        return $this->_event_model;
932
-    }
933
-
934
-
935
-    /**
936
-     * Adds extra buttons to the WP CPT permalink field row.
937
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
938
-     *
939
-     * @param string $return    the current html
940
-     * @param int    $id        the post id for the page
941
-     * @param string $new_title What the title is
942
-     * @param string $new_slug  what the slug is
943
-     * @return string            The new html string for the permalink area
944
-     */
945
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
946
-    {
947
-        // make sure this is only when editing
948
-        if (! empty($id)) {
949
-            $post = get_post($id);
950
-            $return .= '<a class="button button--small button--secondary" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
951
-                       . esc_html__('Shortcode', 'event_espresso')
952
-                       . '</a> ';
953
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
954
-                       . $post->ID
955
-                       . ']">';
956
-        }
957
-        return $return;
958
-    }
959
-
960
-
961
-    /**
962
-     * _events_overview_list_table
963
-     * This contains the logic for showing the events_overview list
964
-     *
965
-     * @access protected
966
-     * @return void
967
-     * @throws DomainException
968
-     * @throws EE_Error
969
-     * @throws InvalidArgumentException
970
-     * @throws InvalidDataTypeException
971
-     * @throws InvalidInterfaceException
972
-     */
973
-    protected function _events_overview_list_table()
974
-    {
975
-        $after_list_table                           = [];
976
-        $links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
977
-        $links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
978
-        $links_html .= EEH_HTML::div(
979
-            EEH_Template::get_button_or_link(
980
-                get_post_type_archive_link('espresso_events'),
981
-                esc_html__('View Event Archive Page', 'event_espresso'),
982
-                'button button--small button--secondary'
983
-            ),
984
-            '',
985
-            'ee-admin-button-row ee-admin-button-row--align-start'
986
-        );
987
-        $links_html .= EEH_HTML::divx();
988
-
989
-        $after_list_table['view_event_list_button'] = $links_html;
990
-
991
-        $after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
992
-        $this->_admin_page_title                    .= ' ' . $this->get_action_link_or_button(
993
-            'create_new',
994
-            'add',
995
-            [],
996
-            'add-new-h2'
997
-        );
998
-
999
-        $this->_template_args['after_list_table']   = array_merge(
1000
-            (array) $this->_template_args['after_list_table'],
1001
-            $after_list_table
1002
-        );
1003
-        $this->display_admin_list_table_page_with_no_sidebar();
1004
-    }
1005
-
1006
-
1007
-    /**
1008
-     * this allows for extra misc actions in the default WP publish box
1009
-     *
1010
-     * @return void
1011
-     * @throws DomainException
1012
-     * @throws EE_Error
1013
-     * @throws InvalidArgumentException
1014
-     * @throws InvalidDataTypeException
1015
-     * @throws InvalidInterfaceException
1016
-     * @throws ReflectionException
1017
-     */
1018
-    public function extra_misc_actions_publish_box()
1019
-    {
1020
-        $this->_generate_publish_box_extra_content();
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1026
-     * saved.
1027
-     * Typically you would use this to save any additional data.
1028
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1029
-     * ALSO very important.  When a post transitions from scheduled to published,
1030
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1031
-     * other meta saves. So MAKE sure that you handle this accordingly.
1032
-     *
1033
-     * @access protected
1034
-     * @abstract
1035
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1036
-     * @param WP_Post $post    The post object of the cpt that was saved.
1037
-     * @return void
1038
-     * @throws EE_Error
1039
-     * @throws InvalidArgumentException
1040
-     * @throws InvalidDataTypeException
1041
-     * @throws InvalidInterfaceException
1042
-     * @throws ReflectionException
1043
-     */
1044
-    protected function _insert_update_cpt_item($post_id, $post)
1045
-    {
1046
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1047
-            // get out we're not processing an event save.
1048
-            return;
1049
-        }
1050
-        $event_values = [
1051
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1052
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1053
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1054
-        ];
1055
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1056
-        if (! $this->admin_config->useAdvancedEditor() || ! $this->feature->allowed('use_reg_options_meta_box')) {
1057
-            $event_values['EVT_display_ticket_selector']     = $this->request->getRequestParam(
1058
-                'display_ticket_selector',
1059
-                false,
1060
-                'bool'
1061
-            );
1062
-            $event_values['EVT_additional_limit']            = min(
1063
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1064
-                $this->request->getRequestParam(
1065
-                    'additional_limit',
1066
-                    EEM_Event::get_default_additional_limit(),
1067
-                    'int'
1068
-                )
1069
-            );
1070
-            $event_values['EVT_default_registration_status'] = $this->request->getRequestParam(
1071
-                'EVT_default_registration_status',
1072
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1073
-            );
1074
-
1075
-            $event_values['EVT_external_URL'] = $this->request->getRequestParam('externalURL');
1076
-            $event_values['EVT_phone']        = $this->request->getRequestParam('event_phone');
1077
-            $event_values['EVT_display_desc'] = $this->request->getRequestParam('display_desc', false, 'bool');
1078
-        } elseif ($post instanceof WP_Post) {
1079
-            $event_values['EVT_name'] = $post->post_title;
1080
-            $event_values['EVT_desc'] = $post->post_content;
1081
-        }
1082
-        // update event
1083
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1084
-        // get event_object for other metaboxes...
1085
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1086
-        // i have to setup where conditions to override the filters in the model
1087
-        // that filter out auto-draft and inherit statuses so we GET the inherit id!
1088
-        /** @var EE_Event $event */
1089
-        $event = $this->_event_model()->get_one(
1090
-            [
1091
-                [
1092
-                    $this->_event_model()->primary_key_name() => $post_id,
1093
-                    'OR'                                      => [
1094
-                        'status'   => $post->post_status,
1095
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1096
-                        // but the returned object here has a status of "publish", so use the original post status as well
1097
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1098
-                    ],
1099
-                ],
1100
-            ]
1101
-        );
1102
-
1103
-        // the following are default callbacks for event attachment updates
1104
-        // that can be overridden by caffeinated functionality and/or addons.
1105
-        $event_update_callbacks = [];
1106
-        if (! $this->admin_config->useAdvancedEditor()) {
1107
-            $event_update_callbacks['_default_venue_update']   = [$this, '_default_venue_update'];
1108
-            $event_update_callbacks['_default_tickets_update'] = [$this, '_default_tickets_update'];
1109
-        }
1110
-        $event_update_callbacks = apply_filters(
1111
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1112
-            $event_update_callbacks
1113
-        );
1114
-
1115
-        $att_success = true;
1116
-        foreach ($event_update_callbacks as $e_callback) {
1117
-            $_success = is_callable($e_callback)
1118
-                ? $e_callback($event, $this->request->requestParams())
1119
-                : false;
1120
-            // if ANY of these updates fail then we want the appropriate global error message
1121
-            $att_success = $_success !== false ? $att_success : false;
1122
-        }
1123
-        // any errors?
1124
-        if ($success && $att_success === false) {
1125
-            EE_Error::add_error(
1126
-                esc_html__(
1127
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1128
-                    'event_espresso'
1129
-                ),
1130
-                __FILE__,
1131
-                __FUNCTION__,
1132
-                __LINE__
1133
-            );
1134
-        } elseif ($success === false) {
1135
-            EE_Error::add_error(
1136
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1137
-                __FILE__,
1138
-                __FUNCTION__,
1139
-                __LINE__
1140
-            );
1141
-        }
1142
-    }
1143
-
1144
-
1145
-    /**
1146
-     * @param int $post_id
1147
-     * @param int $revision_id
1148
-     * @throws EE_Error
1149
-     * @throws EE_Error
1150
-     * @throws ReflectionException
1151
-     * @see parent::restore_item()
1152
-     */
1153
-    protected function _restore_cpt_item($post_id, $revision_id)
1154
-    {
1155
-        // copy existing event meta to new post
1156
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1157
-        if ($post_evt instanceof EE_Event) {
1158
-            // meta revision restore
1159
-            $post_evt->restore_revision($revision_id);
1160
-            // related objs restore
1161
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1162
-        }
1163
-    }
1164
-
1165
-
1166
-    /**
1167
-     * Attach the venue to the Event
1168
-     *
1169
-     * @param EE_Event $event Event Object to add the venue to
1170
-     * @param array    $data  The request data from the form
1171
-     * @return bool           Success or fail.
1172
-     * @throws EE_Error
1173
-     * @throws ReflectionException
1174
-     */
1175
-    protected function _default_venue_update(EE_Event $event, $data)
1176
-    {
1177
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1178
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1179
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1180
-        // very important.  If we don't have a venue name...
1181
-        // then we'll get out because not necessary to create empty venue
1182
-        if (empty($data['venue_title'])) {
1183
-            return false;
1184
-        }
1185
-        $venue_array = [
1186
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1187
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1188
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1189
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1190
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1191
-                ? $data['venue_short_description']
1192
-                : null,
1193
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1194
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1195
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1196
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1197
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1198
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1199
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1200
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1201
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1202
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1203
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1204
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1205
-            'status'              => 'publish',
1206
-        ];
1207
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1208
-        if (! empty($venue_id)) {
1209
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1210
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1211
-            // we've gotta make sure that the venue is always attached to a revision..
1212
-            // add_relation_to should take care of making sure that the relation is already present.
1213
-            $event->_add_relation_to($venue_id, 'Venue');
1214
-            return $rows_affected > 0;
1215
-        }
1216
-        // we insert the venue
1217
-        $venue_id = $venue_model->insert($venue_array);
1218
-        $event->_add_relation_to($venue_id, 'Venue');
1219
-        return ! empty($venue_id);
1220
-        // when we have the ancestor come in it's already been handled by the revision save.
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1226
-     *
1227
-     * @param EE_Event $event The Event object we're attaching data to
1228
-     * @param array    $data  The request data from the form
1229
-     * @return array
1230
-     * @throws EE_Error
1231
-     * @throws ReflectionException
1232
-     * @throws Exception
1233
-     */
1234
-    protected function _default_tickets_update(EE_Event $event, $data)
1235
-    {
1236
-        if ($this->admin_config->useAdvancedEditor()) {
1237
-            return [];
1238
-        }
1239
-        $datetime       = null;
1240
-        $saved_tickets  = [];
1241
-        $event_timezone = $event->get_timezone();
1242
-        $date_formats   = ['Y-m-d', 'h:i a'];
1243
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1244
-            // trim all values to ensure any excess whitespace is removed.
1245
-            $datetime_data                = array_map('trim', $datetime_data);
1246
-            $datetime_data['DTT_EVT_end'] =
1247
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1248
-                    ? $datetime_data['DTT_EVT_end']
1249
-                    : $datetime_data['DTT_EVT_start'];
1250
-            $datetime_values              = [
1251
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1252
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1253
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1254
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1255
-                'DTT_order'     => $row,
1256
-            ];
1257
-            // if we have an id then let's get existing object first and then set the new values.
1258
-            //  Otherwise we instantiate a new object for save.
1259
-            if (! empty($datetime_data['DTT_ID'])) {
1260
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1261
-                if (! $datetime instanceof EE_Datetime) {
1262
-                    throw new RuntimeException(
1263
-                        sprintf(
1264
-                            esc_html__(
1265
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1266
-                                'event_espresso'
1267
-                            ),
1268
-                            $datetime_data['DTT_ID']
1269
-                        )
1270
-                    );
1271
-                }
1272
-                $datetime->set_date_format($date_formats[0]);
1273
-                $datetime->set_time_format($date_formats[1]);
1274
-                foreach ($datetime_values as $field => $value) {
1275
-                    $datetime->set($field, $value);
1276
-                }
1277
-            } else {
1278
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1279
-            }
1280
-            if (! $datetime instanceof EE_Datetime) {
1281
-                throw new RuntimeException(
1282
-                    sprintf(
1283
-                        esc_html__(
1284
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1285
-                            'event_espresso'
1286
-                        ),
1287
-                        print_r($datetime_values, true)
1288
-                    )
1289
-                );
1290
-            }
1291
-            // before going any further make sure our dates are setup correctly
1292
-            // so that the end date is always equal or greater than the start date.
1293
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1294
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1295
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1296
-            }
1297
-            $datetime->save();
1298
-            $event->_add_relation_to($datetime, 'Datetime');
1299
-        }
1300
-        // no datetimes get deleted so we don't do any of that logic here.
1301
-        // update tickets next
1302
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1303
-
1304
-        // set up some default start and end dates in case those are not present in the incoming data
1305
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1306
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1307
-        // use the start date of the first datetime for the end date
1308
-        $first_datetime   = $event->first_datetime();
1309
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1310
-
1311
-        // now process the incoming data
1312
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1313
-            $update_prices = false;
1314
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1315
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1316
-                : 0;
1317
-            // trim inputs to ensure any excess whitespace is removed.
1318
-            $ticket_data   = array_map('trim', $ticket_data);
1319
-            $ticket_values = [
1320
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1321
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1322
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1323
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1324
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1325
-                    ? $ticket_data['TKT_start_date']
1326
-                    : $default_start_date,
1327
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1328
-                    ? $ticket_data['TKT_end_date']
1329
-                    : $default_end_date,
1330
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1331
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1332
-                    ? $ticket_data['TKT_qty']
1333
-                    : EE_INF,
1334
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1335
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1336
-                    ? $ticket_data['TKT_uses']
1337
-                    : EE_INF,
1338
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1339
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1340
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1341
-                'TKT_price'       => $ticket_price,
1342
-                'TKT_row'         => $row,
1343
-            ];
1344
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1345
-            // which means in turn that the prices will become new prices as well.
1346
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1347
-                $ticket_values['TKT_ID']         = 0;
1348
-                $ticket_values['TKT_is_default'] = 0;
1349
-                $update_prices                   = true;
1350
-            }
1351
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1352
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1353
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1354
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1355
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1356
-            if (! empty($ticket_data['TKT_ID'])) {
1357
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1358
-                if (! $existing_ticket instanceof EE_Ticket) {
1359
-                    throw new RuntimeException(
1360
-                        sprintf(
1361
-                            esc_html__(
1362
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1363
-                                'event_espresso'
1364
-                            ),
1365
-                            $ticket_data['TKT_ID']
1366
-                        )
1367
-                    );
1368
-                }
1369
-                $ticket_sold = $existing_ticket->count_related(
1370
-                    'Registration',
1371
-                    [
1372
-                            [
1373
-                                'STS_ID' => [
1374
-                                    'NOT IN',
1375
-                                    [EEM_Registration::status_id_incomplete],
1376
-                                ],
1377
-                            ],
1378
-                        ]
1379
-                ) > 0;
1380
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1381
-                // if they are different then we create a new ticket (if $ticket_sold)
1382
-                // if they aren't different then we go ahead and modify existing ticket.
1383
-                $create_new_ticket = $ticket_sold
1384
-                                     && $ticket_price !== $existing_ticket->price()
1385
-                                     && ! $existing_ticket->deleted();
1386
-                $existing_ticket->set_date_format($date_formats[0]);
1387
-                $existing_ticket->set_time_format($date_formats[1]);
1388
-                // set new values
1389
-                foreach ($ticket_values as $field => $value) {
1390
-                    if ($field == 'TKT_qty') {
1391
-                        $existing_ticket->set_qty($value);
1392
-                    } elseif ($field == 'TKT_price') {
1393
-                        $existing_ticket->set('TKT_price', $ticket_price);
1394
-                    } else {
1395
-                        $existing_ticket->set($field, $value);
1396
-                    }
1397
-                }
1398
-                $ticket = $existing_ticket;
1399
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1400
-                //  Otherwise we have to create a new ticket.
1401
-                if ($create_new_ticket) {
1402
-                    // archive the old ticket first
1403
-                    $existing_ticket->set('TKT_deleted', 1);
1404
-                    $existing_ticket->save();
1405
-                    // make sure this ticket is still recorded in our $saved_tickets
1406
-                    // so we don't run it through the regular trash routine.
1407
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1408
-                    // create new ticket that's a copy of the existing except,
1409
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1410
-                    $new_ticket = clone $existing_ticket;
1411
-                    $new_ticket->set('TKT_ID', 0);
1412
-                    $new_ticket->set('TKT_deleted', 0);
1413
-                    $new_ticket->set('TKT_sold', 0);
1414
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1415
-                    $update_prices = true;
1416
-                    $ticket        = $new_ticket;
1417
-                }
1418
-            } else {
1419
-                // no TKT_id so a new ticket
1420
-                $ticket_values['TKT_price'] = $ticket_price;
1421
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1422
-                $update_prices              = true;
1423
-            }
1424
-            if (! $ticket instanceof EE_Ticket) {
1425
-                throw new RuntimeException(
1426
-                    sprintf(
1427
-                        esc_html__(
1428
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1429
-                            'event_espresso'
1430
-                        ),
1431
-                        print_r($ticket_values, true)
1432
-                    )
1433
-                );
1434
-            }
1435
-            // cap ticket qty by datetime reg limits
1436
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1437
-            // update ticket.
1438
-            $ticket->save();
1439
-            // before going any further make sure our dates are setup correctly
1440
-            // so that the end date is always equal or greater than the start date.
1441
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1442
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1443
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1444
-                $ticket->save();
1445
-            }
1446
-            // initially let's add the ticket to the datetime
1447
-            $datetime->_add_relation_to($ticket, 'Ticket');
1448
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1449
-            // add prices to ticket
1450
-            $prices_data = isset($data['edit_prices'][ $row ]) && is_array($data['edit_prices'][ $row ])
1451
-                ? $data['edit_prices'][ $row ]
1452
-                : [];
1453
-            $this->_add_prices_to_ticket($prices_data, $ticket, $update_prices);
1454
-        }
1455
-        // however now we need to handle permanently deleting tickets via the ui.
1456
-        // Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1457
-        // However, it does allow for deleting tickets that have no tickets sold,
1458
-        // in which case we want to get rid of permanently because there is no need to save in db.
1459
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1460
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1461
-        foreach ($tickets_removed as $id) {
1462
-            $id = absint($id);
1463
-            // get the ticket for this id
1464
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1465
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1466
-                continue;
1467
-            }
1468
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1469
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1470
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1471
-            foreach ($related_datetimes as $related_datetime) {
1472
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1473
-            }
1474
-            // need to do the same for prices (except these prices can also be deleted because again,
1475
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1476
-            $ticket_to_remove->delete_related_permanently('Price');
1477
-            // finally let's delete this ticket
1478
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1479
-            $ticket_to_remove->delete_permanently();
1480
-        }
1481
-        return [$datetime, $saved_tickets];
1482
-    }
1483
-
1484
-
1485
-    /**
1486
-     * This attaches a list of given prices to a ticket.
1487
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1488
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1489
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1490
-     *
1491
-     * @access  private
1492
-     * @param array     $prices_data Array of prices from the form.
1493
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1494
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1495
-     * @return  void
1496
-     * @throws EE_Error
1497
-     * @throws ReflectionException
1498
-     */
1499
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1500
-    {
1501
-        $timezone = $ticket->get_timezone();
1502
-        foreach ($prices_data as $row => $price_data) {
1503
-            $price_values = [
1504
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1505
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1506
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1507
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1508
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1509
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1510
-                'PRC_order'      => $row,
1511
-            ];
1512
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1513
-                $price_values['PRC_ID'] = 0;
1514
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1515
-            } else {
1516
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1517
-                // update this price with new values
1518
-                foreach ($price_values as $field => $new_price) {
1519
-                    $price->set($field, $new_price);
1520
-                }
1521
-            }
1522
-            if (! $price instanceof EE_Price) {
1523
-                throw new RuntimeException(
1524
-                    sprintf(
1525
-                        esc_html__(
1526
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1527
-                            'event_espresso'
1528
-                        ),
1529
-                        print_r($price_values, true)
1530
-                    )
1531
-                );
1532
-            }
1533
-            $price->save();
1534
-            $ticket->_add_relation_to($price, 'Price');
1535
-        }
1536
-    }
1537
-
1538
-
1539
-    /**
1540
-     * Add in our autosave ajax handlers
1541
-     *
1542
-     */
1543
-    protected function _ee_autosave_create_new()
1544
-    {
1545
-    }
1546
-
1547
-
1548
-    /**
1549
-     * More autosave handlers.
1550
-     */
1551
-    protected function _ee_autosave_edit()
1552
-    {
1553
-    }
1554
-
1555
-
1556
-    /**
1557
-     * @throws EE_Error
1558
-     * @throws ReflectionException
1559
-     */
1560
-    private function _generate_publish_box_extra_content()
1561
-    {
1562
-        // load formatter helper
1563
-        // args for getting related registrations
1564
-        $approved_query_args        = [
1565
-            [
1566
-                'REG_deleted' => 0,
1567
-                'STS_ID'      => EEM_Registration::status_id_approved,
1568
-            ],
1569
-        ];
1570
-        $not_approved_query_args    = [
1571
-            [
1572
-                'REG_deleted' => 0,
1573
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1574
-            ],
1575
-        ];
1576
-        $pending_payment_query_args = [
1577
-            [
1578
-                'REG_deleted' => 0,
1579
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1580
-            ],
1581
-        ];
1582
-        // publish box
1583
-        $publish_box_extra_args = [
1584
-            'view_approved_reg_url'        => add_query_arg(
1585
-                [
1586
-                    'action'      => 'default',
1587
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1588
-                    '_reg_status' => EEM_Registration::status_id_approved,
1589
-                ],
1590
-                REG_ADMIN_URL
1591
-            ),
1592
-            'view_not_approved_reg_url'    => add_query_arg(
1593
-                [
1594
-                    'action'      => 'default',
1595
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1596
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1597
-                ],
1598
-                REG_ADMIN_URL
1599
-            ),
1600
-            'view_pending_payment_reg_url' => add_query_arg(
1601
-                [
1602
-                    'action'      => 'default',
1603
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1604
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1605
-                ],
1606
-                REG_ADMIN_URL
1607
-            ),
1608
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1609
-                'Registration',
1610
-                $approved_query_args
1611
-            ),
1612
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1613
-                'Registration',
1614
-                $not_approved_query_args
1615
-            ),
1616
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1617
-                'Registration',
1618
-                $pending_payment_query_args
1619
-            ),
1620
-            'misc_pub_section_class'       => apply_filters(
1621
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1622
-                'misc-pub-section'
1623
-            ),
1624
-        ];
1625
-        ob_start();
1626
-        do_action(
1627
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1628
-            $this->_cpt_model_obj
1629
-        );
1630
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1631
-        // load template
1632
-        EEH_Template::display_template(
1633
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1634
-            $publish_box_extra_args
1635
-        );
1636
-    }
1637
-
1638
-
1639
-    /**
1640
-     * @return EE_Event
1641
-     */
1642
-    public function get_event_object()
1643
-    {
1644
-        return $this->_cpt_model_obj;
1645
-    }
1646
-
1647
-
1648
-
1649
-
1650
-    /** METABOXES * */
1651
-    /**
1652
-     * _register_event_editor_meta_boxes
1653
-     * add all metaboxes related to the event_editor
1654
-     *
1655
-     * @return void
1656
-     * @throws EE_Error
1657
-     * @throws ReflectionException
1658
-     */
1659
-    protected function _register_event_editor_meta_boxes()
1660
-    {
1661
-        $this->verify_cpt_object();
1662
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1663
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1664
-        if (! $use_advanced_editor || ! $this->feature->allowed('use_reg_options_meta_box')) {
1665
-            $this->addMetaBox(
1666
-                'espresso_event_editor_event_options',
1667
-                esc_html__('Event Registration Options', 'event_espresso'),
1668
-                [$this, 'registration_options_meta_box'],
1669
-                $this->page_slug,
1670
-                'side'
1671
-            );
1672
-        }
1673
-        if (! $use_advanced_editor) {
1674
-            $this->addMetaBox(
1675
-                'espresso_event_editor_tickets',
1676
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1677
-                [$this, 'ticket_metabox'],
1678
-                $this->page_slug,
1679
-                'normal',
1680
-                'high'
1681
-            );
1682
-        } elseif ($this->feature->allowed('use_reg_options_meta_box')) {
1683
-            add_action(
1684
-                'add_meta_boxes_espresso_events',
1685
-                function () {
1686
-                    global $current_screen;
1687
-                    remove_meta_box('authordiv', $current_screen, 'normal');
1688
-                },
1689
-                99
1690
-            );
1691
-        }
1692
-        // NOTE: if you're looking for other metaboxes in here,
1693
-        // where a metabox has a related management page in the admin
1694
-        // you will find it setup in the related management page's "_Hooks" file.
1695
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1696
-    }
1697
-
1698
-
1699
-    /**
1700
-     * @throws DomainException
1701
-     * @throws EE_Error
1702
-     * @throws ReflectionException
1703
-     */
1704
-    public function ticket_metabox()
1705
-    {
1706
-        $existing_datetime_ids = $existing_ticket_ids = [];
1707
-        // defaults for template args
1708
-        $template_args = [
1709
-            'existing_datetime_ids'    => '',
1710
-            'event_datetime_help_link' => '',
1711
-            'ticket_options_help_link' => '',
1712
-            'time'                     => null,
1713
-            'ticket_rows'              => '',
1714
-            'existing_ticket_ids'      => '',
1715
-            'total_ticket_rows'        => 1,
1716
-            'ticket_js_structure'      => '',
1717
-            'trash_icon'               => 'dashicons dashicons-lock',
1718
-            'disabled'                 => '',
1719
-        ];
1720
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1721
-        /**
1722
-         * 1. Start with retrieving Datetimes
1723
-         * 2. Fore each datetime get related tickets
1724
-         * 3. For each ticket get related prices
1725
-         */
1726
-        /** @var EEM_Datetime $datetime_model */
1727
-        $datetime_model = EE_Registry::instance()->load_model('Datetime');
1728
-        /** @var EEM_Ticket $datetime_model */
1729
-        $ticket_model = EE_Registry::instance()->load_model('Ticket');
1730
-        $times        = $datetime_model->get_all_event_dates($event_id);
1731
-        /** @type EE_Datetime $first_datetime */
1732
-        $first_datetime = reset($times);
1733
-        // do we get related tickets?
1734
-        if (
1735
-            $first_datetime instanceof EE_Datetime
1736
-            && $first_datetime->ID() !== 0
1737
-        ) {
1738
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1739
-            $template_args['time']   = $first_datetime;
1740
-            $related_tickets         = $first_datetime->tickets(
1741
-                [
1742
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1743
-                    'default_where_conditions' => 'none',
1744
-                ]
1745
-            );
1746
-            if (! empty($related_tickets)) {
1747
-                $template_args['total_ticket_rows'] = count($related_tickets);
1748
-                $row                                = 0;
1749
-                foreach ($related_tickets as $ticket) {
1750
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1751
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1752
-                    $row++;
1753
-                }
1754
-            } else {
1755
-                $template_args['total_ticket_rows'] = 1;
1756
-                /** @type EE_Ticket $ticket */
1757
-                $ticket                       = $ticket_model->create_default_object();
1758
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1759
-            }
1760
-        } else {
1761
-            $template_args['time'] = $times[0];
1762
-            /** @type EE_Ticket[] $tickets */
1763
-            $tickets                      = $ticket_model->get_all_default_tickets();
1764
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1765
-            // NOTE: we're just sending the first default row
1766
-            // (decaf can't manage default tickets so this should be sufficient);
1767
-        }
1768
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1769
-            'event_editor_event_datetimes_help_tab'
1770
-        );
1771
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1772
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1773
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1774
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1775
-            $ticket_model->create_default_object(),
1776
-            true
1777
-        );
1778
-        $template                                  = apply_filters(
1779
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1780
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1781
-        );
1782
-        EEH_Template::display_template($template, $template_args);
1783
-    }
1784
-
1785
-
1786
-    /**
1787
-     * Setup an individual ticket form for the decaf event editor page
1788
-     *
1789
-     * @access private
1790
-     * @param EE_Ticket $ticket   the ticket object
1791
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1792
-     * @param int       $row
1793
-     * @return string generated html for the ticket row.
1794
-     * @throws EE_Error
1795
-     * @throws ReflectionException
1796
-     */
1797
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1798
-    {
1799
-        $template_args = [
1800
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1801
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1802
-                : '',
1803
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1804
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1805
-            'TKT_name'            => $ticket->get('TKT_name'),
1806
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1807
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1808
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1809
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1810
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1811
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1812
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1813
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1814
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'dashicons dashicons-lock',
1815
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1816
-                : ' disabled=disabled',
1817
-        ];
1818
-        $price         = $ticket->ID() !== 0
1819
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1820
-            : null;
1821
-        $price         = $price instanceof EE_Price
1822
-            ? $price
1823
-            : EEM_Price::instance()->create_default_object();
1824
-        $price_args    = [
1825
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1826
-            'PRC_amount'            => $price->get('PRC_amount'),
1827
-            'PRT_ID'                => $price->get('PRT_ID'),
1828
-            'PRC_ID'                => $price->get('PRC_ID'),
1829
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1830
-        ];
1831
-        // make sure we have default start and end dates if skeleton
1832
-        // handle rows that should NOT be empty
1833
-        if (empty($template_args['TKT_start_date'])) {
1834
-            // if empty then the start date will be now.
1835
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1836
-        }
1837
-        if (empty($template_args['TKT_end_date'])) {
1838
-            // get the earliest datetime (if present);
1839
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1840
-                ? $this->_cpt_model_obj->get_first_related(
1841
-                    'Datetime',
1842
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1843
-                )
1844
-                : null;
1845
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1846
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1847
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1848
-        }
1849
-        $template_args = array_merge($template_args, $price_args);
1850
-        $template      = apply_filters(
1851
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1852
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1853
-            $ticket
1854
-        );
1855
-        return EEH_Template::display_template($template, $template_args, true);
1856
-    }
1857
-
1858
-
1859
-    /**
1860
-     * @throws EE_Error
1861
-     * @throws ReflectionException
1862
-     */
1863
-    public function registration_options_meta_box()
1864
-    {
1865
-        $yes_no_values             = [
1866
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1867
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1868
-        ];
1869
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1870
-            [
1871
-                EEM_Registration::status_id_cancelled,
1872
-                EEM_Registration::status_id_declined,
1873
-                EEM_Registration::status_id_incomplete,
1874
-            ],
1875
-            true
1876
-        );
1877
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1878
-        $template_args['_event']                          = $this->_cpt_model_obj;
1879
-        $template_args['event']                           = $this->_cpt_model_obj;
1880
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1881
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1882
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1883
-            'default_reg_status',
1884
-            $default_reg_status_values,
1885
-            $this->_cpt_model_obj->default_registration_status()
1886
-        );
1887
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1888
-            'display_desc',
1889
-            $yes_no_values,
1890
-            $this->_cpt_model_obj->display_description()
1891
-        );
1892
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1893
-            'display_ticket_selector',
1894
-            $yes_no_values,
1895
-            $this->_cpt_model_obj->display_ticket_selector(),
1896
-            '',
1897
-            '',
1898
-            false
1899
-        );
1900
-        $template_args['additional_registration_options'] = apply_filters(
1901
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1902
-            '',
1903
-            $template_args,
1904
-            $yes_no_values,
1905
-            $default_reg_status_values
1906
-        );
1907
-        EEH_Template::display_template(
1908
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1909
-            $template_args
1910
-        );
1911
-    }
1912
-
1913
-
1914
-    /**
1915
-     * _get_events()
1916
-     * This method simply returns all the events (for the given _view and paging)
1917
-     *
1918
-     * @access public
1919
-     * @param int  $per_page     count of items per page (20 default);
1920
-     * @param int  $current_page what is the current page being viewed.
1921
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1922
-     *                           If FALSE then we return an array of event objects
1923
-     *                           that match the given _view and paging parameters.
1924
-     * @return array|int         an array of event objects or a count of them.
1925
-     * @throws Exception
1926
-     */
1927
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1928
-    {
1929
-        $EEM_Event   = $this->_event_model();
1930
-        $offset      = ($current_page - 1) * $per_page;
1931
-        $limit       = $count ? null : $offset . ',' . $per_page;
1932
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1933
-        $order       = $this->request->getRequestParam('order', 'DESC');
1934
-        $month_range = $this->request->getRequestParam('month_range');
1935
-        if ($month_range) {
1936
-            $pieces = explode(' ', $month_range, 3);
1937
-            // simulate the FIRST day of the month, that fixes issues for months like February
1938
-            // where PHP doesn't know what to assume for date.
1939
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1940
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1941
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1942
-        }
1943
-        $where  = [];
1944
-        $status = $this->request->getRequestParam('status');
1945
-        // determine what post_status our condition will have for the query.
1946
-        switch ($status) {
1947
-            case 'month':
1948
-            case 'today':
1949
-            case null:
1950
-            case 'all':
1951
-                break;
1952
-            case 'draft':
1953
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1954
-                break;
1955
-            default:
1956
-                $where['status'] = $status;
1957
-        }
1958
-        // categories? The default for all categories is -1
1959
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1960
-        if ($category !== -1) {
1961
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1962
-            $where['Term_Taxonomy.term_id']  = $category;
1963
-        }
1964
-        // date where conditions
1965
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1966
-        if ($month_range) {
1967
-            $DateTime = new DateTime(
1968
-                $year_r . '-' . $month_r . '-01 00:00:00',
1969
-                new DateTimeZone('UTC')
1970
-            );
1971
-            $start    = $DateTime->getTimestamp();
1972
-            // set the datetime to be the end of the month
1973
-            $DateTime->setDate(
1974
-                $year_r,
1975
-                $month_r,
1976
-                $DateTime->format('t')
1977
-            )->setTime(23, 59, 59);
1978
-            $end                             = $DateTime->getTimestamp();
1979
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1980
-        } elseif ($status === 'today') {
1981
-            $DateTime                        =
1982
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1983
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1984
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1985
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986
-        } elseif ($status === 'month') {
1987
-            $now                             = date('Y-m-01');
1988
-            $DateTime                        =
1989
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1990
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1991
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1992
-                                                        ->setTime(23, 59, 59)
1993
-                                                        ->format(implode(' ', $start_formats));
1994
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1995
-        }
1996
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1997
-            $where['EVT_wp_user'] = get_current_user_id();
1998
-        } else {
1999
-            if (! isset($where['status'])) {
2000
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
2001
-                    $where['OR'] = [
2002
-                        'status*restrict_private' => ['!=', 'private'],
2003
-                        'AND'                     => [
2004
-                            'status*inclusive' => ['=', 'private'],
2005
-                            'EVT_wp_user'      => get_current_user_id(),
2006
-                        ],
2007
-                    ];
2008
-                }
2009
-            }
2010
-        }
2011
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
2012
-        if (
2013
-            $wp_user
2014
-            && $wp_user !== get_current_user_id()
2015
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2016
-        ) {
2017
-            $where['EVT_wp_user'] = $wp_user;
2018
-        }
2019
-        // search query handling
2020
-        $search_term = $this->request->getRequestParam('s');
2021
-        if ($search_term) {
2022
-            $search_term = '%' . $search_term . '%';
2023
-            $where['OR'] = [
2024
-                'EVT_name'       => ['LIKE', $search_term],
2025
-                'EVT_desc'       => ['LIKE', $search_term],
2026
-                'EVT_short_desc' => ['LIKE', $search_term],
2027
-            ];
2028
-        }
2029
-        // filter events by venue.
2030
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
2031
-        if ($venue) {
2032
-            $where['Venue.VNU_ID'] = $venue;
2033
-        }
2034
-        $request_params = $this->request->requestParams();
2035
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
2036
-        $query_params   = apply_filters(
2037
-            'FHEE__Events_Admin_Page__get_events__query_params',
2038
-            [
2039
-                $where,
2040
-                'limit'    => $limit,
2041
-                'order_by' => $orderby,
2042
-                'order'    => $order,
2043
-                'group_by' => 'EVT_ID',
2044
-            ],
2045
-            $request_params
2046
-        );
2047
-
2048
-        // let's first check if we have special requests coming in.
2049
-        $active_status = $this->request->getRequestParam('active_status');
2050
-        if ($active_status) {
2051
-            switch ($active_status) {
2052
-                case 'upcoming':
2053
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
2054
-                case 'expired':
2055
-                    return $EEM_Event->get_expired_events($query_params, $count);
2056
-                case 'active':
2057
-                    return $EEM_Event->get_active_events($query_params, $count);
2058
-                case 'inactive':
2059
-                    return $EEM_Event->get_inactive_events($query_params, $count);
2060
-            }
2061
-        }
2062
-
2063
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
2064
-    }
2065
-
2066
-
2067
-    /**
2068
-     * handling for WordPress CPT actions (trash, restore, delete)
2069
-     *
2070
-     * @param string $post_id
2071
-     * @throws EE_Error
2072
-     * @throws ReflectionException
2073
-     */
2074
-    public function trash_cpt_item($post_id)
2075
-    {
2076
-        $this->request->setRequestParam('EVT_ID', $post_id);
2077
-        $this->_trash_or_restore_event('trash', false);
2078
-    }
2079
-
2080
-
2081
-    /**
2082
-     * @param string $post_id
2083
-     * @throws EE_Error
2084
-     * @throws ReflectionException
2085
-     */
2086
-    public function restore_cpt_item($post_id)
2087
-    {
2088
-        $this->request->setRequestParam('EVT_ID', $post_id);
2089
-        $this->_trash_or_restore_event('draft', false);
2090
-    }
2091
-
2092
-
2093
-    /**
2094
-     * @param string $post_id
2095
-     * @throws EE_Error
2096
-     * @throws EE_Error
2097
-     */
2098
-    public function delete_cpt_item($post_id)
2099
-    {
2100
-        throw new EE_Error(
2101
-            esc_html__(
2102
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2103
-                'event_espresso'
2104
-            )
2105
-        );
2106
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2107
-        // $this->_delete_event();
2108
-    }
2109
-
2110
-
2111
-    /**
2112
-     * _trash_or_restore_event
2113
-     *
2114
-     * @access protected
2115
-     * @param string $event_status
2116
-     * @param bool   $redirect_after
2117
-     * @throws EE_Error
2118
-     * @throws EE_Error
2119
-     * @throws ReflectionException
2120
-     */
2121
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2122
-    {
2123
-        // determine the event id and set to array.
2124
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2125
-        // loop thru events
2126
-        if ($EVT_ID) {
2127
-            // clean status
2128
-            $event_status = sanitize_key($event_status);
2129
-            // grab status
2130
-            if (! empty($event_status)) {
2131
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2132
-            } else {
2133
-                $success = false;
2134
-                $msg     = esc_html__(
2135
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2136
-                    'event_espresso'
2137
-                );
2138
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2139
-            }
2140
-        } else {
2141
-            $success = false;
2142
-            $msg     = esc_html__(
2143
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2144
-                'event_espresso'
2145
-            );
2146
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2147
-        }
2148
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2149
-        if ($redirect_after) {
2150
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2151
-        }
2152
-    }
2153
-
2154
-
2155
-    /**
2156
-     * _trash_or_restore_events
2157
-     *
2158
-     * @access protected
2159
-     * @param string $event_status
2160
-     * @return void
2161
-     * @throws EE_Error
2162
-     * @throws EE_Error
2163
-     * @throws ReflectionException
2164
-     */
2165
-    protected function _trash_or_restore_events($event_status = 'trash')
2166
-    {
2167
-        // clean status
2168
-        $event_status = sanitize_key($event_status);
2169
-        // grab status
2170
-        if (! empty($event_status)) {
2171
-            $success = true;
2172
-            // determine the event id and set to array.
2173
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2174
-            // loop thru events
2175
-            foreach ($EVT_IDs as $EVT_ID) {
2176
-                if ($EVT_ID = absint($EVT_ID)) {
2177
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2178
-                    $success = $results !== false ? $success : false;
2179
-                } else {
2180
-                    $msg = sprintf(
2181
-                        esc_html__(
2182
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2183
-                            'event_espresso'
2184
-                        ),
2185
-                        $EVT_ID
2186
-                    );
2187
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2188
-                    $success = false;
2189
-                }
2190
-            }
2191
-        } else {
2192
-            $success = false;
2193
-            $msg     = esc_html__(
2194
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2195
-                'event_espresso'
2196
-            );
2197
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2198
-        }
2199
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2200
-        $success = $success ? 2 : false;
2201
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2202
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2203
-    }
2204
-
2205
-
2206
-    /**
2207
-     * @param int    $EVT_ID
2208
-     * @param string $event_status
2209
-     * @return bool
2210
-     * @throws EE_Error
2211
-     * @throws ReflectionException
2212
-     */
2213
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2214
-    {
2215
-        // grab event id
2216
-        if (! $EVT_ID) {
2217
-            $msg = esc_html__(
2218
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2219
-                'event_espresso'
2220
-            );
2221
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2222
-            return false;
2223
-        }
2224
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2225
-        // clean status
2226
-        $event_status = sanitize_key($event_status);
2227
-        // grab status
2228
-        if (empty($event_status)) {
2229
-            $msg = esc_html__(
2230
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2231
-                'event_espresso'
2232
-            );
2233
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2234
-            return false;
2235
-        }
2236
-        // was event trashed or restored ?
2237
-        switch ($event_status) {
2238
-            case 'draft':
2239
-                $action = 'restored from the trash';
2240
-                $hook   = 'AHEE_event_restored_from_trash';
2241
-                break;
2242
-            case 'trash':
2243
-                $action = 'moved to the trash';
2244
-                $hook   = 'AHEE_event_moved_to_trash';
2245
-                break;
2246
-            default:
2247
-                $action = 'updated';
2248
-                $hook   = false;
2249
-        }
2250
-        // use class to change status
2251
-        $this->_cpt_model_obj->set_status($event_status);
2252
-        $success = $this->_cpt_model_obj->save();
2253
-        if (! $success) {
2254
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2255
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2256
-            return false;
2257
-        }
2258
-        if ($hook) {
2259
-            do_action($hook);
2260
-        }
2261
-        return true;
2262
-    }
2263
-
2264
-
2265
-    /**
2266
-     * @param array $event_ids
2267
-     * @return array
2268
-     * @since   4.10.23.p
2269
-     */
2270
-    private function cleanEventIds(array $event_ids)
2271
-    {
2272
-        return array_map('absint', $event_ids);
2273
-    }
2274
-
2275
-
2276
-    /**
2277
-     * @return array
2278
-     * @since   4.10.23.p
2279
-     */
2280
-    private function getEventIdsFromRequest()
2281
-    {
2282
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2283
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2284
-        } else {
2285
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2286
-        }
2287
-    }
2288
-
2289
-
2290
-    /**
2291
-     * @param bool $preview_delete
2292
-     * @throws EE_Error
2293
-     */
2294
-    protected function _delete_event($preview_delete = true)
2295
-    {
2296
-        $this->_delete_events($preview_delete);
2297
-    }
2298
-
2299
-
2300
-    /**
2301
-     * Gets the tree traversal batch persister.
2302
-     *
2303
-     * @return NodeGroupDao
2304
-     * @throws InvalidArgumentException
2305
-     * @throws InvalidDataTypeException
2306
-     * @throws InvalidInterfaceException
2307
-     * @since 4.10.12.p
2308
-     */
2309
-    protected function getModelObjNodeGroupPersister()
2310
-    {
2311
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2312
-            $this->model_obj_node_group_persister =
2313
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2314
-        }
2315
-        return $this->model_obj_node_group_persister;
2316
-    }
2317
-
2318
-
2319
-    /**
2320
-     * @param bool $preview_delete
2321
-     * @return void
2322
-     * @throws EE_Error
2323
-     */
2324
-    protected function _delete_events($preview_delete = true)
2325
-    {
2326
-        $event_ids = $this->getEventIdsFromRequest();
2327
-        if ($preview_delete) {
2328
-            $this->generateDeletionPreview($event_ids);
2329
-        } else {
2330
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2331
-        }
2332
-    }
2333
-
2334
-
2335
-    /**
2336
-     * @param array $event_ids
2337
-     */
2338
-    protected function generateDeletionPreview(array $event_ids)
2339
-    {
2340
-        $event_ids = $this->cleanEventIds($event_ids);
2341
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2342
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2343
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2344
-            [
2345
-                'action'            => 'preview_deletion',
2346
-                'deletion_job_code' => $deletion_job_code,
2347
-            ],
2348
-            $this->_admin_base_url
2349
-        );
2350
-        EEH_URL::safeRedirectAndExit(
2351
-            EE_Admin_Page::add_query_args_and_nonce(
2352
-                [
2353
-                    'page'              => EED_Batch::PAGE_SLUG,
2354
-                    'batch'             => EED_Batch::batch_job,
2355
-                    'EVT_IDs'           => $event_ids,
2356
-                    'deletion_job_code' => $deletion_job_code,
2357
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2358
-                    'return_url'        => urlencode($return_url),
2359
-                ],
2360
-                admin_url()
2361
-            )
2362
-        );
2363
-    }
2364
-
2365
-
2366
-    /**
2367
-     * Checks for a POST submission
2368
-     *
2369
-     * @since 4.10.12.p
2370
-     */
2371
-    protected function confirmDeletion()
2372
-    {
2373
-        $deletion_redirect_logic =
2374
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2375
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2376
-    }
2377
-
2378
-
2379
-    /**
2380
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2381
-     *
2382
-     * @throws EE_Error
2383
-     * @since 4.10.12.p
2384
-     */
2385
-    protected function previewDeletion()
2386
-    {
2387
-        $preview_deletion_logic =
2388
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2389
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2390
-        $this->display_admin_page_with_no_sidebar();
2391
-    }
2392
-
2393
-
2394
-    /**
2395
-     * get total number of events
2396
-     *
2397
-     * @access public
2398
-     * @return int
2399
-     * @throws EE_Error
2400
-     * @throws EE_Error
2401
-     */
2402
-    public function total_events()
2403
-    {
2404
-        return EEM_Event::instance()->count(
2405
-            ['caps' => 'read_admin'],
2406
-            'EVT_ID',
2407
-            true
2408
-        );
2409
-    }
2410
-
2411
-
2412
-    /**
2413
-     * get total number of draft events
2414
-     *
2415
-     * @access public
2416
-     * @return int
2417
-     * @throws EE_Error
2418
-     * @throws EE_Error
2419
-     */
2420
-    public function total_events_draft()
2421
-    {
2422
-        return EEM_Event::instance()->count(
2423
-            [
2424
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2425
-                'caps' => 'read_admin',
2426
-            ],
2427
-            'EVT_ID',
2428
-            true
2429
-        );
2430
-    }
2431
-
2432
-
2433
-    /**
2434
-     * get total number of trashed events
2435
-     *
2436
-     * @access public
2437
-     * @return int
2438
-     * @throws EE_Error
2439
-     * @throws EE_Error
2440
-     */
2441
-    public function total_trashed_events()
2442
-    {
2443
-        return EEM_Event::instance()->count(
2444
-            [
2445
-                ['status' => 'trash'],
2446
-                'caps' => 'read_admin',
2447
-            ],
2448
-            'EVT_ID',
2449
-            true
2450
-        );
2451
-    }
2452
-
2453
-
2454
-    /**
2455
-     *    _default_event_settings
2456
-     *    This generates the Default Settings Tab
2457
-     *
2458
-     * @return void
2459
-     * @throws DomainException
2460
-     * @throws EE_Error
2461
-     * @throws InvalidArgumentException
2462
-     * @throws InvalidDataTypeException
2463
-     * @throws InvalidInterfaceException
2464
-     */
2465
-    protected function _default_event_settings()
2466
-    {
2467
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2468
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2469
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
2470
-            $this->_default_event_settings_form()->get_html(),
2471
-            '',
2472
-            'padding'
2473
-        );
2474
-        $this->display_admin_page_with_sidebar();
2475
-    }
2476
-
2477
-
2478
-    /**
2479
-     * Return the form for event settings.
2480
-     *
2481
-     * @return EE_Form_Section_Proper
2482
-     * @throws EE_Error
2483
-     */
2484
-    protected function _default_event_settings_form()
2485
-    {
2486
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2487
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2488
-        // exclude
2489
-            [
2490
-                EEM_Registration::status_id_cancelled,
2491
-                EEM_Registration::status_id_declined,
2492
-                EEM_Registration::status_id_incomplete,
2493
-                EEM_Registration::status_id_wait_list,
2494
-            ],
2495
-            true
2496
-        );
2497
-        // setup Advanced Editor ???
2498
-        if (
2499
-            $this->raw_req_action === 'default_event_settings'
2500
-            || $this->raw_req_action === 'update_default_event_settings'
2501
-        ) {
2502
-            $this->advanced_editor_admin_form = $this->loader->getShared(AdvancedEditorAdminFormSection::class);
2503
-        }
2504
-        return new EE_Form_Section_Proper(
2505
-            [
2506
-                'name'            => 'update_default_event_settings',
2507
-                'html_id'         => 'update_default_event_settings',
2508
-                'html_class'      => 'form-table',
2509
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2510
-                'subsections'     => apply_filters(
2511
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2512
-                    [
2513
-                        'defaults_section_header' => new EE_Form_Section_HTML(
2514
-                            EEH_HTML::h2(
2515
-                                esc_html__('Default Settings', 'event_espresso'),
2516
-                                '',
2517
-                                'ee-admin-settings-hdr'
2518
-                            )
2519
-                        ),
2520
-                        'default_reg_status'  => new EE_Select_Input(
2521
-                            $registration_stati_for_selection,
2522
-                            [
2523
-                                'default'         => isset($registration_config->default_STS_ID)
2524
-                                                     && array_key_exists(
2525
-                                                         $registration_config->default_STS_ID,
2526
-                                                         $registration_stati_for_selection
2527
-                                                     )
2528
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2529
-                                    : EEM_Registration::status_id_pending_payment,
2530
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2531
-                                                     . EEH_Template::get_help_tab_link(
2532
-                                                         'default_settings_status_help_tab'
2533
-                                                     ),
2534
-                                'html_help_text'  => esc_html__(
2535
-                                    '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.',
2536
-                                    'event_espresso'
2537
-                                ),
2538
-                            ]
2539
-                        ),
2540
-                        'default_max_tickets' => new EE_Integer_Input(
2541
-                            [
2542
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2543
-                                    ? $registration_config->default_maximum_number_of_tickets
2544
-                                    : EEM_Event::get_default_additional_limit(),
2545
-                                'html_label_text' => esc_html__(
2546
-                                    'Default Maximum Tickets Allowed Per Order:',
2547
-                                    'event_espresso'
2548
-                                )
2549
-                                                     . EEH_Template::get_help_tab_link(
2550
-                                                         'default_maximum_tickets_help_tab"'
2551
-                                                     ),
2552
-                                'html_help_text'  => esc_html__(
2553
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2554
-                                    'event_espresso'
2555
-                                ),
2556
-                            ]
2557
-                        ),
2558
-                    ]
2559
-                ),
2560
-            ]
2561
-        );
2562
-    }
2563
-
2564
-
2565
-    /**
2566
-     * @return void
2567
-     * @throws EE_Error
2568
-     * @throws InvalidArgumentException
2569
-     * @throws InvalidDataTypeException
2570
-     * @throws InvalidInterfaceException
2571
-     */
2572
-    protected function _update_default_event_settings()
2573
-    {
2574
-        $form = $this->_default_event_settings_form();
2575
-        if ($form->was_submitted()) {
2576
-            $form->receive_form_submission();
2577
-            if ($form->is_valid()) {
2578
-                $registration_config = EE_Registry::instance()->CFG->registration;
2579
-                $valid_data          = $form->valid_data();
2580
-                if (isset($valid_data['default_reg_status'])) {
2581
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2582
-                }
2583
-                if (isset($valid_data['default_max_tickets'])) {
2584
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2585
-                }
2586
-                do_action(
2587
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2588
-                    $valid_data,
2589
-                    EE_Registry::instance()->CFG,
2590
-                    $this
2591
-                );
2592
-                // update because data was valid!
2593
-                EE_Registry::instance()->CFG->update_espresso_config();
2594
-                EE_Error::overwrite_success();
2595
-                EE_Error::add_success(
2596
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2597
-                );
2598
-            }
2599
-        }
2600
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2601
-    }
2602
-
2603
-
2604
-    /*************        Templates        *************
2605
-     *
2606
-     * @throws EE_Error
2607
-     */
2608
-    protected function _template_settings()
2609
-    {
2610
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2611
-        $this->_template_args['preview_img']  = '<img src="'
2612
-                                                . EVENTS_ASSETS_URL
2613
-                                                . '/images/'
2614
-                                                . 'caffeinated_template_features.jpg" alt="'
2615
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2616
-                                                . '" />';
2617
-        $this->_template_args['preview_text'] = '<strong>'
2618
-                                                . esc_html__(
2619
-                                                    '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.',
2620
-                                                    'event_espresso'
2621
-                                                ) . '</strong>';
2622
-        $this->display_admin_caf_preview_page('template_settings_tab');
2623
-    }
2624
-
2625
-
2626
-    /** Event Category Stuff **/
2627
-    /**
2628
-     * set the _category property with the category object for the loaded page.
2629
-     *
2630
-     * @access private
2631
-     * @return void
2632
-     */
2633
-    private function _set_category_object()
2634
-    {
2635
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2636
-            return;
2637
-        } //already have the category object so get out.
2638
-        // set default category object
2639
-        $this->_set_empty_category_object();
2640
-        // only set if we've got an id
2641
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2642
-        if (! $category_ID) {
2643
-            return;
2644
-        }
2645
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2646
-        if (! empty($term)) {
2647
-            $this->_category->category_name       = $term->name;
2648
-            $this->_category->category_identifier = $term->slug;
2649
-            $this->_category->category_desc       = $term->description;
2650
-            $this->_category->id                  = $term->term_id;
2651
-            $this->_category->parent              = $term->parent;
2652
-        }
2653
-    }
2654
-
2655
-
2656
-    /**
2657
-     * Clears out category properties.
2658
-     */
2659
-    private function _set_empty_category_object()
2660
-    {
2661
-        $this->_category                = new stdClass();
2662
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2663
-        $this->_category->id            = $this->_category->parent = 0;
2664
-    }
2665
-
2666
-
2667
-    /**
2668
-     * @throws DomainException
2669
-     * @throws EE_Error
2670
-     * @throws InvalidArgumentException
2671
-     * @throws InvalidDataTypeException
2672
-     * @throws InvalidInterfaceException
2673
-     */
2674
-    protected function _category_list_table()
2675
-    {
2676
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2677
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2678
-        $this->_admin_page_title .= ' ';
2679
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2680
-            'add_category',
2681
-            'add_category',
2682
-            [],
2683
-            'add-new-h2'
2684
-        );
2685
-        $this->display_admin_list_table_page_with_sidebar();
2686
-    }
2687
-
2688
-
2689
-    /**
2690
-     * Output category details view.
2691
-     *
2692
-     * @throws EE_Error
2693
-     * @throws EE_Error
2694
-     */
2695
-    protected function _category_details($view)
2696
-    {
2697
-        // load formatter helper
2698
-        // load field generator helper
2699
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2700
-        $this->_set_add_edit_form_tags($route);
2701
-        $this->_set_category_object();
2702
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2703
-        $delete_action = 'delete_category';
2704
-        // custom redirect
2705
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2706
-            ['action' => 'category_list'],
2707
-            $this->_admin_base_url
2708
-        );
2709
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2710
-        // take care of contents
2711
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2712
-        $this->display_admin_page_with_sidebar();
2713
-    }
2714
-
2715
-
2716
-    /**
2717
-     * Output category details content.
2718
-     *
2719
-     * @throws DomainException
2720
-     */
2721
-    protected function _category_details_content()
2722
-    {
2723
-        $editor_args['category_desc'] = [
2724
-            'type'          => 'wp_editor',
2725
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2726
-            'class'         => 'my_editor_custom',
2727
-            'wpeditor_args' => ['media_buttons' => false],
2728
-        ];
2729
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2730
-        $all_terms                    = get_terms(
2731
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2732
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2733
-        );
2734
-        // setup category select for term parents.
2735
-        $category_select_values[] = [
2736
-            'text' => esc_html__('No Parent', 'event_espresso'),
2737
-            'id'   => 0,
2738
-        ];
2739
-        foreach ($all_terms as $term) {
2740
-            $category_select_values[] = [
2741
-                'text' => $term->name,
2742
-                'id'   => $term->term_id,
2743
-            ];
2744
-        }
2745
-        $category_select = EEH_Form_Fields::select_input(
2746
-            'category_parent',
2747
-            $category_select_values,
2748
-            $this->_category->parent
2749
-        );
2750
-        $template_args   = [
2751
-            'category'                 => $this->_category,
2752
-            'category_select'          => $category_select,
2753
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2754
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2755
-            'disable'                  => '',
2756
-            'disabled_message'         => false,
2757
-        ];
2758
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2759
-        return EEH_Template::display_template($template, $template_args, true);
2760
-    }
2761
-
2762
-
2763
-    /**
2764
-     * Handles deleting categories.
2765
-     *
2766
-     * @throws EE_Error
2767
-     */
2768
-    protected function _delete_categories()
2769
-    {
2770
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2771
-        foreach ($category_IDs as $category_ID) {
2772
-            $this->_delete_category($category_ID);
2773
-        }
2774
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2775
-        $query_args = [
2776
-            'action' => 'category_list',
2777
-        ];
2778
-        $this->_redirect_after_action(0, '', '', $query_args);
2779
-    }
2780
-
2781
-
2782
-    /**
2783
-     * Handles deleting specific category.
2784
-     *
2785
-     * @param int $cat_id
2786
-     */
2787
-    protected function _delete_category($cat_id)
2788
-    {
2789
-        $cat_id = absint($cat_id);
2790
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2791
-    }
2792
-
2793
-
2794
-    /**
2795
-     * Handles triggering the update or insertion of a new category.
2796
-     *
2797
-     * @param bool $new_category true means we're triggering the insert of a new category.
2798
-     * @throws EE_Error
2799
-     * @throws EE_Error
2800
-     */
2801
-    protected function _insert_or_update_category($new_category)
2802
-    {
2803
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2804
-        $success = 0; // we already have a success message so lets not send another.
2805
-        if ($cat_id) {
2806
-            $query_args = [
2807
-                'action'     => 'edit_category',
2808
-                'EVT_CAT_ID' => $cat_id,
2809
-            ];
2810
-        } else {
2811
-            $query_args = ['action' => 'add_category'];
2812
-        }
2813
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2814
-    }
2815
-
2816
-
2817
-    /**
2818
-     * Inserts or updates category
2819
-     *
2820
-     * @param bool $update (true indicates we're updating a category).
2821
-     * @return bool|mixed|string
2822
-     */
2823
-    private function _insert_category($update = false)
2824
-    {
2825
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2826
-        $category_name       = $this->request->getRequestParam('category_name', '');
2827
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2828
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2829
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2830
-
2831
-        if (empty($category_name)) {
2832
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2833
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2834
-            return false;
2835
-        }
2836
-        $term_args = [
2837
-            'name'        => $category_name,
2838
-            'description' => $category_desc,
2839
-            'parent'      => $category_parent,
2840
-        ];
2841
-        // was the category_identifier input disabled?
2842
-        if ($category_identifier) {
2843
-            $term_args['slug'] = $category_identifier;
2844
-        }
2845
-        $insert_ids = $update
2846
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2847
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2848
-        if (! is_array($insert_ids)) {
2849
-            $msg = esc_html__(
2850
-                'An error occurred and the category has not been saved to the database.',
2851
-                'event_espresso'
2852
-            );
2853
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2854
-        } else {
2855
-            $category_ID = $insert_ids['term_id'];
2856
-            $msg         = sprintf(
2857
-                esc_html__('The category %s was successfully saved', 'event_espresso'),
2858
-                $category_name
2859
-            );
2860
-            EE_Error::add_success($msg);
2861
-        }
2862
-        return $category_ID;
2863
-    }
2864
-
2865
-
2866
-    /**
2867
-     * Gets categories or count of categories matching the arguments in the request.
2868
-     *
2869
-     * @param int  $per_page
2870
-     * @param int  $current_page
2871
-     * @param bool $count
2872
-     * @return EE_Term_Taxonomy[]|int
2873
-     * @throws EE_Error
2874
-     */
2875
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2876
-    {
2877
-        // testing term stuff
2878
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2879
-        $order       = $this->request->getRequestParam('order', 'DESC');
2880
-        $limit       = ($current_page - 1) * $per_page;
2881
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2882
-        $search_term = $this->request->getRequestParam('s');
2883
-        if ($search_term) {
2884
-            $search_term = '%' . $search_term . '%';
2885
-            $where['OR'] = [
2886
-                'Term.name'   => ['LIKE', $search_term],
2887
-                'description' => ['LIKE', $search_term],
2888
-            ];
2889
-        }
2890
-        $query_params = [
2891
-            $where,
2892
-            'order_by'   => [$orderby => $order],
2893
-            'limit'      => $limit . ',' . $per_page,
2894
-            'force_join' => ['Term'],
2895
-        ];
2896
-        return $count
2897
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2898
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2899
-    }
2900
-
2901
-    /* end category stuff */
2902
-
2903
-
2904
-    /**************/
2905
-
2906
-
2907
-    /**
2908
-     * Callback for the `ee_save_timezone_setting` ajax action.
2909
-     *
2910
-     * @throws EE_Error
2911
-     * @throws InvalidArgumentException
2912
-     * @throws InvalidDataTypeException
2913
-     * @throws InvalidInterfaceException
2914
-     */
2915
-    public function saveTimezoneString()
2916
-    {
2917
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2918
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2919
-            EE_Error::add_error(
2920
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2921
-                __FILE__,
2922
-                __FUNCTION__,
2923
-                __LINE__
2924
-            );
2925
-            $this->_template_args['error'] = true;
2926
-            $this->_return_json();
2927
-        }
2928
-
2929
-        update_option('timezone_string', $timezone_string);
2930
-        EE_Error::add_success(
2931
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2932
-        );
2933
-        $this->_template_args['success'] = true;
2934
-        $this->_return_json(true, ['action' => 'create_new']);
2935
-    }
2936
-
2937
-
2938
-    /**
2939 2606
      * @throws EE_Error
2940
-     * @deprecated 4.10.25.p
2941 2607
      */
2942
-    public function save_timezonestring_setting()
2943
-    {
2944
-        $this->saveTimezoneString();
2945
-    }
2608
+	protected function _template_settings()
2609
+	{
2610
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2611
+		$this->_template_args['preview_img']  = '<img src="'
2612
+												. EVENTS_ASSETS_URL
2613
+												. '/images/'
2614
+												. 'caffeinated_template_features.jpg" alt="'
2615
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2616
+												. '" />';
2617
+		$this->_template_args['preview_text'] = '<strong>'
2618
+												. esc_html__(
2619
+													'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.',
2620
+													'event_espresso'
2621
+												) . '</strong>';
2622
+		$this->display_admin_caf_preview_page('template_settings_tab');
2623
+	}
2624
+
2625
+
2626
+	/** Event Category Stuff **/
2627
+	/**
2628
+	 * set the _category property with the category object for the loaded page.
2629
+	 *
2630
+	 * @access private
2631
+	 * @return void
2632
+	 */
2633
+	private function _set_category_object()
2634
+	{
2635
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2636
+			return;
2637
+		} //already have the category object so get out.
2638
+		// set default category object
2639
+		$this->_set_empty_category_object();
2640
+		// only set if we've got an id
2641
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2642
+		if (! $category_ID) {
2643
+			return;
2644
+		}
2645
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2646
+		if (! empty($term)) {
2647
+			$this->_category->category_name       = $term->name;
2648
+			$this->_category->category_identifier = $term->slug;
2649
+			$this->_category->category_desc       = $term->description;
2650
+			$this->_category->id                  = $term->term_id;
2651
+			$this->_category->parent              = $term->parent;
2652
+		}
2653
+	}
2654
+
2655
+
2656
+	/**
2657
+	 * Clears out category properties.
2658
+	 */
2659
+	private function _set_empty_category_object()
2660
+	{
2661
+		$this->_category                = new stdClass();
2662
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2663
+		$this->_category->id            = $this->_category->parent = 0;
2664
+	}
2665
+
2666
+
2667
+	/**
2668
+	 * @throws DomainException
2669
+	 * @throws EE_Error
2670
+	 * @throws InvalidArgumentException
2671
+	 * @throws InvalidDataTypeException
2672
+	 * @throws InvalidInterfaceException
2673
+	 */
2674
+	protected function _category_list_table()
2675
+	{
2676
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2677
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2678
+		$this->_admin_page_title .= ' ';
2679
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2680
+			'add_category',
2681
+			'add_category',
2682
+			[],
2683
+			'add-new-h2'
2684
+		);
2685
+		$this->display_admin_list_table_page_with_sidebar();
2686
+	}
2687
+
2688
+
2689
+	/**
2690
+	 * Output category details view.
2691
+	 *
2692
+	 * @throws EE_Error
2693
+	 * @throws EE_Error
2694
+	 */
2695
+	protected function _category_details($view)
2696
+	{
2697
+		// load formatter helper
2698
+		// load field generator helper
2699
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2700
+		$this->_set_add_edit_form_tags($route);
2701
+		$this->_set_category_object();
2702
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2703
+		$delete_action = 'delete_category';
2704
+		// custom redirect
2705
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2706
+			['action' => 'category_list'],
2707
+			$this->_admin_base_url
2708
+		);
2709
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2710
+		// take care of contents
2711
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2712
+		$this->display_admin_page_with_sidebar();
2713
+	}
2714
+
2715
+
2716
+	/**
2717
+	 * Output category details content.
2718
+	 *
2719
+	 * @throws DomainException
2720
+	 */
2721
+	protected function _category_details_content()
2722
+	{
2723
+		$editor_args['category_desc'] = [
2724
+			'type'          => 'wp_editor',
2725
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2726
+			'class'         => 'my_editor_custom',
2727
+			'wpeditor_args' => ['media_buttons' => false],
2728
+		];
2729
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2730
+		$all_terms                    = get_terms(
2731
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2732
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2733
+		);
2734
+		// setup category select for term parents.
2735
+		$category_select_values[] = [
2736
+			'text' => esc_html__('No Parent', 'event_espresso'),
2737
+			'id'   => 0,
2738
+		];
2739
+		foreach ($all_terms as $term) {
2740
+			$category_select_values[] = [
2741
+				'text' => $term->name,
2742
+				'id'   => $term->term_id,
2743
+			];
2744
+		}
2745
+		$category_select = EEH_Form_Fields::select_input(
2746
+			'category_parent',
2747
+			$category_select_values,
2748
+			$this->_category->parent
2749
+		);
2750
+		$template_args   = [
2751
+			'category'                 => $this->_category,
2752
+			'category_select'          => $category_select,
2753
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2754
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2755
+			'disable'                  => '',
2756
+			'disabled_message'         => false,
2757
+		];
2758
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2759
+		return EEH_Template::display_template($template, $template_args, true);
2760
+	}
2761
+
2762
+
2763
+	/**
2764
+	 * Handles deleting categories.
2765
+	 *
2766
+	 * @throws EE_Error
2767
+	 */
2768
+	protected function _delete_categories()
2769
+	{
2770
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2771
+		foreach ($category_IDs as $category_ID) {
2772
+			$this->_delete_category($category_ID);
2773
+		}
2774
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2775
+		$query_args = [
2776
+			'action' => 'category_list',
2777
+		];
2778
+		$this->_redirect_after_action(0, '', '', $query_args);
2779
+	}
2780
+
2781
+
2782
+	/**
2783
+	 * Handles deleting specific category.
2784
+	 *
2785
+	 * @param int $cat_id
2786
+	 */
2787
+	protected function _delete_category($cat_id)
2788
+	{
2789
+		$cat_id = absint($cat_id);
2790
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2791
+	}
2792
+
2793
+
2794
+	/**
2795
+	 * Handles triggering the update or insertion of a new category.
2796
+	 *
2797
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2798
+	 * @throws EE_Error
2799
+	 * @throws EE_Error
2800
+	 */
2801
+	protected function _insert_or_update_category($new_category)
2802
+	{
2803
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2804
+		$success = 0; // we already have a success message so lets not send another.
2805
+		if ($cat_id) {
2806
+			$query_args = [
2807
+				'action'     => 'edit_category',
2808
+				'EVT_CAT_ID' => $cat_id,
2809
+			];
2810
+		} else {
2811
+			$query_args = ['action' => 'add_category'];
2812
+		}
2813
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2814
+	}
2815
+
2816
+
2817
+	/**
2818
+	 * Inserts or updates category
2819
+	 *
2820
+	 * @param bool $update (true indicates we're updating a category).
2821
+	 * @return bool|mixed|string
2822
+	 */
2823
+	private function _insert_category($update = false)
2824
+	{
2825
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2826
+		$category_name       = $this->request->getRequestParam('category_name', '');
2827
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2828
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2829
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2830
+
2831
+		if (empty($category_name)) {
2832
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2833
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2834
+			return false;
2835
+		}
2836
+		$term_args = [
2837
+			'name'        => $category_name,
2838
+			'description' => $category_desc,
2839
+			'parent'      => $category_parent,
2840
+		];
2841
+		// was the category_identifier input disabled?
2842
+		if ($category_identifier) {
2843
+			$term_args['slug'] = $category_identifier;
2844
+		}
2845
+		$insert_ids = $update
2846
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2847
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2848
+		if (! is_array($insert_ids)) {
2849
+			$msg = esc_html__(
2850
+				'An error occurred and the category has not been saved to the database.',
2851
+				'event_espresso'
2852
+			);
2853
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2854
+		} else {
2855
+			$category_ID = $insert_ids['term_id'];
2856
+			$msg         = sprintf(
2857
+				esc_html__('The category %s was successfully saved', 'event_espresso'),
2858
+				$category_name
2859
+			);
2860
+			EE_Error::add_success($msg);
2861
+		}
2862
+		return $category_ID;
2863
+	}
2864
+
2865
+
2866
+	/**
2867
+	 * Gets categories or count of categories matching the arguments in the request.
2868
+	 *
2869
+	 * @param int  $per_page
2870
+	 * @param int  $current_page
2871
+	 * @param bool $count
2872
+	 * @return EE_Term_Taxonomy[]|int
2873
+	 * @throws EE_Error
2874
+	 */
2875
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2876
+	{
2877
+		// testing term stuff
2878
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2879
+		$order       = $this->request->getRequestParam('order', 'DESC');
2880
+		$limit       = ($current_page - 1) * $per_page;
2881
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2882
+		$search_term = $this->request->getRequestParam('s');
2883
+		if ($search_term) {
2884
+			$search_term = '%' . $search_term . '%';
2885
+			$where['OR'] = [
2886
+				'Term.name'   => ['LIKE', $search_term],
2887
+				'description' => ['LIKE', $search_term],
2888
+			];
2889
+		}
2890
+		$query_params = [
2891
+			$where,
2892
+			'order_by'   => [$orderby => $order],
2893
+			'limit'      => $limit . ',' . $per_page,
2894
+			'force_join' => ['Term'],
2895
+		];
2896
+		return $count
2897
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2898
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2899
+	}
2900
+
2901
+	/* end category stuff */
2902
+
2903
+
2904
+	/**************/
2905
+
2906
+
2907
+	/**
2908
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2909
+	 *
2910
+	 * @throws EE_Error
2911
+	 * @throws InvalidArgumentException
2912
+	 * @throws InvalidDataTypeException
2913
+	 * @throws InvalidInterfaceException
2914
+	 */
2915
+	public function saveTimezoneString()
2916
+	{
2917
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2918
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2919
+			EE_Error::add_error(
2920
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2921
+				__FILE__,
2922
+				__FUNCTION__,
2923
+				__LINE__
2924
+			);
2925
+			$this->_template_args['error'] = true;
2926
+			$this->_return_json();
2927
+		}
2928
+
2929
+		update_option('timezone_string', $timezone_string);
2930
+		EE_Error::add_success(
2931
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2932
+		);
2933
+		$this->_template_args['success'] = true;
2934
+		$this->_return_json(true, ['action' => 'create_new']);
2935
+	}
2936
+
2937
+
2938
+	/**
2939
+	 * @throws EE_Error
2940
+	 * @deprecated 4.10.25.p
2941
+	 */
2942
+	public function save_timezonestring_setting()
2943
+	{
2944
+		$this->saveTimezoneString();
2945
+	}
2946 2946
 }
Please login to merge, or discard this patch.
modules/events_archive/EED_Events_Archive.module.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public static function set_definitions()
122 122
     {
123
-        define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
124
-        define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
123
+        define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
124
+        define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/');
125 125
     }
126 126
 
127 127
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public static function get_iframe_embed_button()
143 143
     {
144
-        if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
144
+        if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
145 145
             self::$_iframe_embed_button = new EventListIframeEmbedButton();
146 146
         }
147 147
         return self::$_iframe_embed_button;
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
         EEH_Event_Query::add_query_filters();
219 219
         // set params that will get used by the filters
220 220
         EEH_Event_Query::set_query_params(
221
-            '',                             // month
222
-            '',                             // category
221
+            '', // month
222
+            '', // category
223 223
             $config->display_expired_events // show_expired
224 224
         );
225 225
         // check what template is loaded
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
     public function template_include($template = '')
282 282
     {
283 283
         // don't add content filter for dedicated EE child themes or private posts
284
-        if (! EEH_Template::is_espresso_theme()) {
284
+        if ( ! EEH_Template::is_espresso_theme()) {
285 285
             /** @type EE_Events_Archive_Config $config */
286 286
             $config = $this->config();
287 287
             // add status banner ?
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
         global $post;
356 356
         if ($post instanceof WP_Post) {
357 357
             return (EED_Events_Archive::isBlockTheme() || in_the_loop()) && $post->ID == $id
358
-                ? espresso_event_status_banner($post->ID) . $title
358
+                ? espresso_event_status_banner($post->ID).$title
359 359
                 : $title;
360 360
         }
361 361
         return $title;
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
         if (post_password_required()) {
460 460
             return $content;
461 461
         }
462
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
462
+        return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content;
463 463
     }
464 464
 
465 465
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
         if (post_password_required()) {
475 475
             return $content;
476 476
         }
477
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
477
+        return EEH_Template::locate_template('content-espresso_events-tickets.php').$content;
478 478
     }
479 479
 
480 480
 
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
         if (post_password_required()) {
502 502
             return $content;
503 503
         }
504
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
504
+        return $content.EEH_Template::locate_template('content-espresso_events-venues.php');
505 505
     }
506 506
 
507 507
 
@@ -737,10 +737,10 @@  discard block
 block discarded – undo
737 737
         // get some style
738 738
         if (apply_filters('FHEE_enable_default_espresso_css', false)) {
739 739
             // first check uploads folder
740
-            if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) {
740
+            if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.'/style.css')) {
741 741
                 wp_register_style(
742 742
                     $this->theme,
743
-                    get_stylesheet_directory_uri() . $this->theme . '/style.css',
743
+                    get_stylesheet_directory_uri().$this->theme.'/style.css',
744 744
                     ['dashicons', 'espresso_default']
745 745
                 );
746 746
             }
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
             'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
763 763
             $template_settings->EED_Events_Archive
764 764
         );
765
-        $events_archive_settings               = [
765
+        $events_archive_settings = [
766 766
             'display_status_banner'   => 0,
767 767
             'display_description'     => 1,
768 768
             'display_ticket_selector' => 0,
@@ -770,12 +770,12 @@  discard block
 block discarded – undo
770 770
             'display_venue'           => 0,
771 771
             'display_expired_events'  => 0,
772 772
         ];
773
-        $events_archive_settings               = array_merge(
773
+        $events_archive_settings = array_merge(
774 774
             $events_archive_settings,
775 775
             (array) $template_settings->EED_Events_Archive
776 776
         );
777 777
         EEH_Template::display_template(
778
-            EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
778
+            EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php',
779 779
             $events_archive_settings
780 780
         );
781 781
     }
Please login to merge, or discard this patch.
Indentation   +1052 added lines, -1052 removed lines patch added patch discarded remove patch
@@ -16,1047 +16,1047 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class EED_Events_Archive extends EED_Module
18 18
 {
19
-    const EVENT_DETAILS_PRIORITY   = 100;
20
-
21
-    const EVENT_DATETIMES_PRIORITY = 110;
22
-
23
-    const EVENT_TICKETS_PRIORITY   = 120;
24
-
25
-    const EVENT_VENUES_PRIORITY    = 130;
26
-
27
-
28
-    public static $espresso_event_list_ID    = 0;
29
-
30
-    public static $espresso_grid_event_lists = [];
31
-
32
-    /**
33
-     * @type bool $using_get_the_excerpt
34
-     */
35
-    protected static $using_get_the_excerpt = false;
36
-
37
-    /**
38
-     * Used to flag when the event list is being called from an external iframe.
39
-     *
40
-     * @var bool $iframe
41
-     */
42
-    protected static $iframe = false;
43
-
44
-    /**
45
-     * @var EventListIframeEmbedButton $_iframe_embed_button
46
-     */
47
-    private static $_iframe_embed_button;
48
-
49
-    /**
50
-     * @type EE_Template_Part_Manager $template_parts
51
-     */
52
-    protected $template_parts;
53
-
54
-
55
-    /**
56
-     * @return EED_Events_Archive
57
-     * @throws EE_Error
58
-     * @throws ReflectionException
59
-     */
60
-    public static function instance()
61
-    {
62
-        return parent::get_instance(__CLASS__);
63
-    }
64
-
65
-
66
-    /**
67
-     * for hooking into EE Core, other modules, etc
68
-     *
69
-     * @return void
70
-     * @throws InvalidArgumentException
71
-     * @throws InvalidDataTypeException
72
-     * @throws InvalidInterfaceException
73
-     */
74
-    public static function set_hooks()
75
-    {
76
-        /** @var CustomPostTypeDefinitions $custom_post_type_definitions */
77
-        $custom_post_type_definitions = LoaderFactory::getLoader()->getShared(CustomPostTypeDefinitions::class);
78
-        $custom_post_types            = $custom_post_type_definitions->getDefinitions();
79
-        EE_Config::register_route(
80
-            $custom_post_types['espresso_events']['plural_slug'],
81
-            'Events_Archive',
82
-            'run'
83
-        );
84
-        EE_Config::register_route(
85
-            'event_list',
86
-            'Events_Archive',
87
-            'event_list'
88
-        );
89
-        EE_Config::register_route(
90
-            'iframe',
91
-            'Events_Archive',
92
-            'event_list_iframe',
93
-            'event_list'
94
-        );
95
-        add_action('wp_loaded', ['EED_Events_Archive', 'set_definitions'], 2);
96
-    }
97
-
98
-
99
-    /**
100
-     * for hooking into EE Admin Core, other modules, etc
101
-     *
102
-     * @return void
103
-     */
104
-    public static function set_hooks_admin()
105
-    {
106
-        add_action('wp_loaded', ['EED_Events_Archive', 'set_definitions'], 2);
107
-        // hook into the end of the \EE_Admin_Page::_load_page_dependencies()
108
-        // to load assets for "espresso_events" page on the "default" route (action)
109
-        add_action(
110
-            'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default',
111
-            ['EED_Events_Archive', 'event_list_iframe_embed_button'],
112
-            10
113
-        );
114
-    }
115
-
116
-
117
-    /**
118
-     * @return void
119
-     */
120
-    public static function set_definitions()
121
-    {
122
-        define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
123
-        define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
124
-    }
125
-
126
-
127
-    /**
128
-     * set up EE_Events_Archive_Config
129
-     */
130
-    protected function set_config()
131
-    {
132
-        $this->set_config_section('template_settings');
133
-        $this->set_config_class('EE_Events_Archive_Config');
134
-        $this->set_config_name('EED_Events_Archive');
135
-    }
136
-
137
-
138
-    /**
139
-     * @return EventListIframeEmbedButton
140
-     */
141
-    public static function get_iframe_embed_button()
142
-    {
143
-        if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
144
-            self::$_iframe_embed_button = new EventListIframeEmbedButton();
145
-        }
146
-        return self::$_iframe_embed_button;
147
-    }
148
-
149
-
150
-    /**
151
-     * @return void
152
-     */
153
-    public static function event_list_iframe_embed_button()
154
-    {
155
-        $iframe_embed_button = EED_Events_Archive::get_iframe_embed_button();
156
-        $iframe_embed_button->addEmbedButton();
157
-    }
158
-
159
-
160
-    /**
161
-     * @param EE_Events_Archive_Config|null $config
162
-     * @return EE_Template_Part_Manager
163
-     * @throws EE_Error
164
-     */
165
-    public function initialize_template_parts(EE_Events_Archive_Config $config = null)
166
-    {
167
-        $config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
168
-        EEH_Autoloader::register_template_part_autoloaders();
169
-        $template_parts = new EE_Template_Part_Manager();
170
-        $template_parts->add_template_part(
171
-            'tickets',
172
-            esc_html__('Ticket Selector', 'event_espresso'),
173
-            'content-espresso_events-tickets.php',
174
-            $config->display_order_tickets
175
-        );
176
-        $template_parts->add_template_part(
177
-            'datetimes',
178
-            esc_html__('Dates and Times', 'event_espresso'),
179
-            'content-espresso_events-datetimes.php',
180
-            $config->display_order_datetimes
181
-        );
182
-        $template_parts->add_template_part(
183
-            'event',
184
-            esc_html__('Event Description', 'event_espresso'),
185
-            'content-espresso_events-details.php',
186
-            $config->display_order_event
187
-        );
188
-        $template_parts->add_template_part(
189
-            'venue',
190
-            esc_html__('Venue Information', 'event_espresso'),
191
-            'content-espresso_events-venues.php',
192
-            $config->display_order_venue
193
-        );
194
-        do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts);
195
-        return $template_parts;
196
-    }
197
-
198
-
199
-    /**
200
-     * initial module setup
201
-     * this gets called by the EE_Front_Controller if the module route is found in the incoming request
202
-     *
203
-     * @param WP $WP
204
-     * @return void
205
-     */
206
-    public function run($WP)
207
-    {
208
-        do_action('AHEE__EED_Events_Archive__before_run');
209
-        // ensure valid EE_Events_Archive_Config() object exists
210
-        $this->set_config();
211
-        /** @type EE_Events_Archive_Config $config */
212
-        $config = $this->config();
213
-        // load other required components
214
-        $this->load_event_list_assets();
215
-        // filter the WP posts_join, posts_where, and posts_orderby SQL clauses
216
-        // add query filters
217
-        EEH_Event_Query::add_query_filters();
218
-        // set params that will get used by the filters
219
-        EEH_Event_Query::set_query_params(
220
-            '',                             // month
221
-            '',                             // category
222
-            $config->display_expired_events // show_expired
223
-        );
224
-        // check what template is loaded
225
-        add_filter('template_include', [$this, 'template_include'], 999, 1);
226
-    }
227
-
228
-
229
-    /**
230
-     * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting
231
-     *
232
-     * @return void
233
-     */
234
-    public function event_list()
235
-    {
236
-        // ensure valid EE_Events_Archive_Config() object exists
237
-        $this->set_config();
238
-        // load other required components
239
-        $this->load_event_list_assets();
240
-    }
241
-
242
-
243
-    /**
244
-     * @return void
245
-     * @throws EE_Error
246
-     * @throws ReflectionException
247
-     */
248
-    public function event_list_iframe()
249
-    {
250
-        EED_Events_Archive::$iframe = true;
251
-        $event_list_iframe          = new EventsArchiveIframe($this);
252
-        $event_list_iframe->display();
253
-    }
254
-
255
-
256
-    /**
257
-     * @return bool
258
-     */
259
-    public static function is_iframe()
260
-    {
261
-        return EED_Events_Archive::$iframe;
262
-    }
263
-
264
-
265
-    /**
266
-     * @return string
267
-     */
268
-    public static function link_target()
269
-    {
270
-        return EED_Events_Archive::$iframe ? ' target="_blank"' : '';
271
-    }
272
-
273
-
274
-    /**
275
-     * @param string $template
276
-     * @return string
277
-     * @throws EE_Error
278
-     * @throws ReflectionException
279
-     */
280
-    public function template_include($template = '')
281
-    {
282
-        // don't add content filter for dedicated EE child themes or private posts
283
-        if (! EEH_Template::is_espresso_theme()) {
284
-            /** @type EE_Events_Archive_Config $config */
285
-            $config = $this->config();
286
-            // add status banner ?
287
-            if ($config->display_status_banner) {
288
-                add_filter('the_title', ['EED_Events_Archive', 'the_title'], 100, 2);
289
-            }
290
-            // if NOT a custom template
291
-            if (
292
-                apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false)
293
-                || EE_Registry::instance()
294
-                              ->load_core('Front_Controller')
295
-                              ->get_selected_template() !== 'archive-espresso_events.php'
296
-            ) {
297
-                add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true');
298
-                // load functions.php file for the theme (loaded by WP if using child theme)
299
-                EEH_Template::load_espresso_theme_functions();
300
-                EED_Events_Archive::addEventDetailsFilters();
301
-                // don't display entry meta because the existing theme will take care of that
302
-                add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
303
-            }
304
-        }
305
-        return $template;
306
-    }
307
-
308
-
309
-    /**
310
-     * kinda hacky, but if a theme is using get_the_excerpt(),
311
-     * then we need to remove our filters on the_content()
312
-     *
313
-     * @param string $excerpt
314
-     * @return string
315
-     * @throws EE_Error
316
-     * @throws ReflectionException
317
-     */
318
-    public static function get_the_excerpt($excerpt = '')
319
-    {
320
-        if (post_password_required()) {
321
-            return $excerpt;
322
-        }
323
-        if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) {
324
-            EED_Events_Archive::removeEventDetailsFilters(false);
325
-            $excerpt = EED_Events_Archive::event_details($excerpt);
326
-        } else {
327
-            EED_Events_Archive::$using_get_the_excerpt = true;
328
-            add_filter('wp_trim_excerpt', ['EED_Events_Archive', 'end_get_the_excerpt'], 999, 1);
329
-        }
330
-        return $excerpt;
331
-    }
332
-
333
-
334
-    /**
335
-     * @param string $text
336
-     * @return string
337
-     */
338
-    public static function end_get_the_excerpt($text = '')
339
-    {
340
-        EED_Events_Archive::$using_get_the_excerpt = false;
341
-        return $text;
342
-    }
343
-
344
-
345
-    /**
346
-     * @param string $title
347
-     * @param string $id
348
-     * @return string
349
-     * @throws EE_Error
350
-     * @throws ReflectionException
351
-     */
352
-    public static function the_title($title = '', $id = '')
353
-    {
354
-        global $post;
355
-        if ($post instanceof WP_Post) {
356
-            return (EED_Events_Archive::isBlockTheme() || in_the_loop()) && $post->ID == $id
357
-                ? espresso_event_status_banner($post->ID) . $title
358
-                : $title;
359
-        }
360
-        return $title;
361
-    }
362
-
363
-
364
-    /**
365
-     * @param string $content
366
-     * @return string
367
-     * @throws EE_Error
368
-     * @throws ReflectionException
369
-     */
370
-    public static function event_details($content)
371
-    {
372
-        global $post;
373
-        static $current_post_ID = 0;
374
-        if (
375
-            $current_post_ID !== $post->ID
376
-            && $post->post_type === 'espresso_events'
377
-            && ! EED_Events_Archive::$using_get_the_excerpt
378
-            && ! post_password_required()
379
-            && (
380
-                apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false)
381
-                || ! apply_filters('FHEE__content_espresso_events__template_loaded', false)
382
-            )
383
-        ) {
384
-            // Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
385
-            // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
386
-            // BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
387
-            // We want to allow those plugins to still do their thing and have access to our content, but depending on
388
-            // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
389
-            // so the following allows this filter to be applied multiple times, but only once for real
390
-            $current_post_ID = did_action('loop_start') ? $post->ID : 0;
391
-            if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) {
392
-                $content = EED_Events_Archive::use_sortable_display_order();
393
-            } else {
394
-                $content = EED_Events_Archive::use_filterable_display_order();
395
-            }
396
-        }
397
-        return $content;
398
-    }
399
-
400
-
401
-    /**
402
-     * @return string
403
-     * @throws EE_Error
404
-     * @throws ReflectionException
405
-     */
406
-    protected static function use_sortable_display_order()
407
-    {
408
-        // no further password checks required atm
409
-        add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true');
410
-        // remove this callback from being applied to the_content()
411
-        EED_Events_Archive::removeEventDetailsFilters();
412
-        // now add additional content depending on whether event is using the_excerpt() or the_content()
413
-        EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
414
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
415
-        $content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content);
416
-        // re-add our main filters (or else the next event won't have them)
417
-        EED_Events_Archive::addEventDetailsFilters();
418
-        remove_filter(
419
-            'FHEE__EED_Events_Archive__event_details__no_post_password_required',
420
-            '__return_true'
421
-        );
422
-        return $content;
423
-    }
424
-
425
-
426
-    /**
427
-     * @return string
428
-     */
429
-    protected static function use_filterable_display_order()
430
-    {
431
-        // remove this callback from being applied to the_content()
432
-        EED_Events_Archive::removeEventDetailsFilters();
433
-        // now add additional content depending on whether event is using the_excerpt() or the_content()
434
-        EED_Events_Archive::_add_additional_excerpt_filters();
435
-        EED_Events_Archive::_add_additional_content_filters();
436
-        do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters');
437
-        // now load our template
438
-        $content = EEH_Template::locate_template('content-espresso_events-details.php');
439
-        // re-add our main filters (or else the next event won't have them)
440
-        EED_Events_Archive::addEventDetailsFilters();
441
-        // but remove the other filters so that they don't get applied to the next post
442
-        EED_Events_Archive::_remove_additional_events_archive_filters();
443
-        do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters');
444
-        // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
445
-        // return ! empty( $template ) ? $template : $content;
446
-        return $content;
447
-    }
448
-
449
-
450
-    /**
451
-     * adds datetimes ABOVE content
452
-     *
453
-     * @param string $content
454
-     * @return string
455
-     */
456
-    public static function event_datetimes($content)
457
-    {
458
-        if (post_password_required()) {
459
-            return $content;
460
-        }
461
-        return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
462
-    }
463
-
464
-
465
-    /**
466
-     * adds tickets ABOVE content (which includes datetimes)
467
-     *
468
-     * @param string $content
469
-     * @return string
470
-     */
471
-    public static function event_tickets($content)
472
-    {
473
-        if (post_password_required()) {
474
-            return $content;
475
-        }
476
-        return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
477
-    }
478
-
479
-
480
-    /**
481
-     * adds venues BELOW content
482
-     *
483
-     * @param string $content
484
-     * @return string
485
-     */
486
-    public static function event_venue($content)
487
-    {
488
-        return EED_Events_Archive::event_venues($content);
489
-    }
490
-
491
-
492
-    /**
493
-     * adds venues BELOW content
494
-     *
495
-     * @param string $content
496
-     * @return string
497
-     */
498
-    public static function event_venues($content)
499
-    {
500
-        if (post_password_required()) {
501
-            return $content;
502
-        }
503
-        return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
504
-    }
505
-
506
-
507
-    /**
508
-     * @return bool
509
-     * @since $VID:$
510
-     */
511
-    public static function isBlockTheme()
512
-    {
513
-        return function_exists('wp_is_block_theme') && wp_is_block_theme();
514
-    }
515
-
516
-
517
-    /**
518
-     * @return string
519
-     * @since $VID:$
520
-     */
521
-    public static function getExcerptFilter()
522
-    {
523
-        static $excerpt_filter = null;
524
-        if ($excerpt_filter === null) {
525
-            $excerpt_filter = EED_Events_Archive::isBlockTheme() ? 'get_the_excerpt' : 'the_excerpt';
526
-        }
527
-        return $excerpt_filter;
528
-    }
529
-
530
-
531
-    /**
532
-     * @since $VID:$
533
-     */
534
-    protected static function addEventDetailsFilters()
535
-    {
536
-        add_filter(
537
-            'the_content',
538
-            ['EED_Events_Archive', 'event_details'],
539
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
540
-        );
541
-        // but because we don't know if the theme is using the_excerpt()
542
-        add_filter(
543
-            EED_Events_Archive::getExcerptFilter(),
544
-            ['EED_Events_Archive', 'event_details'],
545
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
546
-        );
547
-        // and just in case they are running get_the_excerpt() which DESTROYS things
548
-        add_filter('get_the_excerpt', ['EED_Events_Archive', 'get_the_excerpt'], 1, 1);
549
-    }
550
-
551
-
552
-    /**
553
-     * @param bool $and_get_the_excerpt
554
-     * @since $VID:$
555
-     */
556
-    protected static function removeEventDetailsFilters($and_get_the_excerpt = true)
557
-    {
558
-        // we need to first remove all callbacks from being applied to the_content()
559
-        // (otherwise it will recurse and blow up the interweb)
560
-        remove_filter(
561
-            'the_content',
562
-            ['EED_Events_Archive', 'event_details'],
563
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
564
-        );
565
-        remove_filter(
566
-            EED_Events_Archive::getExcerptFilter(),
567
-            ['EED_Events_Archive', 'event_details'],
568
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
569
-        );
570
-        if ($and_get_the_excerpt) {
571
-            remove_filter('get_the_excerpt', ['EED_Events_Archive', 'get_the_excerpt'], 1);
572
-        }
573
-    }
574
-
575
-
576
-    /**
577
-     * @return void
578
-     */
579
-    private static function _add_additional_excerpt_filters()
580
-    {
581
-        add_filter(
582
-            EED_Events_Archive::getExcerptFilter(),
583
-            ['EED_Events_Archive', 'event_datetimes'],
584
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
585
-        );
586
-        add_filter(
587
-            EED_Events_Archive::getExcerptFilter(),
588
-            ['EED_Events_Archive', 'event_tickets'],
589
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
590
-        );
591
-        add_filter(
592
-            EED_Events_Archive::getExcerptFilter(),
593
-            ['EED_Events_Archive', 'event_venues'],
594
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
595
-        );
596
-    }
597
-
598
-
599
-    /**
600
-     * @return void
601
-     */
602
-    private static function _add_additional_content_filters()
603
-    {
604
-        add_filter(
605
-            'the_content',
606
-            ['EED_Events_Archive', 'event_datetimes'],
607
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
608
-        );
609
-        add_filter(
610
-            'the_content',
611
-            ['EED_Events_Archive', 'event_tickets'],
612
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
613
-        );
614
-        add_filter(
615
-            'the_content',
616
-            ['EED_Events_Archive', 'event_venues'],
617
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
618
-        );
619
-    }
620
-
621
-
622
-    /**
623
-     * @return void
624
-     */
625
-    private static function _remove_additional_events_archive_filters()
626
-    {
627
-        remove_filter(
628
-            EED_Events_Archive::getExcerptFilter(),
629
-            ['EED_Events_Archive', 'event_datetimes'],
630
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
631
-        );
632
-        remove_filter(
633
-            EED_Events_Archive::getExcerptFilter(),
634
-            ['EED_Events_Archive', 'event_tickets'],
635
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
636
-        );
637
-        remove_filter(
638
-            EED_Events_Archive::getExcerptFilter(),
639
-            ['EED_Events_Archive', 'event_venues'],
640
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
641
-        );
642
-        remove_filter(
643
-            'the_content',
644
-            ['EED_Events_Archive', 'event_datetimes'],
645
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
646
-        );
647
-        remove_filter(
648
-            'the_content',
649
-            ['EED_Events_Archive', 'event_tickets'],
650
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
651
-        );
652
-        remove_filter(
653
-            'the_content',
654
-            ['EED_Events_Archive', 'event_venues'],
655
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
656
-        );
657
-    }
658
-
659
-
660
-    /**
661
-     * @return void
662
-     */
663
-    public static function remove_all_events_archive_filters()
664
-    {
665
-        // remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
666
-        remove_filter('the_title', ['EED_Events_Archive', 'the_title'], 1);
667
-        remove_filter(
668
-            EED_Events_Archive::getExcerptFilter(),
669
-            ['EED_Events_Archive', 'event_details'],
670
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
671
-        );
672
-        remove_filter(
673
-            EED_Events_Archive::getExcerptFilter(),
674
-            ['EED_Events_Archive', 'event_datetimes'],
675
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
676
-        );
677
-        remove_filter(
678
-            EED_Events_Archive::getExcerptFilter(),
679
-            ['EED_Events_Archive', 'event_tickets'],
680
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
681
-        );
682
-        remove_filter(
683
-            EED_Events_Archive::getExcerptFilter(),
684
-            ['EED_Events_Archive', 'event_venues'],
685
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
686
-        );
687
-        remove_filter(
688
-            'the_content',
689
-            ['EED_Events_Archive', 'event_details'],
690
-            EED_Events_Archive::EVENT_DETAILS_PRIORITY
691
-        );
692
-        remove_filter(
693
-            'the_content',
694
-            ['EED_Events_Archive', 'event_datetimes'],
695
-            EED_Events_Archive::EVENT_DATETIMES_PRIORITY
696
-        );
697
-        remove_filter(
698
-            'the_content',
699
-            ['EED_Events_Archive', 'event_tickets'],
700
-            EED_Events_Archive::EVENT_TICKETS_PRIORITY
701
-        );
702
-        remove_filter(
703
-            'the_content',
704
-            ['EED_Events_Archive', 'event_venues'],
705
-            EED_Events_Archive::EVENT_VENUES_PRIORITY
706
-        );
707
-        // don't display entry meta because the existing theme will take care of that
708
-        remove_filter(
709
-            'FHEE__content_espresso_events_details_template__display_entry_meta',
710
-            '__return_false'
711
-        );
712
-    }
713
-
714
-
715
-    /**
716
-     * @return void
717
-     */
718
-    public function load_event_list_assets()
719
-    {
720
-        do_action('AHEE__EED_Events_Archive__before_load_assets');
721
-        add_filter('FHEE_load_EE_Session', '__return_true');
722
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
723
-        add_action('wp_enqueue_scripts', [$this, 'wp_enqueue_scripts'], 10);
724
-        if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
725
-            add_action('wp_enqueue_scripts', ['EEH_Maps', 'espresso_google_map_js'], 11);
726
-        }
727
-    }
728
-
729
-
730
-    /**
731
-     * @return void
732
-     * @throws EE_Error
733
-     */
734
-    public function wp_enqueue_scripts()
735
-    {
736
-        // get some style
737
-        if (apply_filters('FHEE_enable_default_espresso_css', false)) {
738
-            // first check uploads folder
739
-            if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) {
740
-                wp_register_style(
741
-                    $this->theme,
742
-                    get_stylesheet_directory_uri() . $this->theme . '/style.css',
743
-                    ['dashicons', 'espresso_default']
744
-                );
745
-            }
746
-            wp_enqueue_style($this->theme);
747
-        }
748
-    }
749
-
750
-
751
-    /**
752
-     * @static
753
-     * @return void
754
-     */
755
-    public static function template_settings_form()
756
-    {
757
-        $template_settings                     = EE_Registry::instance()->CFG->template_settings;
758
-        $template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive)
759
-            ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
760
-        $template_settings->EED_Events_Archive = apply_filters(
761
-            'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
762
-            $template_settings->EED_Events_Archive
763
-        );
764
-        $events_archive_settings               = [
765
-            'display_status_banner'   => 0,
766
-            'display_description'     => 1,
767
-            'display_ticket_selector' => 0,
768
-            'display_datetimes'       => 1,
769
-            'display_venue'           => 0,
770
-            'display_expired_events'  => 0,
771
-        ];
772
-        $events_archive_settings               = array_merge(
773
-            $events_archive_settings,
774
-            (array) $template_settings->EED_Events_Archive
775
-        );
776
-        EEH_Template::display_template(
777
-            EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
778
-            $events_archive_settings
779
-        );
780
-    }
781
-
782
-
783
-    /**
784
-     * @param EE_Template_Config $CFG
785
-     * @param array              $REQ
786
-     * @return EE_Template_Config
787
-     */
788
-    public static function update_template_settings($CFG, $REQ)
789
-    {
790
-        $CFG->EED_Events_Archive = new EE_Events_Archive_Config();
791
-        // unless we are resetting the config...
792
-        if (
793
-            ! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
794
-            || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
795
-        ) {
796
-            $CFG->EED_Events_Archive->display_status_banner   = isset($REQ['EED_Events_Archive_display_status_banner'])
797
-                ? absint($REQ['EED_Events_Archive_display_status_banner'])
798
-                : 0;
799
-            $CFG->EED_Events_Archive->display_description     = isset($REQ['EED_Events_Archive_display_description'])
800
-                ? absint($REQ['EED_Events_Archive_display_description'])
801
-                : 1;
802
-            $CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
803
-                ? absint($REQ['EED_Events_Archive_display_ticket_selector'])
804
-                : 0;
805
-            $CFG->EED_Events_Archive->display_datetimes       = isset($REQ['EED_Events_Archive_display_datetimes'])
806
-                ? absint($REQ['EED_Events_Archive_display_datetimes'])
807
-                : 1;
808
-            $CFG->EED_Events_Archive->display_venue           = isset($REQ['EED_Events_Archive_display_venue'])
809
-                ? absint($REQ['EED_Events_Archive_display_venue'])
810
-                : 0;
811
-            $CFG->EED_Events_Archive->display_expired_events  = isset($REQ['EED_Events_Archive_display_expired_events'])
812
-                ? absint($REQ['EED_Events_Archive_display_expired_events'])
813
-                : 0;
814
-        }
815
-        return $CFG;
816
-    }
817
-
818
-
819
-    /**
820
-     * @param string $extra_class
821
-     * @return string
822
-     */
823
-    public static function event_list_css($extra_class = '')
824
-    {
825
-        $event_list_css   = ! empty($extra_class) ? [$extra_class] : [];
826
-        $event_list_css[] = 'espresso-event-list-event';
827
-        return implode(' ', $event_list_css);
828
-    }
829
-
830
-
831
-    /**
832
-     * @return array
833
-     * @throws EE_Error
834
-     * @throws ReflectionException
835
-     */
836
-    public static function event_categories()
837
-    {
838
-        return EE_Registry::instance()->load_model('Term')->get_all_ee_categories();
839
-    }
840
-
841
-
842
-    /**
843
-     * @param $value
844
-     * @return bool
845
-     */
846
-    public static function display_description($value)
847
-    {
848
-        $config              = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
849
-        $display_description = isset($config->display_description) ? $config->display_description : 1;
850
-        return $display_description === $value;
851
-    }
852
-
853
-
854
-    /**
855
-     * @return bool
856
-     */
857
-    public static function display_ticket_selector()
858
-    {
859
-        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
860
-        return isset($config->display_ticket_selector) && $config->display_ticket_selector;
861
-    }
862
-
863
-
864
-    /**
865
-     * @return bool
866
-     * @throws EE_Error
867
-     * @throws ReflectionException
868
-     */
869
-    public static function display_venue()
870
-    {
871
-        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
872
-        return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name();
873
-    }
874
-
875
-
876
-    /**
877
-     * @return bool
878
-     */
879
-    public static function display_datetimes()
880
-    {
881
-        $config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
882
-        return isset($config->display_datetimes) && $config->display_datetimes;
883
-    }
884
-
885
-
886
-    /**
887
-     * @return string
888
-     */
889
-    public static function event_list_title()
890
-    {
891
-        return apply_filters(
892
-            'FHEE__archive_espresso_events_template__upcoming_events_h1',
893
-            esc_html__('Upcoming Events', 'event_espresso')
894
-        );
895
-    }
896
-
897
-
898
-    // GRAVEYARD
899
-
900
-
901
-    /**
902
-     * @since 4.4.0
903
-     */
904
-    public static function _doing_it_wrong_notice($function = '')
905
-    {
906
-        EE_Error::doing_it_wrong(
907
-            __FUNCTION__,
908
-            sprintf(
909
-                esc_html__(
910
-                    'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s',
911
-                    'event_espresso'
912
-                ),
913
-                $function,
914
-                '<br />',
915
-                '4.6.0'
916
-            ),
917
-            '4.4.0'
918
-        );
919
-    }
920
-
921
-
922
-    /**
923
-     * @deprecated
924
-     * @since 4.4.0
925
-     */
926
-    public function get_post_data()
927
-    {
928
-        EEH_Event_Query::set_query_params();
929
-    }
930
-
931
-
932
-    /**
933
-     * @throws EE_Error
934
-     * @since 4.4.0
935
-     * @deprecated
936
-     */
937
-    public function posts_fields($SQL, WP_Query $wp_query)
938
-    {
939
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
940
-        return EEH_Event_Query::posts_fields($SQL, $wp_query);
941
-    }
942
-
943
-
944
-    /**
945
-     * @throws EE_Error
946
-     * @since 4.4.0
947
-     * @deprecated
948
-     */
949
-    public static function posts_fields_sql_for_orderby($orderby_params = [])
950
-    {
951
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
952
-        return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params);
953
-    }
954
-
955
-
956
-    /**
957
-     * @throws EE_Error
958
-     * @since 4.4.0
959
-     * @deprecated
960
-     */
961
-    public function posts_join($SQL, WP_Query $wp_query)
962
-    {
963
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
964
-        return EEH_Event_Query::posts_join($SQL, $wp_query);
965
-    }
966
-
967
-
968
-    /**
969
-     * @deprecated
970
-     * @since 4.4.0
971
-     */
972
-    public static function posts_join_sql_for_terms($join_terms = null)
973
-    {
974
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
975
-        return EEH_Event_Query::posts_join_sql_for_terms($join_terms);
976
-    }
977
-
978
-
979
-    /**
980
-     * @throws EE_Error
981
-     * @since 4.4.0
982
-     * @deprecated
983
-     */
984
-    public static function posts_join_for_orderby($orderby_params = [])
985
-    {
986
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
987
-        return EEH_Event_Query::posts_join_for_orderby($orderby_params);
988
-    }
989
-
990
-
991
-    /**
992
-     * @throws EE_Error
993
-     * @since 4.4.0
994
-     * @deprecated
995
-     */
996
-    public function posts_where($SQL, WP_Query $wp_query)
997
-    {
998
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
999
-        return EEH_Event_Query::posts_where($SQL, $wp_query);
1000
-    }
1001
-
1002
-
1003
-    /**
1004
-     * @throws EE_Error
1005
-     * @since 4.4.0
1006
-     * @deprecated
1007
-     */
1008
-    public static function posts_where_sql_for_show_expired($show_expired = false)
1009
-    {
1010
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1011
-        return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired);
1012
-    }
1013
-
1014
-
1015
-    /**
1016
-     * @deprecated
1017
-     * @since 4.4.0
1018
-     */
1019
-    public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
1020
-    {
1021
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1022
-        return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug);
1023
-    }
1024
-
1025
-
1026
-    /**
1027
-     * @throws EE_Error
1028
-     * @since 4.4.0
1029
-     * @deprecated
1030
-     */
1031
-    public static function posts_where_sql_for_event_list_month($month = null)
1032
-    {
1033
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1034
-        return EEH_Event_Query::posts_where_sql_for_event_list_month($month);
1035
-    }
1036
-
1037
-
1038
-    /**
1039
-     * @throws EE_Error
1040
-     * @since 4.4.0
1041
-     * @deprecated
1042
-     */
1043
-    public function posts_orderby($SQL, WP_Query $wp_query)
1044
-    {
1045
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1046
-        return EEH_Event_Query::posts_orderby($SQL, $wp_query);
1047
-    }
1048
-
1049
-
1050
-    /**
1051
-     * @throws EE_Error
1052
-     * @since 4.4.0
1053
-     * @deprecated
1054
-     */
1055
-    public static function posts_orderby_sql($orderby_params = [], $sort = 'ASC')
1056
-    {
1057
-        EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1058
-        return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort);
1059
-    }
19
+	const EVENT_DETAILS_PRIORITY   = 100;
20
+
21
+	const EVENT_DATETIMES_PRIORITY = 110;
22
+
23
+	const EVENT_TICKETS_PRIORITY   = 120;
24
+
25
+	const EVENT_VENUES_PRIORITY    = 130;
26
+
27
+
28
+	public static $espresso_event_list_ID    = 0;
29
+
30
+	public static $espresso_grid_event_lists = [];
31
+
32
+	/**
33
+	 * @type bool $using_get_the_excerpt
34
+	 */
35
+	protected static $using_get_the_excerpt = false;
36
+
37
+	/**
38
+	 * Used to flag when the event list is being called from an external iframe.
39
+	 *
40
+	 * @var bool $iframe
41
+	 */
42
+	protected static $iframe = false;
43
+
44
+	/**
45
+	 * @var EventListIframeEmbedButton $_iframe_embed_button
46
+	 */
47
+	private static $_iframe_embed_button;
48
+
49
+	/**
50
+	 * @type EE_Template_Part_Manager $template_parts
51
+	 */
52
+	protected $template_parts;
53
+
54
+
55
+	/**
56
+	 * @return EED_Events_Archive
57
+	 * @throws EE_Error
58
+	 * @throws ReflectionException
59
+	 */
60
+	public static function instance()
61
+	{
62
+		return parent::get_instance(__CLASS__);
63
+	}
64
+
65
+
66
+	/**
67
+	 * for hooking into EE Core, other modules, etc
68
+	 *
69
+	 * @return void
70
+	 * @throws InvalidArgumentException
71
+	 * @throws InvalidDataTypeException
72
+	 * @throws InvalidInterfaceException
73
+	 */
74
+	public static function set_hooks()
75
+	{
76
+		/** @var CustomPostTypeDefinitions $custom_post_type_definitions */
77
+		$custom_post_type_definitions = LoaderFactory::getLoader()->getShared(CustomPostTypeDefinitions::class);
78
+		$custom_post_types            = $custom_post_type_definitions->getDefinitions();
79
+		EE_Config::register_route(
80
+			$custom_post_types['espresso_events']['plural_slug'],
81
+			'Events_Archive',
82
+			'run'
83
+		);
84
+		EE_Config::register_route(
85
+			'event_list',
86
+			'Events_Archive',
87
+			'event_list'
88
+		);
89
+		EE_Config::register_route(
90
+			'iframe',
91
+			'Events_Archive',
92
+			'event_list_iframe',
93
+			'event_list'
94
+		);
95
+		add_action('wp_loaded', ['EED_Events_Archive', 'set_definitions'], 2);
96
+	}
97
+
98
+
99
+	/**
100
+	 * for hooking into EE Admin Core, other modules, etc
101
+	 *
102
+	 * @return void
103
+	 */
104
+	public static function set_hooks_admin()
105
+	{
106
+		add_action('wp_loaded', ['EED_Events_Archive', 'set_definitions'], 2);
107
+		// hook into the end of the \EE_Admin_Page::_load_page_dependencies()
108
+		// to load assets for "espresso_events" page on the "default" route (action)
109
+		add_action(
110
+			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default',
111
+			['EED_Events_Archive', 'event_list_iframe_embed_button'],
112
+			10
113
+		);
114
+	}
115
+
116
+
117
+	/**
118
+	 * @return void
119
+	 */
120
+	public static function set_definitions()
121
+	{
122
+		define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
123
+		define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/');
124
+	}
125
+
126
+
127
+	/**
128
+	 * set up EE_Events_Archive_Config
129
+	 */
130
+	protected function set_config()
131
+	{
132
+		$this->set_config_section('template_settings');
133
+		$this->set_config_class('EE_Events_Archive_Config');
134
+		$this->set_config_name('EED_Events_Archive');
135
+	}
136
+
137
+
138
+	/**
139
+	 * @return EventListIframeEmbedButton
140
+	 */
141
+	public static function get_iframe_embed_button()
142
+	{
143
+		if (! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
144
+			self::$_iframe_embed_button = new EventListIframeEmbedButton();
145
+		}
146
+		return self::$_iframe_embed_button;
147
+	}
148
+
149
+
150
+	/**
151
+	 * @return void
152
+	 */
153
+	public static function event_list_iframe_embed_button()
154
+	{
155
+		$iframe_embed_button = EED_Events_Archive::get_iframe_embed_button();
156
+		$iframe_embed_button->addEmbedButton();
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param EE_Events_Archive_Config|null $config
162
+	 * @return EE_Template_Part_Manager
163
+	 * @throws EE_Error
164
+	 */
165
+	public function initialize_template_parts(EE_Events_Archive_Config $config = null)
166
+	{
167
+		$config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
168
+		EEH_Autoloader::register_template_part_autoloaders();
169
+		$template_parts = new EE_Template_Part_Manager();
170
+		$template_parts->add_template_part(
171
+			'tickets',
172
+			esc_html__('Ticket Selector', 'event_espresso'),
173
+			'content-espresso_events-tickets.php',
174
+			$config->display_order_tickets
175
+		);
176
+		$template_parts->add_template_part(
177
+			'datetimes',
178
+			esc_html__('Dates and Times', 'event_espresso'),
179
+			'content-espresso_events-datetimes.php',
180
+			$config->display_order_datetimes
181
+		);
182
+		$template_parts->add_template_part(
183
+			'event',
184
+			esc_html__('Event Description', 'event_espresso'),
185
+			'content-espresso_events-details.php',
186
+			$config->display_order_event
187
+		);
188
+		$template_parts->add_template_part(
189
+			'venue',
190
+			esc_html__('Venue Information', 'event_espresso'),
191
+			'content-espresso_events-venues.php',
192
+			$config->display_order_venue
193
+		);
194
+		do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts);
195
+		return $template_parts;
196
+	}
197
+
198
+
199
+	/**
200
+	 * initial module setup
201
+	 * this gets called by the EE_Front_Controller if the module route is found in the incoming request
202
+	 *
203
+	 * @param WP $WP
204
+	 * @return void
205
+	 */
206
+	public function run($WP)
207
+	{
208
+		do_action('AHEE__EED_Events_Archive__before_run');
209
+		// ensure valid EE_Events_Archive_Config() object exists
210
+		$this->set_config();
211
+		/** @type EE_Events_Archive_Config $config */
212
+		$config = $this->config();
213
+		// load other required components
214
+		$this->load_event_list_assets();
215
+		// filter the WP posts_join, posts_where, and posts_orderby SQL clauses
216
+		// add query filters
217
+		EEH_Event_Query::add_query_filters();
218
+		// set params that will get used by the filters
219
+		EEH_Event_Query::set_query_params(
220
+			'',                             // month
221
+			'',                             // category
222
+			$config->display_expired_events // show_expired
223
+		);
224
+		// check what template is loaded
225
+		add_filter('template_include', [$this, 'template_include'], 999, 1);
226
+	}
227
+
228
+
229
+	/**
230
+	 * most likely called by the ESPRESSO_EVENTS shortcode which uses this module to do some of it's lifting
231
+	 *
232
+	 * @return void
233
+	 */
234
+	public function event_list()
235
+	{
236
+		// ensure valid EE_Events_Archive_Config() object exists
237
+		$this->set_config();
238
+		// load other required components
239
+		$this->load_event_list_assets();
240
+	}
241
+
242
+
243
+	/**
244
+	 * @return void
245
+	 * @throws EE_Error
246
+	 * @throws ReflectionException
247
+	 */
248
+	public function event_list_iframe()
249
+	{
250
+		EED_Events_Archive::$iframe = true;
251
+		$event_list_iframe          = new EventsArchiveIframe($this);
252
+		$event_list_iframe->display();
253
+	}
254
+
255
+
256
+	/**
257
+	 * @return bool
258
+	 */
259
+	public static function is_iframe()
260
+	{
261
+		return EED_Events_Archive::$iframe;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @return string
267
+	 */
268
+	public static function link_target()
269
+	{
270
+		return EED_Events_Archive::$iframe ? ' target="_blank"' : '';
271
+	}
272
+
273
+
274
+	/**
275
+	 * @param string $template
276
+	 * @return string
277
+	 * @throws EE_Error
278
+	 * @throws ReflectionException
279
+	 */
280
+	public function template_include($template = '')
281
+	{
282
+		// don't add content filter for dedicated EE child themes or private posts
283
+		if (! EEH_Template::is_espresso_theme()) {
284
+			/** @type EE_Events_Archive_Config $config */
285
+			$config = $this->config();
286
+			// add status banner ?
287
+			if ($config->display_status_banner) {
288
+				add_filter('the_title', ['EED_Events_Archive', 'the_title'], 100, 2);
289
+			}
290
+			// if NOT a custom template
291
+			if (
292
+				apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', false)
293
+				|| EE_Registry::instance()
294
+							  ->load_core('Front_Controller')
295
+							  ->get_selected_template() !== 'archive-espresso_events.php'
296
+			) {
297
+				add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true');
298
+				// load functions.php file for the theme (loaded by WP if using child theme)
299
+				EEH_Template::load_espresso_theme_functions();
300
+				EED_Events_Archive::addEventDetailsFilters();
301
+				// don't display entry meta because the existing theme will take care of that
302
+				add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
303
+			}
304
+		}
305
+		return $template;
306
+	}
307
+
308
+
309
+	/**
310
+	 * kinda hacky, but if a theme is using get_the_excerpt(),
311
+	 * then we need to remove our filters on the_content()
312
+	 *
313
+	 * @param string $excerpt
314
+	 * @return string
315
+	 * @throws EE_Error
316
+	 * @throws ReflectionException
317
+	 */
318
+	public static function get_the_excerpt($excerpt = '')
319
+	{
320
+		if (post_password_required()) {
321
+			return $excerpt;
322
+		}
323
+		if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) {
324
+			EED_Events_Archive::removeEventDetailsFilters(false);
325
+			$excerpt = EED_Events_Archive::event_details($excerpt);
326
+		} else {
327
+			EED_Events_Archive::$using_get_the_excerpt = true;
328
+			add_filter('wp_trim_excerpt', ['EED_Events_Archive', 'end_get_the_excerpt'], 999, 1);
329
+		}
330
+		return $excerpt;
331
+	}
332
+
333
+
334
+	/**
335
+	 * @param string $text
336
+	 * @return string
337
+	 */
338
+	public static function end_get_the_excerpt($text = '')
339
+	{
340
+		EED_Events_Archive::$using_get_the_excerpt = false;
341
+		return $text;
342
+	}
343
+
344
+
345
+	/**
346
+	 * @param string $title
347
+	 * @param string $id
348
+	 * @return string
349
+	 * @throws EE_Error
350
+	 * @throws ReflectionException
351
+	 */
352
+	public static function the_title($title = '', $id = '')
353
+	{
354
+		global $post;
355
+		if ($post instanceof WP_Post) {
356
+			return (EED_Events_Archive::isBlockTheme() || in_the_loop()) && $post->ID == $id
357
+				? espresso_event_status_banner($post->ID) . $title
358
+				: $title;
359
+		}
360
+		return $title;
361
+	}
362
+
363
+
364
+	/**
365
+	 * @param string $content
366
+	 * @return string
367
+	 * @throws EE_Error
368
+	 * @throws ReflectionException
369
+	 */
370
+	public static function event_details($content)
371
+	{
372
+		global $post;
373
+		static $current_post_ID = 0;
374
+		if (
375
+			$current_post_ID !== $post->ID
376
+			&& $post->post_type === 'espresso_events'
377
+			&& ! EED_Events_Archive::$using_get_the_excerpt
378
+			&& ! post_password_required()
379
+			&& (
380
+				apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false)
381
+				|| ! apply_filters('FHEE__content_espresso_events__template_loaded', false)
382
+			)
383
+		) {
384
+			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
385
+			// Reason being is that some plugins, like Yoast, need to run through a copy of the loop early
386
+			// BEFORE headers are sent in order to examine the post content and generate content for the HTML header.
387
+			// We want to allow those plugins to still do their thing and have access to our content, but depending on
388
+			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
389
+			// so the following allows this filter to be applied multiple times, but only once for real
390
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
391
+			if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) {
392
+				$content = EED_Events_Archive::use_sortable_display_order();
393
+			} else {
394
+				$content = EED_Events_Archive::use_filterable_display_order();
395
+			}
396
+		}
397
+		return $content;
398
+	}
399
+
400
+
401
+	/**
402
+	 * @return string
403
+	 * @throws EE_Error
404
+	 * @throws ReflectionException
405
+	 */
406
+	protected static function use_sortable_display_order()
407
+	{
408
+		// no further password checks required atm
409
+		add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true');
410
+		// remove this callback from being applied to the_content()
411
+		EED_Events_Archive::removeEventDetailsFilters();
412
+		// now add additional content depending on whether event is using the_excerpt() or the_content()
413
+		EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
414
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
415
+		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content);
416
+		// re-add our main filters (or else the next event won't have them)
417
+		EED_Events_Archive::addEventDetailsFilters();
418
+		remove_filter(
419
+			'FHEE__EED_Events_Archive__event_details__no_post_password_required',
420
+			'__return_true'
421
+		);
422
+		return $content;
423
+	}
424
+
425
+
426
+	/**
427
+	 * @return string
428
+	 */
429
+	protected static function use_filterable_display_order()
430
+	{
431
+		// remove this callback from being applied to the_content()
432
+		EED_Events_Archive::removeEventDetailsFilters();
433
+		// now add additional content depending on whether event is using the_excerpt() or the_content()
434
+		EED_Events_Archive::_add_additional_excerpt_filters();
435
+		EED_Events_Archive::_add_additional_content_filters();
436
+		do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters');
437
+		// now load our template
438
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
439
+		// re-add our main filters (or else the next event won't have them)
440
+		EED_Events_Archive::addEventDetailsFilters();
441
+		// but remove the other filters so that they don't get applied to the next post
442
+		EED_Events_Archive::_remove_additional_events_archive_filters();
443
+		do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters');
444
+		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
445
+		// return ! empty( $template ) ? $template : $content;
446
+		return $content;
447
+	}
448
+
449
+
450
+	/**
451
+	 * adds datetimes ABOVE content
452
+	 *
453
+	 * @param string $content
454
+	 * @return string
455
+	 */
456
+	public static function event_datetimes($content)
457
+	{
458
+		if (post_password_required()) {
459
+			return $content;
460
+		}
461
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content;
462
+	}
463
+
464
+
465
+	/**
466
+	 * adds tickets ABOVE content (which includes datetimes)
467
+	 *
468
+	 * @param string $content
469
+	 * @return string
470
+	 */
471
+	public static function event_tickets($content)
472
+	{
473
+		if (post_password_required()) {
474
+			return $content;
475
+		}
476
+		return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content;
477
+	}
478
+
479
+
480
+	/**
481
+	 * adds venues BELOW content
482
+	 *
483
+	 * @param string $content
484
+	 * @return string
485
+	 */
486
+	public static function event_venue($content)
487
+	{
488
+		return EED_Events_Archive::event_venues($content);
489
+	}
490
+
491
+
492
+	/**
493
+	 * adds venues BELOW content
494
+	 *
495
+	 * @param string $content
496
+	 * @return string
497
+	 */
498
+	public static function event_venues($content)
499
+	{
500
+		if (post_password_required()) {
501
+			return $content;
502
+		}
503
+		return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
504
+	}
505
+
506
+
507
+	/**
508
+	 * @return bool
509
+	 * @since $VID:$
510
+	 */
511
+	public static function isBlockTheme()
512
+	{
513
+		return function_exists('wp_is_block_theme') && wp_is_block_theme();
514
+	}
515
+
516
+
517
+	/**
518
+	 * @return string
519
+	 * @since $VID:$
520
+	 */
521
+	public static function getExcerptFilter()
522
+	{
523
+		static $excerpt_filter = null;
524
+		if ($excerpt_filter === null) {
525
+			$excerpt_filter = EED_Events_Archive::isBlockTheme() ? 'get_the_excerpt' : 'the_excerpt';
526
+		}
527
+		return $excerpt_filter;
528
+	}
529
+
530
+
531
+	/**
532
+	 * @since $VID:$
533
+	 */
534
+	protected static function addEventDetailsFilters()
535
+	{
536
+		add_filter(
537
+			'the_content',
538
+			['EED_Events_Archive', 'event_details'],
539
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
540
+		);
541
+		// but because we don't know if the theme is using the_excerpt()
542
+		add_filter(
543
+			EED_Events_Archive::getExcerptFilter(),
544
+			['EED_Events_Archive', 'event_details'],
545
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
546
+		);
547
+		// and just in case they are running get_the_excerpt() which DESTROYS things
548
+		add_filter('get_the_excerpt', ['EED_Events_Archive', 'get_the_excerpt'], 1, 1);
549
+	}
550
+
551
+
552
+	/**
553
+	 * @param bool $and_get_the_excerpt
554
+	 * @since $VID:$
555
+	 */
556
+	protected static function removeEventDetailsFilters($and_get_the_excerpt = true)
557
+	{
558
+		// we need to first remove all callbacks from being applied to the_content()
559
+		// (otherwise it will recurse and blow up the interweb)
560
+		remove_filter(
561
+			'the_content',
562
+			['EED_Events_Archive', 'event_details'],
563
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
564
+		);
565
+		remove_filter(
566
+			EED_Events_Archive::getExcerptFilter(),
567
+			['EED_Events_Archive', 'event_details'],
568
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
569
+		);
570
+		if ($and_get_the_excerpt) {
571
+			remove_filter('get_the_excerpt', ['EED_Events_Archive', 'get_the_excerpt'], 1);
572
+		}
573
+	}
574
+
575
+
576
+	/**
577
+	 * @return void
578
+	 */
579
+	private static function _add_additional_excerpt_filters()
580
+	{
581
+		add_filter(
582
+			EED_Events_Archive::getExcerptFilter(),
583
+			['EED_Events_Archive', 'event_datetimes'],
584
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
585
+		);
586
+		add_filter(
587
+			EED_Events_Archive::getExcerptFilter(),
588
+			['EED_Events_Archive', 'event_tickets'],
589
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
590
+		);
591
+		add_filter(
592
+			EED_Events_Archive::getExcerptFilter(),
593
+			['EED_Events_Archive', 'event_venues'],
594
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
595
+		);
596
+	}
597
+
598
+
599
+	/**
600
+	 * @return void
601
+	 */
602
+	private static function _add_additional_content_filters()
603
+	{
604
+		add_filter(
605
+			'the_content',
606
+			['EED_Events_Archive', 'event_datetimes'],
607
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
608
+		);
609
+		add_filter(
610
+			'the_content',
611
+			['EED_Events_Archive', 'event_tickets'],
612
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
613
+		);
614
+		add_filter(
615
+			'the_content',
616
+			['EED_Events_Archive', 'event_venues'],
617
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
618
+		);
619
+	}
620
+
621
+
622
+	/**
623
+	 * @return void
624
+	 */
625
+	private static function _remove_additional_events_archive_filters()
626
+	{
627
+		remove_filter(
628
+			EED_Events_Archive::getExcerptFilter(),
629
+			['EED_Events_Archive', 'event_datetimes'],
630
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
631
+		);
632
+		remove_filter(
633
+			EED_Events_Archive::getExcerptFilter(),
634
+			['EED_Events_Archive', 'event_tickets'],
635
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
636
+		);
637
+		remove_filter(
638
+			EED_Events_Archive::getExcerptFilter(),
639
+			['EED_Events_Archive', 'event_venues'],
640
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
641
+		);
642
+		remove_filter(
643
+			'the_content',
644
+			['EED_Events_Archive', 'event_datetimes'],
645
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
646
+		);
647
+		remove_filter(
648
+			'the_content',
649
+			['EED_Events_Archive', 'event_tickets'],
650
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
651
+		);
652
+		remove_filter(
653
+			'the_content',
654
+			['EED_Events_Archive', 'event_venues'],
655
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
656
+		);
657
+	}
658
+
659
+
660
+	/**
661
+	 * @return void
662
+	 */
663
+	public static function remove_all_events_archive_filters()
664
+	{
665
+		// remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
666
+		remove_filter('the_title', ['EED_Events_Archive', 'the_title'], 1);
667
+		remove_filter(
668
+			EED_Events_Archive::getExcerptFilter(),
669
+			['EED_Events_Archive', 'event_details'],
670
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
671
+		);
672
+		remove_filter(
673
+			EED_Events_Archive::getExcerptFilter(),
674
+			['EED_Events_Archive', 'event_datetimes'],
675
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
676
+		);
677
+		remove_filter(
678
+			EED_Events_Archive::getExcerptFilter(),
679
+			['EED_Events_Archive', 'event_tickets'],
680
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
681
+		);
682
+		remove_filter(
683
+			EED_Events_Archive::getExcerptFilter(),
684
+			['EED_Events_Archive', 'event_venues'],
685
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
686
+		);
687
+		remove_filter(
688
+			'the_content',
689
+			['EED_Events_Archive', 'event_details'],
690
+			EED_Events_Archive::EVENT_DETAILS_PRIORITY
691
+		);
692
+		remove_filter(
693
+			'the_content',
694
+			['EED_Events_Archive', 'event_datetimes'],
695
+			EED_Events_Archive::EVENT_DATETIMES_PRIORITY
696
+		);
697
+		remove_filter(
698
+			'the_content',
699
+			['EED_Events_Archive', 'event_tickets'],
700
+			EED_Events_Archive::EVENT_TICKETS_PRIORITY
701
+		);
702
+		remove_filter(
703
+			'the_content',
704
+			['EED_Events_Archive', 'event_venues'],
705
+			EED_Events_Archive::EVENT_VENUES_PRIORITY
706
+		);
707
+		// don't display entry meta because the existing theme will take care of that
708
+		remove_filter(
709
+			'FHEE__content_espresso_events_details_template__display_entry_meta',
710
+			'__return_false'
711
+		);
712
+	}
713
+
714
+
715
+	/**
716
+	 * @return void
717
+	 */
718
+	public function load_event_list_assets()
719
+	{
720
+		do_action('AHEE__EED_Events_Archive__before_load_assets');
721
+		add_filter('FHEE_load_EE_Session', '__return_true');
722
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
723
+		add_action('wp_enqueue_scripts', [$this, 'wp_enqueue_scripts'], 10);
724
+		if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
725
+			add_action('wp_enqueue_scripts', ['EEH_Maps', 'espresso_google_map_js'], 11);
726
+		}
727
+	}
728
+
729
+
730
+	/**
731
+	 * @return void
732
+	 * @throws EE_Error
733
+	 */
734
+	public function wp_enqueue_scripts()
735
+	{
736
+		// get some style
737
+		if (apply_filters('FHEE_enable_default_espresso_css', false)) {
738
+			// first check uploads folder
739
+			if (EEH_File::is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) {
740
+				wp_register_style(
741
+					$this->theme,
742
+					get_stylesheet_directory_uri() . $this->theme . '/style.css',
743
+					['dashicons', 'espresso_default']
744
+				);
745
+			}
746
+			wp_enqueue_style($this->theme);
747
+		}
748
+	}
749
+
750
+
751
+	/**
752
+	 * @static
753
+	 * @return void
754
+	 */
755
+	public static function template_settings_form()
756
+	{
757
+		$template_settings                     = EE_Registry::instance()->CFG->template_settings;
758
+		$template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive)
759
+			? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
760
+		$template_settings->EED_Events_Archive = apply_filters(
761
+			'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
762
+			$template_settings->EED_Events_Archive
763
+		);
764
+		$events_archive_settings               = [
765
+			'display_status_banner'   => 0,
766
+			'display_description'     => 1,
767
+			'display_ticket_selector' => 0,
768
+			'display_datetimes'       => 1,
769
+			'display_venue'           => 0,
770
+			'display_expired_events'  => 0,
771
+		];
772
+		$events_archive_settings               = array_merge(
773
+			$events_archive_settings,
774
+			(array) $template_settings->EED_Events_Archive
775
+		);
776
+		EEH_Template::display_template(
777
+			EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
778
+			$events_archive_settings
779
+		);
780
+	}
781
+
782
+
783
+	/**
784
+	 * @param EE_Template_Config $CFG
785
+	 * @param array              $REQ
786
+	 * @return EE_Template_Config
787
+	 */
788
+	public static function update_template_settings($CFG, $REQ)
789
+	{
790
+		$CFG->EED_Events_Archive = new EE_Events_Archive_Config();
791
+		// unless we are resetting the config...
792
+		if (
793
+			! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
794
+			|| absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
795
+		) {
796
+			$CFG->EED_Events_Archive->display_status_banner   = isset($REQ['EED_Events_Archive_display_status_banner'])
797
+				? absint($REQ['EED_Events_Archive_display_status_banner'])
798
+				: 0;
799
+			$CFG->EED_Events_Archive->display_description     = isset($REQ['EED_Events_Archive_display_description'])
800
+				? absint($REQ['EED_Events_Archive_display_description'])
801
+				: 1;
802
+			$CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
803
+				? absint($REQ['EED_Events_Archive_display_ticket_selector'])
804
+				: 0;
805
+			$CFG->EED_Events_Archive->display_datetimes       = isset($REQ['EED_Events_Archive_display_datetimes'])
806
+				? absint($REQ['EED_Events_Archive_display_datetimes'])
807
+				: 1;
808
+			$CFG->EED_Events_Archive->display_venue           = isset($REQ['EED_Events_Archive_display_venue'])
809
+				? absint($REQ['EED_Events_Archive_display_venue'])
810
+				: 0;
811
+			$CFG->EED_Events_Archive->display_expired_events  = isset($REQ['EED_Events_Archive_display_expired_events'])
812
+				? absint($REQ['EED_Events_Archive_display_expired_events'])
813
+				: 0;
814
+		}
815
+		return $CFG;
816
+	}
817
+
818
+
819
+	/**
820
+	 * @param string $extra_class
821
+	 * @return string
822
+	 */
823
+	public static function event_list_css($extra_class = '')
824
+	{
825
+		$event_list_css   = ! empty($extra_class) ? [$extra_class] : [];
826
+		$event_list_css[] = 'espresso-event-list-event';
827
+		return implode(' ', $event_list_css);
828
+	}
829
+
830
+
831
+	/**
832
+	 * @return array
833
+	 * @throws EE_Error
834
+	 * @throws ReflectionException
835
+	 */
836
+	public static function event_categories()
837
+	{
838
+		return EE_Registry::instance()->load_model('Term')->get_all_ee_categories();
839
+	}
840
+
841
+
842
+	/**
843
+	 * @param $value
844
+	 * @return bool
845
+	 */
846
+	public static function display_description($value)
847
+	{
848
+		$config              = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
849
+		$display_description = isset($config->display_description) ? $config->display_description : 1;
850
+		return $display_description === $value;
851
+	}
852
+
853
+
854
+	/**
855
+	 * @return bool
856
+	 */
857
+	public static function display_ticket_selector()
858
+	{
859
+		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
860
+		return isset($config->display_ticket_selector) && $config->display_ticket_selector;
861
+	}
862
+
863
+
864
+	/**
865
+	 * @return bool
866
+	 * @throws EE_Error
867
+	 * @throws ReflectionException
868
+	 */
869
+	public static function display_venue()
870
+	{
871
+		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
872
+		return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name();
873
+	}
874
+
875
+
876
+	/**
877
+	 * @return bool
878
+	 */
879
+	public static function display_datetimes()
880
+	{
881
+		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
882
+		return isset($config->display_datetimes) && $config->display_datetimes;
883
+	}
884
+
885
+
886
+	/**
887
+	 * @return string
888
+	 */
889
+	public static function event_list_title()
890
+	{
891
+		return apply_filters(
892
+			'FHEE__archive_espresso_events_template__upcoming_events_h1',
893
+			esc_html__('Upcoming Events', 'event_espresso')
894
+		);
895
+	}
896
+
897
+
898
+	// GRAVEYARD
899
+
900
+
901
+	/**
902
+	 * @since 4.4.0
903
+	 */
904
+	public static function _doing_it_wrong_notice($function = '')
905
+	{
906
+		EE_Error::doing_it_wrong(
907
+			__FUNCTION__,
908
+			sprintf(
909
+				esc_html__(
910
+					'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s',
911
+					'event_espresso'
912
+				),
913
+				$function,
914
+				'<br />',
915
+				'4.6.0'
916
+			),
917
+			'4.4.0'
918
+		);
919
+	}
920
+
921
+
922
+	/**
923
+	 * @deprecated
924
+	 * @since 4.4.0
925
+	 */
926
+	public function get_post_data()
927
+	{
928
+		EEH_Event_Query::set_query_params();
929
+	}
930
+
931
+
932
+	/**
933
+	 * @throws EE_Error
934
+	 * @since 4.4.0
935
+	 * @deprecated
936
+	 */
937
+	public function posts_fields($SQL, WP_Query $wp_query)
938
+	{
939
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
940
+		return EEH_Event_Query::posts_fields($SQL, $wp_query);
941
+	}
942
+
943
+
944
+	/**
945
+	 * @throws EE_Error
946
+	 * @since 4.4.0
947
+	 * @deprecated
948
+	 */
949
+	public static function posts_fields_sql_for_orderby($orderby_params = [])
950
+	{
951
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
952
+		return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params);
953
+	}
954
+
955
+
956
+	/**
957
+	 * @throws EE_Error
958
+	 * @since 4.4.0
959
+	 * @deprecated
960
+	 */
961
+	public function posts_join($SQL, WP_Query $wp_query)
962
+	{
963
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
964
+		return EEH_Event_Query::posts_join($SQL, $wp_query);
965
+	}
966
+
967
+
968
+	/**
969
+	 * @deprecated
970
+	 * @since 4.4.0
971
+	 */
972
+	public static function posts_join_sql_for_terms($join_terms = null)
973
+	{
974
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
975
+		return EEH_Event_Query::posts_join_sql_for_terms($join_terms);
976
+	}
977
+
978
+
979
+	/**
980
+	 * @throws EE_Error
981
+	 * @since 4.4.0
982
+	 * @deprecated
983
+	 */
984
+	public static function posts_join_for_orderby($orderby_params = [])
985
+	{
986
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
987
+		return EEH_Event_Query::posts_join_for_orderby($orderby_params);
988
+	}
989
+
990
+
991
+	/**
992
+	 * @throws EE_Error
993
+	 * @since 4.4.0
994
+	 * @deprecated
995
+	 */
996
+	public function posts_where($SQL, WP_Query $wp_query)
997
+	{
998
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
999
+		return EEH_Event_Query::posts_where($SQL, $wp_query);
1000
+	}
1001
+
1002
+
1003
+	/**
1004
+	 * @throws EE_Error
1005
+	 * @since 4.4.0
1006
+	 * @deprecated
1007
+	 */
1008
+	public static function posts_where_sql_for_show_expired($show_expired = false)
1009
+	{
1010
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1011
+		return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired);
1012
+	}
1013
+
1014
+
1015
+	/**
1016
+	 * @deprecated
1017
+	 * @since 4.4.0
1018
+	 */
1019
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
1020
+	{
1021
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1022
+		return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug);
1023
+	}
1024
+
1025
+
1026
+	/**
1027
+	 * @throws EE_Error
1028
+	 * @since 4.4.0
1029
+	 * @deprecated
1030
+	 */
1031
+	public static function posts_where_sql_for_event_list_month($month = null)
1032
+	{
1033
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1034
+		return EEH_Event_Query::posts_where_sql_for_event_list_month($month);
1035
+	}
1036
+
1037
+
1038
+	/**
1039
+	 * @throws EE_Error
1040
+	 * @since 4.4.0
1041
+	 * @deprecated
1042
+	 */
1043
+	public function posts_orderby($SQL, WP_Query $wp_query)
1044
+	{
1045
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1046
+		return EEH_Event_Query::posts_orderby($SQL, $wp_query);
1047
+	}
1048
+
1049
+
1050
+	/**
1051
+	 * @throws EE_Error
1052
+	 * @since 4.4.0
1053
+	 * @deprecated
1054
+	 */
1055
+	public static function posts_orderby_sql($orderby_params = [], $sort = 'ASC')
1056
+	{
1057
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
1058
+		return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort);
1059
+	}
1060 1060
 }
1061 1061
 
1062 1062
 
@@ -1065,9 +1065,9 @@  discard block
 block discarded – undo
1065 1065
  */
1066 1066
 function espresso_get_event_list_ID()
1067 1067
 {
1068
-    EED_Events_Archive::$espresso_event_list_ID++;
1069
-    EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID;
1070
-    return EED_Events_Archive::$espresso_event_list_ID;
1068
+	EED_Events_Archive::$espresso_event_list_ID++;
1069
+	EED_Events_Archive::$espresso_grid_event_lists[] = EED_Events_Archive::$espresso_event_list_ID;
1070
+	return EED_Events_Archive::$espresso_event_list_ID;
1071 1071
 }
1072 1072
 
1073 1073
 
@@ -1076,7 +1076,7 @@  discard block
 block discarded – undo
1076 1076
  */
1077 1077
 function espresso_event_list_title()
1078 1078
 {
1079
-    return EED_Events_Archive::event_list_title();
1079
+	return EED_Events_Archive::event_list_title();
1080 1080
 }
1081 1081
 
1082 1082
 
@@ -1086,7 +1086,7 @@  discard block
 block discarded – undo
1086 1086
  */
1087 1087
 function espresso_event_list_css($extra_class = '')
1088 1088
 {
1089
-    return EED_Events_Archive::event_list_css($extra_class);
1089
+	return EED_Events_Archive::event_list_css($extra_class);
1090 1090
 }
1091 1091
 
1092 1092
 
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
  */
1098 1098
 function espresso_get_event_categories()
1099 1099
 {
1100
-    return EED_Events_Archive::event_categories();
1100
+	return EED_Events_Archive::event_categories();
1101 1101
 }
1102 1102
 
1103 1103
 
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
  */
1107 1107
 function espresso_display_full_description_in_event_list()
1108 1108
 {
1109
-    return EED_Events_Archive::display_description(2);
1109
+	return EED_Events_Archive::display_description(2);
1110 1110
 }
1111 1111
 
1112 1112
 
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
  */
1116 1116
 function espresso_display_excerpt_in_event_list()
1117 1117
 {
1118
-    return EED_Events_Archive::display_description(1);
1118
+	return EED_Events_Archive::display_description(1);
1119 1119
 }
1120 1120
 
1121 1121
 
@@ -1124,7 +1124,7 @@  discard block
 block discarded – undo
1124 1124
  */
1125 1125
 function espresso_display_ticket_selector_in_event_list()
1126 1126
 {
1127
-    return EED_Events_Archive::display_ticket_selector();
1127
+	return EED_Events_Archive::display_ticket_selector();
1128 1128
 }
1129 1129
 
1130 1130
 
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
  */
1136 1136
 function espresso_display_venue_in_event_list()
1137 1137
 {
1138
-    return EED_Events_Archive::display_venue();
1138
+	return EED_Events_Archive::display_venue();
1139 1139
 }
1140 1140
 
1141 1141
 
@@ -1144,5 +1144,5 @@  discard block
 block discarded – undo
1144 1144
  */
1145 1145
 function espresso_display_datetimes_in_event_list()
1146 1146
 {
1147
-    return EED_Events_Archive::display_datetimes();
1147
+	return EED_Events_Archive::display_datetimes();
1148 1148
 }
Please login to merge, or discard this patch.
core/EED_Module.module.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -14,141 +14,141 @@
 block discarded – undo
14 14
  */
15 15
 abstract class EED_Module extends EE_Configurable implements ResettableInterface
16 16
 {
17
-    /**
18
-     * rendered output to be returned to WP
19
-     *
20
-     * @var    string $output
21
-     */
22
-    protected $output = '';
23
-
24
-    /**
25
-     * the current active espresso template theme
26
-     *
27
-     * @var    string $theme
28
-     */
29
-    protected $theme = '';
30
-
31
-
32
-    /**
33
-     * @return void
34
-     */
35
-    public static function reset()
36
-    {
37
-        $module_name = get_called_class();
38
-        new $module_name();
39
-    }
40
-
41
-
42
-    /**
43
-     *    set_hooks - for hooking into EE Core, other modules, etc
44
-     *
45
-     * @access    public
46
-     * @return    void
47
-     */
48
-    public static function set_hooks()
49
-    {
50
-    }
51
-
52
-
53
-    /**
54
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
55
-     *
56
-     * @access    public
57
-     * @return    void
58
-     */
59
-    public static function set_hooks_admin()
60
-    {
61
-    }
62
-
63
-
64
-    /**
65
-     *    run - initial module setup
66
-     *    this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
67
-     *
68
-     * @access    public
69
-     * @var            WP $WP
70
-     * @return    void
71
-     */
72
-    abstract public function run($WP);
73
-
74
-
75
-    /**
76
-     * EED_Module constructor.
77
-     */
78
-    final public function __construct()
79
-    {
80
-        $this->theme = EE_Config::get_current_theme();
81
-        $module_name = $this->module_name();
82
-        EE_Registry::instance()->modules->{$module_name} = $this;
83
-    }
84
-
85
-
86
-    /**
87
-     * @param string $module_name
88
-     * @return EED_Module|mixed
89
-     * @throws EE_Error
90
-     * @throws ReflectionException
91
-     */
92
-    protected static function get_instance($module_name = '')
93
-    {
94
-        $module_name = ! empty($module_name)
95
-            ? $module_name
96
-            : get_called_class();
97
-        if (
98
-            ! isset(EE_Registry::instance()->modules->{$module_name})
99
-            || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
100
-        ) {
101
-            EE_Registry::instance()->add_module($module_name);
102
-        }
103
-        return EE_Registry::instance()->get_module($module_name);
104
-    }
105
-
106
-
107
-    /**
108
-     *    module_name
109
-     *
110
-     * @access    public
111
-     * @return    string
112
-     */
113
-    public function module_name()
114
-    {
115
-        return get_class($this);
116
-    }
117
-
118
-
119
-    /**
120
-     * @return string
121
-     */
122
-    public function theme()
123
-    {
124
-        return $this->theme;
125
-    }
126
-
127
-
128
-    /**
129
-     * @return RequestInterface
130
-     * @since   4.10.14.p
131
-     */
132
-    protected static function getRequest()
133
-    {
134
-        static $request;
135
-        if (! $request instanceof RequestInterface) {
136
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
137
-        }
138
-        return $request;
139
-    }
140
-
141
-
142
-    /**
143
-     * @return ResponseInterface
144
-     * @since   4.10.14.p
145
-     */
146
-    protected static function getResponse()
147
-    {
148
-        static $response;
149
-        if (! $response instanceof RequestInterface) {
150
-            $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
151
-        }
152
-        return $response;
153
-    }
17
+	/**
18
+	 * rendered output to be returned to WP
19
+	 *
20
+	 * @var    string $output
21
+	 */
22
+	protected $output = '';
23
+
24
+	/**
25
+	 * the current active espresso template theme
26
+	 *
27
+	 * @var    string $theme
28
+	 */
29
+	protected $theme = '';
30
+
31
+
32
+	/**
33
+	 * @return void
34
+	 */
35
+	public static function reset()
36
+	{
37
+		$module_name = get_called_class();
38
+		new $module_name();
39
+	}
40
+
41
+
42
+	/**
43
+	 *    set_hooks - for hooking into EE Core, other modules, etc
44
+	 *
45
+	 * @access    public
46
+	 * @return    void
47
+	 */
48
+	public static function set_hooks()
49
+	{
50
+	}
51
+
52
+
53
+	/**
54
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
55
+	 *
56
+	 * @access    public
57
+	 * @return    void
58
+	 */
59
+	public static function set_hooks_admin()
60
+	{
61
+	}
62
+
63
+
64
+	/**
65
+	 *    run - initial module setup
66
+	 *    this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters
67
+	 *
68
+	 * @access    public
69
+	 * @var            WP $WP
70
+	 * @return    void
71
+	 */
72
+	abstract public function run($WP);
73
+
74
+
75
+	/**
76
+	 * EED_Module constructor.
77
+	 */
78
+	final public function __construct()
79
+	{
80
+		$this->theme = EE_Config::get_current_theme();
81
+		$module_name = $this->module_name();
82
+		EE_Registry::instance()->modules->{$module_name} = $this;
83
+	}
84
+
85
+
86
+	/**
87
+	 * @param string $module_name
88
+	 * @return EED_Module|mixed
89
+	 * @throws EE_Error
90
+	 * @throws ReflectionException
91
+	 */
92
+	protected static function get_instance($module_name = '')
93
+	{
94
+		$module_name = ! empty($module_name)
95
+			? $module_name
96
+			: get_called_class();
97
+		if (
98
+			! isset(EE_Registry::instance()->modules->{$module_name})
99
+			|| ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module
100
+		) {
101
+			EE_Registry::instance()->add_module($module_name);
102
+		}
103
+		return EE_Registry::instance()->get_module($module_name);
104
+	}
105
+
106
+
107
+	/**
108
+	 *    module_name
109
+	 *
110
+	 * @access    public
111
+	 * @return    string
112
+	 */
113
+	public function module_name()
114
+	{
115
+		return get_class($this);
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return string
121
+	 */
122
+	public function theme()
123
+	{
124
+		return $this->theme;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @return RequestInterface
130
+	 * @since   4.10.14.p
131
+	 */
132
+	protected static function getRequest()
133
+	{
134
+		static $request;
135
+		if (! $request instanceof RequestInterface) {
136
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
137
+		}
138
+		return $request;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return ResponseInterface
144
+	 * @since   4.10.14.p
145
+	 */
146
+	protected static function getResponse()
147
+	{
148
+		static $response;
149
+		if (! $response instanceof RequestInterface) {
150
+			$response = LoaderFactory::getLoader()->getShared(ResponseInterface::class);
151
+		}
152
+		return $response;
153
+	}
154 154
 }
Please login to merge, or discard this patch.