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-edit-link` block. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
9 |
* Renders the `core/comment-edit-link` 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 |
* |
|
17 |
* @return string Return the post comment's date. |
|
18 |
*/ |
|
19 |
function render_block_core_comment_edit_link( $attributes, $content, $block ) { |
|
20 |
if ( ! isset( $block->context['commentId'] ) || ! current_user_can( 'edit_comment', $block->context['commentId'] ) ) { |
|
21 |
return ''; |
|
22 |
} |
|
23 |
||
24 |
$edit_comment_link = get_edit_comment_link( $block->context['commentId'] ); |
|
25 |
||
26 |
$link_atts = ''; |
|
27 |
||
28 |
if ( ! empty( $attributes['linkTarget'] ) ) { |
|
29 |
$link_atts .= sprintf( 'target="%s"', esc_attr( $attributes['linkTarget'] ) ); |
|
30 |
} |
|
31 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
$classes = array(); |
19 | 33 |
if ( isset( $attributes['textAlign'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
34 |
$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
|
35 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
36 |
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
|
37 |
$classes[] = 'has-link-color'; |
19 | 38 |
} |
39 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
40 |
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); |
19 | 41 |
|
42 |
return sprintf( |
|
43 |
'<div %1$s><a href="%2$s" %3$s>%4$s</a></div>', |
|
44 |
$wrapper_attributes, |
|
45 |
esc_url( $edit_comment_link ), |
|
46 |
$link_atts, |
|
47 |
esc_html__( 'Edit' ) |
|
48 |
); |
|
49 |
} |
|
50 |
||
51 |
/** |
|
52 |
* Registers the `core/comment-edit-link` block on the server. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
53 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
54 |
* @since 6.0.0 |
19 | 55 |
*/ |
56 |
function register_block_core_comment_edit_link() { |
|
57 |
register_block_type_from_metadata( |
|
58 |
__DIR__ . '/comment-edit-link', |
|
59 |
array( |
|
60 |
'render_callback' => 'render_block_core_comment_edit_link', |
|
61 |
) |
|
62 |
); |
|
63 |
} |
|
64 |
||
65 |
add_action( 'init', 'register_block_core_comment_edit_link' ); |