author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
19 | 1 |
<?php |
2 |
/** |
|
3 |
* Server-side rendering of the `core/comments-pagination-previous` block. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
9 |
* Renders the `core/comments-pagination-previous` 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 Returns the previous posts link for the comments pagination. |
|
18 |
*/ |
|
19 |
function render_block_core_comments_pagination_previous( $attributes, $content, $block ) { |
|
20 |
$default_label = __( 'Older Comments' ); |
|
21 |
$label = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label; |
|
22 |
$pagination_arrow = get_comments_pagination_arrow( $block, 'previous' ); |
|
23 |
if ( $pagination_arrow ) { |
|
24 |
$label = $pagination_arrow . $label; |
|
25 |
} |
|
26 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
27 |
$filter_link_attributes = static function () { |
19 | 28 |
return get_block_wrapper_attributes(); |
29 |
}; |
|
30 |
add_filter( 'previous_comments_link_attributes', $filter_link_attributes ); |
|
31 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
32 |
$comment_vars = build_comment_query_vars_from_block( $block ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
33 |
$previous_comments_link = get_previous_comments_link( $label, $comment_vars['paged'] ?? null ); |
19 | 34 |
|
35 |
remove_filter( 'previous_comments_link_attributes', $filter_link_attributes ); |
|
36 |
||
37 |
if ( ! isset( $previous_comments_link ) ) { |
|
38 |
return ''; |
|
39 |
} |
|
40 |
||
41 |
return $previous_comments_link; |
|
42 |
} |
|
43 |
||
44 |
/** |
|
45 |
* Registers the `core/comments-pagination-previous` block on the server. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
46 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
47 |
* @since 6.0.0 |
19 | 48 |
*/ |
49 |
function register_block_core_comments_pagination_previous() { |
|
50 |
register_block_type_from_metadata( |
|
51 |
__DIR__ . '/comments-pagination-previous', |
|
52 |
array( |
|
53 |
'render_callback' => 'render_block_core_comments_pagination_previous', |
|
54 |
) |
|
55 |
); |
|
56 |
} |
|
57 |
add_action( 'init', 'register_block_core_comments_pagination_previous' ); |