-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfunctions.php
executable file
·1205 lines (1047 loc) · 33.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
/**
* Coldbox functions and definitions
*
* @since 1.0.0
* @package Coldbox
*/
if ( ! function_exists( 'cd_scripts' ) ) {
/**
* Enqueue theme styles and scripts
*
* @since 1.0.0
**/
function cd_scripts() {
wp_enqueue_style( 'GoogleFonts', '//fonts.googleapis.com/css?family=Lato:300,400,700&display=swap', array(), '1.0.0' );
wp_enqueue_script( 'comment-reply' );
wp_enqueue_style( 'cd-style', get_theme_file_uri( 'assets/css/style.min.css' ), array(), CD_VER );
wp_enqueue_script( 'cd-script', get_theme_file_uri( 'assets/js/min/scripts.js' ), array( 'wp-polyfill' ), CD_VER, false );
// Load Masonry for responsive sidebar.
wp_enqueue_script( 'masonry', 'masonry', array(), '3.3.2', true );
}
} // End if.
add_action( 'wp_enqueue_scripts', 'cd_scripts' );
if ( ! function_exists( 'cd_load_hljs' ) ) {
/**
* Loads highlight.js
*
* @since 1.0.0
*/
function cd_load_hljs() {
if ( cd_use_normal_hljs() || cd_use_web_hljs() ) {
if ( cd_use_normal_hljs() && ! cd_use_web_hljs() ) {
if ( cd_use_concat_js() ) { // Normal hljs with concat JS.
wp_enqueue_script( 'scripts-hljs', get_theme_file_uri( 'assets/js/min/scripts+hljs.js' ), array( 'wp-polyfill' ), CD_VER, false );
wp_dequeue_script( 'cd-script' );
} else {
wp_enqueue_script( 'hljs', get_theme_file_uri( 'assets/js/min/hljs.js' ), array(), '9.12.0', false );
}
} elseif ( cd_use_web_hljs() && ! cd_use_normal_hljs() || cd_use_web_hljs() && cd_use_normal_hljs() ) {
if ( cd_use_concat_js() ) { // Web hljs with concat JS.
wp_enqueue_script( 'scripts-hljs-web', get_theme_file_uri( 'assets/js/min/scripts+hljs_web.js' ), array( 'wp-polyfill' ), CD_VER, false );
wp_dequeue_script( 'cd-script' );
} else {
wp_enqueue_script( 'hljs', get_theme_file_uri( 'assets/js/min/hljs_web.js' ), array(), '9.12.0', false );
}
}
}
}
} // End if.
add_action( 'wp_enqueue_scripts', 'cd_load_hljs' );
if ( ! function_exists( 'cd_add_attribute_defer' ) ) {
/**
* Add `defer` to the enqueued scripts.
*
* @param string $tag Tag name.
* @param string $handle Handle name.
* @return string
*/
function cd_add_attribute_defer( $tag, $handle ) {
$scripts_to_defer = array( 'cd-script', 'scripts-hljs', 'scripts-hljs-web' );
foreach ( $scripts_to_defer as $defer_script ) {
if ( $defer_script === $handle ) {
return str_replace( ' src', ' defer src', $tag );
}
}
return $tag;
}
}
add_filter( 'script_loader_tag', 'cd_add_attribute_defer', 10, 2 );
if ( ! function_exists( 'cd_add_attribute_async' ) ) {
/**
* Add `async` to the enqueued scripts.
*
* @param string $tag Tag name.
* @param string $handle Handle name.
* @return string
*/
function cd_add_attribute_async( $tag, $handle ) {
$scripts_to_async = array( 'masonry', 'imagesloaded' );
foreach ( $scripts_to_async as $async_script ) {
if ( $async_script === $handle ) {
return str_replace( ' src', ' async src', $tag );
}
}
return $tag;
}
}
add_filter( 'script_loader_tag', 'cd_add_attribute_async', 10, 2 );
if ( ! function_exists( 'cd_loads' ) ) {
/**
* Load the language domain and editor style
*
* @since 1.0.0
**/
function cd_loads() {
load_theme_textdomain( 'coldbox', get_theme_file_path( 'languages' ) );
add_editor_style( 'assets/css/editor-style.min.css' );
}
}
add_action( 'after_setup_theme', 'cd_loads' );
if ( ! function_exists( 'cd_czr' ) ) {
/**
* Load the theme customizer
*
* @since 1.0.0
**/
function cd_czr() {
include_once get_theme_file_path( 'parts/czr/customizer.php' );
require_once get_theme_file_path( 'parts/czr/customizer-functions.php' );
}
}
add_action( 'after_setup_theme', 'cd_czr' );
if ( ! function_exists( 'cd_load_files' ) ) {
/**
* Load the necessaries for the theme.
*
* @since 1.0.0
**/
function cd_load_files() {
include_once get_theme_file_path( 'parts/class-cd-max-mega-menu-support.php' );
}
}
add_action( 'after_setup_theme', 'cd_load_files' );
if ( ! function_exists( 'cd_supports' ) ) {
/**
* Load the supported functions provided by WordPress
*
* @since 1.0.0
**/
function cd_supports() {
// Title tag.
add_theme_support( 'title-tag' );
// Support thumbnail.
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 500, 250, true );
add_image_size( 'cd-small', 150, 150, true );
add_image_size( 'cd-medium', 500, 250, true );
add_image_size( 'cd-standard', 500, 500, true );
// Support RSS link.
add_theme_support( 'automatic-feed-links' );
// Support direct widgets editing shortcut on customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
// Support all post format.
add_theme_support( 'post-formats', array( 'audio', 'aside', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' ) );
// Support HTML5.
add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'gallery', 'caption' ) );
// Support custom header.
add_theme_support(
'custom-header',
array(
'width' => 980,
'height' => 100,
'flex-height' => true,
'flex-width' => true,
)
);
// Support custom logo.
add_theme_support(
'custom-logo',
array(
'height' => 80,
'width' => 230,
'flex-height' => true,
'flex-width' => true,
)
);
// Support custom background color and image.
$custom_background_defaults = array(
'default-color' => '#f8f8f8',
'default-image' => '',
);
add_theme_support( 'custom-background', $custom_background_defaults );
// Register nav menu.
register_nav_menus(
array(
'header-menu' => __( 'Header Menu', 'coldbox' ),
'footer-menu' => __( 'Footer Menu', 'coldbox' ),
)
);
}
} // End if.
add_action( 'after_setup_theme', 'cd_supports' );
if ( ! function_exists( 'cd_pingback_header' ) ) {
/**
* Adds a pingback url when necessary.
*
* @since 1.2.0
*/
function cd_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">' . "\n", esc_url( get_bloginfo( 'pingback_url' ) ) );
}
}
add_action( 'wp_head', 'cd_pingback_header' );
}
// Set the content width.
if ( ! isset( $content_width ) ) {
// phpcs:ignore
$content_width = 680;
}
/*
* ----------------------------------------------------------------------
* Theme Functions
* ----------------------------------------------------------------------
*/
if ( ! function_exists( 'cd_header_menu' ) ) {
/**
* Call the header menu through a filter
*
* @since 1.1.6
*/
function cd_header_menu() {
if ( has_nav_menu( 'header-menu' ) ) {
$close_button = __( 'Close menu', 'coldbox' );
$menu = '<nav id="header-menu" class="header-menu" role="navigation" aria-label="' . esc_attr__( 'Header Menu', 'coldbox' ) . '">';
$menu .= wp_nav_menu(
array(
'theme_location' => 'header-menu',
'container' => '',
'menu_class' => '',
'fallback_cb' => 'wp_page_menu',
'echo' => false,
'items_wrap' => '<ul id="header-nav" class="menu-container">%3$s<li class="menu-item"><button id="close-mobile-menu" class="screen-reader-text close-mobile-menu">' . esc_html( $close_button ) . '</button></li></ul><!--/#header-nav-->',
)
);
$menu .= '</nav>';
echo apply_filters( 'cd_header_menu', $menu ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
}
if ( ! function_exists( 'cd_footer_menu' ) ) {
/**
* Call the footer menu through a filter
*
* @since 1.3.0
*/
function cd_footer_menu() {
if ( has_nav_menu( 'footer-menu' ) ) {
$menu = '<nav id="footer-menu" class="footer-menu" role="navigation" aria-label="' . esc_attr__( 'Footer Menu', 'coldbox' ) . '"><div class="container">';
$menu .= wp_nav_menu(
array(
'theme_location' => 'footer-menu',
'container' => '',
'menu_class' => '',
'fallback_cb' => 'wp_page_menu',
'echo' => false,
'items_wrap' => '<ul id="footer-nav" class="menu-container">%3$s</ul><!--/#footer-nav-->',
)
);
$menu .= '</div></nav>';
echo apply_filters( 'cd_footer_menu', $menu ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
}
if ( ! function_exists( 'cd_standard_thumbnail' ) ) {
/**
* Echo the middle size thumbnail.
*
* @since 1.1.6
* @param bool $alt Whether or not to include alt string.
*/
function cd_standard_thumbnail( $alt = true ) {
if ( ! $alt ) {
$thumbnail_attr = array(
'alt' => '',
);
$noimage_alt = '';
} else {
$thumbnail_attr = array();
$noimage_alt = 'noimage';
$noimage_alt = apply_filters( 'cd_noimage_alt_text', $noimage_alt );
}
if ( has_post_thumbnail() ) {
$thumbnail = get_the_post_thumbnail( get_the_ID(), 'cd-standard', $thumbnail_attr );
} else {
$thumbnail = '<img src="' . esc_url( get_theme_file_uri( 'assets/img/thumb-standard.png' ) ) . '" alt="' . $noimage_alt . '" height="250" width="500">';
}
echo apply_filters( 'cd_standard_thumbnail', $thumbnail ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
if ( ! function_exists( 'cd_middle_thumbnail' ) ) {
/**
* Echo the standard size thumbnail.
*
* @since 1.1.6
* @param bool $alt Whether or not to include alt string.
*/
function cd_middle_thumbnail( $alt = true ) {
if ( ! $alt ) {
$thumbnail_attr = array(
'alt' => '',
);
$noimage_alt = '';
} else {
$thumbnail_attr = array();
$noimage_alt = 'noimage';
$noimage_alt = apply_filters( 'cd_noimage_alt_text', $noimage_alt );
}
if ( has_post_thumbnail() ) {
$thumbnail = get_the_post_thumbnail( get_the_ID(), 'cd-medium', $thumbnail_attr );
} else {
$thumbnail = '<img src="' . esc_url( get_theme_file_uri( 'assets/img/thumb-medium.png' ) ) . '" alt="' . $noimage_alt . '" height="250" width="500">';
}
echo apply_filters( 'cd_middle_thumbnail', $thumbnail ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
if ( ! function_exists( 'cd_middle_thumbnail_template' ) ) {
/**
* Echo the middle size thumbnail for template.
*
* @since 1.2.3
* @param bool $alt Whether or not to include alt string.
*/
function cd_middle_thumbnail_template( $alt = true ) {
if ( ! $alt ) {
$thumbnail_attr = array(
'alt' => '',
);
$noimage_alt = '';
} else {
$thumbnail_attr = array();
$noimage_alt = 'noimage';
$noimage_alt = apply_filters( 'cd_noimage_alt_text', $noimage_alt );
}
if ( has_post_thumbnail() ) {
$thumbnail = get_the_post_thumbnail( get_the_ID(), 'cd-medium', $thumbnail_attr );
} elseif ( cd_index_placefolder_image() ) {
$thumbnail = '<img src="' . esc_url( get_theme_file_uri( 'assets/img/thumb-medium.png' ) ) . '" alt="' . $noimage_alt . '" height="250" width="500">';
} else {
return;
}
echo apply_filters( 'cd_middle_thumbnail_template', $thumbnail ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
if ( ! function_exists( 'cd_standard_thumbnail_template' ) ) {
/**
* Echo the standard size thumbnail for template.
*
* @since 1.2.3
* @param bool $alt Whether or not to include alt string.
*/
function cd_standard_thumbnail_template( $alt = true ) {
if ( ! $alt ) {
$thumbnail_attr = array(
'alt' => '',
);
$noimage_alt = '';
} else {
$thumbnail_attr = array();
$noimage_alt = 'noimage';
$noimage_alt = apply_filters( 'cd_noimage_alt_text', $noimage_alt );
}
if ( has_post_thumbnail() ) {
$thumbnail = get_the_post_thumbnail( get_the_ID(), 'cd-standard', $thumbnail_attr );
} elseif ( cd_index_placefolder_image() ) {
$thumbnail = '<img src="' . esc_url( get_theme_file_uri( 'assets/img/thumb-standard.png' ) ) . '" alt="' . $noimage_alt . '" height="250" width="500">';
} else {
return;
}
echo apply_filters( 'cd_standard_thumbnail_template', $thumbnail ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
if ( ! function_exists( 'cd_large_thumbnail_template' ) ) {
/**
* Echo the large size thumbnail for template.
*
* @since 1.5.4
* @param bool $alt Whether or not to include alt string.
*/
function cd_large_thumbnail_template( $alt = true ) {
if ( ! $alt ) {
$thumbnail_attr = array(
'alt' => '',
);
} else {
$thumbnail_attr = array();
}
if ( has_post_thumbnail() ) {
$thumbnail = get_the_post_thumbnail( get_the_ID(), 'large', $thumbnail_attr );
} else {
return;
}
echo apply_filters( 'cd_large_thumbnail_template', $thumbnail ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
if ( ! function_exists( 'cd_comments_template' ) ) {
/**
* Echo the comments template through action hook.
*
* @since 1.2.0
*/
function cd_comments_template() {
ob_start();
comments_template( '/comments.php', true );
$template = ob_get_clean();
echo apply_filters( 'cd_comments_template', $template ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
if ( ! function_exists( 'cd_get_avatar' ) ) {
/**
* Echo user avatar for the author box.
*
* @since 1.1.6
*/
function cd_get_avatar() {
$avatar = get_avatar( get_the_author_meta( 'ID' ), 74 );
echo apply_filters( 'cd_get_avatar', $avatar ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
if ( ! function_exists( 'cd_body_class' ) ) {
/**
* Adds classes to the body tag.
*
* @param array $classes The classes add to the body class.
* @return array custom body classes.
* @since 1.0.0
**/
function cd_body_class( $classes ) {
// Menu things.
if ( has_nav_menu( 'header-menu' ) ) {
$classes[] = 'header-menu-enabled';
}if ( has_nav_menu( 'footer-menu' ) ) {
$classes[] = 'footer-menu-enabled';
}
if ( cd_header_sticky() ) {
$classes[] = 'sticky-header';
}
// Sidebar things.
if ( cd_sidebar_stg() === 'right' ) {
$classes[] = 'right-sidebar-s1';
} elseif ( cd_sidebar_stg() === 'left' ) {
$classes[] = 'left-sidebar-s1';
} elseif ( cd_sidebar_stg() === 'bottom' ) {
$classes[] = 'bottom-sidebar-s1';
} elseif ( cd_sidebar_stg() === 'hide' ) {
$classes[] = 'hide-sidebar-s1';
}
// Header things.
if ( cd_header_direction() === 'column' ) {
$classes[] = 'header-column';
} elseif ( cd_header_direction() === 'row' ) {
$classes[] = 'header-row';
}
return $classes;
}
}
add_filter( 'body_class', 'cd_body_class' );
if ( ! function_exists( 'cd_load_welcome_page' ) ) {
/**
* Loads the Welcome page.
*
* @since 1.5.0
*/
function cd_load_welcome_page() {
require_once get_theme_file_path( 'parts/about-coldbox.php' );
require_once get_theme_file_path( 'parts/admin-notices.php' );
require_once get_theme_file_path( 'parts/class-cd-admin-notice-upgrades.php' );
require_once get_theme_file_path( 'parts/class-cd-admin-notice-new-install.php' );
}
add_action( 'init', 'cd_load_welcome_page' );
}
if ( ! function_exists( 'cd_css_minify' ) ) {
/**
* Quick and dirty way to mostly minify CSS.
*
* @since 1.5.0
* @author Gary Jones
* @see https://github.com/GaryJones/Simple-PHP-CSS-Minification/blob/master/minify.php
* @license GPL
*
* @param string $css CSS to minify.
*
* @return string Minified CSS
*/
function cd_css_minify( $css ) {
$css = preg_replace( '/\s+/', ' ', $css );
$css = preg_replace( '/(\s+)(\/\*(.*?)\*\/)(\s+)/', '$2', $css );
$css = preg_replace( '~/\*(?![\!|\*])(.*?)\*/~', '', $css );
$css = preg_replace( '/;(?=\s*})/', '', $css );
$css = preg_replace( '/(,|:|;|\{|}|\*\/|>) /', '$1', $css );
$css = preg_replace( '/ (,|;|\{|}|\)|>)/', '$1', $css );
$css = preg_replace( '/(:| )0\.([0-9]+)(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}.${2}${3}', $css );
$css = preg_replace( '/(:| )(\.?)0(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}0', $css );
$css = preg_replace( '/0 0 0 0/', '0', $css );
$css = preg_replace( '/#([a-f0-9])\\1([a-f0-9])\\2([a-f0-9])\\3/i', '#\1\2\3', $css );
return trim( $css );
}
}
/*
* ----------------------------------------------------------------------
* Widgets
* ----------------------------------------------------------------------
*/
if ( ! function_exists( 'cd_widgets_init' ) ) {
/**
* Init widgets area.
*
* @since 1.0.0
**/
function cd_widgets_init() {
register_sidebar(
array(
'name' => __( 'Sidebar', 'coldbox' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here', 'coldbox' ),
'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' => __( 'Footer Sidebar One', 'coldbox' ),
'id' => 'footer-1',
'description' => __( 'Add widgets here', 'coldbox' ),
'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' => __( 'Footer Sidebar Two', 'coldbox' ),
'id' => 'footer-2',
'description' => __( 'Add widgets here', 'coldbox' ),
'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' => __( 'Footer Sidebar Three', 'coldbox' ),
'id' => 'footer-3',
'description' => __( 'Add widgets here', 'coldbox' ),
'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' => __( 'Footer Sidebar Four', 'coldbox' ),
'id' => 'footer-4',
'description' => __( 'Add widgets here', 'coldbox' ),
'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', 'cd_widgets_init' );
if ( ! function_exists( 'cd_get_number_of_footer_sidebar' ) ) {
/**
* Get number of footer sidebar used.
*
* @return int
*/
function cd_get_number_of_footer_sidebar() {
$num = 0;
for ( $i = 1; $i <= 4; $i++ ) {
if ( is_active_sidebar( 'footer-' . $i ) ) {
$num++;
}
}
$num = apply_filters( 'cd_number_of_footer_sidebar', $num );
return $num;
}
}
if ( ! function_exists( 'cd_cat_widget_count' ) ) {
/**
* Make the counts surround with brackets on category widgets.
*
* @param string $output Return the count with brackets.
* @param string $args The widget arguments.
* @return string $output and $args with .count class.
* @since 1.0.0
*/
function cd_cat_widget_count( $output, $args ) {
$replaced_text = preg_replace( '/<\/a> \(([0-9,]*)\)/', ' <span class="count">(${1})</span></a>', $output );
if ( null !== $replaced_text ) {
return $replaced_text;
} else {
return $output;
}
}
}
add_filter( 'wp_list_categories', 'cd_cat_widget_count', 10, 2 );
if ( ! function_exists( 'cd_archive_widget_count' ) ) {
/**
* Make the counts surround with parentheses on archive widgets.
*
* @param string $output return the count with parentheses.
* @since 1.0.0
* @return string Number of posts with parentheses.
*/
function cd_archive_widget_count( $output ) {
$output = str_replace( '</a> (', ' <span class="count">(', $output );
$output = str_replace( ')', ')</span></a>', $output );
return $output;
}
}
add_filter( 'get_archives_link', 'cd_archive_widget_count', 10, 2 );
if ( ! function_exists( 'cd_remove_current_post_on_recent_widgets' ) ) {
/**
* Remove the current post when showing a single article from the recent posts widgets.
*
* @param array $args return widget's argument without current post.
* @since 1.0.0
* @return array
*/
function cd_remove_current_post_on_recent_widgets( $args ) {
if ( is_single() ) {
$args['post_not_in'] = array( get_the_ID() );
}
return $args;
}
}
add_filter( 'widget_posts_args', 'cd_remove_current_post_on_recent_widgets', 10, 3 );
/*
* -------------------------------------------------------------------------
* Call the bottom parts for each page
* -------------------------------------------------------------------------
*/
if ( ! function_exists( 'cd_single_middle_contents' ) ) {
include_once get_theme_file_path( 'parts/class-cd-preg-replace-callback.php' );
/**
* The action hook for adding custom content on the first h2 or h3 tag on each single article through filter.
*
* @since 1.1.6
* @param string $the_content The post contents which are hooked.
* @return string
*/
function cd_single_middle_of_content( $the_content ) {
if ( is_single() ) {
preg_match_all( '/<h2.*?>/i', $the_content, $h2_result ); // Whether or not h2 tag is used.
preg_match_all( '/<h3.*?>/i', $the_content, $h3_result ); // Whether or not h3 tag is used.
$h2_result = $h2_result[0];
$h3_result = $h3_result[0];
$h2_count = count( $h2_result );
$h3_count = count( $h3_result );
ob_start();
do_action( 'cd_single_middle_of_content' );
$middle_content = ob_get_clean();
if ( ! empty( $h2_result[1] ) ) { // If h2 tag is present.
$count = 0;
$callback = new Cd_Preg_Replace_Callback( $count, $middle_content );
$the_content = preg_replace_callback(
'/<h2.*?>/i',
array( $callback, 'cd_single_content_replace' ),
$the_content,
2
);
} elseif ( ! empty( $h3_result[1] ) ) { // If no h2 tag, but h3 tag is found.
$count = 0;
$callback = new Cd_Preg_Replace_Callback( $count, $middle_content );
$the_content = preg_replace_callback(
'/<h3.*?>/i',
array( $callback, 'cd_single_content_replace' ),
$the_content,
2
);
}
ob_start();
do_action( 'cd_single_last_of_content' );
$last_content = ob_get_clean();
if ( ! empty( $h2_result ) && $h2_count >= 3 ) { // If h2 tag is present.
$count = 0;
$callback = new Cd_Preg_Replace_Callback( $count, $last_content, $h2_count );
$the_content = preg_replace_callback(
'/<h2.*?>/i',
array( $callback, 'cd_single_content_replace_last' ),
$the_content
);
} elseif ( ! empty( $h3_result ) && $h3_count >= 3 ) { // If no h2 tag, but h3 tag is found.
$count = 0;
$callback = new Cd_Preg_Replace_Callback( $count, $last_content, $h3_count );
$the_content = preg_replace_callback(
'/<h3.*?>/i',
array( $callback, 'cd_single_content_replace_last' ),
$the_content
);
}
}
return $the_content;
}
add_filter( 'the_content', 'cd_single_middle_of_content' );
}
if ( ! function_exists( 'cd_single_bottom_contents' ) ) {
/**
* Call the the bottom parts of the single articles through filter.
*
* @since 1.1.0
*/
function cd_single_bottom_contents() {
if ( function_exists( 'cd_addon_sns_buttons' ) && function_exists( 'cd_use_snsb' ) ) {
if ( cd_use_snsb() ) {
cd_addon_sns_buttons_list( 'single-bottom' );
}
}
if ( cd_is_post_related() ) {
get_template_part( 'parts/related-posts' );
}
if ( cd_is_post_single_comment() ) {
cd_comments_template();
}
if ( cd_is_post_nav() ) {
get_template_part( 'parts/post-nav' );
}
}
}
if ( ! function_exists( 'cd_single_after_contents' ) ) {
/**
* The action hook for adding some contents after the article contents through filter.
*
* @since 1.1.6
* @param string $contents The contents will be shown after the article contents.
* @return string
*/
function cd_single_after_contents( $contents = null ) {
// You can add something here through the `cd_single_after_contents` filter.
do_action( 'cd_single_after' );
return $contents;
}
}
if ( ! function_exists( 'cd_attachment_bottom_contents' ) ) {
/**
* Call the the bottom parts of the attachment pages through filter.
*
* @since 1.1.2
*/
function cd_attachment_bottom_contents() {
if ( cd_is_post_single_comment() ) {
cd_comments_template();
}
if ( cd_is_post_nav() ) {
get_template_part( 'parts/post-nav' );
}
}
}
if ( ! function_exists( 'cd_pages_bottom_contents' ) ) {
/**
* Call the the bottom parts of the static pages through filter.
*
* @since 1.1.1
*/
function cd_pages_bottom_contents() {
if ( cd_is_post_single_comment() ) {
cd_comments_template();
}
}
}
if ( ! function_exists( 'cd_archive_top_contents' ) ) {
/**
* Call the top parts of the archive pages through filter.
*
* @since 1.1.6
* @param string $contents The contents will be shown on top of the article contents.
* @return string
*/
function cd_archive_top_contents( $contents = null ) {
// You can add something here through `cd_archive_top_contents` filter.
do_action( 'cd_archive_top' );
return $contents;
}
}
if ( ! function_exists( 'cd_archive_bottom_contents' ) ) {
/**
* Call the the bottom parts of the archive pages through filter.
*
* @since 1.1.1
*/
function cd_archive_bottom_contents() {
get_template_part( 'parts/page-nav' );
do_action( 'cd_archive_bottom' );
}
}
/*
* -------------------------------------------------------------------------
* Breadcrumbs
* -------------------------------------------------------------------------
*/
if ( ! function_exists( 'cd_breadcrumb' ) ) {
/**
* Returns suitable breadcrumb
*
* @since 1.0.0
**/
function cd_breadcrumb() {
echo '<a href="' . esc_url( home_url() ) . '">' . esc_html__( 'Home', 'coldbox' ) . '</a> > ';
if ( is_attachment() ) {
esc_html_e( 'Attachment', 'coldbox' );
} elseif ( is_single() ) {
the_category( ' / ' );
} elseif ( is_category() ) {
global $wp_query;
$current_cat = $wp_query->get_queried_object();
$cat = $wp_query->get_queried_object();
if ( $cat->parent ) { // If the category has parent category.
$parent = array();
while ( $cat->parent ) {
$cat = get_category( $cat->parent );
$cat_name = $cat->name;
$cat_url = get_category_link( $cat->cat_ID );
$parent = array_merge(
$parent,
array(
$cat_name => $cat_url,
)
);
}
$parent_rev = array_reverse( $parent );
foreach ( $parent_rev as $key => $value ) {
echo '<a href="' . esc_url( $value ) . '">' . esc_html( $key ) . '</a> > ';
}
echo '<span>' . esc_html( $current_cat->name ) . '</span>';
} else {
echo esc_html( $cat->name );
}
} elseif ( is_author() ) {
the_author();
} elseif ( is_page() ) {
the_title();
}
}
} // End if.
/*
* -------------------------------------------------------------------------
* Appearance
* -------------------------------------------------------------------------
*/
/*
* the_excerpt
* --------------------------------------------------
*/
if ( ! function_exists( 'cd_excerpt_length' ) ) {
/**
* The length of the excerpt which set on the customizer.
*
* @since 1.0.0
* @param int $length The length.
* @return int
*/
function cd_excerpt_length( $length ) {
if ( is_admin() ) {
return $length;
}
return cd_czr_excerpt_length( $length );
}
}
add_filter( 'excerpt_length', 'cd_excerpt_length', 999 );
if ( ! function_exists( 'cd_excerpt_more' ) ) {
/**
* The ending of the excerpt which set on the customizer.
*
* @since 1.0.0
* @param string $more The ending strings.
* @return string
*/
function cd_excerpt_more( $more ) {
if ( is_admin() ) {
return $more;
}
return cd_czr_excerpt_ending( $more );
}