-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunctions.php
1913 lines (1651 loc) · 52.6 KB
/
functions.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
/*
|--------------------------------------------------------------------------
| Load Composer Dependencies
|--------------------------------------------------------------------------
|
|
|
|
*/
$composer = __DIR__ . '/vendor/autoload.php';
if ( file_exists( $composer ) ) {
include_once $composer;
}
/*
|--------------------------------------------------------------------------
| Asynchronous loading js
|--------------------------------------------------------------------------
|
| to improve speed of page load
|
|
*/
add_filter( /**
* @param $tag
* @param $handle
* @param $src
*
* @return string
*/
'script_loader_tag', function ( $tag, $handle, $src ) {
$defer = [
'jquery-ui-position',
'jquery-ui-draggable',
'jquery-ui-resizable',
'jquery-ui-menu',
'jquery-ui-sortable',
'jquery-ui-datepicker',
'jquery-ui-autocomplete',
'jquery-ui-dialog',
'jquery-ui-button',
'bp-confirm',
'bp-jquery-query',
'events-manager',
'jquery-mobilemenu',
'jquery-fitvids',
'modal-video',
'bootstrap-accordion',
'd3',
'donut',
];
$async = [
'bp-jquery-cookie',
'dtheme-ajax-js',
'wp-a11y',
'bp-widget-members',
'groups_widget_groups_list-js',
'joyride',
];
if ( in_array( $handle, $defer, true ) ) {
return "<script defer type='text/javascript' src='{$src}'></script>" . "\n";
}
if ( in_array( $handle, $async, true ) ) {
return "<script async type='text/javascript' src='{$src}'></script>" . "\n";
}
return $tag;
}, 10, 3
);
/*
|--------------------------------------------------------------------------
| Scripts and Styles
|--------------------------------------------------------------------------
|
| early years look, feel, functionality
|
|
*/
/**
* need our stylesheet to fire later than the rest
* in order for: now your base are belong to us
* infinity theme behaves differently than you would expect parent themes to act
*/
add_action(
'wp_enqueue_scripts', function () {
wp_enqueue_style( 'early-years', get_stylesheet_directory_uri() . '/dist/styles/main.css', [ '@:dynamic' ], '', 'screen' );
}, 11
);
/**
* back end, front end parity
*/
add_editor_style( get_stylesheet_directory_uri() . '/dist/styles/main.css' );
/**
* Load our scripts
*/
add_action(
'wp_enqueue_scripts', function () {
$template_dir = get_stylesheet_directory_uri();
// toss Events Manager scripts and their dependencies
wp_dequeue_script( 'events-manager' );
remove_action( 'close_body', 'cbox_theme_flex_slider_script' );
wp_enqueue_script( 'jquery-ui-draggable' );
wp_enqueue_script( 'markerclusterer', $template_dir . '/dist/scripts/markerclusterer.js', [], false, true );
$script_deps = [
'jquery' => 'jquery',
'jquery-ui-core' => 'jquery-ui-core',
'jquery-ui-widget' => 'jquery-ui-widget',
'jquery-ui-position' => 'jquery-ui-position',
'jquery-ui-sortable' => 'jquery-ui-sortable',
'jquery-ui-datepicker' => 'jquery-ui-datepicker',
'jquery-ui-autocomplete' => 'jquery-ui-autocomplete',
'jquery-ui-dialog' => 'jquery-ui-dialog',
'markerclusterer' => 'markerclusterer',
];
wp_enqueue_script( 'events-manager', $template_dir . '/dist/scripts/events-manager.js', array_values( $script_deps ), isset( $EM_VERSION ) );
wp_enqueue_script( 'tinyscrollbar', $template_dir . '/dist/scripts/jquery.tinyscrollbar.min.js', [ 'jquery' ], '1.0', true );
wp_enqueue_style( 'bootstrap-style', $template_dir . '/dist/styles/bootstrap.min.css' );
wp_enqueue_script( 'bootstrap-script', $template_dir . '/dist/scripts/bootstrap.bundle.js', [ 'jquery' ], null, true );
// load popover only for users who aren't logged in
if ( ! is_user_logged_in() ) {
wp_enqueue_script( 'init-tooltip', $template_dir . '/dist/scripts/inittooltip.js', [ 'bootstrap-script' ], null, true );
}
wp_enqueue_script( 'modal-video', $template_dir . '/dist/scripts/modal-video.js', [ 'jquery', 'bootstrap-script' ], null, true );
wp_enqueue_script( 'modal-booking', $template_dir . '/dist/scripts/modal-booking.js', [ 'bootstrap-script' ], null, true );
// load styling for datepicker in myEYPD profile page only
if ( function_exists( 'bp_is_my_profile' ) ) {
if ( bp_is_my_profile() ) {
wp_enqueue_style( 'jquery-style', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' );
wp_enqueue_script( 'bootstrap-accordion', $template_dir . '/dist/scripts/accordion.js', [ 'jquery' ], null, true );
wp_enqueue_script( 'd3', $template_dir . '/dist/scripts/d3.min.js', [], null, true );
wp_enqueue_script( 'donut', $template_dir . '/dist/scripts/donut.js', [ 'd3' ], null, true );
}
}
if ( is_front_page() ) {
wp_enqueue_script( 'jquery-tabs', $template_dir . '/dist/scripts/tabs.js', [ 'jquery' ], null, true );
wp_enqueue_script( 'jquery-ui-tabs' );
}
if ( is_singular( 'event' ) ) {
wp_enqueue_style( 'banner', $template_dir . '/dist/styles/event.css' );
}
if ( is_page( 'edit-events' ) || is_page( 'post-event' ) ) {
wp_enqueue_style( 'media-manager', $template_dir . '/dist/styles/media.css' );
wp_enqueue_style( 'select2-style', $template_dir . '/dist/styles/select2.min.css' );
wp_enqueue_script( 'select2', $template_dir . '/dist/scripts/select2.min.js', [], null, true );
wp_enqueue_script( 'select-multiple', $template_dir . '/dist/scripts/select-multiple.js', [ 'select2' ], null, true );
}
}, 10
);
/*
|--------------------------------------------------------------------------
| Admin Styles
|--------------------------------------------------------------------------
|
| for admin pages only
|
|
*/
add_action(
'admin_enqueue_scripts', function () {
wp_enqueue_style( 'eypd_admin_css', get_stylesheet_directory_uri() . '/dist/styles/admin.css', false, false, 'screen' );
}
);
// remove from parent theme
remove_action( 'wp_head', 'infinity_custom_favicon' );
/*
|--------------------------------------------------------------------------
| Common Stuff
|--------------------------------------------------------------------------
|
|
|
|
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 100, 100 );
/*
|--------------------------------------------------------------------------
| Maps
|--------------------------------------------------------------------------
|
| Hijacks files from events-manager plugin
|
|
*/
if ( function_exists( 'em_content' ) ) {
remove_filter( 'the_content', 'em_content' );
}
if ( function_exists( 'em_content' ) ) {
remove_filter( 'init', 'em_init_actions' );
}
$eypd_actions = get_stylesheet_directory() . '/eypd-actions.php';
$eypd_events = get_stylesheet_directory() . '/eypd-events.php';
if ( file_exists( $eypd_actions ) ) {
require $eypd_actions;
}
if ( file_exists( $eypd_events ) ) {
require $eypd_events;
}
/*
|--------------------------------------------------------------------------
| Events Manager
|--------------------------------------------------------------------------
|
| Creates a new scope for the events manager short code, and then registers it with events manager.
| It will only lists events with a date greater than today's.
|
|
*/
/**
*
* @param $conditions
* @param $args
*
* @return mixed
*/
add_filter( 'em_events_build_sql_conditions', function ( $conditions, $args ) {
if ( ! empty( $args['scope'] ) && $args['scope'] === 'after-today' ) {
$current_date = date( 'Y-m-d', current_time( 'timestamp' ) );
$conditions['scope'] = " (event_start_date > CAST('$current_date' AS DATE))";
}
return $conditions;
}, 1, 2 );
/**
*
* @param $scopes
*
* @return array
*/
add_filter( 'em_get_scopes', function ( $scopes ) {
$my_scopes = [
'after-today' => 'After Today',
];
return $scopes + $my_scopes;
}, 1, 1 );
/*
|--------------------------------------------------------------------------
| Login customization
|--------------------------------------------------------------------------
|
|
|
|
*/
/**
* Custom stylesheet enqueued at login page
*/
add_action(
'login_enqueue_scripts', function () {
wp_enqueue_style( 'custom-login', get_stylesheet_directory_uri() . '/dist/styles/login.css' );
}
);
/**
* Link logo image to our home_url instead of WordPress.org
*
* @return string|void
*/
add_filter(
'login_headerurl', function () {
return home_url();
}
);
/**
* Give the image our sites name
*
* @return string|void
*/
add_filter(
'login_headertitle', function () {
return get_bloginfo( 'name' );
}
);
/**
* Add custom text to login form
*
* @param $message
*
* @return string
*/
add_filter( 'login_message', function ( $message ) {
if ( empty( $message ) ) {
$imgdir = get_stylesheet_directory_uri();
$html = '<p class="login-logo"><picture><source srcset="' . $imgdir . '/dist/images/eypd-logo-small.webp" type="image/webp"><source srcset="' . $imgdir . '/dist/images/eypd-logo-small.png"><img src="' . $imgdir . '/dist/images/eypd-logo-small.png" width="101" height="92" alt="BC Provincial Government"></picture></p>';
$html .= '<p class="logintext">Log in To Your EYPD Account</p>';
echo $html;
} else {
return $message;
}
} );
/**
* Adds Sign Up button and Forgot lost password link
*/
add_action( 'login_form', function () {
$html = '<p class="signuptext">New to EYPD?</p><p><a class ="button button-primary button-large signup" href="' . home_url() . '/sign-up" title="Sign Up">Sign Up</a></p>';
$html .= ' - <a class ="forgot" href="' . wp_lostpassword_url() . '" title="Lost Password">Forgot Password?</a>';
echo $html;
} );
/**
* Redirect user after successful login.
*
* @param string $url URL to redirect to.
* @param string query URL the user is coming from.
* @param object $user Logged user's data.
*
* @return string
*/
add_filter( 'login_redirect', function( $url, $query, $user ) {
return bp_core_get_user_domain( $user->ID ) . '/events/';
}, 10, 3 );
/*
|--------------------------------------------------------------------------
| Excerpt
|--------------------------------------------------------------------------
|
| Filter the read more ...
|
|
*/
/**
* @param $more
*
* @return string
*/
add_filter( 'excerpt_more', function ( $more ) {
global $post;
return ' <a href="' . get_the_permalink( $post->ID ) . '">...[Read full article]</a>';
} );
/*
|--------------------------------------------------------------------------
| Labels/Localization
|--------------------------------------------------------------------------
|
| Addin' sum canadiana to this here 'merican plugin
|
|
*/
function eypd_get_provinces() {
$provinces = [
'Alberta',
'British Columbia',
'Manitoba',
'New Brunswick',
'Newfoundland',
'Northwest Territories',
'Nova Scotia',
'Nunavut',
'Ontario',
'Prince Edward Island',
'Quebec',
'Saskatchewan',
'Yukon',
];
return $provinces;
}
/**
* Runs once to set up defaults
* increase variable $eypd_version to ensure it runs again
*/
function eypd_run_once() {
// change eypd_version value to run it again
$eypd_version = 7.4;
$current_version = get_option( 'eypd_version', 0 );
$img_max_dimension = 1000;
$img_min_dimension = 50;
$img_max_size = 8388608;
$default_no = [
'dbem_css_search',
'dbem_events_form_reshow',
'dbem_events_anonymous_submissions',
'dbem_cp_events_comments',
'dbem_search_form_countries',
'dbem_locations_page_search_form',
'dbem_bookings_anonymous',
'dbem_bookings_approval',
'dbem_bookings_double',
'dbem_bookings_login_form',
'dbem_search_form_geo',
];
$default_yes = [
'dbem_rsvp_enabled',
'dbem_recurrence_enabled',
'dbem_categories_enabled',
'dbem_attributes_enabled',
'dbem_cp_events_custom_fields',
'dbem_locations_enabled',
'dbem_require_location',
'dbem_events_form_editor',
'dbem_cp_events_formats',
'dbem_gmap_is_active',
'dbem_cp_events_formats',
'dbem_bookings_approval_reserved',
'dbem_bookings_user_cancellation',
'dbem_bookings_approval_overbooking',
];
$default_attributes = '#_ATT{Target Audience}
#_ATT{Online}{|Yes|No}
#_ATT{Professional Development Certificate}{|Yes|No|Upon Request|Not Currently Available}
#_ATT{Professional Development Certificate Credit Hours}
#_ATT{Registration Fee}
#_ATT{Registration Space}{|Filling Up!|FULL}
#_ATT{Registration Contact Email}
#_ATT{Registration Contact Phone Number}
#_ATT{Registration Link}
#_ATT{Prerequisite(s)}
#_ATT{Required Materials}
#_ATT{Presenter(s)}
#_ATT{Presenter Information}
#_ATT{Event Sponsors}';
$single_event_format = '<div class="single-event-map">#_LOCATIONMAP</div>
<p>
<strong>Date/Time</strong><br/>
Date(s) - #_EVENTDATES<br /><i>#_EVENTTIMES</i>
</p>
<p>
<strong>Location</strong><br/>
#_LOCATIONLINK
</p>
<p><strong>Add to My Calendar</strong><br>#_EVENTICALLINK</p>
{has_location}
{/has_location}
<br style="clear:both" />
#_EVENTNOTES
<p>
<strong>Categories</strong>
#_CATEGORIES
</p>
{has_bookings}
#_BOOKINGFORM
{/has_bookings}';
$success_message = '<p><strong>Congratulations! You have successfully submitted your training event.</strong></p> <p><strong>Go to the <a href="' . get_site_url() . '">' . 'homepage</a> and use the search or map feature to find your event.</strong></p>';
$loc_balloon_format = '<strong>#_LOCATIONNAME</strong><address>#_LOCATIONADDRESS<br>#_LOCATIONTOWN</address>
#_LOCATIONNEXTEVENTS';
$format_event_list_header = '<table cellpadding="0" cellspacing="0" class="events-table" >
<thead>
<tr>
<th class="event-time" width="150">Date/Time</th>
<th class="event-description" width="*">Event</th>
<th class="event-capacity" width="*">Capacity</th>
</tr>
</thead>
<tbody>';
$format_event_list = '<tr>
<td>#_EVENTDATES<br/>#_EVENTTIMES</td>
<td>#_EVENTLINK
{has_location}<br/><i>#_LOCATIONNAME, #_LOCATIONTOWN #_LOCATIONSTATE</i>{/has_location}
</td>
<td>#_ATT{Registration Space}</td>
</tr>';
$format_event_list_footer = '</tbody></table>';
$format_cat_list_header = '<table cellpadding="0" cellspacing="0" class="category-table" >
<tbody>';
$format_cat_list = '<tr>
<td>
#_EVENTDATES<br>#_EVENTTIMES
</td>
<td>
{has_location}#_EVENTLINK<br>#_LOCATIONNAME<br>#_LOCATIONTOWN, #_LOCATIONSTATE{/has_location}
</td>
<td>#_ATT{Registration Space}</td>
</tr>';
$format_cat_list_footer = '</tbody></table>';
if ( $current_version < $eypd_version ) {
update_option( 'dbem_placeholders_custom', $default_attributes );
update_option( 'dbem_image_max_width', $img_max_dimension );
update_option( 'dbem_image_max_height', $img_max_dimension );
update_option( 'dbem_image_min_width', $img_min_dimension );
update_option( 'dbem_image_min_height', $img_min_dimension );
update_option( 'dbem_image_max_size', $img_max_size );
update_option( 'dbem_events_form_result_success', $success_message );
update_option( 'dbem_events_form_result_success_updated', $success_message );
update_option( 'dbem_map_text_format', $loc_balloon_format );
update_option( 'dbem_event_list_item_format', $format_event_list );
update_option( 'dbem_event_list_item_format_header', $format_event_list_header );
update_option( 'dbem_event_list_item_format_footer', $format_event_list_footer );
update_option( 'dbem_category_event_list_item_format', $format_cat_list );
update_option( 'dbem_category_event_list_item_header_format', $format_cat_list_header );
update_option( 'dbem_category_event_list_item_footer_format', $format_cat_list_footer );
update_option( 'dbem_single_event_format', $single_event_format );
update_option( 'dbem_location_event_list_limit', 20 );
foreach ( $default_no as $no ) {
update_option( $no, 0 );
}
foreach ( $default_yes as $yes ) {
update_option( $yes, 1 );
}
/**
* Changes to search for labels
*/
update_option( 'dbem_search_form_state_label', 'Province' );
update_option( 'dbem_search_form_text_label', 'Search by Topic, Keyword or Location' );
update_option( 'dbem_search_form_dates_label', 'Search by Start Date' );
update_option( 'dbem_search_form_category_label', 'Search by Category' );
update_option( 'dbem_search_form_town_label', 'City/Community/Town' );
update_option( 'dbem_search_form_dates_separator', 'End Date' );
/**
* All events will be in Canada
*/
update_option( 'dbem_location_default_country', 'CA' );
/**
* Most events will be in British Columbia
*/
update_option( 'eypd_location_default_province', 'British Columbia' );
/**
* Booking submit button text
*/
update_option( 'dbem_bookings_submit_button', 'Save to myEYPD' );
/**
* Booking submit success
*/
update_option( 'dbem_booking_feedback', 'Event added! Click on myEYPD (top right of your screen) to find this saved event.' );
/**
* Manage bookings link text
*/
update_option( ' dbem_bookings_form_msg_bookings_link', 'My Profile Page' );
/**
* Update option to current version
*/
update_option( 'eypd_version', $eypd_version );
}
}
add_action( 'wp_loaded', 'eypd_run_once' );
/**
* Changing state to province and other customizations
*
* @param $translated
* @param $original
* @param $domain
*
* @return mixed
*/
function eypd_terminology_modify( $translated, $original, $domain ) {
if ( 'events-manager' === $domain ) {
$modify = [
'State/County:' => 'Province:',
'Details' => 'Event Description and Objectives',
'Category:' => 'Category',
'Submit %s' => 'Post %s',
'You must log in to view and manage your events.' => 'You are using this site in the role as a Learner. Learners may search for, share, and print events. Only Organizers may post and edit events.',
'You are currently viewing your public page, this is what other users will see.' => '',
'Events' => 'myEYPD',
];
}
if ( 'buddypress' === $domain ) {
$modify = [
'Register' => 'Sign Up',
'Email Address' => 'Work Email Address',
'Registering for this site is easy. Just fill in the fields below, and we\'ll get a new account set up for you in no time.' => 'Fill in the fields below to register as an Organizer or a Learner. <b>Learner</b> — you are primarily looking for training events. <b>Organizer</b> — you are primarily posting training events on behalf of your organization.',
'You have successfully created your account! Please log in using the username and password you have just created.' => '',
];
}
if ( isset( $modify[ $original ] ) ) {
$translated = $modify[ $original ];
}
return $translated;
}
add_filter( 'gettext', 'eypd_terminology_modify', 11, 3 );
/**
* Howdy message needs a higher priority and different logic
* than @see eypd_terminology_modify()
*
* @param $translated_text
* @param $text
* @param $domain
*
* @return mixed
*/
function eypd_howdy_message( $translated_text, $text, $domain ) {
$new_message = str_replace( 'Howdy,', '', $text );
return $new_message;
}
add_filter( 'gettext', 'eypd_howdy_message', 10, 3 );
/**
*
* @param int $post_id
* @param array $data
*
* @return array
*/
function eypd_event_output( $post_id = 0, $data = [] ) {
// get the data
if ( is_array( $data ) ) {
$data = get_post_custom( $post_id );
}
// return the design
return $data;
}
/**
* intercepts output, finds post id#s, uses them to get slugs
* insert those slugs into the <li> as classes
*
* @param string $input
*
* @return mixed|string
*/
function eypd_event_etc_output( $input = '' ) {
$output = $input;
preg_match_all( '/<li class="category-(\d+)">/', $input, $output_array );
foreach ( $output_array[1] as $index => $post_id ) {
$cats = wp_get_object_terms( $post_id, 'event-categories' );
$cat_output = $space = '';
foreach ( $cats as $cat ) {
$c = get_category( $cat );
$cat_output .= $space . 'cat_' . str_replace( '-', '_', $c->slug );
$space = ' ';
}
$new_classes = "<li class=\"$cat_output\">";
$output = str_replace( $output_array[0][ $index ], $new_classes, $output );
}
// remove pagination links
$output = preg_replace( '/<strong><span class=\"page-numbers(.*)<\/span>/i', '', $output );
return $output;
}
/**
* use it for two uses -- the Ajax response and the post info
*
* @param int $post_id
* @param bool $ajax
*/
function et_fetch( $post_id = - 1, $ajax = true ) {
if ( $ajax === true ) {
$output = eypd_event_output( $post_id );
echo json_encode( $output ); //encode into JSON format and output
die(); //stop "0" from being output
}
}
add_action( 'wp_ajax_nopriv_cyop_lookup', 'et_fetch' );
add_action( 'wp_ajax_cyop_lookup', 'et_fetch' );
/*
|--------------------------------------------------------------------------
| Navigation
|--------------------------------------------------------------------------
|
| Custom Navigation
|
|
*/
/**
* remove links/menus from the admin bar,
* if you are not an admin
*/
function eypd_admin_bar_render() {
global $wp_admin_bar;
// check if the admin panel is attempting to be displayed
if ( ! is_admin() ) {
$wp_admin_bar->remove_node( 'wp-logo' );
$wp_admin_bar->remove_node( 'search' );
$wp_admin_bar->remove_node( 'comments' );
$wp_admin_bar->remove_node( 'edit' );
$wp_admin_bar->remove_node( 'edit-profile' );
$wp_admin_bar->remove_node( 'logout' );
$wp_admin_bar->remove_node( 'new-content' );
$wp_admin_bar->remove_node( 'updates' );
$wp_admin_bar->remove_node( 'my-blogs' );
$wp_admin_bar->remove_node( 'customize' );
$wp_admin_bar->remove_node( 'site-name' );
$wp_admin_bar->remove_node( 'my-account-buddypress' );
$wp_admin_bar->remove_node( 'bp-notifications' );
$wp_admin_bar->remove_node( 'itsec_admin_bar_menu' );
// add my profile link
$profileurl = eypd_get_my_bookings_url();
$wp_admin_bar->add_node(
[
'id' => 'my_profile',
'title' => 'myEYPD',
'href' => $profileurl,
'parent' => 'user-actions',
'meta' => [
'class' => 'my-profile-page',
],
]
);
//add logout link after my profile link, and redirect to homepage after logout
$logouturl = wp_logout_url( home_url() );
$wp_admin_bar->add_node(
[
'id' => 'logout',
'title' => 'Logout',
'href' => $logouturl,
'parent' => 'user-actions',
'meta' => [
'class' => 'my-logout-link',
],
]
);
// maintain a way for admins to access the dashboard
if ( current_user_can( 'activate_plugins' ) ) {
$url = get_admin_url();
$wp_admin_bar->add_node(
[
'id' => 'eypd_dashboard',
'title' => 'Dashboard',
'href' => $url,
'meta' => [
'class' => 'my-toolbar-page',
],
]
);
}
}
}
add_action( 'wp_before_admin_bar_render', 'eypd_admin_bar_render' );
/**
* Remove BP sidebar menu items
*/
function eypd_bp_nav() {
global $bp;
bp_core_remove_nav_item( 'activity' );
bp_core_remove_nav_item( 'forums' );
bp_core_remove_nav_item( 'groups' );
bp_core_remove_nav_item( 'friends' );
bp_core_remove_nav_item( 'messages' );
bp_core_remove_nav_item( 'notifications' );
//subnav
bp_core_remove_subnav_item( 'events', 'attending' );
bp_core_remove_subnav_item( 'events', 'my-bookings' );
bp_core_remove_subnav_item( 'events', 'my-events' );
}
// Commenting out 2018-11-26 to restore BP functionality
//add_action( 'bp_setup_nav', 'eypd_bp_nav', 1000 );
// Filter wp_nav_menu() to add pop-overs to links in header menu
add_filter(
'wp_nav_menu_items', function ( $nav, $args ) {
if ( $args->theme_location === 'main-menu' ) {
// adds home link to mobile only using bootstraps responsive utilities class
$nav = '<li class="d-block d-sm-none home"><a href=' . home_url() . '>Home</a></li>';
$nav .= '<li class="home"><a href=' . home_url() . '/events>Find Events</a></li>';
if ( is_user_logged_in() ) {
$nav .= '<li class="home"><a href=' . home_url() . '/post-event>Post an Event</a></li>';
$nav .= '<li class="home"><a href=' . home_url() . '/edit-events>Edit Events</a></li>';
$nav .= '<li class="home"><a href="' . eypd_get_my_bookings_url() . '">' . __( '<i>my</i>EYPD' ) . '</a></li>';
} else {
//add tooltip with a message, and login and sign-up links
$popover = '<li class="home"><a tabindex="0" href="#" data-toggle="tooltip" data-placement="bottom" data-container="body" data-trigger="focus click" data-html="true" data-title="Please <a href=\'' . wp_login_url() . '\'>Login</a> or <a href=\'' . home_url() . '/sign-up\'>Sign up</a> to ';
$nav .= $popover . 'post events.">Post an Event</a></li>';
$nav .= $popover . 'edit your events.">Edit Event</a></li>';
$nav .= $popover . ' view your events."><i>my</i>EYPD</a></li>';
}
}
return $nav;
}, 10, 2
);
/**
* add Professional Interests to profile area
* ensure only the member whose page it is can see it
*/
add_action(
'bp_setup_nav', function () {
$args = [
'name' => __( 'My Professional Interests', 'early-years' ),
'slug' => 'professional-interests',
'default_subnav_slug' => 'prof-int',
'position' => 50,
'show_for_displayed_user' => false,
'screen_function' => 'eypd_custom_user_nav_item_screen',
'item_css_id' => 'prof-int',
'site_admin_only' => false,
];
bp_core_new_nav_item( $args );
}, 11
);
/**
* custom navigation
*/
function eypd_custom_user_nav_item_screen() {
add_action( 'bp_template_content', 'eypd_custom_screen_content' );
bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
}
/*
|--------------------------------------------------------------------------
| Forms n' stuff
|--------------------------------------------------------------------------
|
|
|
|
*/
/**
* Validating that required attribute fields are not empty
*/
function eypd_validate_attributes() {
global $EM_Event;
// bail early if not an object
if ( ! is_object( $EM_Event ) ) {
return false;
}
if ( empty( $EM_Event->event_attributes['Professional Development Certificate'] ) ) {
$EM_Event->add_error( sprintf( __( '%s is required.', 'early-years' ), __( 'Professional Development Certificate', 'early-years' ) ) );
}
if ( ! isset( $EM_Event->event_attributes['Registration Fee'] ) ) {
$EM_Event->add_error( sprintf( __( '%s is required.', 'early-years' ), __( 'Registration Fee', 'early-years' ) ) );
}
if ( ! empty( $EM_Event->event_attributes['Registration Link'] ) && false === eypd_maybe_url( $EM_Event->event_attributes['Registration Link'] ) ) {
$EM_Event->add_error( sprintf( __( '%s is not a valid URL.', 'early-years' ), __( 'Registration Link', 'early-years' ) ) );
}
return $EM_Event;
}
add_action( 'em_event_validate', 'eypd_validate_attributes' );
/**
* Enable user to register for an event when its expired
* Notes/Assumptions: $booking_spaces = 0 occurs when event expires
* $feedback_message = '' when event expires????
* $EM_Booking->event->get_bookings()->is_open() returns false when an event expires
*
* @return bool|mixed|void
*/
function eypd_validate_bookings() {
global $EM_Booking;
// bail early if not an object
if ( ! is_object( $EM_Booking ) ) {
return false;
}
if ( $EM_Booking->booking_spaces === 0 && $EM_Booking->feedback_message === '' && ! $EM_Booking->event->get_bookings()->is_open() ) {
$EM_Booking->errors = [];
}
return $EM_Booking;
}
add_action( 'em_booking_validate', 'eypd_validate_bookings' );
/**
* Add open graph doctype, needed to make FB posts pretty when sharing
*
* @param $output
*
* @return string
*/
function eypd_doctype_opengraph( $output ) {
return $output . '
xmlns:og="http://opengraphprotocol.org/schema/"
xmlns:fb="http://www.facebook.com/2008/fbml"';
}
add_filter( 'language_attributes', 'eypd_doctype_opengraph' );
/**
* Add content to the open graph tags for FB
*/
function eypd_fb_opengraph() {
global $post;
$img_src = get_stylesheet_directory_uri() . '/dist/images/eypd-logo.png';
if ( is_single() ) {
if ( has_post_thumbnail( $post->ID ) ) {
$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
}
if ( $post->post_excerpt ) {
$excerpt = strip_tags( $post->post_excerpt );
$excerpt = str_replace( '', "'", $excerpt );
} else {
$excerpt = get_bloginfo( 'description' );
}
?>
<meta property="og:title" content="<?php echo the_title(); ?>"/>
<meta property="og:description" content="<?php echo $excerpt; ?>"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="<?php echo the_permalink(); ?>"/>
<meta property="og:site_name" content="<?php echo get_bloginfo( 'name' ); ?>"/>
<meta property="og:image" content="<?php echo $img_src; ?>"/>
<?php
}
if ( is_page() ) {
if ( has_post_thumbnail( $post->ID ) ) {
$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
}
?>
<meta property="og:title" content="<?php echo the_title(); ?>"/>
<meta property="og:description" content="<?php echo get_bloginfo( 'description' ); ?>"/>
<meta property="og:type" content="page"/>
<meta property="og:url" content="<?php echo get_page_link(); ?>"/>
<meta property="og:site_name" content="<?php echo get_bloginfo( 'name' ); ?>"/>
<meta property="og:image" content="<?php echo $img_src; ?>"/>
<?php } else { ?>
<meta property="og:title" content="<?php echo get_bloginfo( 'name' ); ?>"/>
<meta property="og:description" content="<?php echo get_bloginfo( 'description' ); ?>"/>
<meta property="og:type" content="website"/>
<meta property="og:url" content="<?php echo get_bloginfo( 'url' ); ?>"/>
<meta property="og:site_name" content="<?php echo get_bloginfo( 'name' ); ?>"/>
<meta property="og:image" content="<?php echo $img_src; ?>"/>
<?php
}
}
add_action( 'wp_head', 'eypd_fb_opengraph', 5 );