/
Events_Admin_Page.core.php
2968 lines (2797 loc) · 123 KB
/
Events_Admin_Page.core.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
use EventEspresso\core\domain\entities\custom_post_types\EspressoPostType;
use EventEspresso\core\domain\services\admin\events\default_settings\AdvancedEditorAdminFormSection;
use EventEspresso\core\domain\services\admin\events\editor\ui\TicketSelectorShortcodeButton;
use EventEspresso\core\exceptions\InvalidDataTypeException;
use EventEspresso\core\exceptions\InvalidInterfaceException;
use EventEspresso\core\services\orm\tree_traversal\NodeGroupDao;
use EventEspresso\core\services\request\DataType;
/**
* Events_Admin_Page
* This contains the logic for setting up the Events related pages.
* Any methods without phpdoc comments have inline docs with parent class.
*
* @package Events_Admin_Page
* @subpackage includes/core/admin/Events_Admin_Page.core.php
* @author Darren Ethier
*/
class Events_Admin_Page extends EE_Admin_Page_CPT
{
/**
* primary key for the event model
*/
private int $EVT_ID = 0;
/**
* This will hold the event object for event_details screen.
*
* @var EE_Event|null $_event
*/
protected ?EE_Event $_event = null;
/**
* This will hold the category object for category_details screen.
*/
protected ?stdClass $_category = null;
protected ?EEM_Event $_event_model = null;
/**
* @var EE_Event|EE_CPT_Base|null $_cpt_model_obj
*/
protected $_cpt_model_obj;
protected ?NodeGroupDao $model_obj_node_group_persister = null;
protected ?AdvancedEditorAdminFormSection $advanced_editor_admin_form = null;
/**
* Initialize page props for this admin page group.
*/
protected function _init_page_props()
{
// is there a evt_id in the request?
$this->EVT_ID = $this->request->getRequestParam('EVT_ID', 0, DataType::INT);
$this->EVT_ID = $this->request->getRequestParam('post', $this->EVT_ID, DataType::INT);
$this->EVT_ID = $this->request->getRequestParam('post_ID', $this->EVT_ID, DataType::INT);
$this->page_slug = EVENTS_PG_SLUG;
$this->page_label = EVENTS_LABEL;
$this->_admin_base_url = EVENTS_ADMIN_URL;
$this->_admin_base_path = EVENTS_ADMIN;
$this->_cpt_model_names = [
'create_new' => 'EEM_Event',
'edit' => 'EEM_Event',
];
$this->_cpt_edit_routes = [
'espresso_events' => 'edit',
];
add_action(
'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
[$this, 'verify_event_edit'],
10,
2
);
}
/**
* Sets the ajax hooks used for this admin page group.
*/
protected function _ajax_hooks()
{
add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
}
/**
* Sets the page properties for this admin page group.
*/
protected function _define_page_props()
{
$this->_admin_page_title = EVENTS_LABEL;
$this->_labels = [
'buttons' => [
'add' => esc_html__('Add New Event', 'event_espresso'),
'edit' => esc_html__('Edit Event', 'event_espresso'),
'delete' => esc_html__('Delete Event', 'event_espresso'),
'add_category' => esc_html__('Add New Category', 'event_espresso'),
'edit_category' => esc_html__('Edit Category', 'event_espresso'),
'delete_category' => esc_html__('Delete Category', 'event_espresso'),
],
'editor_title' => [
'espresso_events' => esc_html__('Edit Event', 'event_espresso'),
],
'publishbox' => [
'create_new' => esc_html__('Save New Event', 'event_espresso'),
'edit' => esc_html__('Update Event', 'event_espresso'),
'add_category' => esc_html__('Save New Category', 'event_espresso'),
'edit_category' => esc_html__('Update Category', 'event_espresso'),
'template_settings' => esc_html__('Update Settings', 'event_espresso'),
],
];
}
/**
* Sets the page routes property for this admin page group.
*/
protected function _set_page_routes()
{
$this->_page_routes = [
'default' => [
'func' => [$this, '_events_overview_list_table'],
'capability' => 'ee_read_events',
],
'create_new' => [
'func' => [$this, '_create_new_cpt_item'],
'capability' => 'ee_edit_events',
],
'edit' => [
'func' => [$this, '_edit_cpt_item'],
'capability' => 'ee_edit_event',
'obj_id' => $this->EVT_ID,
],
'copy_event' => [
'func' => [$this, '_copy_events'],
'capability' => 'ee_edit_event',
'obj_id' => $this->EVT_ID,
'noheader' => true,
],
'trash_event' => [
'func' => [$this, '_trash_or_restore_event'],
'args' => ['event_status' => 'trash'],
'capability' => 'ee_delete_event',
'obj_id' => $this->EVT_ID,
'noheader' => true,
],
'trash_events' => [
'func' => [$this, '_trash_or_restore_events'],
'args' => ['event_status' => 'trash'],
'capability' => 'ee_delete_events',
'noheader' => true,
],
'restore_event' => [
'func' => [$this, '_trash_or_restore_event'],
'args' => ['event_status' => 'draft'],
'capability' => 'ee_delete_event',
'obj_id' => $this->EVT_ID,
'noheader' => true,
],
'restore_events' => [
'func' => [$this, '_trash_or_restore_events'],
'args' => ['event_status' => 'draft'],
'capability' => 'ee_delete_events',
'noheader' => true,
],
'delete_event' => [
'func' => [$this, '_delete_event'],
'capability' => 'ee_delete_event',
'obj_id' => $this->EVT_ID,
'noheader' => true,
],
'delete_events' => [
'func' => [$this, '_delete_events'],
'capability' => 'ee_delete_events',
'noheader' => true,
],
'view_report' => [
'func' => [$this, '_view_report'],
'capability' => 'ee_edit_events',
],
'default_event_settings' => [
'func' => [$this, '_default_event_settings'],
'capability' => 'manage_options',
],
'update_default_event_settings' => [
'func' => [$this, '_update_default_event_settings'],
'capability' => 'manage_options',
'noheader' => true,
],
'template_settings' => [
'func' => [$this, '_template_settings'],
'capability' => 'manage_options',
],
// event category tab related
'add_category' => [
'func' => [$this, '_category_details'],
'capability' => 'ee_edit_event_category',
'args' => ['view' => 'add'],
],
'edit_category' => [
'func' => [$this, '_category_details'],
'capability' => 'ee_edit_event_category',
'args' => ['view' => 'edit'],
],
'delete_categories' => [
'func' => [$this, '_delete_categories'],
'capability' => 'ee_delete_event_category',
'noheader' => true,
],
'delete_category' => [
'func' => [$this, '_delete_categories'],
'capability' => 'ee_delete_event_category',
'noheader' => true,
],
'insert_category' => [
'func' => [$this, '_insert_or_update_category'],
'args' => ['new_category' => true],
'capability' => 'ee_edit_event_category',
'noheader' => true,
],
'update_category' => [
'func' => [$this, '_insert_or_update_category'],
'args' => ['new_category' => false],
'capability' => 'ee_edit_event_category',
'noheader' => true,
],
'category_list' => [
'func' => [$this, '_category_list_table'],
'capability' => 'ee_manage_event_categories',
],
'preview_deletion' => [
'func' => [$this, 'previewDeletion'],
'capability' => 'ee_delete_events',
],
'confirm_deletion' => [
'func' => [$this, 'confirmDeletion'],
'capability' => 'ee_delete_events',
'noheader' => true,
],
];
}
/**
* Set the _page_config property for this admin page group.
*/
protected function _set_page_config()
{
$post_id = $this->request->getRequestParam('post', 0, DataType::INT);
$EVT_CAT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, DataType::INT);
$this->_page_config = [
'default' => [
'nav' => [
'label' => esc_html__('Overview', 'event_espresso'),
'icon' => 'dashicons-list-view',
'order' => 10,
],
'list_table' => 'Events_Admin_List_Table',
'help_tabs' => [
'events_overview_help_tab' => [
'title' => esc_html__('Events Overview', 'event_espresso'),
'filename' => 'events_overview',
],
'events_overview_table_column_headings_help_tab' => [
'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
'filename' => 'events_overview_table_column_headings',
],
'events_overview_filters_help_tab' => [
'title' => esc_html__('Events Overview Filters', 'event_espresso'),
'filename' => 'events_overview_filters',
],
'events_overview_view_help_tab' => [
'title' => esc_html__('Events Overview Views', 'event_espresso'),
'filename' => 'events_overview_views',
],
'events_overview_other_help_tab' => [
'title' => esc_html__('Events Overview Other', 'event_espresso'),
'filename' => 'events_overview_other',
],
],
'require_nonce' => false,
],
'create_new' => [
'nav' => [
'label' => esc_html__('Add New Event', 'event_espresso'),
'icon' => 'dashicons-plus-alt',
'order' => 15,
'persistent' => false,
],
'metaboxes' => ['_register_event_editor_meta_boxes'],
'help_tabs' => [
'event_editor_help_tab' => [
'title' => esc_html__('Event Editor', 'event_espresso'),
'filename' => 'event_editor',
],
'event_editor_title_richtexteditor_help_tab' => [
'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
'filename' => 'event_editor_title_richtexteditor',
],
'event_editor_venue_details_help_tab' => [
'title' => esc_html__('Event Venue Details', 'event_espresso'),
'filename' => 'event_editor_venue_details',
],
'event_editor_event_datetimes_help_tab' => [
'title' => esc_html__('Event Datetimes', 'event_espresso'),
'filename' => 'event_editor_event_datetimes',
],
'event_editor_event_tickets_help_tab' => [
'title' => esc_html__('Event Tickets', 'event_espresso'),
'filename' => 'event_editor_event_tickets',
],
'event_editor_event_registration_options_help_tab' => [
'title' => esc_html__('Event Registration Options', 'event_espresso'),
'filename' => 'event_editor_event_registration_options',
],
'event_editor_tags_categories_help_tab' => [
'title' => esc_html__('Event Tags & Categories', 'event_espresso'),
'filename' => 'event_editor_tags_categories',
],
'event_editor_questions_registrants_help_tab' => [
'title' => esc_html__('Questions for Registrants', 'event_espresso'),
'filename' => 'event_editor_questions_registrants',
],
'event_editor_save_new_event_help_tab' => [
'title' => esc_html__('Save New Event', 'event_espresso'),
'filename' => 'event_editor_save_new_event',
],
'event_editor_other_help_tab' => [
'title' => esc_html__('Event Other', 'event_espresso'),
'filename' => 'event_editor_other',
],
],
'qtips' => ['EE_Event_Editor_Decaf_Tips'],
'require_nonce' => false,
],
'edit' => [
'nav' => [
'label' => esc_html__('Edit Event', 'event_espresso'),
'icon' => 'dashicons-edit',
'order' => 15,
'persistent' => false,
'url' => $post_id
? EE_Admin_Page::add_query_args_and_nonce(
['post' => $post_id, 'action' => 'edit'],
$this->_current_page_view_url
)
: $this->_admin_base_url,
],
'metaboxes' => ['_register_event_editor_meta_boxes'],
'help_tabs' => [
'event_editor_help_tab' => [
'title' => esc_html__('Event Editor', 'event_espresso'),
'filename' => 'event_editor',
],
'event_editor_title_richtexteditor_help_tab' => [
'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
'filename' => 'event_editor_title_richtexteditor',
],
'event_editor_venue_details_help_tab' => [
'title' => esc_html__('Event Venue Details', 'event_espresso'),
'filename' => 'event_editor_venue_details',
],
'event_editor_event_datetimes_help_tab' => [
'title' => esc_html__('Event Datetimes', 'event_espresso'),
'filename' => 'event_editor_event_datetimes',
],
'event_editor_event_tickets_help_tab' => [
'title' => esc_html__('Event Tickets', 'event_espresso'),
'filename' => 'event_editor_event_tickets',
],
'event_editor_event_registration_options_help_tab' => [
'title' => esc_html__('Event Registration Options', 'event_espresso'),
'filename' => 'event_editor_event_registration_options',
],
'event_editor_tags_categories_help_tab' => [
'title' => esc_html__('Event Tags & Categories', 'event_espresso'),
'filename' => 'event_editor_tags_categories',
],
'event_editor_questions_registrants_help_tab' => [
'title' => esc_html__('Questions for Registrants', 'event_espresso'),
'filename' => 'event_editor_questions_registrants',
],
'event_editor_save_new_event_help_tab' => [
'title' => esc_html__('Save New Event', 'event_espresso'),
'filename' => 'event_editor_save_new_event',
],
'event_editor_other_help_tab' => [
'title' => esc_html__('Event Other', 'event_espresso'),
'filename' => 'event_editor_other',
],
],
'require_nonce' => false,
],
'default_event_settings' => [
'nav' => [
'label' => esc_html__('Default Settings', 'event_espresso'),
'icon' => 'dashicons-admin-generic',
'order' => 40,
],
'metaboxes' => array_merge(['_publish_post_box'], $this->_default_espresso_metaboxes),
'labels' => [
'publishbox' => esc_html__('Update Settings', 'event_espresso'),
],
'help_tabs' => [
'default_settings_help_tab' => [
'title' => esc_html__('Default Event Settings', 'event_espresso'),
'filename' => 'events_default_settings',
],
'default_settings_status_help_tab' => [
'title' => esc_html__('Default Registration Status', 'event_espresso'),
'filename' => 'events_default_settings_status',
],
'default_maximum_tickets_help_tab' => [
'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
'filename' => 'events_default_settings_max_tickets',
],
],
'require_nonce' => false,
],
// template settings
'template_settings' => [
'nav' => [
'label' => esc_html__('Templates', 'event_espresso'),
'icon' => 'dashicons-layout',
'order' => 30,
],
'metaboxes' => $this->_default_espresso_metaboxes,
'help_tabs' => [
'general_settings_templates_help_tab' => [
'title' => esc_html__('Templates', 'event_espresso'),
'filename' => 'general_settings_templates',
],
],
'require_nonce' => false,
],
// event category stuff
'add_category' => [
'nav' => [
'label' => esc_html__('Add Category', 'event_espresso'),
'icon' => 'dashicons-plus-alt',
'order' => 25,
'persistent' => false,
],
'help_tabs' => [
'add_category_help_tab' => [
'title' => esc_html__('Add New Event Category', 'event_espresso'),
'filename' => 'events_add_category',
],
],
'metaboxes' => ['_publish_post_box'],
'require_nonce' => false,
],
'edit_category' => [
'nav' => [
'label' => esc_html__('Edit Category', 'event_espresso'),
'icon' => 'dashicons-edit',
'order' => 25,
'persistent' => false,
'url' => $EVT_CAT_ID
? add_query_arg(
['EVT_CAT_ID' => $EVT_CAT_ID],
$this->_current_page_view_url
)
: $this->_admin_base_url,
],
'help_tabs' => [
'edit_category_help_tab' => [
'title' => esc_html__('Edit Event Category', 'event_espresso'),
'filename' => 'events_edit_category',
],
],
'metaboxes' => ['_publish_post_box'],
'require_nonce' => false,
],
'category_list' => [
'nav' => [
'label' => esc_html__('Categories', 'event_espresso'),
'icon' => 'dashicons-networking',
'order' => 20,
],
'list_table' => 'Event_Categories_Admin_List_Table',
'help_tabs' => [
'events_categories_help_tab' => [
'title' => esc_html__('Event Categories', 'event_espresso'),
'filename' => 'events_categories',
],
'events_categories_table_column_headings_help_tab' => [
'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
'filename' => 'events_categories_table_column_headings',
],
'events_categories_view_help_tab' => [
'title' => esc_html__('Event Categories Views', 'event_espresso'),
'filename' => 'events_categories_views',
],
'events_categories_other_help_tab' => [
'title' => esc_html__('Event Categories Other', 'event_espresso'),
'filename' => 'events_categories_other',
],
],
'metaboxes' => $this->_default_espresso_metaboxes,
'require_nonce' => false,
],
'preview_deletion' => [
'nav' => [
'label' => esc_html__('Preview Deletion', 'event_espresso'),
'icon' => 'dashicons-remove',
'order' => 15,
'persistent' => false,
'url' => '',
],
'require_nonce' => false,
],
];
}
/**
* Used to register any global screen options if necessary for every route in this admin page group.
*/
protected function _add_screen_options()
{
}
/**
* Implementing the screen options for the 'default' route.
*
* @throws InvalidArgumentException
* @throws InvalidDataTypeException
* @throws InvalidInterfaceException
*/
protected function _add_screen_options_default()
{
$this->_per_page_screen_option();
}
/**
* Implementing screen options for the category list route.
*
* @throws InvalidArgumentException
* @throws InvalidDataTypeException
* @throws InvalidInterfaceException
*/
protected function _add_screen_options_category_list()
{
$page_title = $this->_admin_page_title;
$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
$this->_per_page_screen_option();
$this->_admin_page_title = $page_title;
}
/**
* Used to register any global feature pointers for the admin page group.
*/
protected function _add_feature_pointers()
{
}
/**
* Registers and enqueues any global scripts and styles for the entire admin page group.
*/
public function load_scripts_styles()
{
wp_register_style(
'events-admin-css',
EVENTS_ASSETS_URL . 'events-admin-page.css',
[],
EVENT_ESPRESSO_VERSION
);
wp_register_style(
'ee-cat-admin',
EVENTS_ASSETS_URL . 'ee-cat-admin.css',
[],
EVENT_ESPRESSO_VERSION
);
wp_enqueue_style('events-admin-css');
wp_enqueue_style('ee-cat-admin');
// scripts
wp_register_script(
'event_editor_js',
EVENTS_ASSETS_URL . 'event_editor.js',
['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
EVENT_ESPRESSO_VERSION,
true
);
}
/**
* Enqueuing scripts and styles specific to this view
*/
public function load_scripts_styles_create_new()
{
$this->load_scripts_styles_edit();
}
/**
* Enqueuing scripts and styles specific to this view
*/
public function load_scripts_styles_edit()
{
// styles
wp_enqueue_style('espresso-ui-theme');
wp_register_style(
'event-editor-css',
EVENTS_ASSETS_URL . 'event-editor.css',
['ee-admin-css'],
EVENT_ESPRESSO_VERSION
);
wp_enqueue_style('event-editor-css');
// scripts
if (! $this->admin_config->useAdvancedEditor()) {
wp_register_script(
'event-datetime-metabox',
EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
['event_editor_js', 'ee-datepicker'],
EVENT_ESPRESSO_VERSION
);
wp_enqueue_script('event-datetime-metabox');
}
}
/**
* Populating the _views property for the category list table view.
*/
protected function _set_list_table_views_category_list()
{
$this->_views = [
'all' => [
'slug' => 'all',
'label' => esc_html__('All', 'event_espresso'),
'count' => 0,
'bulk_action' => [
'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
],
],
];
}
/**
* For adding anything that fires on the admin_init hook for any route within this admin page group.
*/
public function admin_init()
{
EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
'Do you really want to delete this image? Please remember to update your event to complete the removal.',
'event_espresso'
);
}
/**
* For adding anything that should be triggered on the admin_notices hook for any route within this admin page
* group.
*/
public function admin_notices()
{
}
/**
* For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
* this admin page group.
*/
public function admin_footer_scripts()
{
}
/**
* Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a
* warning (via EE_Error::add_error());
*
* @param EE_Event|null $event Event object
* @param string $req_type
* @return void
* @throws EE_Error
* @throws ReflectionException
*/
public function verify_event_edit(?EE_Base_Class $event = null, string $req_type = '')
{
// don't need to do this when processing
if (! empty($req_type)) {
return;
}
// no event?
if (! $event instanceof EE_Event) {
$event = $this->_cpt_model_obj;
}
// STILL no event?
if (! $event instanceof EE_Event) {
return;
}
// don't need to keep calling this
remove_action(
'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
[$this, 'verify_event_edit']
);
$orig_status = $event->status();
// first check if event is active.
if (
$orig_status === EEM_Event::cancelled
|| $orig_status === EEM_Event::postponed
|| $event->is_expired()
|| $event->is_inactive()
) {
return;
}
// made it here so it IS active... next check that any of the tickets are sold.
if ($event->is_sold_out(true)) {
if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
EE_Error::add_attention(
sprintf(
esc_html__(
'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.',
'event_espresso'
),
EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
)
);
}
return;
}
if ($orig_status === EEM_Event::sold_out) {
EE_Error::add_attention(
sprintf(
esc_html__(
'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.',
'event_espresso'
),
EEH_Template::pretty_status($event->status(), false, 'sentence')
)
);
}
// now we need to determine if the event has any tickets on sale. If not then we dont' show the error
if (! $event->tickets_on_sale()) {
return;
}
// made it here so show warning
$this->_edit_event_warning();
}
/**
* This is the text used for when an event is being edited that is public and has tickets for sale.
* When needed, hook this into a EE_Error::add_error() notice.
*
* @access protected
* @return void
*/
protected function _edit_event_warning()
{
// we don't want to add warnings during these requests
if ($this->request->getRequestParam('action') === 'editpost') {
return;
}
EE_Error::add_attention(
sprintf(
esc_html__(
'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
'event_espresso'
),
'<a class="espresso-help-tab-lnk ee-help-tab-link">',
'</a>'
)
);
}
/**
* When a user is creating a new event, notify them if they haven't set their timezone.
* Otherwise, do the normal logic
*
* @return void
* @throws EE_Error
* @throws InvalidArgumentException
* @throws InvalidDataTypeException
* @throws InvalidInterfaceException
* @throws ReflectionException
*/
protected function _create_new_cpt_item()
{
$has_timezone_string = get_option('timezone_string');
// only nag them about setting their timezone if it's their first event, and they haven't already done it
if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
EE_Error::add_attention(
sprintf(
esc_html__(
'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',
'event_espresso'
),
'<br>',
'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
. '</select>',
'<button class="button button--secondary timezone-submit">',
'</button><span class="spinner"></span>'
),
__FILE__,
__FUNCTION__,
__LINE__
);
}
parent::_create_new_cpt_item();
}
/**
* Sets the _views property for the default route in this admin page group.
*/
protected function _set_list_table_views_default()
{
$this->_views = [
'all' => [
'slug' => 'all',
'label' => esc_html__('View All Events', 'event_espresso'),
'count' => 0,
'bulk_action' => [
'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
],
],
'draft' => [
'slug' => 'draft',
'label' => esc_html__('Draft', 'event_espresso'),
'count' => 0,
'bulk_action' => [
'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
],
],
];
if ($this->capabilities->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
$this->_views['trash'] = [
'slug' => 'trash',
'label' => esc_html__('Trash', 'event_espresso'),
'count' => 0,
'bulk_action' => [
'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
'delete_events' => esc_html__('Delete Permanently', 'event_espresso'),
],
];
}
}
/**
* Provides the legend item array for the default list table view.
*
* @return array
* @throws EE_Error
* @throws EE_Error
*/
protected function _event_legend_items(): array
{
$items = [
'view_details' => [
'class' => 'dashicons dashicons-visibility',
'desc' => esc_html__('View Event', 'event_espresso'),
],
'edit_event' => [
'class' => 'dashicons dashicons-calendar-alt',
'desc' => esc_html__('Edit Event Details', 'event_espresso'),
],
'view_attendees' => [
'class' => 'dashicons dashicons-groups',
'desc' => esc_html__('View Registrations for Event', 'event_espresso'),
],
];
$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
$statuses = [
'sold_out_status' => [
'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::sold_out,
'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
],
'active_status' => [
'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::active,
'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
],
'upcoming_status' => [
'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::upcoming,
'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
],
'postponed_status' => [
'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::postponed,
'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
],
'cancelled_status' => [
'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::cancelled,
'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
],
'expired_status' => [
'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::expired,
'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
],
'inactive_status' => [
'class' => 'ee-status-legend ee-status-bg--' . EE_Datetime::inactive,
'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
],
];
$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
return array_merge($items, $statuses);
}
/**
* @return EEM_Event
* @throws EE_Error
* @throws InvalidArgumentException
* @throws InvalidDataTypeException
* @throws InvalidInterfaceException
* @throws ReflectionException
*/
private function _event_model(): EEM_Event
{
if (! $this->_event_model instanceof EEM_Event) {
$this->_event_model = EE_Registry::instance()->load_model('Event');
}
return $this->_event_model;
}
/**
* Adds extra buttons to the WP CPT permalink field row.
* Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
*
* @param string $return the current html
* @param int $id the post id for the page
* @param string|null $new_title What the title is
* @param string|null $new_slug what the slug is
* @return string The new html string for the permalink area
* @deprecated 5.0.0.p
* @see TicketSelectorShortcodeButton::addButton
*/
public function extra_permalink_field_buttons(
string $return,
int $id,
?string $new_title,
?string $new_slug
): string {
return TicketSelectorShortcodeButton::addButton($return, $id, $new_title, $new_slug);
}
/**
* _events_overview_list_table
* This contains the logic for showing the events_overview list
*
* @access protected
* @return void
* @throws DomainException
* @throws EE_Error
* @throws InvalidArgumentException
* @throws InvalidDataTypeException
* @throws InvalidInterfaceException
*/
protected function _events_overview_list_table()
{
$after_list_table = [];
$links_html = EEH_HTML::div('', '', 'ee-admin-section ee-layout-stack');
$links_html .= EEH_HTML::h3(esc_html__('Links', 'event_espresso'));
$links_html .= EEH_HTML::div(
EEH_Template::get_button_or_link(
get_post_type_archive_link(EspressoPostType::EVENTS),
esc_html__('View Event Archive Page', 'event_espresso'),
'button button--small button--secondary'
),
'',
'ee-admin-button-row ee-admin-button-row--align-start'
);
$links_html .= EEH_HTML::divx();
$after_list_table['view_event_list_button'] = $links_html;
$after_list_table['legend'] = $this->_display_legend($this->_event_legend_items());
$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
'create_new',
'add',
[],
'add-new-h2'
);
$this->_template_args['after_list_table'] = array_merge(
(array) $this->_template_args['after_list_table'],
$after_list_table
);
$this->display_admin_list_table_page_with_no_sidebar();
}
/**
* this allows for extra misc actions in the default WP publish box