PluginProbe
Gutenberg / 22.9.0
Gutenberg v22.9.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / block-library / comments-pagination-previous.php

comments-pagination-previous.php in Gutenberg 22.9.0, at build/scripts/block-library/comments-pagination-previous.php

58 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 *
11 * @since 6.0.0
12 *
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 gutenberg_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
27 $filter_link_attributes = static function () {
28 return get_block_wrapper_attributes();
29 };
30 add_filter( 'previous_comments_link_attributes', $filter_link_attributes );
31
32 $comment_vars = build_comment_query_vars_from_block( $block );
33 $previous_comments_link = get_previous_comments_link( $label, $comment_vars['paged'] ?? null );
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.
46 *
47 * @since 6.0.0
48 */
49 function gutenberg_register_block_core_comments_pagination_previous() {
50 register_block_type_from_metadata(
51 __DIR__ . '/comments-pagination-previous',
52 array(
53 'render_callback' => 'gutenberg_render_block_core_comments_pagination_previous',
54 )
55 );
56 }
57 add_action( 'init', 'gutenberg_register_block_core_comments_pagination_previous', 20 );
58