-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
1766 lines (1379 loc) · 51.4 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
/**
* cap2019 functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package cap2019
*/
if ( ! function_exists( 'cap_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function cap_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on cap2019, use a find and replace
* to change 'cap' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'cap', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'menu-1' => esc_html__( 'Header Navigation 1', 'cap' ),
'menu-2' => esc_html__( 'Header Navigation 2', 'cap' ),
'menu-3' => esc_html__( 'Footer 1', 'cap' ),
'menu-4' => esc_html__( 'Footer 2', 'cap' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'cap_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
) ) );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support( 'custom-logo', array(
'height' => 89,
'width' => 260,
'flex-width' => false,
'flex-height' => true,
) );
/* Gutenberg related
======================================================================================== */
// Adding support for core block visual styles.
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds.
//add_theme_support( 'responsive-embeds' );
// Add support for Editor Styles
add_editor_style( 'assets/css/editor-style.css' );
// Add support for Wide Images
add_theme_support( 'align-wide' );
// Add support for Font Styles
add_theme_support( 'editor-font-sizes', array(
array(
'name' => __( 'small', 'cap' ),
'shortName' => __( 'S', 'cap' ),
'size' => 12,
'slug' => 'small'
),
array(
'name' => __( 'regular', 'cap' ),
'shortName' => __( 'M', 'cap' ),
'size' => 16,
'slug' => 'regular'
),
array(
'name' => __( 'large', 'cap' ),
'shortName' => __( 'L', 'cap' ),
'size' => 20,
'slug' => 'large'
),
array(
'name' => __( 'larger', 'cap' ),
'shortName' => __( 'XL', 'cap' ),
'size' => 24,
'slug' => 'larger'
)
) );
// Disable Custom Colors
//add_theme_support( 'disable-custom-colors' );
// Add support for Editor Color Palette
add_theme_support( 'editor-color-palette', array(
array(
'name' => __( 'Light Grey', 'cap' ),
'slug' => 'light-gray',
'color' => '#f5f5f5',
),
array(
'name' => __( 'Medium Grey', 'cap' ),
'slug' => 'medium-gray',
'color' => '#9E9E9E',
),
array(
'name' => __( 'Dark Grey', 'cap' ),
'slug' => 'dark-gray',
'color' => '#424242',
),
) );
}
endif;
add_action( 'after_setup_theme', 'cap_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function cap_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters( 'cap_content_width', 1260 );
}
add_action( 'after_setup_theme', 'cap_content_width', 0 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function cap_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Default Sidebar', 'cap' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Single Template Sidebar', 'cap' ),
'id' => 'sidebar-2',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Posts Page Sidebar', 'cap' ),
'id' => 'sidebar-3',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Archive Sidebar - Analysis', 'cap' ),
'id' => 'sidebar-4',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Archive Sidebar - Podcast', 'cap' ),
'id' => 'sidebar-5',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Archive Sidebar - Student Post', 'cap' ),
'id' => 'sidebar-6',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Archive Sidebar - Author Archive', 'cap' ),
'id' => 'sidebar-7',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Archive Sidebar - Category Archive', 'cap' ),
'id' => 'sidebar-8',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Archive Sidebar - Country Archive', 'cap' ),
'id' => 'sidebar-9',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Archive Sidebar - Date Archive', 'cap' ),
'id' => 'sidebar-10',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Member Search Results Sidebar', 'cap' ),
'id' => 'sidebar-11',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Member Single Template Sidebar', 'cap' ),
'id' => 'sidebar-12',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Member Directory Sidebar', 'cap' ),
'id' => 'sidebar-13',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Membership Product Sidebar', 'cap' ),
'id' => 'sidebar-14',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footbar 1', 'cap' ),
'id' => 'footbar-1',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footbar 2', 'cap' ),
'id' => 'footbar-2',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footbar 3', 'cap' ),
'id' => 'footbar-3',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footbar 4', 'cap' ),
'id' => 'footbar-4',
'description' => esc_html__( 'Add widgets here.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Ad Slot - Main Banner', 'cap' ),
'id' => 'adslot-1',
'description' => esc_html__( 'Exlusively for AdRotate widget.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Ad Slot - Home, Full Width Ad_01', 'cap' ),
'id' => 'adslot-2',
'description' => esc_html__( 'Exlusively for AdRotate widget.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Ad Slot - Home, Podcast Block, Vertical', 'cap' ),
'id' => 'adslot-3',
'description' => esc_html__( 'Exlusively for AdRotate widget.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</add_image>',
) );
register_sidebar( array(
'name' => esc_html__( 'Ad Slot - Home, Full Width Ad_02', 'cap' ),
'id' => 'adslot-4',
'description' => esc_html__( 'Exlusively for AdRotate widget.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Ad Slot - Blog Page In-Between Ad', 'cap' ),
'id' => 'adslot-5',
'description' => esc_html__( 'Exlusively for AdRotate widget.', 'cap' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'cap_widgets_init' );
/* ------------------------------------------------------------------------------------------------
# Enqueues
------------------------------------------------------------------------------------------------ */
/**
* Enqueue scripts and styles.
*/
function cap_scripts() {
/* ============================================================================================
# Styles
============================================================================================ */
wp_enqueue_style('dashicons');
wp_enqueue_style( 'cap-googlefonts', 'https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i|PT+Sans+Narrow:400,700|Fira+Mono:400,500,700|PT+Serif:400,400i,700,700i|Roboto+Condensed&display=swap', null, false, 'all' );
wp_enqueue_style( 'cap-slick', get_template_directory_uri() . '/css/slick.css', null, false, 'all' );
wp_enqueue_style( 'cap-slick-theme', get_template_directory_uri() . '/css/slick-theme.css', null, false, 'all' );
wp_enqueue_style( 'cap-colorbox', get_template_directory_uri() . '/css/colorbox.css', null, false, 'all' );
wp_enqueue_style( 'cap-magnipop', get_template_directory_uri() . '/css/magnific-popup.css', null, false, 'all' );
wp_enqueue_style( 'cap-jssocials', get_template_directory_uri() . '/css/jssocials-theme-minima.css', null, false, 'all' );
wp_enqueue_style( 'cap-selectize', get_template_directory_uri() . '/css/selectize.default.css', null, false, 'all' );
wp_enqueue_style(
'cap-style',
get_stylesheet_uri(),
array(
'cap-slick',
'cap-slick-theme',
'cap-colorbox',
'cap-magnipop',
'cap-jssocials',
'cap-selectize',
),
false,
'all'
);
/* ============================================================================================
# Scripts
============================================================================================ */
wp_enqueue_script( 'cap-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
wp_enqueue_script( 'cap-fontawesome', 'https://kit.fontawesome.com/65f3d19268.js', null, false, true );
wp_enqueue_script( 'cap-slick', get_template_directory_uri() . '/js/slick.min.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'cap-colorbox', get_template_directory_uri() . '/js/jquery.colorbox-min.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'cap-magnipop', get_template_directory_uri() . '/js/jquery.magnific-popup.min.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'cap-jssocials', get_template_directory_uri() . '/js/jssocials.min.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'cap-nicefileinput', get_template_directory_uri() . '/js/jquery.nicefileinput.min.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'cap-selectize', get_template_directory_uri() . '/js/selectize.min.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'cap-matchheight', get_template_directory_uri() . '/js/jquery.matchHeight.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'cap-stickykit', get_template_directory_uri() . '/js/jquery.sticky-kit.min.js', array( 'jquery' ), false, true );
wp_register_script(
'cap-global',
get_template_directory_uri() . '/js/global.js',
array(
'jquery',
'cap-fontawesome',
'cap-slick',
'cap-colorbox',
'cap-magnipop',
'cap-jssocials',
'cap-nicefileinput',
'cap-selectize',
'cap-matchheight',
'cap-stickykit',
),
false,
true
);
global $post;
setup_postdata($post);
$pt_Arr = array(
'post',
'page',
'attachment',
'podcast',
'analysis',
'studentpost',
'nwmember',
'memberpressproduct'
);
$is_paid_subscriber = current_user_can( 'mepr-active', 'rule: 7000' );
if ( is_singular( $pt_Arr ) ) :
$id = $post->ID;
$content = has_excerpt( $id ) ? get_the_excerpt( $id ) : get_the_content( $id );
$content = wp_trim_words( $content, $num_words = 50, ' ...' );
$thumbnail_ID = get_post_thumbnail_id( $id );
$thumbnail_Obj = wp_get_attachment_image_src( $thumbnail_ID, 'medium_large', false );
$thumbnail = $thumbnail_Obj[0];
$via = get_field('cap_general_via', 'option');
$via = ( $via && ( '' !== $via ) ) ? $via : 'eolander';
$translation_array = array(
'permalink' => get_permalink(),
'content' => $content,
'title' => get_the_title(),
'thumbnail' => $thumbnail,
'via' => $via,
'is_singular' => true,
'is_single_member' => ( is_singular( 'nwmember' ) ),
'inpostSubscribe' => get_field('cap_general_single_inpost', 'option')
? get_field('cap_general_single_inpost', 'option')
: false,
'showBox' => get_field('cap_single_disable_email_box', $id),
'is_paid_subscriber'=> $is_paid_subscriber,
'templatedir' => get_template_directory_uri(),
);
wp_localize_script( 'cap-global', 'cap', $translation_array );
elseif ( is_home() || is_archive() || is_search() ) :
$translation_array = array(
'is_home' => is_home(),
'is_archive' => is_archive(),
'is_search' => is_search(),
'is_paid_subscriber' => $is_paid_subscriber,
'is_nwmember_archive' => is_post_type_archive( 'nwmember' ),
);
wp_localize_script( 'cap-global', 'cap', $translation_array );
else :
$translation_array = array(
'is_404' => is_404(),
'is_paid_subscriber' => $is_paid_subscriber,
);
wp_localize_script( 'cap-global', 'cap', $translation_array );
endif;
wp_enqueue_script( 'cap-global' );
}
add_action( 'wp_enqueue_scripts', 'cap_scripts' );
/**
* Enqueue admin scripts and styles.
*/
function cap_admin_scripts() {
/* ============================================================================================
# Styles
============================================================================================ */
wp_enqueue_style(
'cap-admin-style',
get_template_directory_uri() . '/css/admin-style.css',
array(),
false,
'all'
);
/* ============================================================================================
# Scripts
============================================================================================ */
wp_register_script(
'cap-global-admin',
get_template_directory_uri() . '/js/global-admin.js',
array(
'jquery',
),
false,
true
);
$translation_array = array(
'siteurl' => get_site_url(),
);
wp_localize_script( 'cap-global-admin', 'cap', $translation_array );
wp_enqueue_script( 'cap-global-admin' );
}
add_action( 'admin_enqueue_scripts', 'cap_admin_scripts' );
/* ------------------------------------------------------------------------------------------------
# Enqueues - Gutenberg
------------------------------------------------------------------------------------------------ */
/**
* Theme Fonts URL
*
*/
function cap_theme_fonts_url() {
/*
* Translators: If there are characters in your language that are not
* supported by Noto Serif, translate this to 'off'. Do not translate
* into your own language.
*/
$notoserif = esc_html_x( 'on', 'Noto Serif font: on or off', 'cap' );
$font_families = apply_filters(
'cap_theme_fonts',
array(
'Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i',
'PT+Sans+Narrow:400,700',
'Fira+Mono:400,500,700',
'PT+Serif:400,400i,700,700i',
'Roboto+Condensed'
)
);
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
return esc_url_raw( $fonts_url ) . '&display=swap';
}
/**
* Gutenberg scripts and styles
*
*/
function cap_gutenberg_scripts() {
/* ============================================================================================
# Styles
============================================================================================ */
wp_enqueue_style( 'cap-fonts', cap_theme_fonts_url() );
wp_enqueue_style( 'cap-editor', get_template_directory_uri() . '/css/editor-style.css', array(), false, 'all' );
/* ============================================================================================
# Scripts
============================================================================================ */
}
add_action( 'enqueue_block_editor_assets', 'cap_gutenberg_scripts' );
/* ------------------------------------------------------------------------------------------------
# Requires
------------------------------------------------------------------------------------------------ */
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Custom post types.
*/
require get_template_directory() . '/inc/custom-post-types.php';
/**
* Custom shortcodes.
*/
require get_template_directory() . '/inc/shortcodes.php';
/**
* Custom shortcodes.
*/
require get_template_directory() . '/inc/widgets.php';
/**
* Load Jetpack compatibility file.
*/
if ( defined( 'JETPACK__VERSION' ) ) {
require get_template_directory() . '/inc/jetpack.php';
}
/**
* Require Mobile Detect
*/
require get_template_directory() . '/inc/Mobile_Detect.php';
/* ------------------------------------------------------------------------------------------------
# Mobile Detect
------------------------------------------------------------------------------------------------ */
$detect = new Mobile_Detect;
// Any mobile device (phones or tablets).
// if ( $detect->isMobile() ) {}
// Any tablet device.
// if( $detect->isTablet() ){}
// Exclude tablets.
// if( $detect->isMobile() && !$detect->isTablet() ){}
/* ------------------------------------------------------------------------------------------------
# Images
------------------------------------------------------------------------------------------------ */
/* Deactivate WP's default image optimization behaviour */
add_filter( 'jpeg_quality', function( $arg ) { return 100; } );
/* Custom image sizes */
add_image_size( 'cap-logo', 260, 9999, false );
add_image_size( 'cap-home-analysis-sticky', 720, 396, array( 'center', 'center' ) );
add_image_size( 'cap-home-analysis-others', 540, 297, array( 'center', 'center' ) );
add_image_size( 'cap-home-memslider', 200, 200, array( 'center', 'center' ) );
add_image_size( 'cap-single-thumbnail', 1000, 650, array( 'center', 'center' ) );
add_image_size( 'yarpp-thumbnail', 360, 201, true );
add_image_size( 'libsyn-thumbnail', 300, 263, true );
add_image_size( 'member-thumbnail', 640, 9999, false );
// Register custom image sizes for backend use
add_filter( 'image_size_names_choose', 'cap_imgsize_names' );
function cap_imgsize_names( $sizes ) {
return array_merge( $sizes, array(
'cap-logo' => __( 'Logo Size (w=260px)' ),
'cap-home-analysis-sticky' => __( 'Home Page Featured Analysis Image (720x396)' ),
'cap-home-analysis-others' => __( 'Home Page You Might Like Block Image (540x297)' ),
'cap-home-memslider' => __( 'Home Page Member Slider Image (200x200)' ),
'cap-single-thumbnail' => __( 'Single Template Featured Image (800x520)' ),
'yarpp-thumbnail' => __( 'Related Posts Thumbnail Size (360x201)' ),
'libsyn-thumbnail' => __( 'Libsyn Player Thumbnail Size (300x263)' ),
'member-thumbnail' => __( 'Member Thumbnail Size (640px width, auto height)' ),
) );
}
define('ALLOW_UNFILTERED_UPLOADS', true);
/* ------------------------------------------------------------------------------------------------
# Dev helpers
------------------------------------------------------------------------------------------------ */
/**
* Enable page excerpts
*/
add_post_type_support( 'page', 'excerpt' );
/**
* Enable shortcodes in text widgets
*/
add_filter('widget_text','do_shortcode');
/**
* Custom body classes
*/
function cap_custom_body_classes( $classes ) {
global $post;
$parent_ID = wp_get_post_parent_id( get_the_ID() );
if ( is_singular() ) :
$classes[] = str_replace(
' ',
'-',
strtolower(
strip_tags(
get_the_title()
)
)
);
endif;
if ( $parent_ID &&
( 'page-resource-center.php' == get_post_meta( $parent_ID, '_wp_page_template', true ) )
) :
$classes[] = 'resource-page';
endif;
$is_search_nw = ( is_search() && !get_search_query() );
if ( is_search() ) $classes[] = 'archive';
if ( $is_search_nw ) $classes[] = 'search-nw';
if (
!current_user_can( 'mepr-active', 'rule: 7000' ) &&
(
is_page_template('page-nw.php') ||
$is_search_nw ||
is_post_type_archive('nwmember')
)
)
$classes[] = 'freeze-overflow';
return $classes;
}
add_filter( 'body_class', 'cap_custom_body_classes' );
/**
* Custom post classes
*/
function cap_custom_post_classes( $classes ) {
global $post;
if ( is_singular() ) :
$classes[] = 'chocolat-parent';
endif;
return $classes;
}
add_filter( 'post_class', 'cap_custom_post_classes' );
/**
* Custom title tags
*/
function cap_return_member_search_query() {
/* The only way to get the whole search query string is using parse_str() with the
$_SERVER[] array.
Based on the Search & Filter plugin documentation there's another way:
global $searchandfilter;
$s = $searchandfilter->get(6614)->current_query();
$s = $s->get_search_term();
But, as it came out, THIS ONLY WORKS WITH THE TEXT (KEYWORD) SEARCH FIELD.
If the user submits the search form with a query based on other form input types (select, multiselect), $searchandfilter doesn't return shit.
*/
$queries = array();
parse_str($_SERVER['QUERY_STRING'], $queries);
/* At first we need to consider and handle the scenario where there are multiple
queries!! For instance the user submits the form with search query for City, First Name and Institution.
To handle this scenario we need to parse at first the whole query, and create a
multidimensional array where the keys will be BASED ON the $queries array's keys,
and the values will be the $queries array's search term values imploded into a
string after some cleaning.
*/
$endval_Arr = [];
$i = 0;
foreach ( $queries as $key=>$value ) :
/* Let's make the key HUMAN-READABLE - then add it as KEY of
the new $endval_Arr array's CURRENT ITEM.
*/
if ( '_sf_s' == $key )
$endval_Arr[$i]['key'] = __( 'Keyword', 'cap' );
if ( '_sft_nw-profession-category' == $key )
$endval_Arr[$i]['key'] = __( 'Profession', 'cap' );
if ( '_sft_nw-country' == $key )
$endval_Arr[$i]['key'] = __( 'Country', 'cap' );
if ( '_sft_nw-lang' == $key )
$endval_Arr[$i]['key'] = __( 'Language(s) Spoken', 'cap' );
if ( '_sfm_net_press' == $key )
$endval_Arr[$i]['key'] = __( 'Press Accessibility', 'cap' );
if ( '_sfm_net_fname' == $key )
$endval_Arr[$i]['key'] = __( 'First Name', 'cap' );
if ( '_sfm_net_lname' == $key )
$endval_Arr[$i]['key'] = __( 'Last Name', 'cap' );
if ( '_sfm_net_city' == $key )
$endval_Arr[$i]['key'] = __( 'City', 'cap' );
if ( '_sfm_net_institution' == $key )
$endval_Arr[$i]['key'] = __( 'Institution', 'cap' );
/* Let's clean and handle the values.
Originally these values look like 'Barcelona-,-Berlin-,-Beijing'.
To get rid of the slashes we need to explode the string at first,
then once we have an array, we can do the cleaning by using ltrim
and rtrim for the removals, and ucfirst to capitalize the values.
Finally - we create the new string type value with implode(), and
we add it as VALUE of the new $endval_Arr array's CURRENT ITEM.;
*/
$val_Arr = explode(',', $value);
$valnew_Arr = [];
foreach( $val_Arr as $val ) :
$valnew_Arr[] = ucfirst(
ltrim(
rtrim($val, '-'),
'-'
)
);
endforeach;
$endval_Arr[$i]['value'] = implode(', ', $valnew_Arr);
$i++;
endforeach;
/* The resulting multidimensional array includes arrays of key - value pairs. We need
a final string sortof
"array1[key] - array1[value]; array2[key] - array2[value]; (...)"
which, with a real world example, would look something like
"City - Beijing, Berlin, Parlis; Institution - Bill & Melinda Gates Foundation, Freelance; (...)".
*/
$endendval_Arr = [];
foreach ( $endval_Arr as $v ) :
if ( isset( $v['key'] ) )
$endendval_Arr[] = $v['key'] . ' - ' . $v['value'];
endforeach;
$s = implode( '; ', $endendval_Arr );
return $s;
}
function cap_custom_title_tags($data) {
$is_search_nw = ( is_search() && !get_search_query() );
if ( $is_search_nw ) :
$s = cap_return_member_search_query();
if ( is_array($s) ) $s = implode(', ', $s);
return sprintf( __( 'Search Results for: %s - The China-Africa Project', 'cap'), ucfirst($s) );
else :
return $data;
endif;
}