-
Notifications
You must be signed in to change notification settings - Fork 15
/
functions.php
executable file
·1477 lines (1221 loc) · 52.2 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
/**
* Framework Functions File
*
* Please do not edit this file. This file is part of the Cyber Chimps Framework and all modifications
* should be made in a child theme.
*
* Text Domain: cyberchimps_core
*
* @category CyberChimps Framework
* @package Framework
* @since 1.0
* @author CyberChimps
* @license http://www.opensource.org/licenses/gpl-license.php GPL v3.0 (or later)
* @link http://www.cyberchimps.com/
*/
// include plugin.php to use is_plugin_active() condition
require_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( ! function_exists( 'cyberchimps_get_option' ) ) {
/**
* Get Option.
*
* Helper function to return the theme option value.
* If no value has been saved, it returns $default.
* Needed because options are saved as serialized strings.
*/
function cyberchimps_get_option( $name, $default = false ) {
$options = get_option( 'cyberchimps_options' );
if ( isset( $options[ $name ] ) ) {
return $options[ $name ];
}
return $default;
}
}
// Enqueue core scripts and core styles
function cyberchimps_core_scripts() {
global $post;
// Define paths
$directory_uri = get_template_directory_uri();
$js_path = $directory_uri . '/cyberchimps/lib/js/';
$bootstrap_path = $directory_uri . '/cyberchimps/lib/bootstrap/';
// set up slimbox for gallery images
if ( cyberchimps_get_option( 'gallery_lightbox', 1 ) ) {
wp_enqueue_script( 'gallery-lightbox', $js_path . 'gallery-lightbox.min.js', array( 'jquery' ), '1.0' );
}
// Load JS for slimbox
wp_enqueue_script( 'slimbox', $js_path . 'jquery.slimbox.min.js', array( 'jquery' ), '1.0' );
// Load library for jcarousel
wp_enqueue_script( 'jcarousel', $js_path . 'jquery.jcarousel.min.js', array( 'jquery' ), '1.0' );
// touch swipe gestures
wp_enqueue_script( 'jquery-mobile-touch', $js_path . 'jquery.mobile.custom.min.js', array( 'jquery' ) );
wp_enqueue_script( 'slider-call', $js_path . 'swipe-call.min.js', array( 'jquery', 'jquery-mobile-touch' ) );
// Load Bootstrap Library Items
wp_enqueue_style( 'bootstrap-style', $bootstrap_path . 'css/bootstrap.min.css', false, '2.0.4' );
wp_enqueue_style( 'bootstrap-responsive-style', $bootstrap_path . 'css/bootstrap-responsive.min.css', array( 'bootstrap-style' ), '2.0.4' );
wp_enqueue_style( 'font-awesome', $directory_uri . '/cyberchimps/lib/css/font-awesome.min.css' );
wp_enqueue_script( 'bootstrap-js', $bootstrap_path . 'js/bootstrap.min.js', array( 'jquery' ), '2.0.4', true );
// responsive design
if ( cyberchimps_get_option( 'responsive_design', 'checked' ) ) {
wp_enqueue_style( 'cyberchimps_responsive', $directory_uri . '/cyberchimps/lib/bootstrap/css/cyberchimps-responsive.min.css', array( 'bootstrap-responsive-style', 'bootstrap-style' ), '1.0' );
} else {
wp_dequeue_style( 'cyberchimps_responsive' );
}
// Load core JS
wp_enqueue_script( 'core-js', $js_path . 'core.min.js', array( 'jquery' ) );
// Placeholder fix for IE8/9
if ( preg_match( '/(?i)msie [8-9]/', $_SERVER['HTTP_USER_AGENT'] ) ) {
wp_enqueue_script( 'placeholder', $js_path . 'jquery.placeholder.js', array( 'jquery' ) );
}
/**
* With the use of @2x at the end of an image it will use that to display the retina image. Both images have to been in the same folder
*/
wp_enqueue_script( 'retina-js', $js_path . 'retina-1.1.0.min.js', '', '1.1.0', true );
// Load Core Stylesheet
wp_enqueue_style( 'core-style', $directory_uri . '/cyberchimps/lib/css/core.css', array( 'bootstrap-responsive-style', 'bootstrap-style' ), '1.0' );
// Load Theme Stylesheet
wp_enqueue_style( 'style', get_stylesheet_uri(), array( 'core-style' ), '1.0' );
// add javascript for comments
if ( is_singular() ) {
wp_enqueue_script( 'comment-reply' );
}
if ( cyberchimps_get_option( 'responsive_videos' ) == '1' ) {
wp_enqueue_script( 'video', $js_path . 'video.min.js' );
}
}
add_action( 'wp_enqueue_scripts', 'cyberchimps_core_scripts', 20 );
/**
* WooCommerce
*
* Unhook/Hook the WooCommerce Wrappers
*/
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
add_action( 'woocommerce_before_main_content', 'cyberchimps_wrapper_start', 10 );
add_action( 'woocommerce_after_main_content', 'cyberchimps_wrapper_end', 10 );
if ( ! function_exists( 'cyberchimps_wrapper_start' ) ) {
function cyberchimps_wrapper_start() {
?>
<div id="cc_woocommerce" class="container-full-width">
<div class="container">
<div class="container-fluid">
<div id="container" <?php cyberchimps_filter_container_class(); ?>>
<?php do_action( 'cyberchimps_before_content_container' ); ?>
<div id="content" <?php cyberchimps_filter_content_class(); ?>>
<?php
do_action( 'cyberchimps_before_content' );
}
}
if ( ! function_exists( 'cyberchimps_wrapper_end' ) ) {
function cyberchimps_wrapper_end() {
?>
<?php do_action( 'cyberchimps_after_content' ); ?>
</div><!-- #content -->
<?php do_action( 'cyberchimps_after_content_container' ); ?>
</div><!-- #container .row-fluid-->
</div><!-- container fluid -->
</div><!-- conatiner -->
</div><!-- container full width -->
<?php
}
}
// Enables woocommerce support for the theme.
add_theme_support( 'woocommerce' );
// wc-product-gallery-zoom.
add_theme_support( 'wc-product-gallery-zoom' );
// wc-product-gallery-lightbox.
add_theme_support( 'wc-product-gallery-lightbox' );
// wc-product-gallery-slider.
add_theme_support( 'wc-product-gallery-slider' );
function cyberchimps_create_layout() {
global $post;
if ( is_single() ) {
$layout_type = cyberchimps_get_option( 'single_post_sidebar_options', 'right_sidebar' );
} elseif ( is_home() ) {
$layout_type = cyberchimps_get_option( 'sidebar_images', 'right_sidebar' );
} elseif ( is_page() ) {
$page_sidebar = get_post_meta( $post->ID, 'cyberchimps_page_sidebar' );
$layout_type = ( isset( $page_sidebar[0] ) ) ? $page_sidebar[0] : 'right_sidebar';
} elseif ( is_plugin_active( 'woocommerce/woocommerce.php' ) && is_woocommerce() && is_shop() ) {
$page_sidebar = get_post_meta( wc_get_page_id( 'shop' ), 'cyberchimps_page_sidebar' );
$layout_type = ( isset( $page_sidebar[0] ) ) ? $page_sidebar[0] : 'right_sidebar';
} elseif ( is_archive() ) {
$layout_type = cyberchimps_get_option( 'archive_sidebar_options', 'right_sidebar' );
} elseif ( is_search() ) {
$layout_type = cyberchimps_get_option( 'search_sidebar_options', 'right_sidebar' );
} elseif ( is_404() ) {
$layout_type = cyberchimps_get_option( 'error_sidebar_options', 'right_sidebar' );
} else {
$layout_type = apply_filters( 'cyberchimps_default_layout', 'right_sidebar' );
}
cyberchimps_get_layout( $layout_type );
}
add_action( 'wp', 'cyberchimps_create_layout' );
function cyberchimps_get_layout( $layout_type ) {
$wide_sidebar = cyberchimps_get_option( 'wide_sidebar', 0 );
$layout_type = ( $layout_type ) ? $layout_type : 'right_sidebar';
$content_span = ( $wide_sidebar == 1 ) ? 'cyberchimps_class_span8' : 'cyberchimps_class_span9';
$sidebar_span = ( $wide_sidebar == 1 ) ? 'cyberchimps_class_span4' : 'cyberchimps_class_span3';
if ( is_page_template( 'templates/full-width-page.php' ) ) {
$layout_type = 'full_width';
}
switch ( $layout_type ) {
case 'full_width':
add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span12' );
break;
case 'right_sidebar':
add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_right' );
add_filter( 'cyberchimps_content_class', $content_span );
add_filter( 'cyberchimps_content_class', 'cyberchimps_content_sbr_class' );
add_filter( 'cyberchimps_sidebar_right_class', $sidebar_span );
break;
case 'left_sidebar':
add_action( 'cyberchimps_before_content_container', 'cyberchimps_add_sidebar_left' );
add_filter( 'cyberchimps_content_class', $content_span );
add_filter( 'cyberchimps_content_class', 'cyberchimps_content_sbl_class' );
add_filter( 'cyberchimps_sidebar_left_class', $sidebar_span );
break;
case 'content_middle':
add_action( 'cyberchimps_before_content_container', 'cyberchimps_add_sidebar_left' );
add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_right' );
add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span6' );
add_filter( 'cyberchimps_content_class', 'cyberchimps_content_sb2_class' );
add_filter( 'cyberchimps_sidebar_left_class', 'cyberchimps_class_span3' );
add_filter( 'cyberchimps_sidebar_right_class', 'cyberchimps_class_span3' );
break;
case 'left_right_sidebar':
add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_left' );
add_action( 'cyberchimps_after_content_container', 'cyberchimps_add_sidebar_right' );
add_filter( 'cyberchimps_content_class', 'cyberchimps_class_span6' );
add_filter( 'cyberchimps_content_class', 'cyberchimps_content_sb2r_class' );
add_filter( 'cyberchimps_sidebar_left_class', 'cyberchimps_class_span3' );
add_filter( 'cyberchimps_sidebar_right_class', 'cyberchimps_class_span3' );
break;
}
}
class cyberchimps_Walker extends Walker_Nav_Menu {
function start_lvl( &$output, $depth = 0, $args = array() ) {
// In a child UL, add the 'dropdown-menu' class
if ( $depth == 0 ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul class=\"dropdown-menu\">\n";
} else {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul>\n";
}
}
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$li_attributes = '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
// Add class and attribute to LI element that contains a submenu UL.
if ( $args->has_children && $depth < 1 ) {
$classes[] = 'dropdown';
$li_attributes .= ' data-dropdown="dropdown"';
}
if ( $args->has_children && $depth == 1 ) {
$classes[] = 'grandchild';
}
$classes[] = 'menu-item-' . $item->ID;
// If we are on the current page, add the active class to that menu item.
$classes[] = ( $item->current ) ? 'active' : '';
// Make sure you still add all of the WordPress classes.
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args );
$id = strlen( $id ) ? ' id="' . esc_attr( $id ) . '"' : '';
$output .= $indent . '<li' . $id . $value . $class_names . $li_attributes . '>';
// Add attributes to link element.
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) . '"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) . '"' : '';
$attributes .= ( $args->has_children && $depth < 1 ) ? ' class="dropdown-toggle"' : '';
$item_output = $args->before;
$item_output .= '<a' . $attributes . '>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= ( $args->has_children && $depth < 1 ) ? ' <b class="caret"></b> ' : '';
$item_output .= ( $args->has_children && $depth == 1 ) ? apply_filters( 'cyberchimps_menu_grandchild_caret', '' ) : '';
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
// Overwrite display_element function to add has_children attribute. Not needed in >= WordPress 3.4
function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
if ( ! $element ) {
return;
}
$id_field = $this->db_fields['id'];
// display this element
if ( is_array( $args[0] ) ) {
$args[0]['has_children'] = ! empty( $children_elements[ $element->$id_field ] );
} else {
if ( is_object( $args[0] ) ) {
$args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] );
}
}
$cb_args = array_merge( array( &$output, $element, $depth ), $args );
call_user_func_array( array( &$this, 'start_el' ), $cb_args );
$id = $element->$id_field;
// descend only when the depth is right and there are childrens for this element
if ( ( $max_depth == 0 || $max_depth > $depth + 1 ) && isset( $children_elements[ $id ] ) ) {
foreach ( $children_elements[ $id ] as $child ) {
if ( ! isset( $newlevel ) ) {
$newlevel = true;
// start the child delimiter
$cb_args = array_merge( array( &$output, $depth ), $args );
call_user_func_array( array( &$this, 'start_lvl' ), $cb_args );
}
$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
}
unset( $children_elements[ $id ] );
}
if ( isset( $newlevel ) && $newlevel ) {
// end the child delimiter
$cb_args = array_merge( array( &$output, $depth ), $args );
call_user_func_array( array( &$this, 'end_lvl' ), $cb_args );
}
// end this element
$cb_args = array_merge( array( &$output, $element, $depth ), $args );
call_user_func_array( array( &$this, 'end_el' ), $cb_args );
}
}
class Cyberchimps_Fallback_Walker extends Walker_Page {
function start_lvl( &$output, $depth = 0, $args = array() ) {
if ( $depth == 0 ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul class=\"dropdown-menu\">\n";
} else {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent<ul>\n";
}
}
function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
if ( $depth ) {
$indent = str_repeat( "\t", $depth );
} else {
$indent = '';
}
extract( $args, EXTR_SKIP );
$class_attr = '';
$data = '';
$link_class_attr = '';
$caret = '';
if ( $depth == 0 && ! empty( $args['has_children'] ) ) {
$class_attr .= 'dropdown ';
$data = 'data-dropdown="dropdown"';
$link_class_attr = 'dropdown-toggle';
$caret = '<b class="caret"></b>';
}
if ( ! empty( $current_page ) ) {
$_current_page = get_page( $current_page );
if ( ( isset( $_current_page->ancestors ) && in_array( $page->ID, (array) $_current_page->ancestors ) ) || ( $page->ID == $current_page ) || ( $_current_page && $page->ID == $_current_page->post_parent ) ) {
$class_attr .= 'current-menu-item current_page_item active';
}
} elseif ( ( is_single() || is_archive() ) && ( $page->ID == get_option( 'page_for_posts' ) ) ) {
$class_attr = '';
}
if ( $class_attr != '' ) {
$class_attr = ' class="' . $class_attr . '"';
}
$output .= $indent . '<li' . $class_attr . $data . '><a href="' . get_page_link( $page->ID ) . '"' . $link_class_attr . '>' . apply_filters( 'the_title', $page->post_title, $page->ID ) . $caret . '</a>';
}
}
// Sets fallback menu for 1 level. Could use preg_split to have children displayed too
function cyberchimps_fallback_menu() {
$walker = new cyberchimps_fallback_walker();
$args = array(
'depth' => 0,
'show_date' => '',
'date_format' => '',
'child_of' => 0,
'exclude' => '',
'include' => '',
'title_li' => '',
'echo' => 0,
'authors' => '',
'sort_column' => 'menu_order, post_title',
'link_before' => '',
'link_after' => '',
'walker' => $walker,
'post_type' => 'page',
'post_status' => 'publish',
);
$pages = wp_list_pages( $args );
$prepend = '<ul id="menu-menu" class="nav">';
$pages = apply_filters( 'cyberchimps_fallback_menu_filter', $pages, $args );
$append = '</ul>';
$output = $prepend . $pages . $append;
echo $output;
}
// Prints HTML with meta information for the current post date/time.
if ( ! function_exists( 'cyberchimps_posted_on' ) ) {
function cyberchimps_posted_on() {
// Get value of post byline date toggle option from theme option for different pages
if ( is_single() ) {
$show_date = ( cyberchimps_get_option( 'single_post_byline_date', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_date', 1 ) : false;
} elseif ( is_archive() ) {
$show_date = ( cyberchimps_get_option( 'archive_post_byline_date', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_date', 1 ) : false;
} else {
$show_date = ( cyberchimps_get_option( 'post_byline_date', 1 ) ) ? cyberchimps_get_option( 'post_byline_date', 1 ) : false;
}
// Get all data related to date.
$date_url = esc_url( get_permalink() );
$date_title = esc_attr( get_the_time() );
$date_time = esc_attr( get_the_time() );
$date_time = esc_attr( get_the_date( 'c' ) );
$date = esc_html( get_the_date() );
// Set the HTML for date link.
$posted_on = sprintf(
__( 'Posted on %s', 'cyberchimps_core' ),
'<a href="' . $date_url . '" title="' . $date_title . '" rel="bookmark">
<time class="entry-date updated" datetime="' . $date_time . '">' . $date . '</time>
</a>'
);
// If post byline date toggle is on then print HTML for date link.
if ( $show_date ) {
echo apply_filters( 'cyberchimps_posted_on', $posted_on );
}
}
}
// Prints HTML for author link of the post.
if ( ! function_exists( 'cyberchimps_posted_by' ) ) {
function cyberchimps_posted_by() {
// Get value of post byline author toggle option from theme option for different pages.
if ( is_single() ) {
$show_author = ( cyberchimps_get_option( 'single_post_byline_author', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_author', 1 ) : false;
} elseif ( is_archive() ) {
$show_author = ( cyberchimps_get_option( 'archive_post_byline_author', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_author', 1 ) : false;
} else {
$show_author = ( cyberchimps_get_option( 'post_byline_author', 1 ) ) ? cyberchimps_get_option( 'post_byline_author', 1 ) : false;
}
// Get url of all author archive( the page will contain all posts by the author).
$auther_posts_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
// Set author title text which will appear on hover over the author link.
$auther_link_title = esc_attr( sprintf( __( 'View all posts by %s', 'cyberchimps_core' ), get_the_author() ) );
// Set the HTML for author link.
$posted_by = sprintf(
'<span class="byline"> ' . __( 'by %s', 'cyberchimps_core' ),
'<span class="author vcard">
<a class="url fn n" href="' . $auther_posts_url . '" title="' . $auther_link_title . '" rel="author">' . esc_html( get_the_author() ) . '</a>
</span>
</span>'
);
// If post byline author toggle is on then print HTML for author link.
if ( $show_author ) {
echo apply_filters( 'cyberchimps_posted_by', $posted_by );
}
}
}
if ( ! function_exists( 'cyberchimps_posted_in' ) ) {
// add meta entry category to single post, archive and blog list if set in options
function cyberchimps_posted_in() {
global $post;
if ( is_single() ) {
$show = ( cyberchimps_get_option( 'single_post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_categories', 1 ) : false;
} elseif ( is_archive() ) {
$show = ( cyberchimps_get_option( 'archive_post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_categories', 1 ) : false;
} else {
$show = ( cyberchimps_get_option( 'post_byline_categories', 1 ) ) ? cyberchimps_get_option( 'post_byline_categories', 1 ) : false;
}
if ( $show ) :
$categories_list = get_the_category_list( ', ' );
if ( $categories_list ) :
$cats = sprintf( __( 'Posted in %s', 'cyberchimps_core' ), $categories_list );
?>
<span class="cat-links">
<?php echo apply_filters( 'cyberchimps_post_categories', $cats ); ?>
</span>
<span class="sep"> <?php echo apply_filters( 'cyberchimps_entry_meta_sep', '|' ); ?> </span>
<?php
endif;
endif;
}
}
if ( ! function_exists( 'cyberchimps_post_tags' ) ) {
// add meta entry tags to single post, archive and blog list if set in options
function cyberchimps_post_tags() {
global $post;
if ( is_single() ) {
$show = ( cyberchimps_get_option( 'single_post_byline_tags', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_tags', 1 ) : false;
} elseif ( is_archive() ) {
$show = ( cyberchimps_get_option( 'archive_post_byline_tags', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_tags', 1 ) : false;
} else {
$show = ( cyberchimps_get_option( 'post_byline_tags', 1 ) ) ? cyberchimps_get_option( 'post_byline_tags', 1 ) : false;
}
if ( $show ) :
$tags_list = get_the_tag_list( '', ', ' );
if ( $tags_list ) :
$tags = sprintf( __( 'Tags: %s', 'cyberchimps_core' ), $tags_list );
?>
<span class="taglinks">
<?php echo apply_filters( 'cyberchimps_post_tags', $tags ); ?>
</span>
<span class="sep"> <?php echo apply_filters( 'cyberchimps_entry_meta_sep', '|' ); ?> </span>
<?php
endif; // End if $tags_list
endif;
}
}
if ( ! function_exists( 'cyberchimps_post_comments' ) ) {
// add meta entry comments to single post, archive and blog list if set in options
function cyberchimps_post_comments() {
global $post;
if ( is_single() ) {
$show = ( cyberchimps_get_option( 'single_post_byline_comments', 1 ) ) ? cyberchimps_get_option( 'single_post_byline_comments', 1 ) : false;
} elseif ( is_archive() ) {
$show = ( cyberchimps_get_option( 'archive_post_byline_comments', 1 ) ) ? cyberchimps_get_option( 'archive_post_byline_comments', 1 ) : false;
} else {
$show = ( cyberchimps_get_option( 'post_byline_comments', 1 ) ) ? cyberchimps_get_option( 'post_byline_comments', 1 ) : false;
}
$leave_comment = ( is_single() || is_page() ) ? '' : __( 'Leave a comment', 'cyberchimps_core' );
if ( $show ) :
if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) :
?>
<span class="comments-link"><?php comments_popup_link( $leave_comment, __( '1 Comment', 'cyberchimps_core' ), '% ' . __( 'Comments', 'cyberchimps_core' ) ); ?></span>
<span class="sep"> <?php echo ( $leave_comment != '' ) ? apply_filters( 'cyberchimps_entry_meta_sep', '|' ) : ''; ?> </span>
<?php
endif;
endif;
}
}
// change default comments labels and form
add_filter( 'comment_form_defaults', 'cyberchimps_comment_form_filter' );
function cyberchimps_comment_form_filter( $defaults ) {
$defaults['title_reply'] = __( 'Leave a comment', 'cyberchimps_core' );
return $defaults;
}
// add featured image to single post, archive and blog page if set in options
function cyberchimps_featured_image() {
global $post;
if ( is_single() ) {
$show = ( cyberchimps_get_option( 'single_post_featured_images', 1 ) ) ? cyberchimps_get_option( 'single_post_featured_images', 1 ) : false;
} elseif ( is_archive() ) {
$show = ( cyberchimps_get_option( 'archive_featured_images', 1 ) ) ? cyberchimps_get_option( 'archive_featured_images', 1 ) : false;
} else {
$show = ( cyberchimps_get_option( 'post_featured_images', 1 ) ) ? cyberchimps_get_option( 'post_featured_images', 1 ) : false;
}
if ( $show ) :
if ( has_post_thumbnail() ) :
?>
<div class="featured-image">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'cyberchimps_core' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php the_post_thumbnail( apply_filters( 'cyberchimps_post_thumbnail_size', 'thumbnail' ) ); ?>
</a>
</div>
<?php
endif;
endif;
}
function cyberchimps_post_format_icon() {
global $post;
$format = get_post_format( $post->ID );
if ( $format == '' ) {
$format = 'default';
}
if ( is_single() ) {
$show = ( cyberchimps_get_option( 'single_post_format_icons', 1 ) ) ? cyberchimps_get_option( 'single_post_format_icons', 1 ) : false;
} elseif ( is_archive() ) {
$show = ( cyberchimps_get_option( 'archive_format_icons', 1 ) ) ? cyberchimps_get_option( 'archive_format_icons', 1 ) : false;
} else {
$show = ( cyberchimps_get_option( 'post_format_icons', 1 ) ) ? cyberchimps_get_option( 'post_format_icons', 1 ) : false;
}
if ( ! is_page() && $show ) :
// array of post formats and the matching font icons
$icons = array(
'aside' => '<span class="glyphicon glyphicon-list-alt"></span>',
'audio' => '<span class="glyphicon glyphicon-volume-up"></span>',
'chat' => '<span class="glyphicon glyphicon-comment"></span>',
'default' => '<span class="glyphicon glyphicon-file"></span>',
'gallery' => '<span class="glyphicon glyphicon-film"></span>',
'image' => '<span class="glyphicon glyphicon-picture"></span>',
'link' => '<span class="glyphicon glyphicon-link"></span>',
'quote' => '<span class="glyphicon glyphicon-share"></span>',
'status' => '<span class="glyphicon glyphicon-th"></span>',
'video' => '<span class="glyphicon glyphicon-facetime-video"></span>',
);
?>
<div class="postformats"><!--begin format icon-->
<?php echo $icons[ $format ]; ?>
</div><!--end format-icon-->
<?php
endif;
}
// Returns true if a blog has more than 1 category
function cyberchimps_categorized_blog() {
if ( false === ( $cyberchimps_categorized_transient = get_transient( 'cyberchimps_categorized_transient' ) ) ) {
// Create an array of all the categories that are attached to posts
$cyberchimps_categorized_transient = get_categories(
array(
'hide_empty' => 1,
)
);
// Count the number of categories that are attached to the posts
$cyberchimps_categorized_transient = count( $cyberchimps_categorized_transient );
set_transient( 'cyberchimps_categorized_transient', $cyberchimps_categorized_transient );
}
if ( '1' != $cyberchimps_categorized_transient ) {
// This blog has more than 1 category so cyberchimps_categorized_blog should return true
return true;
} else {
// This blog has only 1 category so cyberchimps_categorized_blog should return false
return false;
}
}
// Flush out the transients used in cyberchimps_categorized_blog
function cyberchimps_category_transient_flusher() {
// Remove transient
delete_transient( 'cyberchimps_categorized_transient' );
}
add_action( 'edit_category', 'cyberchimps_category_transient_flusher' );
add_action( 'save_post', 'cyberchimps_category_transient_flusher' );
// Prints out default title of the site.
function cyberchimps_default_site_title() {
global $page, $paged;
// Add the blog name.
if ( ! is_feed() ) {
bloginfo( 'name' );
}
// Title for page/post
if ( is_page() || is_single() ) {
echo ' | ' . get_the_title();
}
// Title for archives
if ( is_archive() ) {
echo ' | ';
if ( is_category() ) {
printf( __( 'Category Archives: %s', 'cyberchimps_core' ), single_cat_title( '', false ) );
} elseif ( is_tag() ) {
printf( __( 'Tag Archives: %s', 'cyberchimps_core' ), single_tag_title( '', false ) );
} elseif ( is_author() ) {
_e( 'Author Archives', 'cyberchimps_core' );
} elseif ( is_day() ) {
printf( __( 'Daily Archives: %s', 'cyberchimps_core' ), get_the_date() );
} elseif ( is_month() ) {
printf( __( 'Monthly Archives: %s', 'cyberchimps_core' ), get_the_date( 'F Y' ) );
} elseif ( is_year() ) {
printf( __( 'Yearly Archives: %s', 'cyberchimps_core' ), get_the_date( 'Y' ) );
} elseif ( is_plugin_active( 'woocommerce/woocommerce.php' ) && is_woocommerce() && is_shop() ) {
_e( 'Shop', 'cyberchimps_core' );
} else {
_e( 'Archives', 'cyberchimps_core' );
}
}
// Title for search
if ( is_search() ) {
echo ' | ' . sprintf( __( 'Search for " %s "', 'cyberchimps_core' ), get_search_query() );
}
// Title for 404
if ( is_404() ) {
echo ' | ' . __( 'Not Found', 'cyberchimps_core' ) . ' ';
}
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
echo ' | ' . $site_description;
}
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 ) {
echo ' | ' . sprintf( __( 'Page %s', 'cyberchimps_core' ), max( $paged, $page ) );
}
}
add_filter( 'wp_title', 'cyberchimps_default_site_title' );
// Remove default site title if seo plugin is active
function cyberchimps_seo_compatibility_check() {
if ( cyberchimps_detect_seo_plugins() ) {
remove_filter( 'wp_title', 'cyberchimps_default_site_title', 10, 3 );
}
}
add_action( 'after_setup_theme', 'cyberchimps_seo_compatibility_check', 5 );
// Add thumbnail size
function cyberchimps_add_thumbnail_size() {
add_image_size( 'featured-thumb', 100, 80, true );
add_image_size( 'headline-thumb', 200, 225, true );
}
add_action( 'after_setup_theme', 'cyberchimps_add_thumbnail_size', 5 );
// Detect some SEO Plugin that add constants, classes or functions.
function cyberchimps_detect_seo_plugins() {
return cyberchimps_detect_plugin(
// Use this filter to adjust plugin tests.
apply_filters(
'cyberchimps_detect_seo_plugins',
/** Add to this array to add new plugin checks. */
array(
// Classes to detect.
'classes' => array(
'wpSEO',
'All_in_One_SEO_Pack',
'HeadSpace_Plugin',
'Platinum_SEO_Pack',
),
// Functions to detect.
'functions' => array(),
// Constants to detect.
'constants' => array( 'WPSEO_VERSION' ),
)
)
);
}
// Detect event plugins
function cyberchimps_detect_event_plugins() {
return cyberchimps_detect_plugin(
// Use this filter to adjust plugin tests.
apply_filters(
'cyberchimps_detect_event_plugins',
/** Add to this array to add new plugin checks. */
array(
// Classes to detect.
'classes' => array( 'TribeEvents' ),
// Functions to detect.
'functions' => array(),
// Constants to detect.
'constants' => array(),
)
)
);
}
// Detect plugin by constant, class or function existence.
function cyberchimps_detect_plugin( $plugins ) {
/** Check for classes */
if ( isset( $plugins['classes'] ) ) {
foreach ( $plugins['classes'] as $name ) {
if ( class_exists( $name ) ) {
return true;
}
}
}
/** Check for functions */
if ( isset( $plugins['functions'] ) ) {
foreach ( $plugins['functions'] as $name ) {
if ( function_exists( $name ) ) {
return true;
}
}
}
/** Check for constants */
if ( isset( $plugins['constants'] ) ) {
foreach ( $plugins['constants'] as $name ) {
if ( defined( $name ) ) {
return true;
}
}
}
/** No class, function or constant found to exist */
return false;
}
// Set read more link for recent post element
function cyberchimps_recent_post_excerpt_more( $more ) {
global $custom_excerpt, $post;
return '…
</p>
<div class="more-link">
<a href="' . get_permalink( $post->ID ) . '">' . cyberchimps_blog_read_more_text() . '</a>
</div>';
}
// Set read more link for featured post element
function cyberchimps_featured_post_excerpt_more( $more ) {
global $post;
return '…</p></span><a class="excerpt-more featured-post-excerpt" href="' . get_permalink( $post->ID ) . '">' . cyberchimps_blog_read_more_text() . '</a>';
}
// Set length of the excerpt
function cyberchimps_featured_post_length( $length ) {
return 70;
}
// Set read more link for magazine featured post element
function cyberchimps_magazine_featured_post_excerpt_more( $more ) {
global $post;
return '…</p></span><a class="excerpt-more magazine-featured-post-excerpt" href="' . get_permalink( $post->ID ) . '">' . cyberchimps_blog_read_more_text() . '</a>';
}
// Set length of the magazine featured post excerpt
function cyberchimps_magazine_featured_post_length( $length ) {
$new_length = cyberchimps_get_option( 'blog_magazine_excerpt_length', 70 );
return $new_length;
}
// For magazine wide post
function cyberchimps_magazine_post_wide( $length ) {
$new_length = cyberchimps_get_option( 'blog_magazine_wide_excerpt_length', 130 );
return $new_length;
}
// more text for search results excerpt
function cyberchimps_search_excerpt_more( $more ) {
global $post;
if ( cyberchimps_get_option( 'search_post_read_more' ) != '' ) {
$more = '<p><a href="' . get_permalink( $post->ID ) . '">' . cyberchimps_get_option( 'search_post_read_more' ) . '</a></p>';
return $more;
} else {
$more = '<p><a class="excerpt-more search-excerpt" href="' . get_permalink( $post->ID ) . '">' . __( 'Read More...', 'cyberchimps_core' ) . '</a></p>';
return $more;
}
}
// excerpt length for search results
function cyberchimps_search_excerpt_length( $length ) {
global $post;
if ( cyberchimps_get_option( 'search_post_excerpt_length' ) != '' ) {
$length = cyberchimps_get_option( 'search_post_excerpt_length' );
return $length;
} else {
$length = 55;
return $length;
}
}
// For archive posts
function cyberchimps_archive_excerpt_more( $more ) {
global $post;
return '<p><a class="excerpt-more archive-excerpt" href="' . get_permalink( $post->ID ) . '">' . cyberchimps_blog_read_more_text() . '</a></p>';
}
if ( cyberchimps_get_option( 'archive_post_excerpts', 0 ) != 0 ) {
add_filter( 'excerpt_more', 'cyberchimps_blog_excerpt_more', 999 );
}
// Set value for blog read more text option.
function cyberchimps_blog_read_more_text() {
// Get the value of blog read more text option.
$read_more = cyberchimps_get_option( 'blog_read_more_text' );
// Check whether any not null value supplied and set the value accordingly.
if ( '' != $read_more ) {
return $read_more;
} else {
return __( 'Read More...', 'cyberchimps_core' );
}
}
// For blog posts
function cyberchimps_blog_excerpt_more( $more ) {
global $post;
return '<p><a class="excerpt-more blog-excerpt" href="' . get_permalink( $post->ID ) . '">' . cyberchimps_blog_read_more_text() . '</a></p>';
}
if ( cyberchimps_get_option( 'post_excerpts', 0 ) != 0 ) {
add_filter( 'excerpt_more', 'cyberchimps_blog_excerpt_more', 10 );
}
/**
* Set custom post excerpt link if excerpt is supplied manually.
*/
function manual_excerpt_read_more_link( $output ) {
global $post;
$linktext = cyberchimps_blog_read_more_text();
if ( ! empty( $post->post_excerpt ) ) {
return $output . '<p><a class="excerpt-more" href="' . get_permalink( $post->ID ) . '">' . $linktext . '</a></p>';
} else {
return $output;
}
}
add_filter( 'the_excerpt', 'manual_excerpt_read_more_link' );
function cyberchimps_blog_excerpt_length( $length ) {
global $post;
if ( cyberchimps_get_option( 'blog_excerpt_length' ) != '' ) {
$length = cyberchimps_get_option( 'blog_excerpt_length' );
return $length;
} else {
$length = 55;
return $length;
}
}
if ( cyberchimps_get_option( 'post_excerpts', 0 ) != 0 ) {
add_filter( 'excerpt_length', 'cyberchimps_blog_excerpt_length', 999 );
}
/* gets post views */
function cyberchimps_getPostViews( $postID ) {
$count_key = 'post_views_count';