-
Notifications
You must be signed in to change notification settings - Fork 5
/
functions.php
1350 lines (1189 loc) · 48.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
/**
* ///
* (o 0)
* ======o00o-(_)-o00o======
* Bootplate v1.9 Main Functions
* @link https://github.com/jdmdigital/bootplate
* Made with love by @jdmdigital
* =========================
*
* Bootplate WordPress Theme, Copyright 2016 JDM Digital, LLC
* Bootplate is distributed under the terms of the GNU GPL
*
* 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. See the
* GNU General Public License for more details.
*/
define('VERSION', 1.9);
define("REPO", 'https://github.com/jdmdigital/bootplate');
define("BRANCH", '');
// get_wpversion()
if(!function_exists('get_wpversion')){
function get_wpversion() {
return get_bloginfo('version');
}
}
if(!function_exists('bootplate_info')) {
function bootplate_info($data = 'version') {
$version = VERSION;
$repo = REPO;
$branch = BRANCH;
if($data == 'repo') {
return $repo;
} elseif($data == 'branch') {
if($branch != '') {
return $branch;
} else {
return $repo;
}
} elseif ($data == 'stringver') {
return sprintf('%1', $version);
} else {
return $version;
}
}
}
if ( ! isset( $content_width ) ) {
$content_width = 1140;
}
if ( !function_exists('bootplate_setup') ) {
function bootplate_setup(){
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Let WordPress manage the document title. NO hard-coded <title> tag in HEAD.
add_theme_support( 'title-tag' );
//Enable support for Post Thumbnails on posts and pages.
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 1140, 600 );
add_image_size('tablet', 980, 515);
add_image_size('mobile', 768, 404);
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'bootplate' ),
'primary-left' => __( 'Primary Menu (left)', 'bootplate' ),
//'blogcats' => __( 'Blog Categories Menu', 'bootplate' ), - Not using this since v1.1
'footer' => __( 'Footer Links Menu', 'bootplate' ),
'social' => __( 'Social Links Menu', 'bootplate' ),
) );
// Include Bootstrap Nav Walker
require get_template_directory() . '/inc/wp_bootstrap_navwalker.php';
// Switch default core markup to output valid HTML5.
add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list', 'caption', 'gallery'
) );
// Add Quote and Link Post Format Support
add_theme_support( 'post-formats', array(
'quote', 'link'
) );
load_theme_textdomain( 'bootplate', get_template_directory().'/languages' );
// Make translation ready
load_theme_textdomain('bootplate', get_template_directory(). '/languages');
$locale = get_locale();
$locale_file = get_template_directory() . "/languages/".$locale.".php";
if ( is_readable($locale_file) ) {
require_once($locale_file);
}
// Style the Editor to resemble the frontend
add_editor_style( array( 'css/editor-style.css') );
}// END setup function
} // END function_exists( 'bootplate_setup' )
add_action( 'after_setup_theme', 'bootplate_setup' );
/* Adds the Excerpts Field to Pages (for SERPS)
* See Issue: https://github.com/jdmdigital/bootplate/issues/106
* @since v1.9
*/
if(!function_exists('bootplate_add_excerpts_to_pages')) {
function bootplate_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
add_action( 'init', 'bootplate_add_excerpts_to_pages' );
}
/**
* Register widget areas.
*/
function bootplate_widgets_init() {
register_sidebar( array(
'name' => __('Footer Widget 1', 'bootplate'),
'id' => 'footer-1',
'description' => __('The first footer widget area.', 'bootplate'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => __('Footer Widget 2', 'bootplate'),
'id' => 'footer-2',
'description' => __('The second footer widget area.', 'bootplate'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => __('Footer Widget 3', 'bootplate'),
'id' => 'footer-3',
'description' => __('The third footer widget area.', 'bootplate'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => __('Footer Widget 4', 'bootplate'),
'id' => 'footer-4',
'description' => __('The fourth footer widget area.', 'bootplate'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => __('Blog Sidebar', 'bootplate'),
'id' => 'blog-sidebar',
'description' => __('Used for sidebar for blog post listings.', 'bootplate'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => __('Page Sidebar Right', 'bootplate'),
'id' => 'page-sidebar-right',
'description' => __('Used for pages using the Page - Sidebar RIGHT template.', 'bootplate'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => __('Page Sidebar Left', 'bootplate'),
'id' => 'page-sidebar-left',
'description' => __('Used for pages using the Page - Sidebar LEFT template.', 'bootplate'),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>',
) );
//include(get_template_directory() . '/inc/widgets.php');
//register_widget( 'bootplate_listgroup_widget' );
}
add_action( 'widgets_init', 'bootplate_widgets_init' );
/**
* Enqueue scripts and styles.
* Updated in v1.7
*/
function bootplate_scripts() {
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), null, 'all' );
// See Issue 49 - https://github.com/jdmdigital/bootplate/issues/49
$child_style = get_stylesheet();
if(!isset($child_style) || $child_style == '') {
$has_child_style = false;
} else {
$has_child_style = true;
}
if( get_theme_mod( 'minify_bootplate_css', 'unmin-bootplate-css' ) == 'min-bootplate-css') {$mincss = true;} else { $mincss = false; }
if( get_theme_mod( 'minify_bootplate_js', 'unmin-bootplate-js' ) == 'min-bootplate-js') {$minjs = true;} else { $minjs = false; }
if(is_child_theme() && $has_child_style) {
// Load Parent.css instead of the full style.css file (or the minified version).
if($mincss) {
wp_enqueue_style( 'bootplate', get_template_directory_uri() . '/css/parent.min.css', array('bootstrap'), bootplate_resource_version() );
} else {
wp_enqueue_style( 'bootplate', get_template_directory_uri() . '/css/parent.css', array('bootstrap'), bootplate_resource_version() );
}
if($mincss) {
wp_enqueue_style( $child_style, get_stylesheet_directory_uri() . '/style.min.css', array( 'bootstrap' ), bootplate_resource_version() );
} else {
wp_enqueue_style( $child_style, get_stylesheet_directory_uri() . '/style.css', array( 'bootstrap' ), bootplate_resource_version() );
}
} else {
// Using Parent Theme. Load full style.css (or the minified version).
if($mincss) {
wp_enqueue_style( 'bootplate', get_template_directory_uri() . '/style.min.css', array('bootstrap'), bootplate_resource_version() );
} else {
wp_enqueue_style( 'bootplate', get_stylesheet_uri(), array('bootstrap'), bootplate_resource_version() );
}
}
// Load the IE-specific stylesheet.
wp_enqueue_style( 'bootplate-ie', get_template_directory_uri() . '/css/ie.css', array( 'bootplate' ), null );
wp_style_add_data( 'bootplate-ie', 'conditional', 'lt IE 9' );
if(function_exists('jdmfab_show_admin_buttons')) {
wp_deregister_script( 'jdm-fab' );
}
wp_deregister_script( 'html5shiv-maxcdn' );
wp_register_script( 'html5shiv-maxcdn', '//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js', '', null, false );
wp_enqueue_script( 'html5shiv-maxcdn' );
wp_script_add_data( 'html5shiv-maxcdn', 'conditional', 'lt IE 9' );
wp_deregister_script( 'respond-js' );
wp_register_script( 'respond-js', '//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js', '', null, false );
wp_enqueue_script( 'respond-js' );
wp_script_add_data( 'respond-js', 'conditional', 'lt IE 9' );
if( get_theme_mod( 'cdn_jquery', 'jquery_cdn' ) == 'jquery_cdn') {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js', '', null, true );
wp_enqueue_script( 'jquery' );
wp_deregister_script( 'jquery-form' );
wp_register_script( 'jquery-form', '//cdnjs.cloudflare.com/ajax/libs/jquery.form/3.51/jquery.form.min.js', array('jquery'), null, true );
} else {
wp_enqueue_script( 'jquery' ); // latest version from core
}
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), null, true );
wp_enqueue_script( 'modernizr', get_template_directory_uri() . '/js/modernizr-custom.js', array('jquery'), null, true );
if($minjs) {
wp_enqueue_script( 'bootplate-plugins', get_template_directory_uri() . '/js/plugins.min.js', array('jquery', 'modernizr'), bootplate_resource_version(), true );
} else {
wp_enqueue_script( 'bootplate-plugins', get_template_directory_uri() . '/js/plugins.js', array('jquery', 'modernizr'), bootplate_resource_version(), true );
}
if(is_child_theme()) {
$child_js = $child_style.'-main';
if($minjs) {
wp_enqueue_script( $child_js, get_stylesheet_directory_uri() . '/js/main.min.js', array('jquery', 'modernizr', 'bootplate-plugins'), bootplate_resource_version(), true );
} else {
wp_enqueue_script( $child_js, get_stylesheet_directory_uri() . '/js/main.js', array('jquery', 'modernizr', 'bootplate-plugins'), bootplate_resource_version(), true );
}
} else {
// Using Parent Theme. Load full style.css (or the minified version).
if($minjs) {
wp_enqueue_script( 'bootplate', get_template_directory_uri() . '/js/main.min.js', array('jquery', 'modernizr', 'bootplate-plugins'), bootplate_resource_version(), true );
} else {
wp_enqueue_script( 'bootplate', get_template_directory_uri() . '/js/main.js', array('jquery', 'modernizr', 'bootplate-plugins'), bootplate_resource_version(), true );
}
}
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'bootplate_scripts' );
// Get rid of bloated styles
function bootplate_deregister_styles() {
wp_deregister_style( 'contact-form-7' );
wp_deregister_style('jdm-fab');
}
add_action( 'wp_print_styles', 'bootplate_deregister_styles', 100 );
// Remove Version Query String
if(!function_exists('bootplate_remove_ver_css_js')) {
function bootplate_remove_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
}
if( get_theme_mod( 'enable_browser_cache', 'no_browser_cache' ) == 'browser_cache') {
add_filter( 'style_loader_src', 'bootplate_remove_ver_css_js', 9999 );
add_filter( 'script_loader_src', 'bootplate_remove_ver_css_js', 9999 );
}
if(!function_exists('bootplate_resource_version')) {
function bootplate_resource_version() {
if( get_theme_mod( 'enable_browser_cache', 'no_browser_cache' ) == 'browser_cache') {
return null;
} else {
//return bootplate_info('stringver');
return VERSION;
}
}
}
// Remove oEmbed Gist Action
global $oe_gist;
remove_action( 'wp_head', array( $oe_gist, 'wp_head' ), 100 );
require get_template_directory() . '/inc/template-tags.php';
/*
* bootplate_get_post_link()
* This function essentially checks the post type and then returns the right link
* if it's standard (not Link post type) it's equivalent to esc_url( get_permalink() )
* otherwise, it'll use the built-in function get_url_in_content()
*
* @since v1.9
*/
if(!function_exists('bootplate_get_post_link')) {
function bootplate_get_post_link() {
if ( get_post_format( get_the_ID() ) == 'link' ) {
$content = get_the_content();
$has_url = get_url_in_content( $content );
if($has_url) {
return $has_url;
} else {
// Ok, maybe the user didn't link it. It's just a string in the form of a link...
// Try and get the URL another way.
//$links = wp_extract_urls($content) - doesn't work in this context
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $content, $urls);
if(isset($urls)) {
//print_r($urls[0]);
$url = $urls[0];
$url = implode('',$url);
return $url;
} else {
// I give up. Fallback.
return apply_filters( 'the_permalink', get_permalink() );
}
}
} else {
// Normal Post Format
return esc_url( get_permalink() );
}
}
} // endif function_exists
/* Function to detect if child theme has the appropriate file
* Arg $url = fully-qualified URL
* Returns TRUE if the file doesn't have 404/500 headers (non-existant) else FALSE
* @since Bootplate v 1.5
*/
if(!function_exists('bootplate_file_exists')) {
function bootplate_file_exists($url = '') {
if($url != '') {
$file_headers = get_headers($url);
$header_code = substr($file_headers[0], 9, 3);
//if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
if($header_code == '404' || $header_code == '500') {
return false;
} else {
return true;
}
} else {
return false;
}
}
}
// LoadCSS - Async Load of child theme's body.css (below the fold styles)
// Rewritten in v1.5
if(!function_exists('bootplate_async_css')) {
function bootplate_async_css() {
if(get_theme_mod( 'minify_bootplate_css', 'unmin-bootplate-css' ) == 'min-bootplate-css') {$bodycss = 'body.min.css';} else {$bodycss = 'body.css';}
if(get_theme_mod( 'minify_bootplate_js', 'unmin-bootplate-js' ) == 'min-bootplate-js') {$loadjs = 'loadcss.min.js';} else {$loadjs = 'loadcss.js';}
$childdir = get_stylesheet_directory_uri();
$parentdir = get_template_directory_uri();
// Default to child theme dir
$bodycss_dir = $childdir.'/css/'.$bodycss;
$loadjs_dir = $childdir.'/js/'.$loadjs;
// Check for body css
if(!bootplate_file_exists($bodycss_dir)) {$bodycss_dir = $parentdir.'/css/'.$bodycss;}
// Check for loadcss js
if(!bootplate_file_exists($loadjs_dir)) {$loadjs_dir = $parentdir.'/js/'.$loadjs;}
echo '
<!-- bootplate_async_css v1.5 -->
<link rel="preload" href="'.$bodycss_dir.'" as="style" onload="this.rel=\'stylesheet\'" type="text/css" />
<noscript><link rel="stylesheet" href="'.$bodycss_dir.'" type="text/css" /></noscript>
<script src="'.$loadjs_dir.'" type="text/javascript"></script>
';
}
}
/* Basic Bootplate SEO tags in header
* Does nothing if SEO plugin is installed and activated
* @since Bootplate v0.5
*
* TESTS FOR:
* - SEO Ultimate: https://wordpress.org/plugins/seo-ultimate/
* - Yoast: https://wordpress.org/plugins/wordpress-seo/
* - Stallion: https://wordpress.org/plugins/stallion-wordpress-seo-plugin/
* - Squirrley: https://wordpress.org/plugins/squirrly-seo/
* - seo-wizard: https://wordpress.org/plugins/seo-wizard/
* - WP Meta SEO: https://wordpress.org/plugins/wp-meta-seo/
*/
if(!function_exists('have_seo')) {
function have_seo($info = 'have'){
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if(is_plugin_active('seo-ultimate/seo-ultimate.php')) {
$seoplugin = true;
$pluginname = 'seo-ultimate';
} elseif(is_plugin_active('wordpress-seo/wp-seo.php')) {
$seoplugin = true;
$pluginname = 'wordpress-seo';
} elseif(is_plugin_active('stallion-wordpress-seo-plugin/stallion-wordpress-seo-plugin.php')) {
$seoplugin = true;
$pluginname = 'stallion-wordpress-seo-plugin';
} elseif(is_plugin_active('squirrly-seo/squirrly.php')) {
$seoplugin = true;
$pluginname = 'squirrly-seo';
} elseif(is_plugin_active('seo-wizard/wp-seo-wizard.php')) {
$seoplugin = true;
$pluginname = 'seo-wizard';
} elseif(is_plugin_active('wp-meta-seo/wp-meta-seo.php')) {
$seoplugin = true;
$pluginname = 'wp-meta-seo';
} else {
$seoplugin = false;
$pluginname = '';
}
if(isset($info) && $info == 'name'){
return $pluginname;
} else {
return $seoplugin;
}
}
}
if(!function_exists('bootplate_meta')) {
function bootplate_meta(){
if(!have_seo()) {
// Let's do the work
global $post, $page;
$metadescription = bootplate_get_meta_description();
echo '<meta name="description" content="'.$metadescription.'" />'."\r\n";
echo ' <meta name="author" content="'.get_bootplate_formal_name().'" />'."\r\n";
echo ' <meta itemprop="name" content="'.esc_url(get_home_url()).'" />'."\r\n";
echo ' <meta itemprop="description" content="'.$metadescription.'" />'."\r\n";
echo ' <meta property="og:site_name" content="'.get_bloginfo('name').'" />'."\r\n";;
echo ' <meta property="og:title" content="'.esc_url(get_home_url()).'" />'."\r\n";
echo ' <meta property="og:description" content="'.$metadescription.'" />'."\r\n";
echo ' <meta property="og:url" content="'.get_home_url().'" />'."\r\n";
echo ' <meta name="apple-mobile-web-app-capable" content="yes">'."\r\n";
echo ' <meta name="apple-mobile-web-app-status-bar-style" content="black">'."\r\n";
echo ' <meta name="apple-mobile-web-app-title" content="'.get_bloginfo('name').'">'."\r\n";
echo ' <meta name="robots" content="noodp"/>'."\r\n";
} else {
// Let the plugin do the work, but add the apple-mobile-web-app stuff
echo '<meta name="apple-mobile-web-app-capable" content="yes">'."\r\n";
echo ' <meta name="apple-mobile-web-app-status-bar-style" content="black">'."\r\n";
echo ' <meta name="apple-mobile-web-app-title" content="'.get_bloginfo('name').'">'."\r\n";
}
}
}
// Returns content for a meta description
if(!function_exists('bootplate_get_meta_description')) {
function bootplate_get_meta_description() {
$maxlength = 155;
$rawcontent = get_the_content();
if(empty($rawcontent)) {
$rawcontent = htmlentities(get_bloginfo('description'));
} else {
$rawcontent = apply_filters('the_content_rss', strip_tags($rawcontent));
$rawcontent = preg_replace('/\[.+\]/','', $rawcontent);
$chars = array("", "\n", "\r", "chr(13)", "\t", "\0", "\x0B");
$rawcontent = htmlentities(str_replace($chars, " ", $rawcontent));
}
if (strlen($rawcontent) < $maxlength) {
return $rawcontent;
} else {
$desc = substr($rawcontent,0,$maxlength);
return $desc;
}
}
}
// AMP CSS Action
// Depends on https://github.com/Automattic/amp-wp/
if(!function_exists('bootplate_amp_css')) {
function bootplate_amp_css( $amp_template ) {
/*include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if(is_plugin_active('amp/amp.php')) {
add_action( 'amp_post_template_css', 'bootplate_amp_css' );
}*/
// only CSS here please...
?>
/* Bootplate Styles */
html body{font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; color: #555; font-size: 18px; font-weight: 300; line-height: 1.4;}
body nav.amp-wp-title-bar {background-color: #6f5499;}
body .amp-wp-meta, body .amp-wp-meta a, body a{color: #6f5499;}
body .amp-wp-title{color:#000;}
body .amp-wp-content{color:#333;}
body blockquote{background: #eeeeee none repeat scroll 0 0; border-left: 4px solid #888; color: #222;}
<?php
}
add_action( 'amp_post_template_css', 'bootplate_amp_css' );
}
// Nicer Search - Creates a specific /search/ page instead of index.php?s=, which confuses google.
if(!function_exists('bootplate_nice_search_redirect') && !function_exists('bootplate_change_ssb_search')) {
function bootplate_nice_search_redirect() {
global $wp_rewrite;
if ( !isset( $wp_rewrite ) || !is_object( $wp_rewrite ) || !$wp_rewrite->using_permalinks() )
return;
$search_base = $wp_rewrite->search_base;
if ( is_search() && !is_admin() && strpos( $_SERVER['REQUEST_URI'], "/{$search_base}/" ) === false ) {
wp_redirect( home_url( "/{$search_base}/" . urlencode( get_query_var( 's' ) ) ) );
exit();
}
}
// For Yoast SEO URL Fix: https://github.com/jdmdigital/bootplate/issues/31
// The returned string must always include {search_term} to indicate where the search term should be used.
// @returns string new searchURL
function bootplate_change_ssb_search() {
global $wp_rewrite;
if ( !isset( $wp_rewrite ) || !is_object( $wp_rewrite ) || !$wp_rewrite->using_permalinks() )
return;
$search_base = $wp_rewrite->search_base;
return home_url("/{$search_base}/").'{search_term}';
//return 'http://mysite.com/?search={search_term}';
}
// Add_Action ONLY if the Enable Search is = 1
if(get_theme_mod( 'bootplate_enable_search', '') == 1) {
if(function_exists('wpseo_init')) {
// For Yoast SEO URL Fix: https://github.com/jdmdigital/bootplate/issues/31
add_filter('wpseo_json_ld_search_url', 'bootplate_change_ssb_search' );
}
add_action( 'template_redirect', 'bootplate_nice_search_redirect' );
}
}
if ( ! function_exists( 'bootplate_comment_nav' ) ) :
/**
* Display navigation to next/previous comments when applicable.
* based on: Twenty Fifteen 1.0
*/
function bootplate_comment_nav() {
// Are there comments to navigate through?
if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
?>
<div class="navigation comment-navigation" role="navigation">
<ul class="pager">
<?php
if ( $prev_link = get_previous_comments_link( '<span class="bp-left-open"></span>' ) ) {
printf( '<li class="pager-prev" title="'.__('Older Comments', 'bootplate').'">%s</li>', $prev_link );
} else {
echo '<li class="pager-prev disabled" title="'.__('Older Comments', 'bootplate').'"><a><span class="bp-left-open"></span></a></li>';
}
if ( $next_link = get_next_comments_link( '<span class="bp-right-open"></span>' ) ) {
printf( '<li class="pager-next" title="'.__('Newer Comments', 'bootplate').'">%s</li>', $next_link );
} else {
echo '<li class="pager-next disabled" title="'.__('Newer Comments', 'bootplate').'"><a><span class="bp-right-open"></span></a></li>';
}
?>
</ul><!-- .nav-links -->
</div><!-- .comment-navigation -->
<?php
endif;
}
endif;
if(!function_exists('is_comment_child')) {
function is_comment_child( $comment_ID = 0 ) { // recursive depth check
global $wpdb;
$comment = get_comment( $comment_ID );
$parent = $comment->comment_parent;
if ( ( 0 == $parent ) || ( bootplate_comment_parent_trashed( $comment ) ) ) // must NOT use '===' because empty result, where we do not have a comment parent at all because it has been deleted, needs to evaluate as true
return false;
else return true ;
}
// Function: Do parents actually exist?
function bootplate_comment_parents_exist( $comment_ID = 0 ) { // explicit check for comments with deleted parents
global $wpdb;
$comment = get_comment( $comment_ID );
$parent = $comment->comment_parent;
if ( $parent == '' ) return false;
elseif ( bootplate_comment_parent_trashed( $comment ) ) return false;
elseif ( 0 == $parent ) return true;
else return bootplate_comment_parents_exist( $parent );
}
// Function: Is parent in the trash?
function bootplate_comment_parent_trashed( $comment ) { // check if comment's immediate parent is in trash
global $wpdb;
$parent = $comment->comment_parent;
if ( '' == $parent ) return false; // no parent, no trash
$approval = get_comment( $parent ); // have to do this in two steps for PHP4 compatibility
$approval = $approval->comment_approved;
if ( $approval == 'trash' ) return true;
else return false;
}
function bootplate_comment_classes ($col = 1) {
if(is_comment_child(get_comment_ID())) {
if($col == 1) {
echo 'col-md-2 col-sm-2 col-md-offset-1 col-sm-offset-0 hidden-xs';
} else {
echo 'col-md-9 col-sm-9';
}
} else {
if($col == 1) {
echo 'col-md-2 col-sm-2 hidden-xs';
} else {
echo 'col-md-10 col-sm-10';
}
}
}
}
if(!function_exists('bootplate_comments')) {
function bootplate_comments($comment, $args, $depth) {
//$tag = 'div';
$add_below = 'artcomm';
if(get_comment_author_url() != '' && get_theme_mod( 'bootplate_enable_comments_url', '') == 1) {
$commentlink = true;
$commentlinkurl = get_comment_author_url();
} else {
$commentlink = false;
}
?>
<article id="comment-<?php comment_ID(); ?>" class="row artcomm">
<div class="<?php bootplate_comment_classes(1); ?>">
<figure class="thumbnail">
<?php echo get_avatar( $comment, 80 ); ?>
</figure>
</div>
<div class="<?php bootplate_comment_classes(2); ?>">
<div class="panel panel-default arrow left">
<div class="panel-body">
<header class="text-left">
<div class="comment-user">
<?php if($commentlink) : ?>
<a href="<?php echo $commentlinkurl; ?>" target="_blank" rel="nofollow"><b><?php comment_author(); ?></b></a>
<?php else : ?>
<b><?php comment_author(); ?></b>
<?php endif; ?>
</div>
<time class="comment-date" datetime="<?php printf( __('%1$s %2$s', 'bootplate'), get_comment_date(), get_comment_time() ); ?>"><?php printf( __('%1$s at %2$s', 'bootplate'), get_comment_date(), get_comment_time() ); ?></time>
</header>
<div class="comment-post<?php if ( $comment->comment_approved == '0' ) {echo ' in-moderation'; } ?>">
<?php comment_text(); ?>
</div>
<?php if ( $comment->comment_approved == '0' ) : ?>
<p class="text-right text-info no-margin-bottom"><?php _e('Your comment is awaiting moderation.', 'bootplate'); ?></p>
<?php else : ?>
<p class="text-right no-margin-bottom"><?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => 2 ) ) ); ?> <?php edit_comment_link( __( 'edit', 'bootplate' ), ' ', '' ); ?></p>
<?php endif; ?>
</div><!--/panel-body-->
</div><!--/.panel-default-->
</div><!--/.col-md-10-->
</article><!-- /.artcomm -->
<?php // End function
}
}
if(!function_exists('bootplate_comments_end')) {
function bootplate_comments_end() {
echo '<!--bootplate_comment_end-->';
}
}// end if !exists
/*
* Retrieve paginated link for archive post pages BUT use Bootstrap class name.
* Based on paginate_links() in wp-includes/general-template.php#L1988
*/
if(!function_exists('bootplate_paginate_links')) {
function bootplate_paginate_links( $args = '' ) {
global $wp_query, $wp_rewrite;
// Setting up default values based on the current URL.
$pagenum_link = html_entity_decode( get_pagenum_link() );
$url_parts = explode( '?', $pagenum_link );
// Get max pages and current page out of the current query, if available.
$total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
$current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
// Append the format placeholder to the base URL.
$pagenum_link = trailingslashit( $url_parts[0] ) . '%_%';
// URL base depends on permalink settings.
$format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
$defaults = array(
'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
'format' => $format, // ?page=%#% : %#% is replaced by the page number
'total' => $total,
'current' => $current,
'show_all' => false,
'prev_next' => true,
'prev_text' => __('« Previous', 'bootplate'),
'next_text' => __('Next »', 'bootplate'),
'end_size' => 1,
'mid_size' => 2,
'type' => 'plain',
'add_args' => array(), // array of query args to add
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
);
$args = wp_parse_args( $args, $defaults );
if ( ! is_array( $args['add_args'] ) ) {
$args['add_args'] = array();
}
// Merge additional query vars found in the original URL into 'add_args' array.
if ( isset( $url_parts[1] ) ) {
// Find the format argument.
$format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) );
$format_query = isset( $format[1] ) ? $format[1] : '';
wp_parse_str( $format_query, $format_args );
// Find the query args of the requested URL.
wp_parse_str( $url_parts[1], $url_query_args );
// Remove the format argument from the array of query arguments, to avoid overwriting custom format.
foreach ( $format_args as $format_arg => $format_arg_value ) {
unset( $url_query_args[ $format_arg ] );
}
$args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) );
}
// Who knows what else people pass in $args
$total = (int) $args['total'];
if ( $total < 2 ) {
return;
}
$current = (int) $args['current'];
$end_size = (int) $args['end_size']; // Out of bounds? Make it the default.
if ( $end_size < 1 ) {
$end_size = 1;
}
$mid_size = (int) $args['mid_size'];
if ( $mid_size < 0 ) {
$mid_size = 2;
}
$add_args = $args['add_args'];
$r = '';
$page_links = array();
$dots = false;
if ( $args['prev_next'] && $current && 1 < $current ) :
$link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] );
$link = str_replace( '%#%', $current - 1, $link );
if ( $add_args )
$link = add_query_arg( $add_args, $link );
$link .= $args['add_fragment'];
/**
* Filter the paginated links for the given archive pages.
*
* @since 3.0.0
*
* @param string $link The paginated link URL.
*/
$page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>';
endif;
for ( $n = 1; $n <= $total; $n++ ) :
if ( $n == $current ) :
$page_links[] = "<span class='page-numbers current'><span class='sr-only screen-reader-text'>(current) </span>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
$dots = true;
else :
if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
$link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
$link = str_replace( '%#%', $n, $link );
if ( $add_args )
$link = add_query_arg( $add_args, $link );
$link .= $args['add_fragment'];
/** This filter is documented in wp-includes/general-template.php */
$page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</a>";
$dots = true;
elseif ( $dots && ! $args['show_all'] ) :
$page_links[] = '<span class="page-numbers dots">' . __( '…', 'bootplate' ) . '</span>';
$dots = false;
endif;
endif;
endfor;
if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) :
$link = str_replace( '%_%', $args['format'], $args['base'] );
$link = str_replace( '%#%', $current + 1, $link );
if ( $add_args )
$link = add_query_arg( $add_args, $link );
$link .= $args['add_fragment'];
/** This filter is documented in wp-includes/general-template.php */
$page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>';
endif;
switch ( $args['type'] ) {
case 'array' :
return $page_links;
case 'list' :
$r .= "<ul class='pagination pagination-lg'>\n\t<li>";
$r .= join("</li>\n\t<li>", $page_links);
$r .= "</li>\n</ul>\n";
break;
default :
$r = join("\n", $page_links);
break;
}
return $r;
} // end bootplate_paginate_links()
}// end if !exists
// Echo Breadcrumbs if Yoast SEO is installed
if(!function_exists('bootplate_breadcrumbs') ) {
function bootplate_breadcrumbs() {
if ( function_exists('yoast_breadcrumb') && function_exists('downey_bootplate_breadcrumbs') ) {
echo downey_bootplate_breadcrumbs();
//
} elseif (function_exists('yoast_breadcrumb') && !function_exists('downey_bootplate_breadcrumbs')) {
yoast_breadcrumb('<p id="breadcrumbs" class="breadcrumb">','</p>');
} else {
echo '<!--No theme-generated breadcrumbs-->';
}
} // END function bootplate_breadcrumbs()
}
// Detect and USE functions from a few subtitle plugins
/* Supports:
* WP Subtitle (recommended) - https://wordpress.org/plugins/wp-subtitle/
* KIA Subtitle - https://wordpress.org/plugins/kia-subtitle/
* Secondary Title - https://wordpress.org/plugins/secondary-title/
*/
// Returns BOOL if a subtitle plugin is installed and active.
// Optional param $info.
// Use have_bootplate_subtitle('name') to return the name of the active plugin
// Leave blank to return a BOOL (if ANY is installed an active)
if(!function_exists('have_bootplate_subtitle')) {
function have_bootplate_subtitle($info = ''){
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if($info == 'name') {
$subtitleplugin = '';
if(is_plugin_active('wp-subtitle/wp-subtitle.php')) {
$subtitleplugin = 'wp-subtitle';
} elseif (is_plugin_active('kia-subtitle/kia-subtitle.php')) {
$subtitleplugin = 'kia-subtitle';
} elseif (is_plugin_active('secondary-title/secondary-title.php')) {
$subtitleplugin = 'secondary-title';
}
} else {
if(is_plugin_active('wp-subtitle/wp-subtitle.php')) {
$subtitleplugin = true;
} elseif (is_plugin_active('kia-subtitle/kia-subtitle.php')) {
$subtitleplugin = true;
} elseif (is_plugin_active('secondary-title/secondary-title.php')) {
$subtitleplugin = true;
} else {
$subtitleplugin = false;
}
}
return $subtitleplugin;
}
}
// Detects the kind of subtitle plugin used, and uses their display function
/* Supports:
* WP Subtitle (recommended) - https://wordpress.org/plugins/wp-subtitle/
* KIA Subtitle - https://wordpress.org/plugins/kia-subtitle/
* Secondary Title - https://wordpress.org/plugins/secondary-title/
*/
if(!function_exists('bootplate_subtitle')) {
function bootplate_subtitle(){
global $post;
//$id = get_the_ID();
if(have_bootplate_subtitle('name') == 'wp-subtitle') {
echo get_the_subtitle($post->ID, '<p>', '</p>', false);
} elseif(have_bootplate_subtitle('name') == 'kia-subtitle') {
echo '<p>'.get_the_subtitle($post->ID).'</p>';
} elseif(have_bootplate_subtitle('name') == 'secondary-title') {
echo get_secondary_title($post->ID, '<p>', '</p>');
}
}
}
if(!function_exists('have_bootplate_btns')) {
function have_bootplate_btns() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if(is_plugin_active('jdm-cta-buttons/jdm-cta-buttons.php') || is_plugin_active('bootplate-cta-buttons/bootplate-cta-buttons.php')) {
return true;
} else {
return false;
}
}
}
/* Featured Image Functions
* @since v0.6
*/
// Adds classes to <header>, usage: <header class="<php echo header_classes() endPHP >
// Will add .has-featured-image to header if there's a featured image set.
if(!function_exists('header_classes')) {
function header_classes() {
$id = get_the_id();
$headerclasses = 'jumbotron jumbotron-fluid bg-custom';
if(is_page_template('page-fullheight.php') || is_page_template('page-homepage.php') || is_page_template('page-search.php')) {
$headerclasses .= ' full-height text-center';
}
if(is_page_template('page-thirdheight.php')) {
$headerclasses .= ' full-height vh33';
}
if(is_page_template('page-twothirdheight.php')) {
$headerclasses .= ' full-height vh66';
}
if ( has_post_thumbnail($id) ) {
$headerclasses .= ' has-featured-image';
}
return $headerclasses;
}
}
if(!function_exists('get_featured_image')) {
function get_featured_image($id = 0, $size = 'full') {
if($id == 0){
$id = get_the_id();
}
if ( has_post_thumbnail($id) ) {
// Has one. return the img src.
$imgsrc = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $size);