author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
19 | 1 |
<?php |
2 |
/** |
|
3 |
* Server-side rendering of the `core/comment-date` block. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
9 |
* Renders the `core/comment-date` 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 date. |
|
17 |
*/ |
|
18 |
function render_block_core_comment_date( $attributes, $content, $block ) { |
|
19 |
if ( ! isset( $block->context['commentId'] ) ) { |
|
20 |
return ''; |
|
21 |
} |
|
22 |
||
23 |
$comment = get_comment( $block->context['commentId'] ); |
|
24 |
if ( empty( $comment ) ) { |
|
25 |
return ''; |
|
26 |
} |
|
27 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
28 |
$classes = ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) ? 'has-link-color' : ''; |
19 | 29 |
|
30 |
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); |
|
31 |
$formatted_date = get_comment_date( |
|
32 |
isset( $attributes['format'] ) ? $attributes['format'] : '', |
|
33 |
$comment |
|
34 |
); |
|
35 |
$link = get_comment_link( $comment ); |
|
36 |
||
37 |
if ( ! empty( $attributes['isLink'] ) ) { |
|
38 |
$formatted_date = sprintf( '<a href="%1s">%2s</a>', esc_url( $link ), $formatted_date ); |
|
39 |
} |
|
40 |
||
41 |
return sprintf( |
|
42 |
'<div %1$s><time datetime="%2$s">%3$s</time></div>', |
|
43 |
$wrapper_attributes, |
|
44 |
esc_attr( get_comment_date( 'c', $comment ) ), |
|
45 |
$formatted_date |
|
46 |
); |
|
47 |
} |
|
48 |
||
49 |
/** |
|
50 |
* Registers the `core/comment-date` block on the server. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
51 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
52 |
* @since 6.0.0 |
19 | 53 |
*/ |
54 |
function register_block_core_comment_date() { |
|
55 |
register_block_type_from_metadata( |
|
56 |
__DIR__ . '/comment-date', |
|
57 |
array( |
|
58 |
'render_callback' => 'render_block_core_comment_date', |
|
59 |
) |
|
60 |
); |
|
61 |
} |
|
62 |
add_action( 'init', 'register_block_core_comment_date' ); |