[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/blocks/ -> comments-pagination-next.php (source)

   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   *
  11   * @param array    $attributes Block attributes.
  12   * @param string   $content    Block default content.
  13   * @param WP_Block $block      Block instance.
  14   *
  15   * @return string Returns the next comments link for the query pagination.
  16   */
  17  function render_block_core_comments_pagination_next( $attributes, $content, $block ) {
  18      // Bail out early if the post ID is not set for some reason.
  19      if ( empty( $block->context['postId'] ) ) {
  20          return '';
  21      }
  22  
  23      $comment_vars     = build_comment_query_vars_from_block( $block );
  24      $max_page         = ( new WP_Comment_Query( $comment_vars ) )->max_num_pages;
  25      $default_label    = __( 'Newer Comments' );
  26      $label            = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label;
  27      $pagination_arrow = get_comments_pagination_arrow( $block, 'next' );
  28  
  29      $filter_link_attributes = function() {
  30          return get_block_wrapper_attributes();
  31      };
  32      add_filter( 'next_comments_link_attributes', $filter_link_attributes );
  33  
  34      if ( $pagination_arrow ) {
  35          $label .= $pagination_arrow;
  36      }
  37  
  38      $next_comments_link = get_next_comments_link( $label, $max_page );
  39  
  40      remove_filter( 'next_posts_link_attributes', $filter_link_attributes );
  41  
  42      if ( ! isset( $next_comments_link ) ) {
  43          return '';
  44      }
  45      return $next_comments_link;
  46  }
  47  
  48  
  49  /**
  50   * Registers the `core/comments-pagination-next` block on the server.
  51   */
  52  function register_block_core_comments_pagination_next() {
  53      register_block_type_from_metadata(
  54          __DIR__ . '/comments-pagination-next',
  55          array(
  56              'render_callback' => 'render_block_core_comments_pagination_next',
  57          )
  58      );
  59  }
  60  add_action( 'init', 'register_block_core_comments_pagination_next' );


Generated: Tue Jun 28 01:00:03 2022 Cross-referenced by PHPXref 0.7.1