From a415c29efee45520ae252d2aa28f1083a521cd7b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 09:56:49 +0200 Subject: Adding upstream version 6.4.3+dfsg1. Signed-off-by: Daniel Baumann --- wp-includes/blocks/latest-comments.php | 158 +++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 wp-includes/blocks/latest-comments.php (limited to 'wp-includes/blocks/latest-comments.php') diff --git a/wp-includes/blocks/latest-comments.php b/wp-includes/blocks/latest-comments.php new file mode 100644 index 0000000..830e22a --- /dev/null +++ b/wp-includes/blocks/latest-comments.php @@ -0,0 +1,158 @@ + $attributes['commentsToShow'], + 'status' => 'approve', + 'post_status' => 'publish', + ), + array() + ) + ); + + $list_items_markup = ''; + if ( ! empty( $comments ) ) { + // Prime the cache for associated posts. This is copied from \WP_Widget_Recent_Comments::widget(). + $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) ); + _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false ); + + foreach ( $comments as $comment ) { + $list_items_markup .= '
  • '; + if ( $attributes['displayAvatar'] ) { + $avatar = get_avatar( + $comment, + 48, + '', + '', + array( + 'class' => 'wp-block-latest-comments__comment-avatar', + ) + ); + if ( $avatar ) { + $list_items_markup .= $avatar; + } + } + + $list_items_markup .= '
    '; + $list_items_markup .= ''; + if ( $attributes['displayExcerpt'] ) { + $list_items_markup .= '
    ' . wpautop( get_comment_excerpt( $comment ) ) . '
    '; + } + $list_items_markup .= '
  • '; + } + } + + $classnames = array(); + if ( $attributes['displayAvatar'] ) { + $classnames[] = 'has-avatars'; + } + if ( $attributes['displayDate'] ) { + $classnames[] = 'has-dates'; + } + if ( $attributes['displayExcerpt'] ) { + $classnames[] = 'has-excerpts'; + } + if ( empty( $comments ) ) { + $classnames[] = 'no-comments'; + } + $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) ); + + return ! empty( $comments ) ? sprintf( + '
      %2$s
    ', + $wrapper_attributes, + $list_items_markup + ) : sprintf( + '
    %2$s
    ', + $wrapper_attributes, + __( 'No comments to show.' ) + ); +} + +/** + * Registers the `core/latest-comments` block. + */ +function register_block_core_latest_comments() { + register_block_type_from_metadata( + __DIR__ . '/latest-comments', + array( + 'render_callback' => 'render_block_core_latest_comments', + ) + ); +} + +add_action( 'init', 'register_block_core_latest_comments' ); -- cgit v1.2.3