author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
18 | 1 |
<?php |
2 |
/** |
|
3 |
* Server-side rendering of the `core/site-title` block. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
9 |
* Renders the `core/site-title` block on the server. |
|
10 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
11 |
* @since 5.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
12 |
* |
18 | 13 |
* @param array $attributes The block attributes. |
14 |
* |
|
15 |
* @return string The render. |
|
16 |
*/ |
|
17 |
function render_block_core_site_title( $attributes ) { |
|
18 |
$site_title = get_bloginfo( 'name' ); |
|
19 |
if ( ! $site_title ) { |
|
20 |
return; |
|
21 |
} |
|
22 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
23 |
$tag_name = 'h1'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
24 |
$classes = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
25 |
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
26 |
$classes .= ' has-link-color'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
27 |
} |
19 | 28 |
|
18 | 29 |
if ( isset( $attributes['level'] ) ) { |
19 | 30 |
$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . (int) $attributes['level']; |
18 | 31 |
} |
32 |
||
19 | 33 |
if ( $attributes['isLink'] ) { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
34 |
$aria_current = ! is_paged() && ( is_front_page() || is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) ? ' aria-current="page"' : ''; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
35 |
$link_target = ! empty( $attributes['linkTarget'] ) ? $attributes['linkTarget'] : '_self'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
36 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
37 |
$site_title = sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
38 |
'<a href="%1$s" target="%2$s" rel="home"%3$s>%4$s</a>', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
39 |
esc_url( home_url() ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
40 |
esc_attr( $link_target ), |
19 | 41 |
$aria_current, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
42 |
esc_html( $site_title ) |
19 | 43 |
); |
44 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
45 |
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classes ) ) ); |
18 | 46 |
|
47 |
return sprintf( |
|
48 |
'<%1$s %2$s>%3$s</%1$s>', |
|
49 |
$tag_name, |
|
50 |
$wrapper_attributes, |
|
19 | 51 |
// already pre-escaped if it is a link. |
52 |
$attributes['isLink'] ? $site_title : esc_html( $site_title ) |
|
18 | 53 |
); |
54 |
} |
|
55 |
||
56 |
/** |
|
57 |
* Registers the `core/site-title` block on the server. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
58 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
59 |
* @since 5.8.0 |
18 | 60 |
*/ |
61 |
function register_block_core_site_title() { |
|
62 |
register_block_type_from_metadata( |
|
63 |
__DIR__ . '/site-title', |
|
64 |
array( |
|
65 |
'render_callback' => 'render_block_core_site_title', |
|
66 |
) |
|
67 |
); |
|
68 |
} |
|
69 |
add_action( 'init', 'register_block_core_site_title' ); |