This repository was archived by the owner on Jul 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
722 lines (573 loc) · 18.7 KB
/
functions.php
File metadata and controls
722 lines (573 loc) · 18.7 KB
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
<?php
/**
* Lenscap functions and definitions
*
* @package Lenscap
*/
if ( ! function_exists( 'lenscap_setup' ) ) :
/**
* Sets up Lenscap's defaults and registers support for various WordPress features
*/
function lenscap_setup() {
/**
* Load Getting Started page and initialize theme updater
*/
require_once( get_template_directory() . '/inc/admin/updater/theme-updater.php' );
/**
* TGM activation class
*/
require_once get_template_directory() . '/inc/admin/tgm/tgm-activation.php';
/**
* Add styles to post editor (editor-style.css)
*/
add_editor_style( array( 'editor-style.css', lenscap_fonts_url() ) );
/*
* Make theme available for translation
*/
load_theme_textdomain( 'lenscap', get_template_directory() . '/languages' );
/**
* Add default posts and comments RSS feed links to head
*/
add_theme_support( 'automatic-feed-links' );
/*
* Post thumbnail support and image sizes
*/
add_theme_support( 'post-thumbnails' );
/*
* Add title output
*/
add_theme_support( 'title-tag' );
// Index post image
add_image_size( 'lenscap-index-thumb', 600, 450, true );
// Index post image
add_image_size( 'lenscap-index-full-thumb', 1200, 900, true );
// Featured image
add_image_size( 'lenscap-featured-image', 1100 );
// Grid thumbnail
add_image_size( 'lenscap-grid-thumb', 375, 250, true );
// Grid thumbnail tall
add_image_size( 'lenscap-grid-thumb-tall', 600, 800, true );
// Testimonial avatar
add_image_size( 'lenscap-testimonial-avatar', 100, 100, true );
// Hero background image
add_image_size( 'lenscap-hero', 1400 );
add_image_size( 'lenscap-hero-tablet', 800 );
add_image_size( 'lenscap-hero-mobile', 600 );
// Hero pager thumb
add_image_size( 'lenscap-hero-thumb', 50, 50, true );
// Logo size
add_image_size( 'lenscap-logo', 300 );
/**
* Register Navigation menu
*/
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'lenscap' ),
'social' => esc_html__( 'Social Icon Menu', 'lenscap' ),
'category-footer' => esc_html__( 'Footer Category Menu', 'lenscap' ),
'footer' => esc_html__( 'Footer Menu', 'lenscap' ),
) );
/**
* Add Site Logo feature
*/
add_theme_support( 'custom-logo', array(
'header-text' => array( 'titles-wrap' ),
'size' => 'lenscap-logo',
) );
/**
* Enable HTML5 markup
*/
add_theme_support( 'html5', array(
'comment-form',
'gallery',
) );
/**
* Enable post formats
*/
add_theme_support( 'post-formats', array( 'video', 'gallery' ) );
/**
* Enable WooCommerce gallery
*/
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
/**
* Mobile Detect
*/
if ( ! class_exists( 'Mobile_Detect' ) ) {
require_once( get_template_directory() . '/inc/mobile/Mobile_Detect.php' );
}
/**
* Include WooCommerce functions and styles
*/
add_theme_support( 'woocommerce' );
if ( class_exists( 'WooCommerce' ) ) {
require_once( get_template_directory() . '/woocommerce/woo-functions.php' );
}
}
endif; // lenscap_setup
add_action( 'after_setup_theme', 'lenscap_setup' );
/**
* Set the content width based on the theme's design and stylesheet
*/
function lenscap_content_width() {
if ( has_post_format( 'gallery' ) ) {
$GLOBALS['content_width'] = apply_filters( 'lenscap_content_width', 1100 );
} else {
$GLOBALS['content_width'] = apply_filters( 'lenscap_content_width', 925 );
}
}
add_action( 'after_setup_theme', 'lenscap_content_width', 0 );
/**
* Gets the gallery shortcode data from post content.
*/
function lenscap_gallery_data() {
global $post;
$pattern = get_shortcode_regex();
if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches )
&& in_array( 'gallery', $matches[2] ) )
{
return $matches;
}
}
/**
* If the post has a carousel gallery, remove the first gallery from the post
*
* @since lenscap 1.0
*/
function lenscap_filtered_content() {
global $post, $wp_embed;
$content = get_the_content( esc_html__( 'Read More', 'lenscap' ) );
if ( has_post_format( 'gallery' ) ) {
$gallery_data = lenscap_gallery_data();
// Remove the first gallery from the post since we're using it in place of the featured image
if ( $gallery_data && is_array( $gallery_data ) ) {
$content = str_replace( $gallery_data[0][0], '', $content );
}
}
if ( has_post_format( 'video' ) ) {
// Remove the first video embed from the post since we're using it in place of the featured image
if ( ! empty( $wp_embed->last_url ) ) {
$content = str_replace( $wp_embed->last_url, '', $content );
} else {
$video = get_media_embedded_in_content( $content );
$content = str_replace( $video, '', $content );
}
}
echo apply_filters( 'the_content', $content );
}
/**
* Register widget area
*/
function lenscap_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'lenscap' ),
'id' => 'sidebar',
'description' => esc_html__( 'Widgets added here will appear on the sidebar of posts and pages.', 'lenscap' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer - Column 1', 'lenscap' ),
'id' => 'footer-1',
'description' => esc_html__( 'Widgets added here will appear in the left column of the footer.', 'lenscap' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer - Column 2', 'lenscap' ),
'id' => 'footer-2',
'description' => esc_html__( 'Widgets added here will appear in the center column of the footer.', 'lenscap' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer - Column 3', 'lenscap' ),
'id' => 'footer-3',
'description' => esc_html__( 'Widgets added here will appear in the right column of the footer.', 'lenscap' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer - Column 4', 'lenscap' ),
'id' => 'footer-4',
'description' => esc_html__( 'Widgets added here will appear in the right column of the footer.', 'lenscap' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'lenscap_widgets_init' );
/**
* Return the Google font stylesheet URL
*/
function lenscap_fonts_url() {
$fonts_url = '';
/* Translators: If there are characters in your language that are not
* supported by Archivo Narrow, translate this to 'off'. Do not translate
* into your own language.
*/
$archivo = esc_html_x( 'on', 'Archivo Narrow font: on or off', 'lenscap' );
/* Translators: If there are characters in your language that are not
* supported by Roboto, translate this to 'off'. Do not translate
* into your own language.
*/
$roboto = esc_html_x( 'on', 'Roboto font: on or off', 'lenscap' );
if ( 'off' !== $archivo || 'off' !== $roboto ) {
$font_families = array();
if ( 'off' !== $archivo )
$font_families[] = 'Archivo Narrow:400,700';
if ( 'off' !== $roboto )
$font_families[] = 'Roboto:400,500,700,300,400italic';
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, "//fonts.googleapis.com/css" );
}
return $fonts_url;
}
/**
* Enqueue scripts and styles
*/
function lenscap_scripts() {
wp_enqueue_style( 'lenscap-style', get_stylesheet_uri() );
/**
* Load fonts from Google
*/
wp_enqueue_style( 'lenscap-fonts', lenscap_fonts_url(), array(), null );
/**
* FontAwesome Icons stylesheet
*/
wp_enqueue_style( 'font-awesome', get_template_directory_uri() . "/inc/fontawesome/css/fontawesome-all.css", array(), '5.0.10', 'screen' );
/**
* Include WooCommerce functions and styles
*/
if ( class_exists( 'WooCommerce' ) ) {
wp_enqueue_style( 'lenscap-woocommerce-style', get_template_directory_uri() . "/woocommerce/lenscap-woo.css", array(), '1.0.9', 'screen' );
}
/**
* Load Lenscap's javascript
*/
wp_enqueue_script( 'lenscap-js', get_template_directory_uri() . '/js/lenscap.js', array( 'jquery' ), '1.0', true );
/**
* Load responsiveSlides javascript
*/
wp_enqueue_script( 'responsive-slides', get_template_directory_uri() . '/js/responsiveslides.js', array(), '1.54', true );
/**
* Load fitvids javascript
*/
wp_enqueue_script( 'fitvids', get_template_directory_uri() . '/js/jquery.fitvids.js', array(), '1.1', true );
/**
* Load touchSwipe javascript
*/
wp_enqueue_script( 'touchSwipe', get_template_directory_uri() . '/js/jquery.touchSwipe.js', array(), '1.6.6', true );
/**
* Load Waypoints
*/
wp_enqueue_script( 'waypoints', get_template_directory_uri() . '/js/jquery.waypoints.js', array(), '4.0.0', true );
wp_enqueue_script( 'waypoints-sticky', get_template_directory_uri() . '/js/sticky.js', array(), '4.0.0', true );
/**
* Localizes the lenscap-js file
*/
wp_localize_script( 'lenscap-js', 'lenscap_js_vars', array(
'ajaxurl' => admin_url( 'admin-ajax.php' )
) );
/**
* Load the comment reply script
*/
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'lenscap_scripts' );
/**
* Custom template tags for Lenscap
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer theme options
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* Modify search form for drawer
*/
function lenscap_big_search( $form ) {
$categories = get_categories(); ?>
<div class="big-search">
<form method="get" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>" role="search">
<label class="screen-reader-text" for="s"><?php esc_html_e( 'Search for:', 'lenscap' ); ?></label>
<input type="text" name="s" class="big-search" placeholder="<?php esc_html_e( 'Search here...', 'lenscap' ); ?>" value="<?php echo esc_attr( get_search_query() ); ?>" onfocus="if(this.value==this.getAttribute('placeholder'))this.value='';" onblur="if(this.value=='')this.value=this.getAttribute('placeholder');"/><br />
<div class="search-controls">
<?php
/**
* Check if we have categories to show
*/
if ( $categories ) { ?>
<div class="search-select-wrap">
<select class="search-select" name="category_name">
<option value=""><?php esc_html_e( 'Entire Site', 'lenscap' ); ?></option>
<?php
/**
* Generate list of categories
*/
foreach ( $categories as $category ) {
echo '<option value="' . esc_attr( $category->slug ) . '">', $category->name, "</option>";
}
?>
</select>
</div>
<?php } ?>
<input type="submit" class="submit button" name="submit" id="big-search-submit" value="<?php esc_attr_e( 'Search', 'lenscap' ); ?>" />
</div><!-- .search-controls -->
</form><!-- #big-searchform -->
</div><!-- .big-search -->
<?php }
/**
* Add button class to next/previous post links
*/
function lenscap_posts_link_attributes() {
return 'class="button"';
}
add_filter( 'next_posts_link_attributes', 'lenscap_posts_link_attributes' );
add_filter( 'previous_posts_link_attributes', 'lenscap_posts_link_attributes' );
/**
* Add layout style class to body
*/
function lenscap_layout_class( $classes ) {
// Add a layout class
if ( 'full-post' === get_option( 'lenscap_layout_style', 'excerpt' ) ) {
$classes[] = 'full-post-view';
} else {
$classes[] = 'excerpt-view';
}
// Adds a class of group-blog to blogs with more than 1 published author.
if ( is_multi_author() ) {
$classes[] = 'group-blog';
}
// Add a featured content class
if ( lenscap_has_featured_posts( 1 ) ) {
$classes[] = 'has-featured-content';
}
// Add a featured content class
if ( ! is_active_sidebar( 'sidebar' ) ) {
$classes[] = 'no-sidebar';
}
return $classes;
}
add_filter( 'body_class', 'lenscap_layout_class' );
/**
* Add post class to drawer posts
*/
function lenscap_grid_class( $classes ) {
$classes[] = 'grid-post';
return $classes;
}
/**
* Add post class index posts
*/
function lenscap_index_class( $classes ) {
$classes[] = 'index-post';
return $classes;
}
/**
* Add featured image class to posts
*/
function lenscap_featured_image_class( $classes ) {
$classes[] = 'post';
// Check for featured image
$classes[] = has_post_thumbnail() ? 'with-featured-image' : 'without-featured-image';
return $classes;
}
add_filter( 'post_class', 'lenscap_featured_image_class' );
/**
* Adjust the grid excerpt length based on customizer setting
*/
function lenscap_extend_excerpt_length( $length ) {
$excerpt_length = get_theme_mod( 'lenscap_grid_excerpt_length', '35' );
return get_theme_mod( 'lenscap_grid_excerpt_length', $excerpt_length );
}
/**
* Adjust the featured content item excerpt length
*/
function lenscap_featured_excerpt( $length ) {
$excerpt_length = get_theme_mod( 'lenscap_featured_excerpt_length', '40' );
return get_theme_mod( 'lenscap_featured_excerpt_length', $excerpt_length );
}
/**
* Add an ellipsis read more link
*/
function lenscap_excerpt_more( $more ) {
return ' <a class="read-more" href="'. esc_url( get_permalink( get_the_ID() ) ) . '">...</a>';
}
add_filter( 'excerpt_more', 'lenscap_excerpt_more' );
/**
* Full size image on attachment pages
*/
function lenscap_attachment_size($p) {
if ( is_attachment() ) {
return '<p>' . wp_get_attachment_link( 0, 'full-size', false ) . '</p>';
}
}
add_filter( 'prepend_attachment', 'lenscap_attachment_size' );
/**
* Get the first letter of the post, used on fallback images
*
* @since lenscap 1.0
*/
function lenscap_get_first_letter() {
$get_title = get_the_title();
$ltr_group = substr($get_title, 0, 1);
echo $ltr_group;
}
/**
* Adds a data-object-id attribute to nav links for category mega menu
*
* @return array $atts The HTML attributes applied to the menu item's <a> element
*/
function lenscap_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
if ( 'category' === $item->object ) {
$atts['data-object-id'] = $item->object_id;
}
return $atts;
}
/**
* Filters the current menu item to add another class.
* Used to restore the active state when using the mega menu.
*/
function lenscap_nav_menu_css_class( $item, $args, $depth ) {
if ( in_array( 'current-menu-item', $item ) ) {
$item[] = 'current-menu-item-original';
}
return $item;
}
/**
* Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
*
* @param array $args Configuration arguments.
* @return array
*/
function lenscap_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'lenscap_page_menu_args' );
/**
* Fetches the posts for the mega menu posts
*/
function lenscap_menu_category_query() {
$term_html = '';
$output = '';
$id = ( ! empty( $_POST['id' ] ) ) ? $_POST['id'] : '';
if ( ! empty( $id ) ) {
$term = get_term( (int) $id, 'category' );
}
if ( ! empty( $term ) && ! is_wp_error( $term ) ) {
$args = array(
'posts_per_page' => '4',
'post_type' => 'post',
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => (int) $id
)
)
);
$posts = new WP_Query( $args );
if ( $posts->have_posts() ) {
ob_start();
while( $posts->have_posts() ) {
$posts->the_post();
add_filter( 'post_class', 'lenscap_grid_class' );
get_template_part( 'template-parts/content-category-item' );
remove_filter( 'post_class', 'lenscap_grid_class' );
}
$output = ob_get_clean();
}
}
wp_send_json( array(
'html' => $output
) );
}
add_action( 'wp_ajax_lenscap_category', 'lenscap_menu_category_query' );
add_action( 'wp_ajax_nopriv_lenscap_category', 'lenscap_menu_category_query' );
/**
* Adds the menu item filters
*/
function lenscap_mega_menu_check() {
add_filter( 'nav_menu_css_class', 'lenscap_nav_menu_css_class', 10, 3 );
add_filter( 'nav_menu_link_attributes', 'lenscap_nav_menu_link_attributes', 10, 4 );
}
add_action( 'template_redirect', 'lenscap_mega_menu_check' );
/**
* Mega menu fallback
*/
function lenscap_fallback_category_menu() {
$args = array(
'orderby' => 'count',
'order' => 'DESC',
'hide_empty' => 'true'
);
$categories = get_categories( $args );
$count=0;
echo "<ul id='footer-category-menu' class='sort-list'>";
foreach( $categories as $category ) {
$count++;
echo '<li class="menu-item menu-item-' . esc_attr( $category->term_id ) . '"><a href="' . esc_url( get_category_link( $category->term_id ) ) . '" title="' . sprintf( esc_html__( "View all posts in %s", 'lenscap' ), $category->name ) . '" ' . ' data-object-id=" ' . esc_attr( $category->term_id ) . ' ">' . esc_html( $category->name ) . '</a></li>';
if( $count > 8 ) break;
}
echo "</ul>";
}
/**
* Removes the built-in styles in the Subtitles plugin.
*
* @since lenscap 1.0
*/
function lenscap_remove_subtitles_styles() {
if ( class_exists( 'Subtitles' ) && method_exists( 'Subtitles', 'subtitle_styling' ) ) {
remove_action( 'wp_head', array( Subtitles::getInstance(), 'subtitle_styling' ) );
}
}
add_action( 'template_redirect', 'lenscap_remove_subtitles_styles' );
/**
* Remove automatic output of subtitles
*
* @since lenscap 1.0
*/
function lenscap_subtitles_mod_supported_views() {
// Subtitle output handled by theme
}
add_filter( 'subtitle_view_supported', 'lenscap_subtitles_mod_supported_views' );
/**
* Responsive Images
*/
function lenscap_post_thumbnail_sizes_attr($attr, $attachment, $size) {
// Featured image thumbnails
if ($size === 'lenscap-featured-image') {
$attr['sizes'] = '(max-width: 1480px) 950px, (max-width: 800px) 800px, (max-width: 600px) 600px';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'lenscap_post_thumbnail_sizes_attr', 10 , 3 );
/**
* Add a js class
*/
function lenscap_html_js_class () {
echo '<script>document.documentElement.className = document.documentElement.className.replace("no-js","js");</script>'. "\n";
}
add_action( 'wp_head', 'lenscap_html_js_class', 1 );