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/comments-pagination-next` block. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
9 |
* Renders the `core/comments-pagination-next` 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 next comments link for the query pagination. |
|
18 |
*/ |
|
19 |
function render_block_core_comments_pagination_next( $attributes, $content, $block ) { |
|
20 |
// Bail out early if the post ID is not set for some reason. |
|
21 |
if ( empty( $block->context['postId'] ) ) { |
|
22 |
return ''; |
|
23 |
} |
|
24 |
||
25 |
$comment_vars = build_comment_query_vars_from_block( $block ); |
|
26 |
$max_page = ( new WP_Comment_Query( $comment_vars ) )->max_num_pages; |
|
27 |
$default_label = __( 'Newer Comments' ); |
|
28 |
$label = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label; |
|
29 |
$pagination_arrow = get_comments_pagination_arrow( $block, 'next' ); |
|
30 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
31 |
$filter_link_attributes = static function () { |
19 | 32 |
return get_block_wrapper_attributes(); |
33 |
}; |
|
34 |
add_filter( 'next_comments_link_attributes', $filter_link_attributes ); |
|
35 |
||
36 |
if ( $pagination_arrow ) { |
|
37 |
$label .= $pagination_arrow; |
|
38 |
} |
|
39 |
||
40 |
$next_comments_link = get_next_comments_link( $label, $max_page ); |
|
41 |
||
42 |
remove_filter( 'next_posts_link_attributes', $filter_link_attributes ); |
|
43 |
||
44 |
if ( ! isset( $next_comments_link ) ) { |
|
45 |
return ''; |
|
46 |
} |
|
47 |
return $next_comments_link; |
|
48 |
} |
|
49 |
||
50 |
||
51 |
/** |
|
52 |
* Registers the `core/comments-pagination-next` 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_comments_pagination_next() { |
|
57 |
register_block_type_from_metadata( |
|
58 |
__DIR__ . '/comments-pagination-next', |
|
59 |
array( |
|
60 |
'render_callback' => 'render_block_core_comments_pagination_next', |
|
61 |
) |
|
62 |
); |
|
63 |
} |
|
64 |
add_action( 'init', 'register_block_core_comments_pagination_next' ); |