-
Notifications
You must be signed in to change notification settings - Fork 46
/
functions.php
1081 lines (929 loc) · 31.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
/** functions.php
*
* @author Konstantin Obenland
* @package The Bootstrap
* @since 1.0.0 - 05.02.2012
*/
if ( ! function_exists( 'the_bootstrap_setup' ) ):
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* @author WordPress.org
* @since 1.0.0 - 05.02.2012
*
* @return void
*/
function the_bootstrap_setup() {
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 770;
}
load_theme_textdomain( 'the-bootstrap', get_template_directory() . '/lang' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'post-formats', array(
'aside',
'chat',
'link',
'gallery',
'status',
'quote',
'image',
'video'
) );
add_theme_support( 'tha_hooks', array( 'all' ) );
if ( version_compare( get_bloginfo( 'version' ), '3.4', '<' ) )
// Custom Theme Options
require_once( get_template_directory() . '/inc/theme-options.php' );
else
// Implement the Theme Customizer script
require_once( get_template_directory() . '/inc/theme-customizer.php' );
/**
* Custom template tags for this theme.
*/
require_once( get_template_directory() . '/inc/template-tags.php' );
/**
* Implement the Custom Header feature
*/
require_once( get_template_directory() . '/inc/custom-header.php' );
/**
* Custom Nav Menu handler for the Navbar.
*/
require_once( get_template_directory() . '/inc/nav-menu-walker.php' );
/**
* Theme Hook Alliance
*/
require_if_theme_supports( 'tha_hooks', get_template_directory() . '/inc/tha-theme-hooks.php' );
/**
* Including three menu (header-menu, primary and footer-menu).
* Primary is wrapping in a navbar containing div (wich support responsive variation)
* Header-menu and Footer-menu are inside pills dropdown menu
*
* @since 1.2.2 - 07.04.2012
* @see http://codex.wordpress.org/Function_Reference/register_nav_menus
*/
register_nav_menus( array(
'primary' => __( 'Main Navigation', 'the-bootstrap' ),
'header-menu' => __( 'Header Menu', 'the-bootstrap' ),
'footer-menu' => __( 'Footer Menu', 'the-bootstrap' )
) );
} // the_bootstrap_setup
endif;
add_action( 'after_setup_theme', 'the_bootstrap_setup' );
/**
* Returns the options object for The Bootstrap.
*
* @author Automattic
* @since 1.3.0 - 06.04.2012
*
* @return stdClass Theme Options
*/
function the_bootstrap_options() {
return (object) wp_parse_args(
get_option( 'the_bootstrap_theme_options', array() ),
the_bootstrap_get_default_theme_options()
);
}
/**
* Returns the default options for The Bootstrap.
*
* @author Automattic
* @since 1.3.0 - 06.04.2012
*
* @return void
*/
function the_bootstrap_get_default_theme_options() {
$default_theme_options = array(
'theme_layout' => 'content-sidebar',
'navbar_site_name' => false,
'navbar_searchform' => true,
'navbar_inverse' => true,
'navbar_position' => 'static',
);
return apply_filters( 'the_bootstrap_default_theme_options', $default_theme_options );
}
/**
* Adds The Bootstrap layout classes to the array of body classes.
*
* @author WordPress.org
* @since 1.3.0 - 06.04.2012
*
* @return void
*/
function the_bootstrap_layout_classes( $existing_classes ) {
$classes = array( the_bootstrap_options()->theme_layout );
$classes = apply_filters( 'the_bootstrap_layout_classes', $classes );
return array_merge( $existing_classes, $classes );
}
add_filter( 'body_class', 'the_bootstrap_layout_classes' );
/**
* Adds Custom Background support
*
* @author Konstantin Obenland
* @since 1.2.5 - 11.04.2012
*
* @return void
*/
function the_bootstrap_custom_background_setup() {
$args = apply_filters( 'the_bootstrap_custom_background_args', array(
'default-color' => 'EFEFEF',
) );
add_theme_support( 'custom-background', $args );
if ( ! function_exists( 'wp_get_theme' ) ) {
// Compat: Versions of WordPress prior to 3.4.
define( 'BACKGROUND_COLOR', $args['default-color'] );
add_custom_background();
}
}
add_action( 'after_setup_theme', 'the_bootstrap_custom_background_setup' );
/**
* Register the sidebars.
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @return void
*/
function the_bootstrap_widgets_init() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'the-bootstrap' ),
'id' => 'main',
'before_widget' => '<aside id="%1$s" class="widget well clearfix %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Image Sidebar', 'the-bootstrap' ),
'description' => __( 'Shown on image attachment pages.', 'the-bootstrap' ),
'id' => 'image',
'before_widget' => '<aside id="%1$s" class="widget well clearfix %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
include_once( 'inc/the-bootstrap-image-meta-widget.php' );
register_widget( 'The_Bootstrap_Image_Meta_Widget' );
include_once( 'inc/the-bootstrap-gallery-widget.php' );
register_widget( 'The_Bootstrap_Gallery_Widget' );
}
add_action( 'widgets_init', 'the_bootstrap_widgets_init' );
/**
* Registration of theme scripts and styles
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @return void
*/
function the_bootstrap_register_scripts_styles() {
if ( ! is_admin() ) {
$theme_version = _the_bootstrap_version();
$suffix = ( defined('SCRIPT_DEBUG') AND SCRIPT_DEBUG ) ? '' : '.min';
/**
* Scripts
*/
wp_register_script(
'tw-bootstrap',
get_template_directory_uri() . "/js/bootstrap{$suffix}.js",
array('jquery'),
'2.0.3',
true
);
wp_register_script(
'the-bootstrap',
get_template_directory_uri() . "/js/the-bootstrap{$suffix}.js",
array('tw-bootstrap'),
$theme_version,
true
);
/**
* Styles
*/
wp_register_style(
'tw-bootstrap',
get_template_directory_uri() . "/css/bootstrap{$suffix}.css",
array(),
'2.0.3'
);
wp_register_style(
'the-bootstrap',
get_template_directory_uri() . "/style{$suffix}.css",
array('tw-bootstrap'),
$theme_version
);
}
}
add_action( 'init', 'the_bootstrap_register_scripts_styles' );
/**
* Properly enqueue frontend scripts
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @return void
*/
function the_bootstrap_print_scripts() {
wp_enqueue_script( 'the-bootstrap' );
}
add_action( 'wp_enqueue_scripts', 'the_bootstrap_print_scripts' );
/**
* Adds IE specific scripts
*
* Respond.js has to be loaded after Theme styles
*
* @author Konstantin Obenland
* @since 1.7.0 - 11.06.2012
*
* @return void
*/
function the_bootstrap_print_ie_scripts() {
?>
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5shiv.min.js" type="text/javascript"></script>
<script src="<?php echo get_template_directory_uri(); ?>/js/respond.min.js" type="text/javascript"></script>
<![endif]-->
<?php
}
add_action( 'wp_head', 'the_bootstrap_print_ie_scripts', 11 );
/**
* Properly enqueue comment-reply script
*
* @author Konstantin Obenland
* @since 1.4.0 - 08.05.2012
*
* @return void
*/
function the_bootstrap_comment_reply() {
if ( get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'comment_form_before', 'the_bootstrap_comment_reply' );
/**
* Properly enqueue frontend styles
*
* Since 'tw-bootstrap' was registered as a dependency, it'll get enqueued
* automatically
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @return void
*/
function the_bootstrap_print_styles() {
if ( is_child_theme() ) {
wp_enqueue_style( 'the-bootstrap-child', get_stylesheet_uri(), array( 'the-bootstrap' ) );
} else {
wp_enqueue_style( 'the-bootstrap' );
}
if ( 'static' != the_bootstrap_options()->navbar_position ) {
$top_bottom = str_replace( 'navbar-fixed-', '', the_bootstrap_options()->navbar_position );
$css = "body > .container{margin-{$top_bottom}:68px;}@media(min-width: 980px){body > .container{margin-{$top_bottom}:58px;}}";
if ( is_admin_bar_showing() AND 'top' == $top_bottom )
$css .= '.navbar.navbar-fixed-top{margin-top:28px;}';
if ( function_exists( 'wp_add_inline_style' ) )
wp_add_inline_style( 'the-bootstrap', $css );
else
echo "<style type='text/css'>\n{$css}\n</style>\n";
}
}
add_action( 'wp_enqueue_scripts', 'the_bootstrap_print_styles' );
if ( ! function_exists( 'the_bootstrap_credits' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author,
* comment and edit link
*
* @author Konstantin Obenland
* @since 1.2.2 - 07.04.2012
*
* @return void
*/
function the_bootstrap_credits() {
printf(
'<span class="credits alignleft">' . __( '© %1$s <a href="%2$s">%3$s</a>, all rights reserved.', 'the-bootstrap' ) . '</span>',
date( 'Y' ),
home_url( '/' ),
get_bloginfo( 'name' )
);
}
endif;
/**
* Returns the blogname if no title was set.
*
* @author Konstantin Obenland
* @since 1.1.0 - 18.03.2012
*
* @param string $title
* @param string $sep
*
* @return string
*/
function the_bootstrap_wp_title( $title, $sep ) {
if ( ! is_feed() ) {
$title .= get_bloginfo( 'name' );
if ( is_front_page() ) {
$title .= " {$sep} " . get_bloginfo( 'description' );
}
}
return $title;
}
add_filter( 'wp_title', 'the_bootstrap_wp_title', 1, 2 );
/**
* Returns a "Continue Reading" link for excerpts
*
* @author WordPress.org
* @since 1.0.0 - 05.02.2012
*
* @param string $more
*
* @return string
*/
function the_bootstrap_continue_reading_link() {
return ' <a href="'. esc_url( get_permalink() ) . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'the-bootstrap' ) . '</a>';
}
/**
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and the_bootstrap_continue_reading_link().
*
* To override this in a child theme, remove the filter and add your own
* function tied to the excerpt_more filter hook.
*
* @author WordPress.org
* @since 1.0.0 - 05.02.2012
*
* @param string $more
*
* @return string
*/
function the_bootstrap_auto_excerpt_more( $more ) {
return '…' . the_bootstrap_continue_reading_link();
}
add_filter( 'excerpt_more', 'the_bootstrap_auto_excerpt_more' );
/**
* Adds a pretty "Continue Reading" link to custom post excerpts.
*
* To override this link in a child theme, remove the filter and add your own
* function tied to the get_the_excerpt filter hook.
*
* @author WordPress.org
* @since 1.0.0 - 05.02.2012
*
* @param string $output
*
* @return string
*/
function the_bootstrap_custom_excerpt_more( $output ) {
if ( has_excerpt() AND ! is_attachment() ) {
$output .= the_bootstrap_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'the_bootstrap_custom_excerpt_more' );
/**
* Get the wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*
* @author WordPress.org
* @since 1.0.0 - 05.02.2012
*
* @param array $args
*
* @return array
*/
function the_bootstrap_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'the_bootstrap_page_menu_args' );
/**
* Filter in a link to a content ID attribute for the next/previous image links on image attachment pages
*
* @author Automattic
* @since 1.0.0 - 05.02.2012
*
* @param string $url
* @param int $id
*
* @return string
*/
function the_bootstrap_enhanced_image_navigation( $url, $id ) {
if ( is_attachment() AND wp_attachment_is_image( $id ) ) {
$image = get_post( $id );
if ( $image->post_parent AND $image->post_parent != $id )
$url .= '#primary';
}
return $url;
}
add_filter( 'attachment_link', 'the_bootstrap_enhanced_image_navigation', 10, 2 );
/**
* Displays comment list, when there are any
*
* @author Konstantin Obenland
* @since 1.7.0 - 16.06.2012
*
* @return void
*/
function the_bootstrap_comments_list() {
if ( post_password_required() ) : ?>
<div id="comments">
<p class="nopassword"><?php _e( 'This post is password protected. Enter the password to view any comments.', 'the-bootstrap' ); ?></p>
</div><!-- #comments -->
<?php
return;
endif;
if ( have_comments() ) : ?>
<div id="comments">
<h2 id="comments-title">
<?php printf( _n( 'One thought on “%2$s”', '%1$s thoughts on “%2$s”', get_comments_number(), 'the-bootstrap' ),
number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' ); ?>
</h2>
<?php the_bootstrap_comment_nav(); ?>
<ol class="commentlist unstyled">
<?php wp_list_comments( array( 'callback' => 'the_bootstrap_comment' ) ); ?>
</ol><!-- .commentlist .unstyled -->
<?php the_bootstrap_comment_nav(); ?>
</div><!-- #comments -->
<?php endif;
}
add_action( 'comment_form_before', 'the_bootstrap_comments_list', 0 );
add_action( 'comment_form_comments_closed', 'the_bootstrap_comments_list', 1 );
/**
* Echoes comments-are-closed message when post type supports comments and we're
* not on a page
*
* @author Konstantin Obenland
* @since 1.7.0 - 16.06.2012
*
* @return void
*/
function the_bootstrap_comments_closed() {
if ( ! is_page() AND post_type_supports( get_post_type(), 'comments' ) ) : ?>
<p class="nocomments"><?php _e( 'Comments are closed.', 'the-bootstrap' ); ?></p>
<?php endif;
}
add_action( 'comment_form_comments_closed', 'the_bootstrap_comments_closed' );
/**
* Filters comments_form() default arguments
*
* @author Konstantin Obenland
* @since 1.7.0 - 16.06.2012
*
* @param array $defaults
*
* @return array
*/
function the_bootstrap_comment_form_defaults( $defaults ) {
return wp_parse_args( array(
'comment_field' => '<div class="comment-form-comment control-group"><label class="control-label" for="comment">' . _x( 'Comment', 'noun', 'the-bootstrap' ) . '</label><div class="controls"><textarea class="span7" id="comment" name="comment" rows="8" aria-required="true"></textarea></div></div>',
'comment_notes_before' => '',
'comment_notes_after' => '<div class="form-allowed-tags control-group"><label class="control-label">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s', 'the-bootstrap' ), '</label><div class="controls"><pre>' . allowed_tags() . '</pre></div>' ) . '</div>
<div class="form-actions">',
'title_reply' => '<legend>' . __( 'Leave a reply', 'the-bootstrap' ) . '</legend>',
'title_reply_to' => '<legend>' . __( 'Leave a reply to %s', 'the-bootstrap' ). '</legend>',
'must_log_in' => '<div class="must-log-in control-group controls">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.', 'the-bootstrap' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( get_the_ID() ) ) ) ) . '</div>',
'logged_in_as' => '<div class="logged-in-as control-group controls">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>', 'the-bootstrap' ), admin_url( 'profile.php' ), wp_get_current_user()->display_name, wp_logout_url( apply_filters( 'the_permalink', get_permalink( get_the_ID() ) ) ) ) . '</div>',
), $defaults );
}
add_filter( 'comment_form_defaults', 'the_bootstrap_comment_form_defaults' );
if ( ! function_exists( 'the_bootstrap_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own the_bootstrap_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param object $comment Comment data object.
* @param array $args
* @param int $depth Depth of comment in reference to parents.
*
* @return void
*/
function the_bootstrap_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
if ( 'pingback' == $comment->comment_type OR 'trackback' == $comment->comment_type ) : ?>
<li id="li-comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
<p class="row">
<strong class="ping-label span1"><?php _e( 'Pingback:', 'the-bootstrap' ); ?></strong>
<span class="span7"><?php comment_author_link(); edit_comment_link( __( 'Edit', 'the-bootstrap' ), '<span class="sep"> </span><span class="edit-link label">', '</span>' ); ?></span>
</p>
<?php else:
$offset = $depth - 1;
$span = 7 - $offset; ?>
<li id="li-comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
<article id="comment-<?php comment_ID(); ?>" class="comment row">
<div class="comment-author-avatar span1<?php if ($offset) echo " offset{$offset}"; ?>">
<?php echo get_avatar( $comment, 70 ); ?>
</div>
<footer class="comment-meta span<?php echo $span; ?>">
<p class="comment-author vcard">
<?php
/* translators: 1: comment author, 2: date and time */
printf( __( '%1$s <span class="says">said</span> on %2$s:', 'the-bootstrap' ),
sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
sprintf( '<a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
/* translators: 1: date, 2: time */
sprintf( __( '%1$s at %2$s', 'the-bootstrap' ), get_comment_date(), get_comment_time() )
)
);
edit_comment_link( __( 'Edit', 'the-bootstrap' ), '<span class="sep"> </span><span class="edit-link label">', '</span>' ); ?>
</p><!-- .comment-author .vcard -->
<?php if ( ! $comment->comment_approved ) : ?>
<div class="comment-awaiting-moderation alert alert-info"><em><?php _e( 'Your comment is awaiting moderation.', 'the-bootstrap' ); ?></em></div>
<?php endif; ?>
</footer><!-- .comment-meta -->
<div class="comment-content span<?php echo $span; ?>">
<?php
comment_text();
comment_reply_link( array_merge( $args, array(
'reply_text' => __( 'Reply <span>↓</span>', 'the-bootstrap' ),
'depth' => $depth,
'max_depth' => $args['max_depth']
) ) ); ?>
</div><!-- .comment-content -->
</article><!-- #comment-<?php comment_ID(); ?> .comment -->
<?php endif; // comment_type
}
endif; // ends check for the_bootstrap_comment()
/**
* Adds markup to the comment form which is needed to make it work with Bootstrap
* needs
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param string $html
*
* @return string
*/
function the_bootstrap_comment_form_top() {
echo '<div class="form-horizontal">';
}
add_action( 'comment_form_top', 'the_bootstrap_comment_form_top' );
/**
* Adds markup to the comment form which is needed to make it work with Bootstrap
* needs
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param string $html
*
* @return string
*/
function the_bootstrap_comment_form() {
echo '</div></div>';
}
add_action( 'comment_form', 'the_bootstrap_comment_form' );
/**
* Custom author form field for the comments form
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param string $html
*
* @return string
*/
function the_bootstrap_comment_form_field_author( $html ) {
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
return '<div class="comment-form-author control-group">
<label for="author" class="control-label">' . __( 'Name', 'the-bootstrap' ) . '</label>
<div class="controls">
<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />
' . ( $req ? '<p class="help-inline"><span class="required">' . __('required', 'the-bootstrap') . '</span></p>' : '' ) . '
</div>
</div>';
}
add_filter( 'comment_form_field_author', 'the_bootstrap_comment_form_field_author');
/**
* Custom HTML5 email form field for the comments form
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param string $html
*
* @return string
*/
function the_bootstrap_comment_form_field_email( $html ) {
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
return '<div class="comment-form-email control-group">
<label for="email" class="control-label">' . __( 'Email', 'the-bootstrap' ) . '</label>
<div class="controls">
<input id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />
<p class="help-inline">' . ( $req ? '<span class="required">' . __('required', 'the-bootstrap') . '</span>, ' : '' ) . __( 'will not be published', 'the-bootstrap' ) . '</p>
</div>
</div>';
}
add_filter( 'comment_form_field_email', 'the_bootstrap_comment_form_field_email');
/**
* Custom HTML5 url form field for the comments form
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param string $html
*
* @return string
*/
function the_bootstrap_comment_form_field_url( $html ) {
$commenter = wp_get_current_commenter();
return '<div class="comment-form-url control-group">
<label for="url" class="control-label">' . __( 'Website', 'the-bootstrap' ) . '</label>
<div class="controls">
<input id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" />
</div>
</div>';
}
add_filter( 'comment_form_field_url', 'the_bootstrap_comment_form_field_url');
/**
* Adjusts an attechment link to hold the class of 'thumbnail' and make it look
* pretty
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param string $link
* @param int $id Post ID.
* @param string $size Default is 'thumbnail'. Size of image, either array or string.
* @param bool $permalink Default is false. Whether to add permalink to image.
* @param bool $icon Default is false. Whether to include icon.
* @param string $text Default is false. If string, then will be link text.
*
* @return string
*/
function the_bootstrap_get_attachment_link( $link, $id, $size, $permalink, $icon, $text ) {
return ( ! $text ) ? str_replace( '<a ', '<a class="thumbnail" ', $link ) : $link;
}
add_filter( 'wp_get_attachment_link', 'the_bootstrap_get_attachment_link', 10, 6 );
/**
* Adds the 'hero-unit' class for extra big font on sticky posts
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param array $classes
*
* @return array
*/
function the_bootstrap_post_classes( $classes ) {
if ( is_sticky() AND is_home() ) {
$classes[] = 'hero-unit';
}
return $classes;
}
add_filter( 'post_class', 'the_bootstrap_post_classes' );
/**
* Callback function to display galleries (in HTML5)
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param string $content
* @param array $attr
*
* @return string
*/
function the_bootstrap_post_gallery( $content, $attr ) {
global $instance, $post;
$instance++;
// 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'] );
}
extract( shortcode_atts( array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'itemtag' => 'figure',
'icontag' => 'div',
'captiontag' => 'figcaption',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => ''
), $attr ) );
$id = intval( $id );
if ( 'RAND' == $order )
$orderby = 'none';
if ( $include ) {
$include = preg_replace( '/[^0-9,]+/', '', $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 ( $exclude ) {
$exclude = preg_replace( '/[^0-9,]+/', '', $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;
if ( is_feed() ) {
$output = "\n";
foreach ( $attachments as $att_id => $attachment )
$output .= wp_get_attachment_link( $att_id, $size, true ) . "\n";
return $output;
}
$itemtag = tag_escape( $itemtag );
$captiontag = tag_escape( $captiontag );
$columns = intval( min( array( 8, $columns ) ) );
$float = (is_rtl()) ? 'right' : 'left';
if ( 4 > $columns )
$size = 'full';
$selector = "gallery-{$instance}";
$size_class = sanitize_html_class( $size );
$output = "<ul id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class} thumbnails'>";
$i = 0;
foreach ( $attachments as $id => $attachment ) {
$comments = get_comments( array(
'post_id' => $id,
'count' => true,
'type' => 'comment',
'status' => 'approve'
) );
$link = wp_get_attachment_link( $id, $size, ! ( isset( $attr['link'] ) AND 'file' == $attr['link'] ) );
$clear_class = ( 0 == $i++ % $columns ) ? ' clear' : '';
$span = 'span' . floor( 8 / $columns );
$output .= "<li class='{$span}{$clear_class}'><{$itemtag} class='gallery-item'>";
$output .= "<{$icontag} class='gallery-icon'>{$link}</{$icontag}>\n";
if ( $captiontag AND ( 0 < $comments OR trim( $attachment->post_excerpt ) ) ) {
$comments = ( 0 < $comments ) ? sprintf( _n('%d comment', '%d comments', $comments, 'the-bootstrap'), $comments ) : '';
$excerpt = wptexturize( $attachment->post_excerpt );
$out = ($comments AND $excerpt) ? " $excerpt <br /> $comments " : " $excerpt$comments ";
$output .= "<{$captiontag} class='wp-caption-text gallery-caption'>{$out}</{$captiontag}>\n";
}
$output .= "</{$itemtag}></li>\n";
}
$output .= "</ul>\n";
return $output;
}
add_filter( 'post_gallery', 'the_bootstrap_post_gallery', 10, 2 );
/**
* HTML 5 caption for pictures
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param string $empty
* @param array $attr
* @param string $content
*
* @return string
*/
function the_bootstrap_img_caption_shortcode( $empty, $attr, $content ) {
extract( shortcode_atts( array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr ) );
if ( 1 > (int) $width OR empty( $caption ) ) {
return $content;
}
if ( $id ) {
$id = 'id="' . $id . '" ';
}
return '<figure ' . $id . 'class="wp-caption thumbnail ' . $align . '" style="width: '.$width.'px;">
' . do_shortcode( str_replace( 'class="thumbnail', 'class="', $content ) ) . '
<figcaption class="wp-caption-text">' . $caption . '</figcaption>
</figure>';
}
add_filter( 'img_caption_shortcode', 'the_bootstrap_img_caption_shortcode', 10, 3 );
/**
* Returns a password form which dispalys nicely with Bootstrap
*
* @author Konstantin Obenland
* @since 1.0.0 - 05.02.2012
*
* @param string $form
*
* @return string The Bootstrap password form
*/
function the_bootstrap_the_password_form( $form ) {
return '<form class="post-password-form form-horizontal" action="' . home_url( 'wp-pass.php' ) . '" method="post"><legend>'. __( 'This post is password protected. To view it please enter your password below:', 'the-bootstrap' ) . '</legend><div class="control-group"><label class="control-label" for="post-password-' . get_the_ID() . '">' . __( 'Password:', 'the-bootstrap' ) .'</label><div class="controls"><input name="post_password" id="post-password-' . get_the_ID() . '" type="password" size="20" /></div></div><div class="form-actions"><button type="submit" class="post-password-submit submit btn btn-primary">' . __( 'Submit', 'the-bootstrap' ) . '</button></div></form>';
}
add_filter( 'the_password_form', 'the_bootstrap_the_password_form' );
/**
* Modifies the category dropdown args for widgets on 404 pages
*
* @author Konstantin Obenland
* @since 1.5.0 - 19.05.2012
*
* @param array $args
*
* @return array
*/
function the_bootstrap_widget_categories_dropdown_args( $args ) {
if ( is_404() ) {
$args = wp_parse_args( $args, array(
'orderby' => 'count',
'order' => 'DESC',
'show_count' => 1,