Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
1000 lines (873 loc) · 28.6 KB
/
Copy pathfunctions.php
File metadata and controls
1000 lines (873 loc) · 28.6 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
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
/**
* Slateframe theme bootstrap.
*
* @package Slateframe
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require_once get_template_directory() . '/inc/template-tags.php';
require_once get_template_directory() . '/inc/content-discovery.php';
require_once get_template_directory() . '/inc/footer-presentation.php';
require_once get_template_directory() . '/inc/customizer.php';
/**
* Register theme supports and navigation locations.
*/
function slateframe_setup() {
load_theme_textdomain( 'slateframe', get_template_directory() . '/languages' );
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'align-wide' );
add_theme_support( 'wp-block-styles' );
add_theme_support( 'editor-styles' );
add_editor_style( array( 'style.css', 'assets/css/forms.css', 'assets/css/form-content.css', 'assets/css/reading.css', 'assets/css/photography.css', 'assets/css/content-modes.css', 'assets/css/query-loop.css', 'assets/css/editor.css' ) );
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
)
);
add_theme_support(
'custom-logo',
array(
'height' => 96,
'width' => 96,
'flex-height' => true,
'flex-width' => true,
)
);
register_nav_menus(
array(
'primary' => __( 'Primary navigation', 'slateframe' ),
'footer' => __( 'Footer navigation', 'slateframe' ),
)
);
}
add_action( 'after_setup_theme', 'slateframe_setup' );
/**
* Register optional block/widget regions.
*
* Footer content is deliberately content-owned: sites can compose Core blocks,
* subscription widgets, project links, or multilingual widgets without the
* theme hard-coding a footer information architecture.
*/
function slateframe_register_widget_areas() {
register_sidebar(
array(
'name' => __( 'Footer content', 'slateframe' ),
'id' => 'footer-content',
'description' => __( 'Optional block or widget content displayed above the footer navigation.', 'slateframe' ),
'before_widget' => '<div id="%1$s" class="slateframe-footer-widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="slateframe-footer-widget-title">',
'after_title' => '</h2>',
)
);
}
add_action( 'widgets_init', 'slateframe_register_widget_areas' );
/**
* Return Photography markers, preserving the legacy broad-filter contract.
*
* @return string[] Class tokens that opt into Photography presentation.
*/
function slateframe_photography_marker_classes() {
$markers = array(
'is-style-slateframe-contact-sheet',
'is-style-slateframe-diptych',
'is-style-slateframe-photo-feature',
'is-style-slateframe-photo-sequence',
'slateframe-photography-sequence',
'slateframe-gallery-sequence',
);
$legacy_markers = apply_filters( 'slateframe_content_mode_markers', array() );
if ( is_array( $legacy_markers ) ) {
$markers = array_merge( $markers, $legacy_markers );
}
/**
* Filters class markers that opt a document into Slateframe Photography.
*
* @param string[] $markers Photography presentation markers.
*/
return apply_filters( 'slateframe_photography_markers', $markers );
}
/**
* Return site-neutral Portfolio and Knowledge presentation markers.
*
* @return string[] Content-mode class tokens.
*/
function slateframe_content_mode_marker_classes() {
$markers = array(
'is-style-slateframe-project-feature',
'is-style-slateframe-learning-path',
'slateframe-project-grid',
'slateframe-knowledge-checklist',
'is-style-slateframe-steps',
'is-style-slateframe-checklist',
'is-style-slateframe-key-facts',
'is-style-slateframe-learning-callout',
'is-style-slateframe-definition',
'is-style-slateframe-metrics',
'is-style-slateframe-ledger',
'is-style-slateframe-project-brief',
);
/**
* Filters class markers that trigger Slateframe's contextual styles.
*
* @param string[] $markers Content markers to scan for.
*/
return apply_filters( 'slateframe_content_mode_markers', $markers );
}
/**
* Return markers for the optional Core Query Loop presentation layer.
*
* @return string[] Query Loop class tokens.
*/
function slateframe_query_loop_marker_classes() {
/**
* Filters class markers that opt a document into Query Loop presentation.
*
* @param string[] $markers Query Loop markers.
*/
return apply_filters( 'slateframe_query_loop_markers', array( 'slateframe-project-grid' ) );
}
/**
* Check stored post content for exact CSS class markers.
*
* Marker detection is intentionally class-aware instead of substring-based so
* prose, code samples, or translated copy that mention a marker name do not
* accidentally load contextual assets.
*
* @param string $content Stored post content.
* @param string[] $markers Class markers to detect.
* @param bool $parse_blocks Whether to inspect Gutenberg comments (false for Classic widgets).
* @return bool
*/
function slateframe_content_has_class_marker( $content, $markers, $parse_blocks = true ) {
if ( '' === trim( (string) $content ) || ! is_array( $markers ) || empty( $markers ) ) {
return false;
}
$processor = new WP_HTML_Tag_Processor( $content );
while ( $processor->next_tag() ) {
foreach ( $markers as $marker ) {
if ( is_string( $marker ) && '' !== $marker && $processor->has_class( $marker ) ) {
return true;
}
}
}
// Dynamic Core blocks may store their className without HTML markup.
if ( $parse_blocks && false !== strpos( $content, '<!-- wp:' ) && false !== strpos( $content, '"className"' ) ) {
static $block_cache = array();
$key = md5( $content );
if ( ! isset( $block_cache[ $key ] ) ) {
if ( 8 <= count( $block_cache ) ) {
array_shift( $block_cache );
}
$block_cache[ $key ] = parse_blocks( $content );
}
return slateframe_blocks_have_class_marker( $block_cache[ $key ], $markers );
}
return false;
}
/**
* Detect exact Core block className tokens, including nested blocks.
*
* @param array[] $blocks Parsed Core blocks.
* @param string[] $markers Requested markers.
* @return bool
*/
function slateframe_blocks_have_class_marker( $blocks, $markers ) {
if ( ! is_array( $blocks ) || ! is_array( $markers ) ) {
return false;
}
foreach ( $blocks as $block ) {
if ( ! is_array( $block ) ) {
continue;
}
$class_name = isset( $block['attrs']['className'] ) ? $block['attrs']['className'] : '';
if ( is_string( $class_name ) && '' !== trim( $class_name ) ) {
$classes = preg_split( '/\\s+/', trim( $class_name ) );
foreach ( $markers as $marker ) {
if ( is_string( $marker ) && '' !== $marker && in_array( $marker, $classes, true ) ) {
return true;
}
}
}
if ( ! empty( $block['innerBlocks'] ) && slateframe_blocks_have_class_marker( $block['innerBlocks'], $markers ) ) {
return true;
}
}
return false;
}
/**
* Determine whether stored content contains an actual HTML form element.
*
* @param string $content Stored post content.
* @return bool
*/
function slateframe_content_has_form( $content ) {
// Avoid constructing the HTML processor for ordinary text and block markup.
if ( false === stripos( (string) $content, '<form' ) ) {
return false;
}
$processor = new WP_HTML_Tag_Processor( $content );
return (bool) $processor->next_tag( array( 'tag_name' => 'FORM' ) );
}
/**
* Recognize Core's legacy Search block without depending on its widget ID.
*
* @param array[] $blocks Parsed blocks, including nested groups.
* @return bool
*/
function slateframe_blocks_have_legacy_search( $blocks ) {
foreach ( $blocks as $block ) {
if (
'core/legacy-widget' === ( isset( $block['blockName'] ) ? $block['blockName'] : '' ) &&
'search' === ( isset( $block['attrs']['idBase'] ) ? $block['attrs']['idBase'] : '' )
) {
return true;
}
if ( ! empty( $block['innerBlocks'] ) && slateframe_blocks_have_legacy_search( $block['innerBlocks'] ) ) {
return true;
}
}
return false;
}
/**
* Collect published Core synced-pattern content without rendering blocks.
*
* Only core/block references are followed. Ordinary Group/Columns nesting
* does not consume the eight-reference depth budget. Track the shallowest depth
* across sibling branches so a repeated reference is fetched only when a
* shorter path can reveal descendants beyond the original depth budget.
*
* @param array[] $blocks Parsed blocks, including nested containers.
* @param int[] $seen Shallowest reference depth per ID, by reference.
* @param int $depth Current synced-reference depth.
* @return string[] Published pattern contents in discovery order.
*/
function slateframe_synced_pattern_contents( $blocks, &$seen, $depth = 0 ) {
$contents = array();
if ( ! is_array( $blocks ) || $depth >= 8 ) {
return $contents;
}
foreach ( $blocks as $block ) {
if ( ! is_array( $block ) ) {
continue;
}
if ( ! empty( $block['innerBlocks'] ) ) {
$contents = array_merge( $contents, slateframe_synced_pattern_contents( $block['innerBlocks'], $seen, $depth ) );
}
if ( 'core/block' !== ( isset( $block['blockName'] ) ? $block['blockName'] : '' ) ) {
continue;
}
$raw_ref = isset( $block['attrs']['ref'] ) ? $block['attrs']['ref'] : null;
$ref = ( is_int( $raw_ref ) || ( is_string( $raw_ref ) && ctype_digit( $raw_ref ) ) ) ? (int) $raw_ref : 0;
if ( $ref <= 0 || ( isset( $seen[ $ref ] ) && $seen[ $ref ] <= $depth ) ) {
continue;
}
$seen[ $ref ] = $depth;
$post = get_post( $ref );
if ( ! $post instanceof WP_Post || 'wp_block' !== $post->post_type || 'publish' !== $post->post_status ) {
continue;
}
$contents[] = $post->post_content;
if ( has_block( 'core/block', $post->post_content ) ) {
$contents = array_merge(
$contents,
slateframe_synced_pattern_contents( parse_blocks( $post->post_content ), $seen, $depth + 1 )
);
}
}
return $contents;
}
/**
* Derive form stylesheet flags from resolved published pattern content.
*
* @param string[] $contents Published pattern contents.
* @return array<string,bool> Required form stylesheet flags.
*/
function slateframe_pattern_form_assets( $contents ) {
$needed = array(
'forms' => false,
'search_form' => false,
'form_content' => false,
);
foreach ( $contents as $content ) {
if ( has_block( 'core/search', $content ) ) {
$needed['forms'] = true;
}
if (
has_block( 'core/legacy-widget', $content ) &&
slateframe_blocks_have_legacy_search( parse_blocks( $content ) )
) {
$needed['forms'] = true;
$needed['search_form'] = true;
}
if ( slateframe_content_has_form( $content ) ) {
$needed['forms'] = true;
$needed['form_content'] = true;
}
}
return $needed;
}
/**
* Discover form assets in published Core synced patterns.
*
* @param array[] $blocks Parsed blocks containing Core pattern references.
* @param bool[] $seen Already visited pattern IDs.
* @param int $depth Current synced-reference depth.
* @return array<string,bool> Required form stylesheet flags.
*/
function slateframe_synced_form_assets( $blocks, $seen = array(), $depth = 0 ) {
return slateframe_pattern_form_assets( slateframe_synced_pattern_contents( $blocks, $seen, $depth ) );
}
/**
* Resolve patterns in the current singular post once per request.
*
* Shared by form, Photography, Portfolio, Knowledge, and Query Loop asset
* detection. Does not render arbitrary blocks or execute shortcodes.
*
* @return string[] Published synced-pattern content.
*/
function slateframe_singular_synced_pattern_contents() {
static $cache = array();
if ( ! is_singular() ) {
return array();
}
$post = get_post();
if ( ! $post instanceof WP_Post || ! has_block( 'core/block', $post->post_content ) ) {
return array();
}
$key = (int) $post->ID . ':' . md5( $post->post_content );
if ( ! isset( $cache[ $key ] ) ) {
$seen = array();
$cache[ $key ] = slateframe_synced_pattern_contents( parse_blocks( $post->post_content ), $seen );
}
return $cache[ $key ];
}
/**
* Discover forms in active Core/classic footer widgets before assets enqueue.
*
* The footer is content-owned, so checking only the current post misses Core
* Search blocks and classic Search widgets inserted through Appearance >
* Widgets. Inactive widgets must not load any CSS. Dynamic third-party forms
* may opt in through the existing stylesheet filters.
*
* @return array<string,bool> Flags for forms, the theme search form, and form states.
*/
function slateframe_footer_form_assets() {
static $cache = null;
if ( null !== $cache ) {
return $cache;
}
$sources = slateframe_footer_widget_sources();
$needed = array(
'forms' => $sources['search_widget'],
'search_form' => $sources['search_widget'],
'form_content' => false,
);
foreach ( $sources['contents'] as $source ) {
$content = $source['content'];
if ( $source['block'] ) {
if ( has_block( 'core/search', $content ) ) {
$needed['forms'] = true;
}
if (
has_block( 'core/legacy-widget', $content ) &&
slateframe_blocks_have_legacy_search( parse_blocks( $content ) )
) {
$needed['forms'] = true;
$needed['search_form'] = true;
}
}
if ( slateframe_content_has_form( $content ) ) {
$needed['forms'] = true;
$needed['form_content'] = true;
}
}
$cache = $needed;
return $cache;
}
/**
* Discover synced-pattern forms referenced by the current singular post.
*
* @return array<string,bool> Required form stylesheet flags.
*/
function slateframe_singular_synced_form_assets() {
static $cache = array();
if ( ! is_singular() ) {
return slateframe_pattern_form_assets( array() );
}
$post = get_post();
if ( ! $post instanceof WP_Post ) {
return slateframe_pattern_form_assets( array() );
}
$key = (int) $post->ID . ':' . md5( $post->post_content );
if ( ! isset( $cache[ $key ] ) ) {
$cache[ $key ] = slateframe_pattern_form_assets( slateframe_singular_synced_pattern_contents() );
}
return $cache[ $key ];
}
/**
* Determine whether the current request renders Slateframe's theme search form.
*
* @return bool
*/
function slateframe_search_form_styles_needed() {
$footer = slateframe_footer_form_assets();
$needed = is_search() || is_404() || $footer['search_form'] || slateframe_singular_synced_form_assets()['search_form'];
global $wp_query;
if (
! $needed &&
( is_home() || is_archive() || is_author() ) &&
isset( $wp_query ) &&
0 === (int) $wp_query->post_count
) {
$needed = true;
}
return $needed;
}
/**
* Determine whether the current request needs the shared form-control layer.
*
* Search, recovery, empty-state, comments, Core Search, and author-owned forms
* all use the same geometry without making form CSS a global request cost.
*
* @return bool
*/
function slateframe_forms_styles_needed() {
$footer = slateframe_footer_form_assets();
$needed = slateframe_search_form_styles_needed() || $footer['forms'] || slateframe_singular_synced_form_assets()['forms'];
if ( ! $needed && is_singular() ) {
$needed = comments_open() || (bool) get_comments_number();
$post = get_post();
if ( ! $needed && $post instanceof WP_Post ) {
$needed = has_block( 'core/search', $post ) || slateframe_content_has_form( $post->post_content );
}
}
/**
* Filters whether Slateframe's shared form-control stylesheet is needed.
*
* Integrations that render forms outside post content may opt in without
* coupling the theme to a plugin, widget ID, locale, or URL structure.
*
* @param bool $needed Whether the form-control layer is needed.
*/
return (bool) apply_filters( 'slateframe_forms_styles_needed', $needed );
}
/**
* Determine whether authored content needs the richer form-state layer.
*
* @return bool
*/
function slateframe_form_content_styles_needed() {
$footer = slateframe_footer_form_assets();
$needed = $footer['form_content'] || slateframe_singular_synced_form_assets()['form_content'];
if ( is_singular() ) {
$post = get_post();
if ( $post instanceof WP_Post ) {
$needed = $needed || slateframe_content_has_form( $post->post_content );
}
}
/**
* Filters whether Slateframe's authored form-state stylesheet is needed.
*
* @param bool $needed Whether readonly, invalid, grouping, and help states are needed.
*/
return (bool) apply_filters( 'slateframe_form_content_styles_needed', $needed );
}
/**
* Determine whether a parsed block tree enables WordPress Core's native lightbox.
*
* @param array[] $blocks Parsed blocks.
* @return bool
*/
function slateframe_blocks_have_lightbox( $blocks ) {
foreach ( $blocks as $block ) {
$block_name = isset( $block['blockName'] ) ? $block['blockName'] : '';
if (
in_array( $block_name, array( 'core/image', 'core/gallery' ), true ) &&
! empty( $block['attrs']['lightbox']['enabled'] )
) {
return true;
}
if ( ! empty( $block['innerBlocks'] ) && slateframe_blocks_have_lightbox( $block['innerBlocks'] ) ) {
return true;
}
}
return false;
}
/**
* Determine whether the current singular document needs Photography styles.
*
* New integrations should use the narrow Photography filter. Markers added
* through the older broad content-mode filter are also honored so documented
* extension callbacks keep their pre-split behavior.
*
* @return bool
*/
function slateframe_photography_styles_needed() {
if ( ! is_singular() ) {
return false;
}
$post = get_post();
if ( ! $post instanceof WP_Post ) {
return false;
}
$markers = slateframe_photography_marker_classes();
$contents = array_merge( array( $post->post_content ), slateframe_singular_synced_pattern_contents() );
foreach ( $contents as $content ) {
if ( is_array( $markers ) && slateframe_content_has_class_marker( $content, array_unique( $markers ) ) ) {
return true;
}
if ( slateframe_blocks_have_lightbox( parse_blocks( $content ) ) ) {
return true;
}
}
return false;
}
/**
* Determine whether the current singular document needs Portfolio/Knowledge styles.
*
* @return bool
*/
function slateframe_content_modes_needed() {
if ( ! is_singular() ) {
return false;
}
$post = get_post();
if ( ! $post instanceof WP_Post ) {
return false;
}
$markers = slateframe_content_mode_marker_classes();
if ( ! is_array( $markers ) ) {
return false;
}
foreach ( array_merge( array( $post->post_content ), slateframe_singular_synced_pattern_contents() ) as $content ) {
if ( slateframe_content_has_class_marker( $content, $markers ) ) {
return true;
}
}
return false;
}
/**
* Determine whether the current document contains Slateframe's native Query Loop grid.
*
* @return bool
*/
function slateframe_query_loop_styles_needed() {
if ( ! is_singular() ) {
return false;
}
$post = get_post();
if ( ! $post instanceof WP_Post ) {
return false;
}
$markers = slateframe_query_loop_marker_classes();
foreach ( array_merge( array( $post->post_content ), slateframe_singular_synced_pattern_contents() ) as $content ) {
if ( slateframe_content_has_class_marker( $content, $markers ) ) {
return true;
}
}
return false;
}
/**
* Enqueue the intentionally small frontend asset layer.
*/
function slateframe_assets() {
$version = wp_get_theme()->get( 'Version' );
$footer_presentation = slateframe_footer_presentation_assets();
$photography_needed = slateframe_photography_styles_needed() || $footer_presentation['photography'];
$content_modes_needed = slateframe_content_modes_needed() || $footer_presentation['content_modes'];
$query_loop_needed = slateframe_query_loop_styles_needed() || $footer_presentation['query_loop'];
$forms_needed = slateframe_forms_styles_needed();
$form_content_needed = slateframe_form_content_styles_needed();
$search_form_needed = slateframe_search_form_styles_needed();
// Preserve CSS dependency closure even when extension filters disagree.
$forms_needed = $forms_needed || $form_content_needed || $search_form_needed;
wp_enqueue_style( 'slateframe-style', get_stylesheet_uri(), array(), $version );
wp_enqueue_style(
'slateframe-navigation',
get_template_directory_uri() . '/assets/css/navigation.css',
array( 'slateframe-style' ),
$version
);
wp_enqueue_style(
'slateframe-footer',
get_template_directory_uri() . '/assets/css/footer.css',
array( 'slateframe-style' ),
$version
);
if ( $forms_needed ) {
wp_enqueue_style(
'slateframe-forms',
get_template_directory_uri() . '/assets/css/forms.css',
array( 'slateframe-style' ),
$version
);
}
if ( $search_form_needed ) {
wp_enqueue_style(
'slateframe-search-form',
get_template_directory_uri() . '/assets/css/search-form.css',
array( 'slateframe-forms' ),
$version
);
}
if ( is_singular() ) {
wp_enqueue_style(
'slateframe-reading',
get_template_directory_uri() . '/assets/css/reading.css',
array( 'slateframe-style' ),
$version
);
}
global $wp_query;
$empty_state_needed = ( is_home() || is_archive() || is_search() ) && isset( $wp_query ) && 0 === (int) $wp_query->post_count;
if ( $empty_state_needed ) {
wp_enqueue_style(
'slateframe-empty-state',
get_template_directory_uri() . '/assets/css/empty-state.css',
array( 'slateframe-style' ),
$version
);
}
if ( is_singular() || is_author() || is_404() ) {
$publishing_dependencies = is_singular() ? array( 'slateframe-reading' ) : array( 'slateframe-style' );
wp_enqueue_style(
'slateframe-publishing',
get_template_directory_uri() . '/assets/css/publishing.css',
$publishing_dependencies,
$version
);
}
if ( $form_content_needed ) {
wp_enqueue_style(
'slateframe-form-content',
get_template_directory_uri() . '/assets/css/form-content.css',
array( 'slateframe-forms' ),
$version
);
}
if ( $photography_needed ) {
wp_enqueue_style(
'slateframe-photography',
get_template_directory_uri() . '/assets/css/photography.css',
is_singular() ? array( 'slateframe-reading' ) : array( 'slateframe-style' ),
$version
);
}
if ( $content_modes_needed || $query_loop_needed ) {
wp_enqueue_style(
'slateframe-content-modes',
get_template_directory_uri() . '/assets/css/content-modes.css',
is_singular() ? array( 'slateframe-reading' ) : array( 'slateframe-style' ),
$version
);
}
if ( $query_loop_needed ) {
wp_enqueue_style(
'slateframe-query-loop',
get_template_directory_uri() . '/assets/css/query-loop.css',
array( 'slateframe-content-modes' ),
$version
);
}
if ( is_singular() && ( comments_open() || get_comments_number() ) ) {
wp_enqueue_style(
'slateframe-comments',
get_template_directory_uri() . '/assets/css/comments.css',
array( 'slateframe-reading', 'slateframe-forms' ),
$version
);
}
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_rtl() ) {
wp_enqueue_style(
'slateframe-rtl',
get_template_directory_uri() . '/rtl.css',
array( 'slateframe-style' ),
$version
);
}
wp_enqueue_style(
'slateframe-print',
get_template_directory_uri() . '/assets/css/print.css',
array( 'slateframe-style' ),
$version,
'print'
);
wp_enqueue_script(
'slateframe-theme',
get_template_directory_uri() . '/assets/js/theme.js',
array(),
$version,
array(
'in_footer' => true,
'strategy' => 'defer',
)
);
}
add_action( 'wp_enqueue_scripts', 'slateframe_assets' );
/**
* Keep potentially scrollable Core table blocks reachable from the keyboard.
*
* The wrapper owns horizontal overflow at narrow widths and text zoom, so it
* needs a focus stop even when the table happens to fit at the current width.
* Preserve an author-supplied tabindex when one is present.
*
* @param string $block_content Rendered Core table block markup.
* @return string
*/
function slateframe_focusable_table_block( $block_content ) {
if ( '' === $block_content ) {
return $block_content;
}
$processor = new WP_HTML_Tag_Processor( $block_content );
while ( $processor->next_tag( array( 'tag_name' => 'FIGURE' ) ) ) {
if ( ! $processor->has_class( 'wp-block-table' ) ) {
continue;
}
if ( null === $processor->get_attribute( 'tabindex' ) ) {
$processor->set_attribute( 'tabindex', '0' );
}
break;
}
return $processor->get_updated_html();
}
add_filter( 'render_block_core/table', 'slateframe_focusable_table_block' );
/**
* Make Core Calendar's horizontal scroll container keyboard reachable.
*
* Calendar renders a seven-column table inside a Core-owned wrapper. At
* narrow widths or text zoom, the wrapper scrolls instead of changing the
* table semantics. Keep author-supplied tabindex values untouched.
*
* @param string $block_content Rendered Core Calendar markup.
* @return string
*/
function slateframe_focusable_calendar_block( $block_content ) {
if ( '' === $block_content || false === strpos( $block_content, 'wp-block-calendar' ) ) {
return $block_content;
}
$processor = new WP_HTML_Tag_Processor( $block_content );
while ( $processor->next_tag( array( 'tag_name' => 'DIV' ) ) ) {
if ( ! $processor->has_class( 'wp-block-calendar' ) ) {
continue;
}
if ( null === $processor->get_attribute( 'tabindex' ) ) {
$processor->set_attribute( 'tabindex', '0' );
}
break;
}
return $processor->get_updated_html();
}
add_filter( 'render_block_core/calendar', 'slateframe_focusable_calendar_block' );
/**
* Render only the custom-logo image inside Slateframe's own brand link.
*
* Core get_custom_logo() includes its own anchor. Rendering the attachment
* directly avoids invalid nested links in the header.
*/
function slateframe_brand_mark() {
$logo_id = (int) get_theme_mod( 'custom_logo' );
if ( ! $logo_id ) {
return;
}
echo wp_kses_post(
wp_get_attachment_image(
$logo_id,
'full',
false,
array(
'class' => 'slateframe-brand-logo',
'alt' => '',
'aria-hidden' => 'true',
'loading' => 'eager',
'decoding' => 'async',
)
)
);
}
/**
* Render an optional language selector supplied by an integration plugin.
*
* Core remains language-agnostic: no locale list, URL pattern, or plugin is
* assumed here.
*/
function slateframe_language_switcher() {
$html = apply_filters( 'slateframe_language_switcher_html', '' );
if ( ! $html ) {
return;
}
echo '<div class="slateframe-language-slot">';
echo wp_kses_post( $html );
echo '</div>';
}
/**
* Register reusable editorial block styles.
*/
function slateframe_register_block_styles() {
$styles = array(
array( 'core/quote', 'slateframe-note', __( 'Editorial note', 'slateframe' ) ),
array( 'core/paragraph', 'slateframe-lead', __( 'Editorial lead', 'slateframe' ) ),
array( 'core/group', 'slateframe-project-feature', __( 'Project feature', 'slateframe' ) ),
array( 'core/group', 'slateframe-learning-path', __( 'Learning path', 'slateframe' ) ),
array( 'core/image', 'slateframe-frame', __( 'Editorial frame', 'slateframe' ) ),
array( 'core/gallery', 'slateframe-photo-sequence', __( 'Photo sequence', 'slateframe' ) ),
array( 'core/table', 'slateframe-data', __( 'Data table', 'slateframe' ) ),
array( 'core/details', 'slateframe-disclosure', __( 'Editorial disclosure', 'slateframe' ) ),
array( 'core/gallery', 'slateframe-contact-sheet', __( 'Contact sheet', 'slateframe' ) ),
array( 'core/gallery', 'slateframe-diptych', __( 'Photography diptych', 'slateframe' ) ),
array( 'core/image', 'slateframe-photo-feature', __( 'Photography feature', 'slateframe' ) ),
array( 'core/list', 'slateframe-steps', __( 'Numbered steps', 'slateframe' ) ),
array( 'core/list', 'slateframe-checklist', __( 'Editorial checklist', 'slateframe' ) ),
array( 'core/group', 'slateframe-key-facts', __( 'Key facts', 'slateframe' ) ),
array( 'core/group', 'slateframe-project-brief', __( 'Project brief', 'slateframe' ) ),
array( 'core/group', 'slateframe-learning-callout', __( 'Learning callout', 'slateframe' ) ),
array( 'core/group', 'slateframe-definition', __( 'Definition', 'slateframe' ) ),
array( 'core/columns', 'slateframe-metrics', __( 'Project metrics', 'slateframe' ) ),
array( 'core/columns', 'slateframe-ledger', __( 'Editorial ledger', 'slateframe' ) ),
);
foreach ( $styles as $style ) {
register_block_style(
$style[0],
array(
'name' => $style[1],
'label' => $style[2],
)
);
}
}
add_action( 'init', 'slateframe_register_block_styles' );
/**
* Register Slateframe's pattern category.
*/
function slateframe_pattern_category() {
$categories = array(
'slateframe' => __( 'Slateframe', 'slateframe' ),
'slateframe-photography' => __( 'Slateframe: Photography', 'slateframe' ),
'slateframe-portfolio' => __( 'Slateframe: Portfolio', 'slateframe' ),
'slateframe-knowledge' => __( 'Slateframe: Knowledge', 'slateframe' ),
);
foreach ( $categories as $slug => $label ) {
register_block_pattern_category(
$slug,
array(
'label' => $label,
)
);
}
}
add_action( 'init', 'slateframe_pattern_category' );