Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
680 lines (616 loc) · 25.5 KB
/
Copy pathfunctions.php
File metadata and controls
680 lines (616 loc) · 25.5 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
<?php
/**
* Origin theme bootstrap file. Keeps the PHP layer lean so block templates
* remain the source of truth for layout decisions.
*
* @package Origin_Canvas
*/
if ( ! defined( 'ORIGIN_CANVAS_VERSION' ) ) {
$origin_canvas_theme = wp_get_theme();
define( 'ORIGIN_CANVAS_VERSION', $origin_canvas_theme->get( 'Version' ) );
}
// The palette rename (#116): the map, the pre-rename mark and the aliases; the content migration lives in a separate plugin.
require_once get_template_directory() . '/inc/palette-map.php';
require_once get_template_directory() . '/inc/palette-state.php';
require_once get_template_directory() . '/inc/palette-aliases.php';
if ( ! function_exists( 'origin_canvas_setup' ) ) {
/**
* Register core theme supports.
*/
function origin_canvas_setup() {
add_theme_support( 'wp-block-styles' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'editor-styles' );
add_editor_style( 'style.css' );
}
}
add_action( 'after_setup_theme', 'origin_canvas_setup' );
if ( ! function_exists( 'origin_canvas_enqueue_styles' ) ) {
/**
* Enqueue the base stylesheet so classic scripts inherit typography defaults.
*/
function origin_canvas_enqueue_styles() {
// Version by mtime, as the block-style loader does, so a changed style.css
// gets a fresh URL instead of a stale cached copy.
$file = get_stylesheet_directory() . '/style.css';
$mtime = file_exists( $file ) ? filemtime( $file ) : false;
wp_enqueue_style( 'origin-canvas-style', get_stylesheet_uri(), array(), $mtime ? $mtime : ORIGIN_CANVAS_VERSION );
}
}
add_action( 'wp_enqueue_scripts', 'origin_canvas_enqueue_styles' );
if ( ! function_exists( 'origin_canvas_enqueue_scripts' ) ) {
/**
* Enqueue the anchor-navigation script: smooth same-page scrolling below the
* sticky chrome and the current-section navigation marker. Front end only.
*
* The `origin_canvas_enqueue_anchor_navigation` filter switches the script off.
* The `scroll-padding-top` rules in style.css stay in place either way, like the
* sticky-header rule they accompany.
*/
function origin_canvas_enqueue_scripts() {
if ( ! apply_filters( 'origin_canvas_enqueue_anchor_navigation', true ) ) {
return;
}
$path = get_theme_file_path( 'assets/js/anchor-navigation.js' );
$mtime = file_exists( $path ) ? filemtime( $path ) : false;
wp_enqueue_script(
'origin-canvas-anchor-navigation',
get_theme_file_uri( 'assets/js/anchor-navigation.js' ),
array(),
$mtime ? $mtime : ORIGIN_CANVAS_VERSION,
array( 'strategy' => 'defer' )
);
}
}
add_action( 'wp_enqueue_scripts', 'origin_canvas_enqueue_scripts' );
if ( ! function_exists( 'origin_canvas_register_custom_patterns' ) ) {
/**
* Ensure custom patterns are available when the editor cache lags behind.
*/
function origin_canvas_register_custom_patterns() {
if ( ! function_exists( 'register_block_pattern' ) ) {
return;
}
if ( ! class_exists( 'WP_Block_Patterns_Registry' ) ) {
return;
}
$registry = WP_Block_Patterns_Registry::get_instance();
$patterns = array(
'origin-canvas/hidden-single-right-sidebar' => array(
'title' => __( 'Hidden: Single Right Sidebar', 'origin-canvas' ),
'inserter' => false,
'categories' => array( 'hidden' ),
'file' => 'patterns/hidden-single-right-sidebar.php',
),
'origin-canvas/process-numbered' => array(
'title' => __( 'Process Numbered', 'origin-canvas' ),
'inserter' => true,
'categories' => array( 'origin-canvas/features' ),
'file' => 'patterns/process-numbered.php',
),
'origin-canvas/cta-band' => array(
'title' => __( 'CTA Card Split', 'origin-canvas' ),
'inserter' => true,
'categories' => array( 'call-to-action' ),
'file' => 'patterns/cta-band.php',
),
);
foreach ( $patterns as $pattern_slug => $pattern ) {
if ( $registry->is_registered( $pattern_slug ) ) {
continue;
}
$pattern_file = get_theme_file_path( $pattern['file'] );
if ( ! file_exists( $pattern_file ) ) {
continue;
}
ob_start();
include $pattern_file;
$pattern_contents = ob_get_clean();
if ( empty( $pattern_contents ) ) {
continue;
}
register_block_pattern(
$pattern_slug,
array(
'title' => $pattern['title'],
'inserter' => $pattern['inserter'],
'categories' => $pattern['categories'],
'content' => trim( $pattern_contents ),
)
);
}
}
}
add_action( 'init', 'origin_canvas_register_custom_patterns' );
if ( ! function_exists( 'origin_canvas_register_pattern_categories' ) ) {
/**
* Register Origin-namespaced block pattern categories.
*/
function origin_canvas_register_pattern_categories() {
// Only categories WordPress does not already provide. Core supplies text,
// testimonials, team, posts, contact and gallery — using ours alongside them
// would show the editor two near-identical entries for the same thing.
$categories = array(
'origin-canvas/hero' => array( 'label' => __( 'Hero', 'origin-canvas' ) ),
'origin-canvas/page' => array( 'label' => __( 'Pages', 'origin-canvas' ) ),
'origin-canvas/features' => array( 'label' => __( 'Features', 'origin-canvas' ) ),
'origin-canvas/stats' => array( 'label' => __( 'Stats', 'origin-canvas' ) ),
'origin-canvas/pricing' => array( 'label' => __( 'Pricing', 'origin-canvas' ) ),
'origin-canvas/card' => array( 'label' => __( 'Cards', 'origin-canvas' ) ),
'origin-canvas/faq' => array( 'label' => __( 'FAQ', 'origin-canvas' ) ),
'origin-canvas/logos' => array( 'label' => __( 'Logos', 'origin-canvas' ) ),
'origin-canvas/author' => array( 'label' => __( 'Author', 'origin-canvas' ) ),
);
foreach ( $categories as $slug => $props ) {
register_block_pattern_category( $slug, $props );
}
}
}
add_action( 'init', 'origin_canvas_register_pattern_categories', 9 );
if ( ! function_exists( 'origin_canvas_featured_image_fallback' ) ) {
/**
* Render a placeholder when a featured image is missing in curated loops.
*
* @param string $block_content Rendered block HTML.
* @param array $block Block data.
* @return string
*/
function origin_canvas_featured_image_fallback( $block_content, $block ) {
$attrs = $block['attrs'] ?? array();
$class_name = $attrs['className'] ?? '';
if ( strpos( $class_name, 'origin-canvas-featured-fallback' ) === false ) {
return $block_content;
}
$post = get_post();
if ( $post && has_post_thumbnail( $post ) ) {
return $block_content;
}
$classes = preg_split( '/\s+/', $class_name, -1, PREG_SPLIT_NO_EMPTY );
$classes[] = 'origin-canvas-featured-fallback';
$class_string = implode( ' ', array_unique( $classes ) );
$classes = array( 'wp-block-post-featured-image', $class_string );
if ( ! empty( $attrs['align'] ) ) {
$classes[] = 'align' . $attrs['align'];
}
$style_output = array();
if ( ! empty( $attrs['style'] ) ) {
$style_output = wp_style_engine_get_styles( $attrs['style'] );
}
if ( ! empty( $style_output['classnames'] ) ) {
$classes[] = $style_output['classnames'];
}
$wrapper_styles = $style_output['css'] ?? '';
if ( ! empty( $attrs['aspectRatio'] ) ) {
$wrapper_styles .= 'aspect-ratio:' . $attrs['aspectRatio'] . ';';
}
if ( ! empty( $attrs['width'] ) ) {
$wrapper_styles .= 'width:' . $attrs['width'] . ';';
}
if ( ! empty( $attrs['height'] ) ) {
$height = trim( (string) $attrs['height'] );
if ( is_numeric( $height ) ) {
$height .= 'px';
}
$wrapper_styles .= 'height:' . $height . ';';
}
$wrapper_attributes = sprintf(
'class="%s"%s',
esc_attr( trim( implode( ' ', array_filter( $classes ) ) ) ),
'' !== $wrapper_styles ? ' style="' . esc_attr( safecss_filter_attr( $wrapper_styles ) ) . '"' : ''
);
$link_open = '';
$link_close = '';
if ( ! empty( $attrs['isLink'] ) && $post ) {
$link_open = sprintf(
'<a class="origin-canvas-featured-fallback__link" href="%s" aria-label="%s">',
esc_url( get_permalink( $post ) ),
esc_attr( get_the_title( $post ) )
);
$link_close = '</a>';
}
return sprintf(
'<figure %1$s>%2$s<span class="origin-canvas-featured-fallback__media" aria-hidden="true"></span>%3$s</figure>',
$wrapper_attributes,
$link_open,
$link_close
);
}
}
add_filter( 'render_block_core/post-featured-image', 'origin_canvas_featured_image_fallback', 10, 2 );
if ( ! function_exists( 'origin_canvas_register_block_styles' ) ) {
/**
* Register block style variations.
*
* @return void
*/
function origin_canvas_register_block_styles() {
$block_styles = array(
'core/accordion' => array(
array( 'name' => 'origin-canvas-accordion-minimal', 'label' => __( 'Minimal', 'origin-canvas' ) ),
),
'core/button' => array(
array( 'name' => 'origin-canvas-outline-light', 'label' => __( 'Outline Light', 'origin-canvas' ) ),
array( 'name' => 'origin-canvas-fill-primary', 'label' => __( 'Fill Primary', 'origin-canvas' ) ),
),
'core/list' => array(
array( 'name' => 'origin-canvas-list-check', 'label' => __( 'Check Primary', 'origin-canvas' ) ),
array( 'name' => 'origin-canvas-list-check-circle', 'label' => __( 'Check Circle Primary', 'origin-canvas' ) ),
array( 'name' => 'origin-canvas-list-check-neutral', 'label' => __( 'Check Neutral', 'origin-canvas' ) ),
array( 'name' => 'origin-canvas-list-check-circle-neutral', 'label' => __( 'Check Circle Neutral', 'origin-canvas' ) ),
),
'core/navigation' => array(
array( 'name' => 'origin-canvas-hover-accent', 'label' => __( 'Hover Primary', 'origin-canvas' ) ),
array( 'name' => 'origin-canvas-hover-pill', 'label' => __( 'Hover Pill', 'origin-canvas' ) ),
),
'core/separator' => array(
array( 'name' => 'origin-canvas-separator-dotted', 'label' => __( 'Dotted', 'origin-canvas' ) ),
array( 'name' => 'origin-canvas-separator-thin', 'label' => __( 'Thin', 'origin-canvas' ) ),
),
'core/image' => array(
array( 'name' => 'origin-canvas-rounded-full', 'label' => __( 'Rounded Full', 'origin-canvas' ) ),
array( 'name' => 'origin-canvas-media-boxed', 'label' => __( 'Boxed', 'origin-canvas' ) ),
),
'core/post-terms' => array(
array(
'name' => 'origin-canvas-term-chip',
'label' => __( 'Chip', 'origin-canvas' ),
'style_data' => array(
'elements' => array(
'link' => array(
'color' => array(
'text' => 'var:preset|color|contrast',
'background' => 'var:preset|color|base-2',
),
'border' => array(
'radius' => 'var:custom|radius|medium',
),
'spacing' => array(
'padding' => array(
'top' => '6px',
'right' => '8px',
'bottom' => '6px',
'left' => '8px',
),
),
'typography' => array(
'fontSize' => 'var:preset|font-size|extra-small',
),
':hover' => array(
'color' => array(
'background' => 'var:preset|color|base-5',
),
),
),
),
),
),
array(
'name' => 'origin-canvas-term-inline',
'label' => __( 'Inline', 'origin-canvas' ),
'style_data' => array(
'color' => array(
'text' => 'var:preset|color|contrast-2',
),
'elements' => array(
'link' => array(
'color' => array(
'text' => 'var:preset|color|contrast',
),
'typography' => array(
'textDecoration' => 'none',
),
':hover' => array(
'color' => array(
'text' => 'var:preset|color|primary',
),
),
),
),
),
),
),
'core/post-navigation-link' => array(
array( 'name' => 'origin-canvas-postnav-stacked', 'label' => __( 'Stacked', 'origin-canvas' ) ),
),
'core/tag-cloud' => array(
array( 'name' => 'origin-canvas-tag-chip', 'label' => __( 'Chip', 'origin-canvas' ) ),
),
'core/post-excerpt' => array(
array( 'name' => 'origin-canvas-excerpt-truncate-2', 'label' => __( 'Truncate 2 Lines', 'origin-canvas' ) ),
array( 'name' => 'origin-canvas-excerpt-truncate-3', 'label' => __( 'Truncate 3 Lines', 'origin-canvas' ) ),
),
'core/code' => array(
array( 'name' => 'origin-canvas-dark-code', 'label' => __( 'Dark', 'origin-canvas' ) ),
),
'core/preformatted' => array(
array( 'name' => 'origin-canvas-preformatted-dark', 'label' => __( 'Dark', 'origin-canvas' ) ),
),
'core/cover' => array(
array( 'name' => 'origin-canvas-blur-image-less', 'label' => __( 'Blur Image Less', 'origin-canvas' ) ),
array( 'name' => 'origin-canvas-blur-image-more', 'label' => __( 'Blur Image More', 'origin-canvas' ) ),
),
'core/video' => array(
array( 'name' => 'origin-canvas-media-boxed', 'label' => __( 'Boxed', 'origin-canvas' ) ),
),
);
foreach ( $block_styles as $block_name => $styles ) {
foreach ( $styles as $style ) {
register_block_style( $block_name, $style );
}
}
}
}
add_action( 'init', 'origin_canvas_register_block_styles' );
if ( ! function_exists( 'origin_canvas_enqueue_block_styles' ) ) {
/**
* Enqueue per-block CSS only when the block is used on the page.
*
* Scans assets/styles/ for CSS files named {namespace}-{block}.css
* (e.g. core-list.css) and registers them via wp_enqueue_block_style().
*/
function origin_canvas_enqueue_block_styles() {
$files = glob( get_template_directory() . '/assets/styles/*.css' );
if ( empty( $files ) ) {
return;
}
foreach ( $files as $file ) {
$filename = basename( $file, '.css' );
$block_name = str_replace( 'core-', 'core/', $filename );
// Version each stylesheet by its on-disk mtime so any change gets a fresh
// URL; browsers otherwise cache the file under the fixed theme version and
// serve stale CSS across edits. Fall back to the theme version if the file
// cannot be stat-ed.
$mtime = file_exists( $file ) ? filemtime( $file ) : false;
$ver = $mtime ? $mtime : ORIGIN_CANVAS_VERSION;
wp_enqueue_block_style(
$block_name,
array(
'handle' => "origin-canvas-block-{$filename}",
'src' => get_theme_file_uri( "assets/styles/{$filename}.css" ),
'path' => get_theme_file_path( "assets/styles/{$filename}.css" ),
'ver' => $ver,
)
);
}
}
}
add_action( 'init', 'origin_canvas_enqueue_block_styles' );
if ( ! function_exists( 'origin_canvas_add_block_editor_styles' ) ) {
/**
* Inject every per-block stylesheet into the block editor canvas.
*
* The front-end loader (origin_canvas_enqueue_block_styles) registers per-block
* CSS on-demand via wp_enqueue_block_style(), which does not reach the iframed
* editor canvas. add_editor_style() is the block-theme-idiomatic way to get CSS
* into that iframe, so the editor previews every block style variation.
*
* Paths must be theme-relative (not absolute URIs); strip the template-dir
* prefix from each globbed file before handing it to add_editor_style().
*/
function origin_canvas_add_block_editor_styles() {
$files = glob( get_template_directory() . '/assets/styles/*.css' );
if ( empty( $files ) ) {
return;
}
$prefix = trailingslashit( get_template_directory() );
$paths = array();
foreach ( $files as $file ) {
$paths[] = str_replace( $prefix, '', $file );
}
add_editor_style( $paths );
}
}
add_action( 'after_setup_theme', 'origin_canvas_add_block_editor_styles' );
if ( ! function_exists( 'origin_canvas_rewrite_legacy_card_image_paths' ) ) {
/**
* Back-compat shim for card images inserted under 1.0.x. Sunset: 2.0.0.
*
* Versions 1.0.0 to 1.0.4 shipped the card images under /assets/images/cards/; 1.1.0 moved
* them to /patterns/images/ (commit 1de024e). Image and Cover are static blocks, so a site that
* inserted a card pattern under 1.0.x holds the old absolute URL in its saved content, and
* wordpress.org distributed those versions. The rewrite happens at render time only: the
* database is not touched and the old folder is not brought back. Scoped to the two block
* types that carry these URLs. card-team-1.webp is not covered: it left the theme in 1.3.0
* (commit 4415891) and has no file to point at.
*
* The shim shipped in 1.1.0 with a 1.3.0 sunset, was removed in 1.4.0, and is restored in
* 1.4.3 because 1.0.x sites are still updating from wordpress.org. A shipped asset name now
* changes only at a major version (CLAUDE.md, 3b), so the shim leaves with 2.0.0.
*
* @param string $block_content Rendered block HTML.
* @return string Block HTML with the legacy card-image path rewritten.
*/
function origin_canvas_rewrite_legacy_card_image_paths( $block_content ) {
// Scoped to this theme's own directory path, whatever the scheme or host the URL was
// saved with, so an image under another theme's or a plugin's assets/images/cards/ is
// left alone.
$theme_path = (string) wp_parse_url( get_template_directory_uri(), PHP_URL_PATH );
$old = $theme_path . '/assets/images/cards/';
if ( false === strpos( $block_content, $old ) ) {
return $block_content;
}
return str_replace( $old, $theme_path . '/patterns/images/', $block_content );
}
}
add_filter( 'render_block_core/image', 'origin_canvas_rewrite_legacy_card_image_paths' );
add_filter( 'render_block_core/cover', 'origin_canvas_rewrite_legacy_card_image_paths' );
if ( ! function_exists( 'origin_canvas_swap_nav_chevron' ) ) {
/**
* Replace core's submenu caret SVG with the Lucide `chevron-down` glyph.
*
* Core renders its caret on a 12-unit viewBox (path "M1.50002 4L6.00002 8L10.5 4"),
* whose geometry CSS cannot reshape into Lucide's. We swap the whole SVG at render
* time for the Lucide chevron-down (path "m6 9 6 6 6-6"). The swap is UNGATED so
* the desktop dropdown AND the mobile overlay share one identical glyph.
*
* The Lucide arrow occupies only the middle band of its native 0 0 24 24 viewBox
* (x 6→18, y 9→15), so at the small display sizes here (11px desktop / 20px mobile)
* a full-viewBox glyph reads tiny and appears off-centre against the close ✕. We
* therefore emit the SAME path in a TIGHT viewBox cropped to the arrow ("5 8 14 8")
* so it fills the icon box at both sizes; per-surface box size stays in CSS.
*
* @param string $block_content Rendered navigation block HTML.
* @param array $block Parsed block (unused; kept for the filter signature).
* @return string Navigation HTML with the caret swapped for Lucide chevron-down.
*/
function origin_canvas_swap_nav_chevron( $block_content, $block = array() ) {
if ( false === strpos( $block_content, 'M1.50002 4L6.00002 8L10.5 4' ) ) {
return $block_content;
}
$lucide_chevron = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="5 8 14 8" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="m6 9 6 6 6-6"></path></svg>';
return preg_replace(
'#<svg[^>]*viewBox="0 0 12 12"[^>]*>\s*<path d="M1\.50002 4L6\.00002 8L10\.5 4"[^>]*>\s*</path>\s*</svg>#',
$lucide_chevron,
$block_content
);
}
}
add_filter( 'render_block_core/navigation', 'origin_canvas_swap_nav_chevron', 10, 2 );
if ( ! function_exists( 'origin_canvas_scope_overlay_nav_context' ) ) {
/**
* Give the navigation inside a custom overlay part its own overlay context.
*
* The header navigation sets `overlay` to a template part, and core renders
* that part inside its own responsive container. Core forces the part's
* navigation to `overlayMenu: never` and, because a non-responsive navigation
* is not an overlay, gives its wrapper no `data-wp-context`. Its submenu
* toggles are still bound to `state.isSubmenuOpen`, which reads
* `overlayOpenedBy` from the nearest context — the HEADER navigation's, one
* level up. While the hamburger is open that reads true, so every toggle
* in the overlay renders aria-expanded="true" and a tap never changes it.
*
* Shadow that one key on the part's navigation wrapper. Its submenus then
* see an overlay nobody has opened and fall through to their own state, so
* the toggle, the chevron rotation and the collapse rules all work. The
* overlay close button lives outside this wrapper and keeps inheriting the
* header's context, which is the context it closes.
*
* Upstream fix: Gutenberg PR #82596 (24.1) adds `hasCustomOverlay` to the
* overlay context and makes the getter ignore `overlayOpenedBy` under a
* custom overlay; this shadow is then a no-op. Remove it once the theme's
* WordPress floor includes that change.
*
* @param string $block_content Rendered navigation block HTML.
* @param array $block Parsed block; core marks a navigation rendered
* inside an overlay part with
* `_isWithinOverlayTemplatePart`.
* @return string Navigation HTML, with the context on the wrapper when the
* block is inside an overlay part and the wrapper has none.
*/
function origin_canvas_scope_overlay_nav_context( $block_content, $block = array() ) {
if ( empty( $block['attrs']['_isWithinOverlayTemplatePart'] ) ) {
return $block_content;
}
$tags = new WP_HTML_Tag_Processor( $block_content );
// The block wrapper is the first tag. Anything else means core changed
// its markup, and the shadow would land on the wrong element.
if ( ! $tags->next_tag() || ! $tags->has_class( 'wp-block-navigation' ) ) {
return $block_content;
}
// A wrapper that already carries a context has been given one by core;
// defer to it.
if ( null !== $tags->get_attribute( 'data-wp-context' ) ) {
return $block_content;
}
$tags->set_attribute(
'data-wp-context',
'core/navigation::' . wp_json_encode(
array(
'overlayOpenedBy' => array(
'click' => false,
'hover' => false,
'focus' => false,
),
)
)
);
return $tags->get_updated_html();
}
}
add_filter( 'render_block_core/navigation', 'origin_canvas_scope_overlay_nav_context', 10, 2 );
if ( ! function_exists( 'origin_canvas_comment_author_badge' ) ) {
/**
* Append an "Author" pill badge to the comment author name when the
* commenter is the post author — the same relationship core marks with
* the .bypostauthor class. Text is ink on a primary-tracking tint per
* the badges/pills design rule.
*
* Disable via: add_filter( 'origin_canvas_render_author_badge', '__return_false' );
*
* @param string $block_content Rendered block HTML.
* @param array $parsed_block Parsed block array (unused).
* @param WP_Block $block Block instance carrying commentId context.
* @return string Filtered block HTML.
*/
function origin_canvas_comment_author_badge( $block_content, $parsed_block, $block ) {
if ( '' === $block_content || empty( $block->context['commentId'] ) ) {
return $block_content;
}
if ( false !== strpos( $block_content, 'origin-canvas-author-badge' ) ) {
return $block_content;
}
$comment = get_comment( $block->context['commentId'] );
if ( ! $comment || ! $comment->user_id ) {
return $block_content;
}
$post = get_post( $comment->comment_post_ID );
if ( ! $post || (int) $comment->user_id !== (int) $post->post_author ) {
return $block_content;
}
if ( ! apply_filters( 'origin_canvas_render_author_badge', true, $comment ) ) {
return $block_content;
}
$badge = '<span class="origin-canvas-author-badge">' . esc_html__( 'Author', 'origin-canvas' ) . '</span>';
$closing = strrpos( $block_content, '</div>' );
if ( false === $closing ) {
return $block_content;
}
return substr_replace( $block_content, $badge, $closing, 0 );
}
}
add_filter( 'render_block_core/comment-author-name', 'origin_canvas_comment_author_badge', 10, 3 );
if ( ! function_exists( 'origin_canvas_site_title_fit_text' ) ) {
/**
* Offer Fit Text on the Site Title block.
*
* Core gives Fit Text only to Paragraph and Heading. Footer Wordmark sets the site's own
* name across the full width with it, so the footer follows the site title when the site
* is renamed. The editor reads the support from the server's block definition, which wins
* over the block's own script registration, so the control appears there too.
*
* @param array $metadata Block metadata read from block.json.
* @return array Metadata with typography.fitText supported for core/site-title.
*/
function origin_canvas_site_title_fit_text( $metadata ) {
if ( isset( $metadata['name'] ) && 'core/site-title' === $metadata['name'] ) {
$metadata['supports']['typography']['fitText'] = true;
}
return $metadata;
}
}
add_filter( 'block_type_metadata', 'origin_canvas_site_title_fit_text' );
if ( ! function_exists( 'origin_canvas_site_title_fit_text_class' ) ) {
/**
* Add the has-fit-text class to a Site Title set to Fit Text on the front end.
*
* Core adds the class, which keeps the text on one line while it is sized, only in the
* editor and in the saved markup of static blocks. Site Title renders on the server, so
* without it a title of several words wraps and is fitted to its longest word.
*
* @param string $block_content Rendered Site Title HTML.
* @param array $block Parsed block.
* @return string Site Title HTML with has-fit-text on its wrapper when fitText is set.
*/
function origin_canvas_site_title_fit_text_class( $block_content, $block ) {
if ( empty( $block['attrs']['fitText'] ) ) {
return $block_content;
}
$processor = new WP_HTML_Tag_Processor( $block_content );
if ( ! $processor->next_tag() ) {
return $block_content;
}
$processor->add_class( 'has-fit-text' );
return $processor->get_updated_html();
}
}
add_filter( 'render_block_core/site-title', 'origin_canvas_site_title_fit_text_class', 10, 2 );