-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.php
2057 lines (1820 loc) · 79.4 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
/**
* Ephemeris functions and definitions
*
* @package Ephemeris
* @since Ephemeris 1.0
*/
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which runs
* before the init hook. The init hook is too late for some features, such as indicating
* support post thumbnails.
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_setup' ) ) {
function ephemeris_setup() {
$defaults = ephemeris_generate_defaults();
$sidebar_content_width = 865;
$nosidebar_content_width = 1160;
// Make theme available for translation
load_theme_textdomain( 'ephemeris' );
// Add support for editor styles.
add_theme_support( 'editor-styles' );
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style( array(
'editor-style.css',
'css/fontawesome-all.min.css',
ephemeris_fonts_url()
)
);
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// Enable support for Post Thumbnails
add_theme_support( 'post-thumbnails' );
// Calculate the optimal featured image size based on the layout width.
// Default image width will be 865px with a site layout width of 1200px assuming 75/25 grid layout
// $sidebar_content_width = ( ( site width - 20px padding ) * 75% grid container ) - 20px grid padding
// $nosidebar_content_width = site width - 20px padding - 20px grid padding
$sidebar_content_width = absint( ( ( get_theme_mod( 'ephemeris_layout_width', $defaults['ephemeris_layout_width'] ) - 20 ) * 0.75 ) - 20 );
$nosidebar_content_width = absint( get_theme_mod( 'ephemeris_layout_width', $defaults['ephemeris_layout_width'] ) - 20 - 20 );
// Create extra image sizes for the Post & Page featured images
add_image_size( 'ephemeris_post_feature_full_width', $sidebar_content_width, 500, true );
add_image_size( 'ephemeris_nosidebar_feature_image_width', $nosidebar_content_width, 500, true );
// Set the width of our content when using the default template
$GLOBALS['content_width'] = $sidebar_content_width;
// This theme uses wp_nav_menu() in one location
register_nav_menus( array(
'primary-menu' => esc_html__( 'Primary Menu', 'ephemeris' )
)
);
// This theme supports a variety of post formats
add_theme_support( 'post-formats', array(
'aside',
'audio',
'chat',
'gallery',
'image',
'link',
'quote',
'status',
'video'
)
);
// Add theme support for HTML5 markup for the search forms, comment forms, comment lists, gallery, and caption
add_theme_support( 'html5', array(
'comment-list',
'comment-form',
'gallery',
'caption'
)
);
// Enable support for widget sidebars selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
// Enable support for Custom Backgrounds
add_theme_support( 'custom-background', array(
// Background color default
'default-color' => 'fff',
'wp-head-callback' => 'ephemeris_custom_background_cb',
)
);
// Enable support for Custom Headers
add_theme_support( 'custom-header', array(
// Header text display default
'header-text' => false,
// Header text color default
'default-text-color' => 'fff',
// Flexible width
'flex-width' => true,
// Header image width (in pixels)
'width' => 1160,
// Flexible height
'flex-height' => true,
// Header image height (in pixels)
'height' => 280
)
);
// Enable support for Theme Logos
add_theme_support( 'custom-logo', array(
'width' => 300,
'height' => 80,
'flex-height' => true,
'flex-width' => true,
'header-text' => array( 'site-title', 'site-description' ),
)
);
// Let WordPress manage the document title.
// By adding theme support, we declare that this theme does not use a hard-coded <title> tag in the document head, and expect WordPress to provide it for us.
add_theme_support( 'title-tag' );
// Enable support for WooCommerce & WooCommerce product galleries
add_theme_support( 'woocommerce', array(
'product_grid' => array(
'default_rows' => 3,
'default_columns' => 4,
),
) );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
// Add support for Wide and Full blocks in the Block Editor (Gutenberg)
add_theme_support( 'align-wide' );
// Add support for custom colours in the Block Editor (Gutenberg)
add_theme_support( 'editor-color-palette', array(
array(
'name' => 'Eclipse',
'slug' => 'eclipse',
'color' => '#3a3a3a',
),
array(
'name' => 'San Juan',
'slug' => 'san-juan',
'color' => '#334861',
),
array(
'name' => 'Denim',
'slug' => 'denim',
'color' => '#2979c7',
),
array(
'name' => 'Electric Violet',
'slug' => 'electric-violet',
'color' => '#8309e7',
),
array(
'name' => 'Cerise',
'slug' => 'cerise',
'color' => '#df49b8',
),
array(
'name' => 'Alizarin',
'slug' => 'alizarin',
'color' => '#df312c',
),
array(
'name' => 'Pumpkin',
'slug' => 'pumpkin',
'color' => '#FF8228',
),
array(
'name' => 'Titanium Yellow',
'slug' => 'titanium-yellow',
'color' => '#eef000',
),
array(
'name' => 'Atlantis',
'slug' => 'atlantis',
'color' => '#7ed934',
),
array(
'name' => 'White Smoke',
'slug' => 'white-smoke',
'color' => '#eee',
),
array(
'name' => 'White',
'slug' => 'white',
'color' => '#fff',
)
) );
// Add support for custom font sizes in the Block Editor (Gutenberg)
add_theme_support( 'editor-font-sizes', array(
array(
'name' => __( 'Small', 'ephemeris' ),
'shortName' => __( 'S', 'ephemeris' ),
'size' => 13,
'slug' => 'small'
),
array(
'name' => __( 'Normal', 'ephemeris' ),
'shortName' => __( 'N', 'ephemeris' ),
'size' => 16,
'slug' => 'normal'
),
array(
'name' => __( 'Medium', 'ephemeris' ),
'shortName' => __( 'M', 'ephemeris' ),
'size' => 24,
'slug' => 'medium'
),
array(
'name' => __( 'Large', 'ephemeris' ),
'shortName' => __( 'L', 'ephemeris' ),
'size' => 36,
'slug' => 'large'
),
array(
'name' => __( 'Huge', 'ephemeris' ),
'shortName' => __( 'H', 'ephemeris' ),
'size' => 48,
'slug' => 'huge'
)
) );
// Add support for Custom Line Heights and Custom Units
add_theme_support( 'custom-line-height' );
add_theme_support( 'custom-units' );
// Add support for loading default block styles on front-end
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds
add_theme_support( 'responsive-embeds' );
// Add support for padding controls when supported by blocks
add_theme_support('custom-spacing');
// Display a handy map of where all the theme hooks reside
// Only used when WP_EPHEMERIS_HOOKS is defined as true in wp-config.php
if ( defined( 'WP_EPHEMERIS_HOOKS') && WP_EPHEMERIS_HOOKS ) {
$ephemeris_hooks = ephemeris_get_hooks();
foreach ( $ephemeris_hooks as $hook ) {
add_action( $hook, 'ephemeris_display_hook' );
}
}
}
}
add_action( 'after_setup_theme', 'ephemeris_setup' );
/**
* Enqueue scripts and styles
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_scripts_styles' ) ) {
function ephemeris_scripts_styles() {
/**
* Register and enqueue our stylesheets
*/
// Start off with a clean base by using normalise.
wp_enqueue_style( 'normalize', trailingslashit( get_template_directory_uri() ) . 'css/normalize.css', array(), '8.0.1', 'all' );
// Register and enqueue our icon font
// We're using the awesome Font Awesome icon font. https://fontawesome.com
wp_enqueue_style( 'font-awesome-6', trailingslashit( get_template_directory_uri() ) . 'css/fontawesome-all.min.css', array( 'normalize' ), '6.6.0', 'all' );
// Our styles for setting up the grid. We're using Unsemantic. http://unsemantic.com
wp_enqueue_style( 'unsemantic-grid', trailingslashit( get_template_directory_uri() ) . 'css/unsemantic.css', array( 'font-awesome-6' ), '1.2.3', 'all' );
/*
* Load our Google Fonts.
*
* To disable in a child theme, use wp_dequeue_style()
* function mytheme_dequeue_fonts() {
* wp_dequeue_style( 'ephemeris-fonts' );
* }
* add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 );
*/
$fonts_url = ephemeris_fonts_url();
if ( !empty( $fonts_url ) ) {
wp_enqueue_style( 'ephemeris-fonts', $fonts_url, array(), null );
}
// If using a child theme, auto-load the parent theme style.
// Props to Justin Tadlock for this recommendation - http://justintadlock.com/archives/2014/11/03/loading-parent-styles-for-child-themes
if ( is_child_theme() ) {
wp_enqueue_style( 'parent-style', trailingslashit( get_template_directory_uri() ) . 'style.css' );
}
// Enqueue the default WordPress stylesheet
wp_enqueue_style( 'ephemeris-style', get_stylesheet_uri() );
/**
* Register and enqueue our scripts
*/
// Adds JavaScript to pages with the comment form to support sites with threaded comments (when in use)
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
// Load jQuery Validation as well as the initialiser to provide client side comment form validation
// You can change the validation error messages below or by using the corresponding filter
if ( is_singular() && comments_open() ) {
wp_register_script( 'validate', trailingslashit( get_template_directory_uri() ) . 'js/jquery.validate.min.js', array( 'jquery' ), '1.17.0', true );
wp_enqueue_script( 'comment-validate', trailingslashit( get_template_directory_uri() ) . 'js/comment-form-validation.js', array( 'jquery', 'validate' ), '1.0.0', true );
wp_localize_script( 'comment-validate', 'comments_object', array(
'req' => get_option( 'require_name_email' ),
'author' => apply_filters( 'ephemeris_comment_form_author_validation_error', esc_html__( 'Please enter your name', 'ephemeris' ) ),
'email' => apply_filters( 'ephemeris_comment_form_email_validation_error', esc_html__( 'Please enter a valid email address', 'ephemeris' ) ),
'comment' => apply_filters( 'ephemeris_comment_form_comment_validation_error', esc_html__( 'Please add a comment', 'ephemeris' ) )
) );
}
// Enqueue our common scripts
wp_enqueue_script( 'ephemeris-common-js', trailingslashit( get_template_directory_uri() ) . 'js/common.js', array( 'jquery' ), '0.1.1', true );
}
}
add_action( 'wp_enqueue_scripts', 'ephemeris_scripts_styles' );
/**
* Load our Block Editor styles to style the Editor like the front-end.
* Increased the width of the Block Editor blocks to match the site width from the Customizer by dynamically loading our styles into the <head>
*
* Some styles are duplicated (with different classes) because Core Devs ignore backwards compatibility, and also because they've now added
* everything within in an iframe (but only under certain conditions)
*
* @since Ephemeris 1.4
*
* @return string css styles
*/
if ( ! function_exists( 'ephemeris_block_editor_styles' ) ) {
function ephemeris_block_editor_styles() {
$defaults = ephemeris_generate_defaults();
$ephemeris_layout_width = get_theme_mod( 'ephemeris_layout_width', $defaults['ephemeris_layout_width'] );
$styles = '';
// Enqueue our seperate Block Editor stylesheet with the rest of our styles
wp_enqueue_style( 'ephemeris-blocks-style', trailingslashit( get_template_directory_uri() ) . 'css/blocks-style.css', array(), '1.0.1', 'all' );
// Make sure paragraph blocks within blocks are centered within
$styles .= 'body.block-editor-iframe__body .block-editor-block-list__layout.is-root-container :where(:not(.alignleft):not(.alignright)) {margin-left: auto !important;margin-right: auto !important;}';
// Increase width of all Blocks & Block Appender
$styles .= 'body.block-editor-page .edit-post-visual-editor .wp-block {max-width: ' . esc_attr( $ephemeris_layout_width - 40 ) . 'px;}';
$styles .= 'body.block-editor-iframe__body .block-editor-block-list__layout .wp-block {max-width: ' . esc_attr( $ephemeris_layout_width - 40 ) . 'px;}';
// Increase width of the post title wrapper when iframed
$styles .= 'body.block-editor-iframe__body .editor-visual-editor__post-title-wrapper .wp-block {max-width: ' . esc_attr( $ephemeris_layout_width - 40 ) . 'px;}';
// Increase width of Wide blocks
$styles .= 'body.block-editor-page .edit-post-visual-editor .wp-block[data-align="wide"],body.block-editor-page .edit-post-visual-editor .wp-block.alignwide {max-width: ' . esc_attr( $ephemeris_layout_width - 40 + 400 ) . 'px;}';
$styles .= 'body.block-editor-page .edit-post-visual-editor .wp-block[data-align="wide"] .wp-block,body.block-editor-page .edit-post-visual-editor .wp-block.alignwide .wp-block {max-width: ' . esc_attr( $ephemeris_layout_width - 40 + 400 ) . 'px;}';
$styles .= 'body.block-editor-iframe__body .block-editor-block-list__layout .wp-block[data-align="wide"] .wp-block,body.block-editor-iframe__body .block-editor-block-list__layout .wp-block.alignwide {max-width: ' . esc_attr( $ephemeris_layout_width - 40 + 400 ) . 'px;}';
// Remove max-width on Full blocks
$styles .= 'body.block-editor-page .edit-post-visual-editor .wp-block[data-align="full"],body.block-editor-page .edit-post-visual-editor .wp-block.alignfull {max-width: none;}';
$styles .= 'body.block-editor-page .edit-post-visual-editor .wp-block[data-align="full"] .wp-block,body.block-editor-page .edit-post-visual-editor .wp-block.alignfull .wp-block {max-width: none;}';
$styles .= 'body.block-editor-iframe__body .block-editor-block-list__layout .wp-block[data-align="full"] .wp-block,body.block-editor-iframe__body .block-editor-block-list__layout .wp-block.alignfull {max-width: none;}';
// Constrain width of Wide and Full Group Containers
$styles .= 'body.block-editor-page .edit-post-visual-editor .wp-block-group.alignwide.is-layout-constrained {max-width: ' . esc_attr( $ephemeris_layout_width - 40 + 400 ) . 'px;}';
$styles .= 'body.block-editor-page .edit-post-visual-editor .wp-block-group.alignfull.is-layout-constrained {max-width: none;}';
$styles .= 'body.block-editor-iframe__body .block-editor-block-list__layout .wp-block-group.alignfull.is-layout-constrained {max-width: none;}';
// Constrain width of Cover Block Inner Containers
$styles .= 'body.block-editor-page .edit-post-visual-editor .wp-block-cover .wp-block-cover__inner-container {max-width: ' . esc_attr( $ephemeris_layout_width - 40 ) . 'px;}';
$styles .= 'body.block-editor-page .edit-post-visual-editor .wp-block-cover.is-style-extended-inner-container .wp-block-cover__inner-container {max-width: ' . esc_attr( $ephemeris_layout_width - 40 + 400 ) . 'px;}';
$styles .= 'body.block-editor-page .edit-post-visual-editor .wp-block-cover.is-style-extended-inner-container .wp-block-cover__inner-container .wp-block {max-width: 100%;}';
$styles .= 'body.block-editor-iframe__body .block-editor-block-list__layout .wp-block-cover.is-style-extended-inner-container .wp-block-cover__inner-container .wp-block {max-width: 100%;}';
// Output our styles into the <head> whenever our block styles are enqueued
wp_add_inline_style( 'ephemeris-blocks-style', $styles );
}
}
add_action( 'enqueue_block_editor_assets', 'ephemeris_block_editor_styles' );
/**
* Output Block styles in the site header based on Customizer settings
*
* @since Ephemeris 1.4
*
* @return string css styles
*/
if ( ! function_exists( 'ephemeris_dynamic_block_editor_styles' ) ) {
function ephemeris_dynamic_block_editor_styles() {
$defaults = ephemeris_generate_defaults();
$ephemeris_layout_width = get_theme_mod( 'ephemeris_layout_width', $defaults['ephemeris_layout_width'] );
$styles = '';
// Layout styles
$styles .= '@media only screen and (max-width: ' . esc_attr( $ephemeris_layout_width + 400 ) . 'px) {';
$styles .= '.site-content .grid-100 .alignwide {margin-left: 0;margin-right: 0;}';
$styles .= '.site-content .grid-100 .wp-block-table.alignwide {width: 100%;}';
$styles .= '.site-content .grid-100 figure.alignwide.wp-block-embed.is-type-video {width: 100%;}';
$styles .= '}';
// Constrain width of Wide and Full Group Containers
$styles .= '.wp-block-group.alignwide.is-layout-constrained {max-width: ' . esc_attr( $ephemeris_layout_width - 40 + 400 ) . 'px;}';
$styles .= '.wp-block-group.alignfull.is-layout-constrained {max-width: none;}';
$styles .= 'body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)) {max-width: ' . esc_attr( $ephemeris_layout_width - 40 ) . 'px;}';
// Constrain width of Cover Block Inner Containers
$styles .= '.wp-block-cover .wp-block-cover__inner-container {max-width: ' . esc_attr( $ephemeris_layout_width - 40 ) . 'px;}';
$styles .= '.wp-block-cover.is-style-extended-inner-container .wp-block-cover__inner-container {max-width: ' . esc_attr( $ephemeris_layout_width - 40 + 400 ) . 'px;}';
echo '<style type="text/css">' . $styles . '</style>';
}
}
add_action( 'wp_head', 'ephemeris_dynamic_block_editor_styles' );
/**
* Enqueue scripts for our Customizer preview
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_customizer_preview_scripts' ) ) {
function ephemeris_customizer_preview_scripts() {
wp_enqueue_script( 'ephemeris-customizer-preview-js', trailingslashit( get_template_directory_uri() ) . 'js/customizer-preview.js', array( 'customize-preview', 'jquery' ), '1.0', true );
wp_enqueue_script( 'ephemeris-common-js', trailingslashit( get_template_directory_uri() ) . 'js/common.js', array( 'jquery' ), '1.0', true );
}
}
add_action( 'customize_preview_init', 'ephemeris_customizer_preview_scripts' );
/**
* Enqueue scripts for our Customizer controls. Allows Customizer preview to update based on panel selected
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_customize_controls_enqueue_scripts' ) ) {
function ephemeris_customize_controls_enqueue_scripts() {
// Register and enqueue our icon font
// We're using the awesome Font Awesome icon font. https://fontawesome.com
wp_enqueue_style( 'font-awesome-6', trailingslashit( get_template_directory_uri() ) . 'css/fontawesome-all.min.css', array(), '6.6.0', 'all' );
if( ephemeris_is_plugin_active( 'woocommerce' ) ) {
$shop_page_url = wc_get_page_permalink( 'shop' );
wp_enqueue_script( 'ephemeris-customize-controls-js', trailingslashit( get_template_directory_uri() ) . 'js/customize-controls.js', array( 'customize-controls' ), '1.0', true );
wp_localize_script( 'ephemeris-customize-controls-js', 'ephemeris_customizer_data',
array(
'ephemeris_woocommerce_url' => $shop_page_url
)
);
}
}
}
add_action( 'customize_controls_enqueue_scripts', 'ephemeris_customize_controls_enqueue_scripts' );
/**
* Action any theme or plugin specific hooks. Fires before determining which template to load. Will also work in Customizer preview.
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_template_redirect' ) ) {
function ephemeris_template_redirect() {
$defaults = ephemeris_generate_defaults();
$template = '';
// If WooCommerce is running, check if we should be displaying the Breadcrumbs
if( ephemeris_is_plugin_active( 'woocommerce' ) && !get_theme_mod( 'ephemeris_woocommerce_breadcrumbs', $defaults['ephemeris_woocommerce_breadcrumbs'] ) ) {
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}
// Check whether we are replacing the default Header and ensure the builder is actually active
$template = ephemeris_has_pagebuilder_template( 'header' );
if ( !empty( $template ) ) {
add_action( 'ephemeris_before_header', 'ephemeris_display_' . $template . '_header' );
}
else {
add_action( 'ephemeris_announcement_bar_content', 'ephemeris_social_header' );
add_action( 'ephemeris_header_content', 'ephemeris_logo_grid' );
add_action( 'ephemeris_header_content', 'ephemeris_nav_grid' );
}
// Check whether we are replacing the default footer and ensure the builder is actually active
$template = ephemeris_has_pagebuilder_template( 'footer' );
if ( !empty( $template ) ) {
add_action( 'ephemeris_after_footer', 'ephemeris_display_' . $template . '_footer' );
}
if ( has_header_image() ) {
add_action( 'ephemeris_before_main_content', 'ephemeris_header_image' );
}
}
}
add_action( 'template_redirect', 'ephemeris_template_redirect' );
/**
* Display the social header icons, including its grid container.
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_social_header' ) ) {
function ephemeris_social_header() {
$social_header = '';
$social_header .= '<div class="grid-100 tablet-grid-100 social-header">';
$social_header .= ephemeris_get_social_media();
$social_header .= '</div> <!-- /.grid-100.social-header -->';
echo $social_header;
}
}
/**
* Display the site logo or site title, including its grid container.
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_logo_grid' ) ) {
function ephemeris_logo_grid() {
$logo_grid = '';
$logo_grid .= '<div class="grid-40 tablet-grid-40 mobile-grid-100 site-title' . ( is_rtl() ? ' push-60 tablet-push-60' : '' ) . '">';
$logo_grid .= ephemeris_the_custom_logo();
$logo_grid .= '</div> <!-- /.grid-40.site-title -->';
echo $logo_grid;
}
}
/**
* Display the main navigation.
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_nav_grid' ) ) {
function ephemeris_nav_grid() {
$nav_grid = '';
$nav_grid .= '<div class="grid-60 tablet-grid-60 mobile-grid-100' . ( is_rtl() ? ' pull-40 tablet-pull-40' : '' ) . '">';
$nav_grid .= '<nav id="site-navigation" class="main-navigation" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">';
$nav_grid .= '<div class="assistive-text skip-link"><a href="#content" title="' . esc_attr__( 'Skip to content', 'ephemeris' ) . '">' . esc_html__( 'Skip to content', 'ephemeris' ) . '</a></div>';
$nav_grid .= wp_nav_menu(
array(
'theme_location' => 'primary-menu',
'menu_class' => 'nav-menu',
'echo' => false
) );
$nav_grid .= '</nav> <!-- /.site-navigation.main-navigation -->';
$nav_grid .= '</div> <!-- /.grid-60 -->';
echo $nav_grid;
}
}
/**
* Display the elementor header template.
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_display_elementor_header' ) ) {
function ephemeris_display_elementor_header() {
$defaults = ephemeris_generate_defaults();
echo do_shortcode( '[elementor-template id="' . get_theme_mod( 'ephemeris_elementor_header_template', $defaults['ephemeris_elementor_header_template'] ) . '"]' );
}
}
/**
* Display the elementor footer template.
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_display_elementor_footer' ) ) {
function ephemeris_display_elementor_footer() {
$defaults = ephemeris_generate_defaults();
echo do_shortcode( '[elementor-template id="' . get_theme_mod( 'ephemeris_elementor_footer_template', $defaults['ephemeris_elementor_footer_template'] ) . '"]' );
}
}
/**
* Returns the optional custom logo. If no logo is available, it returns the Site Title
*
* @since Ephemeris 1.0
*
* @return string The logo or Site Title link
*/
if ( ! function_exists( 'ephemeris_the_custom_logo' ) ) {
function ephemeris_the_custom_logo() {
$logo_title = '';
if ( function_exists( 'the_custom_logo' ) && has_custom_logo() ) {
$logo_title .= get_custom_logo();
}
else {
$logo_title .= '<span class="site-title-link">';
$logo_title .= '<a href="' . esc_url( home_url( '/' ) ) . '" title="' . esc_attr( get_bloginfo( 'name' ) ) . '" rel="home">';
$logo_title .= get_bloginfo( 'name' );
if ( !empty( get_bloginfo( 'description' ) ) ) {
$logo_title .= '<div class="site-title-tagline">';
$logo_title .= get_bloginfo( 'description' );
$logo_title .= '</div>';
}
$logo_title .= '</a>';
$logo_title .= '</span>';
}
return $logo_title;
}
}
/**
* Display the header image if there is one.
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_header_image' ) ) {
function ephemeris_header_image() {
$header_image = "";
if ( has_header_image() ) {
$header_image .= '<div id="bannercontainer"><div class="banner grid-container"><div class="header-image grid-100">';
$header_image .= '<a href="' . esc_url( home_url( '/' ) ) . '" rel="home">';
$header_image .= sprintf( '<img src="%1$s" srcset="%2$s" width="%3$s" height="%4$s" alt="%5$s">',
get_header_image(),
esc_attr( wp_get_attachment_image_srcset( get_custom_header()->attachment_id ) ),
esc_attr( get_custom_header()->width ),
esc_attr( get_custom_header()->height ),
esc_attr( get_bloginfo( 'name', 'display' ) )
);
$header_image .= '</a>';
$header_image .= '</div> <!-- .header-image.grid-100 --></div> <!-- /.banner.grid-container --></div> <!-- /#bannercontainer -->';
echo $header_image;
}
}
}
/**
* Returns the Google font stylesheet URL, if available.
*
* The use of Open Sans and Dosis by default is localized. For languages that use characters not supported by the fonts, the fonts can be disabled.
*
* @since Ephemeris 1.0
*
* @return string Font stylesheet or empty string if disabled.
*/
if ( ! function_exists( 'ephemeris_fonts_url' ) ) {
function ephemeris_fonts_url() {
$fonts_url = '';
$subsets = 'latin';
/* translators: If there are characters in your language that are not supported by Open Sans, translate this to 'off'.
* Do not translate into your own language.
*/
$bodyFont = _x( 'on', 'Open Sans font: on or off', 'ephemeris' );
/* translators: To add an additional Open Sans character subset specific to your language, translate this to 'greek', 'cyrillic' or 'vietnamese'.
* Do not translate into your own language.
*/
$subset = _x( 'no-subset', 'Open Sans font: add new subset (cyrillic)', 'ephemeris' );
if ( 'cyrillic' == $subset ) {
$subsets .= ',cyrillic';
}
/* translators: If there are characters in your language that are not supported by Dosis, translate this to 'off'.
* Do not translate into your own language.
*/
$headerFont = _x( 'on', 'Dosis font: on or off', 'ephemeris' );
if ( 'off' !== $bodyFont || 'off' !== $headerFont ) {
$font_families = array();
if ( 'off' !== $bodyFont )
$font_families[] = 'Open Sans:400,400i,700,700i';
if ( 'off' !== $headerFont )
$font_families[] = 'Dosis:700';
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( $subsets ),
'display' => urlencode( 'fallback' ),
);
$fonts_url = add_query_arg( $query_args, "https://fonts.bunny.net/css" );
}
return esc_url_raw( $fonts_url );
}
}
/**
* Get the container grid widths for all the major theme sections (i.e. announcement bar, header, body content, footer credits)
* Note: The footer widths for the footer widgets are automatically calculated based on the numbmer of widgets in use
*
* @since Ephemeris 1.5.2
*
* @return array
*/
if ( ! function_exists( 'ephemeris_get_container_widths' ) ) {
function ephemeris_get_container_widths() {
$container_width_defaults = array(
'ephemeris_announcement_bar_width' => 100,
'ephemeris_header_site_title_width' => 40,
'ephemeris_header_nav_width' => 60,
'ephemeris_body_main_content_width' => 75,
'ephemeris_body_sidebar_content_width' => 25,
'ephemeris_body_fullwidth_content_width' => 100,
'ephemeris_footer_credits_width' => 100,
);
return apply_filters( 'ephemeris_container_width_defaults', $container_width_defaults );
}
}
/**
* Register widgetized areas
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_widgets_init' ) ) {
function ephemeris_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Main Sidebar', 'ephemeris' ),
'id' => 'sidebar-main',
'description' => esc_html__( 'Appears in the sidebar on all posts and pages', 'ephemeris' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
register_sidebar( array(
'name' => esc_html__( 'Blog Sidebar', 'ephemeris' ),
'id' => 'sidebar-blog',
'description' => esc_html__( 'Appears in the sidebar on the blog and archive pages only', 'ephemeris' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
register_sidebar( array(
'name' => esc_html__( 'Single Post Sidebar', 'ephemeris' ),
'id' => 'sidebar-single',
'description' => esc_html__( 'Appears in the sidebar on single posts only', 'ephemeris' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
register_sidebar( array(
'name' => esc_html__( 'Page Sidebar', 'ephemeris' ),
'id' => 'sidebar-page',
'description' => esc_html__( 'Appears in the sidebar on pages only', 'ephemeris' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
if ( ephemeris_is_plugin_active( 'woocommerce' ) ) {
register_sidebar( array(
'name' => esc_html__( 'WooCommerce Sidebar', 'ephemeris' ),
'id' => 'sidebar-shop',
'description' => esc_html__( 'Appears in the sidebar on WooCommerce pages only', 'ephemeris' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
}
if ( ephemeris_is_plugin_active( 'bbpress' ) ) {
register_sidebar( array(
'name' => esc_html__( 'bbPress Sidebar', 'ephemeris' ),
'id' => 'sidebar-bbpress',
'description' => esc_html__( 'Appears in the sidebar on bbPress Forum pages only', 'ephemeris' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
}
register_sidebar( array(
'name' => esc_html__( 'Footer Widget 1', 'ephemeris' ),
'id' => 'sidebar-footer1',
'description' => esc_html__( 'Appears in the footer in column 1', 'ephemeris' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
register_sidebar( array(
'name' => esc_html__( 'Footer Widget 2', 'ephemeris' ),
'id' => 'sidebar-footer2',
'description' => esc_html__( 'Appears in the footer in column 2', 'ephemeris' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
register_sidebar( array(
'name' => esc_html__( 'Footer Widget 3', 'ephemeris' ),
'id' => 'sidebar-footer3',
'description' => esc_html__( 'Appears in the footer in column 3', 'ephemeris' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
register_sidebar( array(
'name' => esc_html__( 'Footer Widget 4', 'ephemeris' ),
'id' => 'sidebar-footer4',
'description' => esc_html__( 'Appears in the footer in column 4', 'ephemeris' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
}
}
add_action( 'widgets_init', 'ephemeris_widgets_init' );
/**
* Custom Background Callback
*
* @since Ephemeris 1.0
*
* @return void
*/
if ( ! function_exists( 'ephemeris_custom_background_cb' ) ) {
function ephemeris_custom_background_cb() {
// $background is the saved custom image, or the default image.
$background = set_url_scheme( get_background_image() );
// $color is the saved custom color.
// A default has to be specified in style.css. It will not be printed here.
$color = get_background_color();
if ( $color === get_theme_support( 'custom-background', 'default-color' ) ) {
$color = false;
}
if ( ! $background && ! $color ) {
if ( is_customize_preview() ) {
echo '<style type="text/css" id="custom-background-css"></style>';
}
return;
}
$style = $color ? "background-color: #$color;" : '';
if ( $background ) {
$image = " background-image: url(" . wp_json_encode( $background ) . ");";
// Background Position.
$position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );
$position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) );
if ( ! in_array( $position_x, array( 'left', 'center', 'right' ), true ) ) {
$position_x = 'left';
}
if ( ! in_array( $position_y, array( 'top', 'center', 'bottom' ), true ) ) {
$position_y = 'top';
}
$position = " background-position: $position_x $position_y;";
// Background Size.
$size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) );
if ( ! in_array( $size, array( 'auto', 'contain', 'cover' ), true ) ) {
$size = 'auto';
}
$size = " background-size: $size;";
// Background Repeat.
$repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) );
if ( ! in_array( $repeat, array( 'repeat-x', 'repeat-y', 'repeat', 'no-repeat' ), true ) ) {
$repeat = 'repeat';
}
$repeat = " background-repeat: $repeat;";
// Background Scroll.
$attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) );
if ( 'fixed' !== $attachment ) {
$attachment = 'scroll';
}
$attachment = " background-attachment: $attachment;";
$style .= $image . $position . $size . $repeat . $attachment;
}
printf( '<style type="text/css" id="custom-background-css">body.custom-background main { %1$s }</style>', trim( $style ) );
}
}
/**
* Get the classes for the main content container.
*
* @since Ephemeris 1.0
*
* @param array Echo on screen or return value
* @param array Extra classes to append
* @return string Containing list of classes or empty string if echoed to screen
*/
if ( ! function_exists( 'ephemeris_main_class' ) ) {
function ephemeris_main_class( $echo=true, $addon_classes='' ) {
$defaults = ephemeris_generate_defaults();
$sidebar_layout = '';
$classes = '';
if ( is_page() ) {
$sidebar_layout = strtolower( get_theme_mod( 'ephemeris_page_template_default', $defaults['ephemeris_page_template_default'] ) );
} elseif ( is_singular( 'post' ) || is_attachment() ) {
$sidebar_layout = strtolower( get_theme_mod( 'ephemeris_post_template_default', $defaults['ephemeris_post_template_default'] ) );
} elseif ( is_home() ) {
$sidebar_layout = strtolower( get_theme_mod( 'ephemeris_post_archive_template_default', $defaults['ephemeris_post_archive_template_default'] ) );
}
if ( !empty( $sidebar_layout ) ) {
switch ( $sidebar_layout ) {
case 'left':
$classes = 'grid-75 tablet-grid-75 mobile-grid-100 push-25 tablet-push-25';
break;
case 'right':
$classes = 'grid-75 tablet-grid-75 mobile-grid-100';
break;
case 'none':
$classes = 'grid-100';
break;
default:
$classes = 'grid-75 tablet-grid-75 mobile-grid-100';
break;
}
} else {
$classes = 'grid-75 tablet-grid-75 mobile-grid-100' . ( !empty( $addon_classes ) ? ' ' . $addon_classes : '' );
}
return ephemeris_classes( $echo, $classes );
}
}