Make WordPress Core

Ticket #48447: 48447-readability-fixes.diff

File 48447-readability-fixes.diff, 4.0 KB (added by azaozz, 5 years ago)
  • src/wp-includes/blocks/latest-comments.php

     
    2727 */
    2828function wp_latest_comments_draft_or_post_title( $post = 0 ) {
    2929        $title = get_the_title( $post );
     30
    3031        if ( empty( $title ) ) {
    3132                $title = __( '(no title)' );
    3233        }
     34
    3335        return esc_html( $title );
    3436}
    3537
     
    4143 * @return string Returns the post content with latest comments added.
    4244 */
    4345function render_block_core_latest_comments( $attributes = array() ) {
    44         // This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php.
    45         $comments = get_comments(
    46                 apply_filters(
    47                         'widget_comments_args',
    48                         array(
    49                                 'number'      => $attributes['commentsToShow'],
    50                                 'status'      => 'approve',
    51                                 'post_status' => 'publish',
    52                         )
    53                 )
     46        $comments_args = array(
     47                'number'      => $attributes['commentsToShow'],
     48                'status'      => 'approve',
     49                'post_status' => 'publish',
    5450        );
    5551
     52        // This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php.
     53        $comments_args = apply_filters( 'widget_comments_args', $comments_args );
     54
     55        $comments          = get_comments( $comments_args );
    5656        $list_items_markup = '';
     57
    5758        if ( ! empty( $comments ) ) {
    5859                // Prime the cache for associated posts. This is copied from \WP_Widget_Recent_Comments::widget().
    5960                $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
     
    6162
    6263                foreach ( $comments as $comment ) {
    6364                        $list_items_markup .= '<li class="wp-block-latest-comments__comment">';
     65
    6466                        if ( $attributes['displayAvatar'] ) {
    65                                 $avatar = get_avatar(
    66                                         $comment,
    67                                         48,
    68                                         '',
    69                                         '',
    70                                         array(
    71                                                 'class' => 'wp-block-latest-comments__comment-avatar',
    72                                         )
    73                                 );
     67                                $avatar = get_avatar( $comment, 48, '', '', array( 'class' => 'wp-block-latest-comments__comment-avatar' ) );
     68
    7469                                if ( $avatar ) {
    7570                                        $list_items_markup .= $avatar;
    7671                                }
     
    7974                        $list_items_markup .= '<article>';
    8075                        $list_items_markup .= '<footer class="wp-block-latest-comments__comment-meta">';
    8176                        $author_url         = get_comment_author_url( $comment );
     77
    8278                        if ( empty( $author_url ) && ! empty( $comment->user_id ) ) {
    8379                                $author_url = get_author_posts_url( $comment->user_id );
    8480                        }
    8581
    8682                        $author_markup = '';
     83
    8784                        if ( $author_url ) {
    8885                                $author_markup .= '<a class="wp-block-latest-comments__comment-author" href="' . esc_url( $author_url ) . '">' . get_comment_author( $comment ) . '</a>';
    8986                        } else {
     
    108105                                        date_i18n( get_option( 'date_format' ), get_comment_date( 'U', $comment ) )
    109106                                );
    110107                        }
     108
    111109                        $list_items_markup .= '</footer>';
     110
    112111                        if ( $attributes['displayExcerpt'] ) {
    113112                                $list_items_markup .= '<div class="wp-block-latest-comments__comment-excerpt">' . wpautop( get_comment_excerpt( $comment ) ) . '</div>';
    114113                        }
     114
    115115                        $list_items_markup .= '</article></li>';
    116116                }
    117117        }
    118118
    119119        $class = 'wp-block-latest-comments';
     120
    120121        if ( ! empty( $attributes['className'] ) ) {
    121122                $class .= ' ' . $attributes['className'];
    122123        }
     124
    123125        if ( isset( $attributes['align'] ) ) {
    124126                $class .= " align{$attributes['align']}";
    125127        }
     128
    126129        if ( $attributes['displayAvatar'] ) {
    127130                $class .= ' has-avatars';
    128131        }
     132
    129133        if ( $attributes['displayDate'] ) {
    130134                $class .= ' has-dates';
    131135        }
     136
    132137        if ( $attributes['displayExcerpt'] ) {
    133138                $class .= ' has-excerpts';
    134139        }
     140
    135141        if ( empty( $comments ) ) {
    136142                $class .= ' no-comments';
    137143        }
     144
    138145        $classnames = esc_attr( $class );
    139146
    140         return ! empty( $comments ) ? sprintf(
    141                 '<ol class="%1$s">%2$s</ol>',
    142                 $classnames,
    143                 $list_items_markup
    144         ) : sprintf(
    145                 '<div class="%1$s">%2$s</div>',
    146                 $classnames,
    147                 __( 'No comments to show.' )
    148         );
     147        if ( ! empty( $comments ) ) {
     148                return sprintf( '<ol class="%1$s">%2$s</ol>', $classnames, $list_items_markup );
     149        } else {
     150                return sprintf( '<div class="%1$s">%2$s</div>', $classnames, __( 'No comments to show.' ) );
     151        }
    149152}
    150153
    151154/**