author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
19 | 1 |
<?php |
2 |
/** |
|
3 |
* Server-side rendering of the `core/comment-author-name` block. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
9 |
* Renders the `core/comment-author-name` 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 6.0.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
12 |
* |
19 | 13 |
* @param array $attributes Block attributes. |
14 |
* @param string $content Block default content. |
|
15 |
* @param WP_Block $block Block instance. |
|
16 |
* @return string Return the post comment's author. |
|
17 |
*/ |
|
18 |
function render_block_core_comment_author_name( $attributes, $content, $block ) { |
|
19 |
if ( ! isset( $block->context['commentId'] ) ) { |
|
20 |
return ''; |
|
21 |
} |
|
22 |
||
23 |
$comment = get_comment( $block->context['commentId'] ); |
|
24 |
$commenter = wp_get_current_commenter(); |
|
25 |
$show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author']; |
|
26 |
if ( empty( $comment ) ) { |
|
27 |
return ''; |
|
28 |
} |
|
29 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
30 |
$classes = array(); |
19 | 31 |
if ( isset( $attributes['textAlign'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
$classes[] = 'has-text-align-' . $attributes['textAlign']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
34 |
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
|
35 |
$classes[] = 'has-link-color'; |
19 | 36 |
} |
37 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
38 |
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); |
19 | 39 |
$comment_author = get_comment_author( $comment ); |
40 |
$link = get_comment_author_url( $comment ); |
|
41 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
42 |
if ( ! empty( $link ) && ! empty( $attributes['isLink'] ) && ! empty( $attributes['linkTarget'] ) ) { |
19 | 43 |
$comment_author = sprintf( '<a rel="external nofollow ugc" href="%1s" target="%2s" >%3s</a>', esc_url( $link ), esc_attr( $attributes['linkTarget'] ), $comment_author ); |
44 |
} |
|
45 |
if ( '0' === $comment->comment_approved && ! $show_pending_links ) { |
|
46 |
$comment_author = wp_kses( $comment_author, array() ); |
|
47 |
} |
|
48 |
||
49 |
return sprintf( |
|
50 |
'<div %1$s>%2$s</div>', |
|
51 |
$wrapper_attributes, |
|
52 |
$comment_author |
|
53 |
); |
|
54 |
} |
|
55 |
||
56 |
/** |
|
57 |
* Registers the `core/comment-author-name` 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 6.0.0 |
19 | 60 |
*/ |
61 |
function register_block_core_comment_author_name() { |
|
62 |
register_block_type_from_metadata( |
|
63 |
__DIR__ . '/comment-author-name', |
|
64 |
array( |
|
65 |
'render_callback' => 'render_block_core_comment_author_name', |
|
66 |
) |
|
67 |
); |
|
68 |
} |
|
69 |
add_action( 'init', 'register_block_core_comment_author_name' ); |