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-content` block. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
9 |
* Renders the `core/comment-content` 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 content. |
|
17 |
*/ |
|
18 |
function render_block_core_comment_content( $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 |
||
30 |
$args = array(); |
|
31 |
$comment_text = get_comment_text( $comment, $args ); |
|
32 |
if ( ! $comment_text ) { |
|
33 |
return ''; |
|
34 |
} |
|
35 |
||
36 |
/** This filter is documented in wp-includes/comment-template.php */ |
|
37 |
$comment_text = apply_filters( 'comment_text', $comment_text, $comment, $args ); |
|
38 |
||
39 |
$moderation_note = ''; |
|
40 |
if ( '0' === $comment->comment_approved ) { |
|
41 |
$commenter = wp_get_current_commenter(); |
|
42 |
||
43 |
if ( $commenter['comment_author_email'] ) { |
|
44 |
$moderation_note = __( 'Your comment is awaiting moderation.' ); |
|
45 |
} else { |
|
46 |
$moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.' ); |
|
47 |
} |
|
48 |
$moderation_note = '<p><em class="comment-awaiting-moderation">' . $moderation_note . '</em></p>'; |
|
49 |
if ( ! $show_pending_links ) { |
|
50 |
$comment_text = wp_kses( $comment_text, array() ); |
|
51 |
} |
|
52 |
} |
|
53 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
54 |
$classes = array(); |
19 | 55 |
if ( isset( $attributes['textAlign'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
56 |
$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
|
57 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
58 |
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
|
59 |
$classes[] = 'has-link-color'; |
19 | 60 |
} |
61 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
62 |
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); |
19 | 63 |
|
64 |
return sprintf( |
|
65 |
'<div %1$s>%2$s%3$s</div>', |
|
66 |
$wrapper_attributes, |
|
67 |
$moderation_note, |
|
68 |
$comment_text |
|
69 |
); |
|
70 |
} |
|
71 |
||
72 |
/** |
|
73 |
* Registers the `core/comment-content` block on the server. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
74 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
75 |
* @since 6.0.0 |
19 | 76 |
*/ |
77 |
function register_block_core_comment_content() { |
|
78 |
register_block_type_from_metadata( |
|
79 |
__DIR__ . '/comment-content', |
|
80 |
array( |
|
81 |
'render_callback' => 'render_block_core_comment_content', |
|
82 |
) |
|
83 |
); |
|
84 |
} |
|
85 |
add_action( 'init', 'register_block_core_comment_content' ); |