forked from bonfirelab/bearded
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
1191 lines (945 loc) · 38.7 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
/**
* The functions file is used to initialize everything in the theme. It controls how the theme is loaded and
* sets up the supported features, default actions, and default filters. If making customizations, users
* should create a child theme and make changes to its functions.php file (not this one). Friends don't let
* friends modify parent theme files. ;)
*
* Child themes should do their setup on the 'after_setup_theme' hook with a priority of 11 if they want to
* override parent theme features. Use a priority of 9 if wanting to run before the parent theme.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package Bearded
* @subpackage Functions
* @version 1.0.0
* @since 0.1.0
* @author Hermanto Lim <[email protected]>
* @copyright Copyright (c) 2013, Hermanto Lim
* @link http://bonfirelab.com/themes/bearded
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
/* Load the core theme framework. */
require_once( trailingslashit( get_template_directory() ) . 'library/hybrid.php' );
new Hybrid();
if(!defined("BEARDED_IMAGES")) {
define("BEARDED_IMAGES", trailingslashit( get_template_directory_uri() ) . 'assets/images/');
}
if(!defined("BEARDED_CSS")) {
define("BEARDED_CSS", trailingslashit( get_template_directory_uri() ) . 'assets/css/');
}
if(!defined("BEARDED_JS")) {
define("BEARDED_JS", trailingslashit( get_template_directory_uri() ) . 'assets/js/');
}
if(!defined("BEARDED_INC")) {
define("BEARDED_INC", trailingslashit( get_template_directory() ) . 'inc/');
}
/* Do theme setup on the 'after_setup_theme' hook. */
add_action( 'after_setup_theme', 'bearded_theme_setup' );
/**
* Theme setup function. This function adds support for theme features and defines the default theme
* actions and filters.
*
* @since 0.1.0
* @access public
* @return void
*/
function bearded_theme_setup() {
/* Get action/filter hook prefix. */
$prefix = hybrid_get_prefix();
/* Register menus. */
add_theme_support(
'hybrid-core-menus',
array( 'primary' )
);
/* Register sidebars. */
add_theme_support(
'hybrid-core-sidebars',
array( 'primary')
);
/* Load scripts. */
add_theme_support(
'hybrid-core-scripts',
array( 'comment-reply' )
);
/* Load styles. */
add_theme_support(
'hybrid-core-styles',
array( 'gallery', 'style' )
);
add_theme_support(
'hybrid-core-theme-settings',
array( 'about', 'footer' )
);
add_theme_support(
'animate-slider',
array( 'link', 'button', 'caption-style', 'caption-position', 'background')
);
if ( is_admin() )
require_once( trailingslashit( BEARDED_INC ) . 'functions-admin.php' );
add_theme_support( 'post-thumbnails' );
/* Load widgets. */
add_theme_support( 'hybrid-core-widgets' );
/* Load shortcodes. */
add_theme_support( 'hybrid-core-shortcodes' );
/* Load the media grabber. */
add_theme_support( 'hybrid-core-media-grabber' );
/* Enable theme layouts (need to add stylesheet support). */
add_theme_support(
'theme-layouts',
array( '1c', '2c-l', '2c-r' ),
array( 'default' => '2c-l', 'customizer' => true )
);
/* Support pagination instead of prev/next links. */
add_theme_support( 'loop-pagination' );
/* The best thumbnail/image script ever. */
add_theme_support( 'get-the-image' );
/* Nicer [gallery] shortcode implementation. */
add_theme_support( 'cleaner-gallery' );
/* Better captions for themes to style. */
add_theme_support( 'cleaner-caption' );
/* Automatically add feed links to <head>. */
add_theme_support( 'automatic-feed-links' );
/* Post formats. */
add_theme_support(
'post-formats',
array( 'aside', 'audio', 'chat', 'image', 'gallery', 'link', 'quote', 'status', 'video' )
);
/* Custom background. */
add_theme_support(
'custom-background',
array( 'default-color' => 'f3f3f3' )
);
add_action( 'init', 'bearded_image_size' );
add_action( 'widgets_init', 'bearded_footer_sidebar', 50);
add_filter( "{$prefix}_sidebar_defaults", 'bearded_sidebar_default_setting', 10);
add_filter( 'wp_tag_cloud', 'bearded_no_inline_style_tag_cloud' );
add_filter( "{$prefix}_list_comments_args", 'bearded_filter_comment_args', 10);
add_filter('post_class', 'bearded_post_class_last', 10, 3);
add_shortcode( 'gallery-carousel' , 'bearded_gallery_carousel_shortcode' );
add_action( 'ccp_item_info_meta_box', 'bearded_portfolio_metabox', 10, 2 );
add_action( 'save_post', 'bearded_save_portfolio_meta', 10, 2 );
add_action( 'admin_enqueue_scripts', 'bearded_enqueue_portfolio_script' );
/* Handle content width for embeds and images. */
hybrid_set_content_width( 570 );
add_filter( 'embed_defaults', 'bearded_embed_defaults' );
/* Filter the sidebar widgets. */
add_filter( 'sidebars_widgets', 'bearded_disable_sidebars' );
add_action( 'template_redirect', 'bearded_set_column' );
add_action( "{$prefix}_open_main_row", "bearded_open_main_row_hook", 1 );
add_action( "{$prefix}_close_main_row", "bearded_close_main_row_hook", 1 );
add_theme_support( 'color-palette', array( 'callback' => 'bearded_register_colors' ) );
add_action( 'wp_head', 'bearded_wp_head_shadow_css' );
add_filter( "{$prefix}_footer_content", "bearded_footer_content" );
if( function_exists( 'is_woocommerce') ) {
require_once( BEARDED_INC . 'functions-woocommerce.php');
require_once( BEARDED_INC . 'widgets/widget-home-product.php');
}
add_action('init', 'bearded_setup_admin_bar');
}
/**
* Set up image size for bearded
*
* @since 0.1.0
* @access public
* @return void
*/
function bearded_image_size() {
set_post_thumbnail_size( 575, 350, true);
add_image_size( 'featured-slider', 1160, 480, true);
add_image_size( 'featured-slider-content',530,480,true);
add_image_size( 'home-thumbnail',300,300);
add_image_size( 'portfolio-thumbnail',500,500);
}
/**
* remove inline style in tag cloud
*
* @since 0.1.0
* @access public
* @return string
*/
function bearded_no_inline_style_tag_cloud( $list ) {
$list = preg_replace('/style=("|\')(.*?)("|\')/','',$list);
return $list;
}
/**
* Filter sidebar default before_title and after_title
*
* @since 0.1.0
* @access public
* @return void
*/
function bearded_sidebar_default_setting( $defaults ) {
$defaults['before_title'] = '<h3 class="widget-title"><span>';
$defaults['after_title'] = '</span></h3>';
return $defaults;
}
/**
* Register sidebar widget in footer
*
* @since 0.1.0
* @access public
* @return void
*/
function bearded_footer_sidebar() {
$sidebars = array(
'footer-1' => array(
'id' => 'footer-1',
'name' => _x( 'Footer 1', 'sidebar', 'bearded' ),
),
'footer-2' => array(
'id' => 'footer-2',
'name' => _x( 'Footer 2', 'sidebar', 'bearded' ),
),
'footer-3' => array(
'id' => 'footer-3',
'name' => _x( 'Footer 3', 'sidebar', 'bearded' ),
)
);
/* Set up some default sidebar arguments. */
$defaults = array(
'before_widget' => '<section id="%1$s" class="widget %2$s widget-%2$s">',
'after_widget' => '</section>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
);
$home_sidebar = array(
'id' => 'homepage',
'name' => _x( 'Home Page', 'sidebar', 'bearded' ),
);
$shop_sidebar = array(
'id' => 'shop',
'name' => _x( 'Shop', 'sidebar', 'bearded'),
'before_title' => '<h3 class="widget-title"><span>',
'after_title' => '</span></h3>'
);
$home_sidebar = wp_parse_args( $home_sidebar, $defaults );
$shop_sidebar = wp_parse_args( $shop_sidebar, $defaults );
register_sidebar($home_sidebar);
register_sidebar($shop_sidebar);
/* Parse the sidebar arguments and defaults. */
for( $i = 1; $i <= 3; $i++ ) {
$args = wp_parse_args( $sidebars[ 'footer-'. $i ], $defaults );
/* Register the sidebar. */
register_sidebar( $args );
}
}
/**
* Enqueue Bearded required javascript files
*
* @since 0.1.0
* @access public
* @return void
*/
function bearded_enqueue_scripts() {
if(!is_admin()) {
wp_enqueue_script( 'modernizer', BEARDED_JS . 'libs/custom.modernizr.js' , array(), false, false );
wp_enqueue_script( 'imagesloaded', BEARDED_JS . 'libs/imagesloaded.min.js' , array('jquery'), '3.0.4', true );
wp_enqueue_script( 'isotope', BEARDED_JS . 'libs/jquery.isotope.min.js' , array('jquery'), false, true );
wp_enqueue_script( 'fitvids', BEARDED_JS . 'libs/jquery.fitvids.js' , array('jquery'), false, true );
if( wp_script_is( 'bxslider', 'registered' ) === false ) {
wp_register_script( 'bxslider', BEARDED_JS . 'libs/jquery.bxslider.min.js', array('jquery'), '', true );
}
wp_enqueue_script( 'custom', BEARDED_JS . 'custom.js' , array('jquery'), '0.1', true );
wp_enqueue_style( 'font-awesome', BEARDED_CSS . 'font-awesome.css' , '', '3.0', 'all' );
$params = array(
'i18n_add_wishlist' => esc_attr__( 'Add to wishlist', 'bearded' ),
'i18n_exists_wishlist' => esc_attr__( 'Product already in the wishlist', 'bearded' ),
'i18n_added_wishlist' => esc_attr__( 'Product added to wishlist', 'bearded' ),
);
wp_localize_script( 'custom', 'bearded_woocommerce', apply_filters( 'bearded_woocommerce', $params ) );
}
}
add_action('wp_enqueue_scripts', 'bearded_enqueue_scripts');
/**
* Filters the first and last nav menu objects in your menus
* to add custom classes.
*
* This also supports nested menus.
*
* @since 0.1.0
* @access public
* @param array $objects An array of nav menu objects
* @param object $args Nav menu object args
* @return object $objects Amended array of nav menu objects with new class
*/
function bearded_first_and_last_menu_class( $objects, $args ) {
// Add first/last classes to nested menu items
$ids = array();
$parent_ids = array();
$top_ids = array();
foreach ( $objects as $i => $object ) {
// If there is no menu item parent, store the ID and skip over the object
if ( 0 == $object->menu_item_parent ) {
$top_ids[$i] = $object;
continue;
}
// Add first item class to nested menus
if ( ! in_array( $object->menu_item_parent, $ids ) ) {
$objects[$i]->classes[] = 'first-menu-item';
$ids[] = $object->menu_item_parent;
}
// If we have just added the first menu item class, skip over adding the ID
if ( in_array( 'first-menu-item', $object->classes ) )
continue;
// Store the menu parent IDs in an array
$parent_ids[$i] = $object->menu_item_parent;
}
// Remove any duplicate values and pull out the last menu item
$sanitized_parent_ids = array_unique( array_reverse( $parent_ids, true ) );
// Loop through the IDs and add the last menu item class to the appropriate objects
foreach ( $sanitized_parent_ids as $i => $id )
$objects[$i]->classes[] = 'last-menu-item';
$keys = array_keys( $top_ids );
// Finish it off by adding classes to the top level menu items
$objects[1]->classes[] = 'first-menu-item'; // We can be assured 1 will be the first item in the menu :-)
$objects[end( $keys )]->classes[] = 'last-menu-item';
// Return the menu objects
return $objects;
}
add_filter('wp_nav_menu_objects', 'bearded_first_and_last_menu_class', 10 , 2);
/**
* Social Icon list array
*
* @since 0.1.0
* @access public
* @return array()
*/
function bearded_get_social_lists() {
$social_lists = array(
'facebook' => esc_url( hybrid_get_setting('bearded_social_facebook') ),
'twitter' => esc_url( hybrid_get_setting('bearded_social_twitter') ),
'pinterest' => esc_url( hybrid_get_setting('bearded_social_pinterest') ),
'dribbble' => esc_url( hybrid_get_setting('bearded_social_dribbble') ),
'github' => esc_url( hybrid_get_setting('bearded_social_github') ),
'google-plus' => esc_url( hybrid_get_setting('bearded_social_google-plus') ),
'tumblr' => esc_url( hybrid_get_setting('bearded_social_tumblr') ),
'linkedin' => esc_url( hybrid_get_setting('bearded_social_linkedin') ),
);
return $social_lists;
}
/**
* Generating post format icon
*
* @since 0.1.0
* @access public
* @param $format string (post format)
* @return string
*/
function bearded_get_post_format_icon( $format = '' ) {
global $post;
$o = '<a href="' . get_post_format_link( $format ) . '" title="' . sprintf( __( 'Browse %s posts','bearded' ), $format ) .'">';
switch ($format) {
case 'aside':
$o .= apply_atomic( 'aside_format_icon', '<i class="icon-paper-clip"></i>' );
break;
case 'audio':
$o .= apply_atomic( 'audio_format_icon', '<i class="icon-headphones"></i>' );
break;
case 'chat':
$o .= apply_atomic( 'chat_format_icon', '<i class="icon-comments"></i>' );
break;
case 'image':
$o .= apply_atomic( 'image_format_icon', '<i class="icon-camera"></i>' );
break;
case 'gallery':
$o .= apply_atomic( 'gallery_format_icon', '<i class="icon-picture"></i>' );
break;
case 'link':
$o .= apply_atomic( 'link_format_icon', '<i class="icon-link"></i>' );
break;
case 'quote':
$o .= apply_atomic( 'quote_format_icon', '<i class="icon-quote-left"></i>' );
break;
case 'status':
$o .= apply_atomic( 'status_format_icon', '<i class="icon-file"></i>' );
break;
case 'video':
$o .= apply_atomic( 'video_format_icon', '<i class="icon-play"></i>' );
break;
case 'portfolio':
$o .= apply_atomic( 'portfolio_item_icon', '<i class="icon-briefcase"></i>' );
break;
default:
$o .= apply_atomic( 'standard_format_icon', '<i class="icon-file"></i>' );
break;
}
$o .= '</a>';
return apply_atomic('post_format_icon', $o);
}
/**
* Echo Post format icon
*
* @since 0.1.0
* @access public
* @param $format string (post format)
* @return string
*/
function bearded_post_format_icon( $format = '' ) {
echo bearded_get_post_format_icon( $format );
}
/**
* Filter avatar size in comment args
*
* @since 0.1.0
* @access public
* @param $args array()
* @return $args array
*/
function bearded_filter_comment_args( $args ) {
$args['avatar_size'] = 51;
return $args;
}
/**
* Filter post class, add post-last into the last post for each post page
*
* @since 0.1.0
* @access public
* @param $classes array()
* @param $class string
* @param $post_id string
* @return array
*/
function bearded_post_class_last( $classes, $class, $post_id ) {
global $wp_query;
if(!is_singular() && $wp_query->post_count == $wp_query->current_post + 1) {
$classes[] = 'post-last';
}
if( is_singular() && ( post_password_required() || ( !have_comments() && !comments_open() && !pings_open() ) ) ) {
$classes[] = 'singular-no-comments';
}
return $classes;
}
/**
* Shortcode function for running gallery-carousel
*
* @since 0.1.0
* @access public
* @param $attr array()
* @return string
*/
function bearded_gallery_carousel_shortcode( $attr ) {
global $post;
if( wp_script_is('bxslider', 'enqueued') === false ) {
wp_enqueue_script( 'bxslider' );
}
$post = get_post();
static $instance = 0;
$instance++;
if ( ! empty( $attr['ids'] ) ) {
// 'ids' is explicitly ordered, unless you specify otherwise.
if ( empty( $attr['orderby'] ) )
$attr['orderby'] = 'post__in';
$attr['include'] = $attr['ids'];
}
// Allow plugins/themes to override the default gallery template.
$o = apply_filters('post_gallery_carousel', '', $attr);
if ( $o != '' )
return $o;
// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
if ( isset( $attr['orderby'] ) ) {
$attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
if ( !$attr['orderby'] )
unset( $attr['orderby'] );
}
$layout = get_theme_mod('theme_layout');
$size = 'post-thumbnail';
if($layout === '1c') {
$size = 'featured-slider';
}
$defaults = array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post ? $post->ID : 0,
'size' => $size,
'include' => '',
'exclude' => ''
);
$attr = shortcode_atts( $defaults, $attr );
extract($attr);
$id = intval($id);
if ( 'RAND' == $order )
$orderby = 'none';
if ( !empty($include) ) {
$_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif ( !empty($exclude) ) {
$attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
} else {
$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
}
if ( empty($attachments) )
return '';
$item = '';
foreach ( $attachments as $id => $attachment ) {
if ( ! empty( $attr['link'] ) && 'file' === $attr['link'] )
$image_output = wp_get_attachment_link( $id, $size, false, false );
elseif ( ! empty( $attr['link'] ) && 'none' === $attr['link'] )
$image_output = wp_get_attachment_image( $id, $size, false );
else
$image_output = wp_get_attachment_link( $id, $size, true, false );
$item .= '<div class="gallery-carousel-item">';
$item .= $image_output;
if( !empty($attachment->post_excerpt) ) {
$item .= '<div class="carousel-caption gallery-carousel-caption">';
$item .= wptexturize( $attachment->post_excerpt );
$item .= '</div>'; // close caption
}
$item .= '</div>'; // close gallery-carousel-item
}
$o .= '<div class="bearded-gallery-carousel-container">';
$o .= '<div id="bearded-gallery-carousel-'.$instance.'" class="bearded-gallery-carousel">';
$o .= $item;
$o .= '</div>';
$o .= '<div class="bearded-carousel-control" id="bearded-gallery-carousel-'.$instance.'-control"></div>';
$o .= '</div>';
return $o;
}
/**
* Called in not singular post format gallery.
* Turn gallery into a slideshow.
*
* @since 0.1.0
* @access public
* @return do_shortcode(gallery-carousel)
*/
function bearded_gallery_carousel() {
global $post;
$content = $post->post_content;
/* Finds matches for shortcodes in the content. */
preg_match_all( '/' . get_shortcode_regex() . '/s', $content , $matches, PREG_SET_ORDER );
/* If matches are found, loop through them and check if they match one of WP's media shortcodes. */
if ( !empty( $matches ) ) {
foreach ( $matches as $shortcode ) {
/* Call the method related to the specific shortcode found and break out of the loop. */
if ( in_array( $shortcode[2], array( 'embed', 'gallery' ) ) ) {
$original_media = array_shift( $shortcode );
if( shortcode_exists('gallery-carousel') ) {
$original_media = str_replace('[gallery', '[gallery-carousel', $original_media);
}
echo apply_atomic_shortcode('gallery_carousel', $original_media );
break;
}
}
}
}
/**
* Filter and add metabox to Portfolio Info
*
* @since 0.1.0
* @access public
* @param $object OBJECT
* @param $box optional
* @return void
*/
function bearded_portfolio_metabox( $object, $box ) {
$client = esc_attr(get_post_meta( $object->ID, 'ccp-portfolio-item-client', true));
$date = esc_attr(get_post_meta( $object->ID, 'ccp-portfolio-item-date', true));
wp_nonce_field( basename( __FILE__ ), 'ccp-portfolio-item-detail-nonce' ); ?>
<p>
<label for="ccp-portfolio-item-client"><?php _e( 'Client:', 'bearded' ); ?></label>
<br />
<input type="text" style="width:99%" name="ccp-portfolio-item-client" id="ccp-portfolio-item-client" value="<?php echo $client; ?>" />
</p>
<p>
<label for="ccp-portfolio-item-date"><?php _e( 'Date:', 'bearded' ); ?></label>
<br />
<input type="text" style="width:99%" class="portfolio-datepicker" name="ccp-portfolio-item-date" id="ccp-portfolio-item-date" value="<?php echo $date; ?>" />
</p>
<?php
}
/**
* Saving Portfolio Meta
*
* @since 0.1.0
* @access public
* @param $post_id string ID
* @param $post object
* @return void
*/
function bearded_save_portfolio_meta( $post_id, $post = '' ) {
/* Fix for attachment save issue in WordPress 3.5. @link http://core.trac.wordpress.org/ticket/21963 */
if ( !is_object( $post ) )
$post = get_post();
/* Verify the nonce before proceeding. */
/* The nonce is use custom nonce generated while creating the output */
/* Dunno why cannot use default nonce by ccp looks like already used before this post is saved */
if ( !isset( $_POST['ccp-portfolio-item-detail-nonce'] ) || !wp_verify_nonce( $_POST['ccp-portfolio-item-detail-nonce'], basename( __FILE__ ) ) )
return $post_id;
$meta = array(
'ccp-portfolio-item-client' => sanitize_text_field( esc_attr( $_POST['ccp-portfolio-item-client'] ) ),
'ccp-portfolio-item-date' => sanitize_text_field( esc_attr( $_POST['ccp-portfolio-item-date'] ) ),
);
foreach ( $meta as $meta_key => $new_meta_value ) {
/* Get the meta value of the custom field key. */
$meta_value = get_post_meta( $post_id, $meta_key, true );
/* If there is no new meta value but an old value exists, delete it. */
if ( current_user_can( 'delete_post_meta', $post_id, $meta_key ) && '' == $new_meta_value && $meta_value )
delete_post_meta( $post_id, $meta_key, $meta_value );
/* If a new meta value was added and there was no previous value, add it. */
elseif ( current_user_can( 'add_post_meta', $post_id, $meta_key ) && $new_meta_value && '' == $meta_value )
add_post_meta( $post_id, $meta_key, $new_meta_value, true );
/* If the new meta value does not match the old value, update it. */
elseif ( current_user_can( 'edit_post_meta', $post_id, $meta_key ) && $new_meta_value && $new_meta_value != $meta_value )
update_post_meta( $post_id, $meta_key, $new_meta_value );
}
}
/**
* Enqueue scripts for use in portfolio_item post type to make the date input field into datepicker
*
* @since 0.1.0
* @access public
* @return void
*/
function bearded_enqueue_portfolio_script( $hook ) {
global $post;
if( ($hook == 'post-new.php' || $hook == 'post.php') && $post->post_type === 'portfolio_item') {
wp_register_style('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
wp_enqueue_style( 'jquery-ui' );
wp_enqueue_script( 'bearded-portfolio-admin', trailingslashit( BEARDED_JS ) . 'admin/portfolio.js', array('jquery', 'jquery-ui-datepicker') , '1.0' );
}
}
/**
* Disables sidebars if viewing a one-column page.
*
* @since 0.1.0
* @param array $sidebars_widgets A multidimensional array of sidebars and widgets.
* @return array $sidebars_widgets
*/
function bearded_disable_sidebars( $sidebars_widgets ) {
global $wp_customize;
$customize = ( is_object( $wp_customize ) && $wp_customize->is_preview() ) ? true : false;
if ( (!is_admin() && !$customize && '1c' == get_theme_mod( 'theme_layout' )) || is_page_template( 'page-templates/home.php' ) ) {
$sidebars_widgets['primary'] = false;
$sidebars_widgets['shop'] = false;
}
return $sidebars_widgets;
}
/**
* Function for deciding which pages should have a one-column layout.
*
* @since 0.1.0
* @access public
* @return void
*/
function bearded_set_column() {
if( function_exists('is_woocommerce') && is_woocommerce() && !is_active_sidebar('shop') ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif( ( function_exists( 'is_cart' ) && is_cart() ) || ( function_exists( 'is_checkout' ) && is_checkout() ) ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif( function_exists( 'is_account_page') && is_account_page() && !is_active_sidebar('shop') ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif ( !is_active_sidebar( 'primary' ) && !is_active_sidebar( 'secondary' ) ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif ( is_attachment() && wp_attachment_is_image() ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif ( is_page_template( 'page-templates/portfolio-3.php' ) || is_page_template( 'page-templates/portfolio-4.php' ) ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_one_column' );
}
elseif ( is_singular() && 'default' === get_post_layout( get_queried_object_id() ) ) {
add_filter( 'theme_mod_theme_layout', 'bearded_theme_layout_default_column' );
}
elseif( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
add_filter( 'theme_mod_theme_layout', 'bearded_woocommerce_column' );
}
}
/**
* Filters custom woocommerce page.
*
* @since 0.1.4
* @return boolean
*/
function bearded_is_woopage() {
if( ( function_exists( 'is_cart' ) && is_cart() ) || ( function_exists( 'is_checkout' ) && is_checkout() ) || ( function_exists( 'is_account_page' ) && is_account_page() ) ) {
return true;
}
}
function bearded_woocommerce_column() {
$layout = get_post_layout( wc_get_page_id( 'shop' ) );
return $layout;
}
/**
* Filters 'get_theme_layout' by returning 'layout-1c'.
*
* @since 0.1.0
* @param string $layout The layout of the current page.
* @return string
*/
function bearded_theme_layout_one_column( $layout ) {
return '1c';
}
function bearded_theme_layout_default_column( $layout ) {
return '2c-l';
}
/**
* Overwrites the default widths for embeds. This is especially useful for making sure videos properly
* expand the full width on video pages. This function overwrites what the $content_width variable handles
* with context-based widths.
*
* @since 0.1.0
* @access public
* @param array $args
* @return array
*/
function bearded_embed_defaults( $args ) {
$args['width'] = 570;
if ( current_theme_supports( 'theme-layouts' ) && '1c' == get_theme_mod( 'theme_layout' ) )
$args['width'] = 930;
return $args;
}
/**
* Output the featured image post thumbnail base on layout size and post format.
*
* @since 0.1.0
* @access public
* @return string html
*/
function bearded_post_thumbnail() {
$o = '';
$layout = get_theme_mod('theme_layout');
if( current_theme_supports('get-the-image') ) {
if($layout === '1c') {
if( get_post_format() === 'image' ) {
$o = get_the_image( array( 'meta_key' => false, 'link_to_post' => false, 'before' => '<div class="featured-image">', 'size' => 'featured-slider', 'after' => '</div>' ) );
} else {
$o = get_the_image( array( 'before' => '<div class="featured-image">', 'size' => 'featured-slider', 'after' => '</div>' ) );
}
} else {
if( get_post_format() === 'image' ) {
$o = get_the_image( array( 'meta_key' => false, 'link_to_post' => false, 'before' => '<div class="featured-image">', 'size' => 'post-thumbnail', 'after' => '</div>' ) );
}
else {
$o = get_the_image( array( 'before' => '<div class="featured-image">', 'size' => 'post-thumbnail', 'after' => '</div>' ) );
}
}
}
echo $o;
}
function bearded_open_main_row_hook() {
$layout = get_theme_mod('theme_layout');
if(empty($layout)) {
$layout = get_post_layout(get_queried_object_id());
}
if($layout == '2c-r' ) {
if( ( function_exists('is_woocommerce') && is_woocommerce() ) || bearded_is_woopage() ) {
get_sidebar( 'shop' );
} else {
get_sidebar( 'primary' );
}
}
}
function bearded_close_main_row_hook() {
$layout = get_theme_mod('theme_layout');
if(empty($layout)) {
$layout = get_post_layout(get_queried_object_id());
}
if($layout == '2c-l' || $layout == 'default') {
if( ( function_exists('is_woocommerce') && is_woocommerce() ) || bearded_is_woopage() ) {
get_sidebar( 'shop' );
} else {
get_sidebar( 'primary' );
}
}
}
/**
* Returns a link to the porfolio item URL if it has been set.
*
* @since 0.1.0
* @access public
* @return void
*/
function bearded_get_portfolio_item_link() {
$url = get_post_meta( get_the_ID(), 'portfolio_item_url', true );
if ( !empty( $url ) )
return '<span class="project-url"><strong>' . __( 'Project <abbr title="Uniform Resource Locator">URL</abbr>:', 'bearded' ) . '</strong> <a class="portfolio-item-link" href="' . esc_url( $url ) . '">' . $url . '</a></span> ';
}
/**
* Registers colors for the Color Palette extension.
*
* @since 0.1.0
* @access public
* @param object $color_palette
* @return void
*/
function bearded_register_colors( $color_palette ) {
/* Add custom colors. */
$color_palette->add_color(
array( 'id' => 'primary', 'label' => __( 'Primary Color', 'bearded' ), 'default' => 'f47e00' )