[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   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   * @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 previous posts link for the comments pagination.
  16   */
  17  function render_block_core_comments_pagination_previous( $attributes, $content, $block ) {
  18      $default_label    = __( 'Older Comments' );
  19      $label            = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label;
  20      $pagination_arrow = get_comments_pagination_arrow( $block, 'previous' );
  21      if ( $pagination_arrow ) {
  22          $label = $pagination_arrow . $label;
  23      }
  24  
  25      $filter_link_attributes = static function () {
  26          return get_block_wrapper_attributes();
  27      };
  28      add_filter( 'previous_comments_link_attributes', $filter_link_attributes );
  29  
  30      $previous_comments_link = get_previous_comments_link( $label );
  31  
  32      remove_filter( 'previous_comments_link_attributes', $filter_link_attributes );
  33  
  34      if ( ! isset( $previous_comments_link ) ) {
  35          return '';
  36      }
  37  
  38      return $previous_comments_link;
  39  }
  40  
  41  /**
  42   * Registers the `core/comments-pagination-previous` block on the server.
  43   */
  44  function register_block_core_comments_pagination_previous() {
  45      register_block_type_from_metadata(
  46          __DIR__ . '/comments-pagination-previous',
  47          array(
  48              'render_callback' => 'render_block_core_comments_pagination_previous',
  49          )
  50      );
  51  }
  52  add_action( 'init', 'register_block_core_comments_pagination_previous' );


Generated : Fri Mar 29 08:20:02 2024 Cross-referenced by PHPXref