Ticket #48447: 48447-readability-fixes.diff
File 48447-readability-fixes.diff, 4.0 KB (added by , 5 years ago) |
---|
-
src/wp-includes/blocks/latest-comments.php
27 27 */ 28 28 function wp_latest_comments_draft_or_post_title( $post = 0 ) { 29 29 $title = get_the_title( $post ); 30 30 31 if ( empty( $title ) ) { 31 32 $title = __( '(no title)' ); 32 33 } 34 33 35 return esc_html( $title ); 34 36 } 35 37 … … 41 43 * @return string Returns the post content with latest comments added. 42 44 */ 43 45 function 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', 54 50 ); 55 51 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 ); 56 56 $list_items_markup = ''; 57 57 58 if ( ! empty( $comments ) ) { 58 59 // Prime the cache for associated posts. This is copied from \WP_Widget_Recent_Comments::widget(). 59 60 $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) ); … … 61 62 62 63 foreach ( $comments as $comment ) { 63 64 $list_items_markup .= '<li class="wp-block-latest-comments__comment">'; 65 64 66 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 74 69 if ( $avatar ) { 75 70 $list_items_markup .= $avatar; 76 71 } … … 79 74 $list_items_markup .= '<article>'; 80 75 $list_items_markup .= '<footer class="wp-block-latest-comments__comment-meta">'; 81 76 $author_url = get_comment_author_url( $comment ); 77 82 78 if ( empty( $author_url ) && ! empty( $comment->user_id ) ) { 83 79 $author_url = get_author_posts_url( $comment->user_id ); 84 80 } 85 81 86 82 $author_markup = ''; 83 87 84 if ( $author_url ) { 88 85 $author_markup .= '<a class="wp-block-latest-comments__comment-author" href="' . esc_url( $author_url ) . '">' . get_comment_author( $comment ) . '</a>'; 89 86 } else { … … 108 105 date_i18n( get_option( 'date_format' ), get_comment_date( 'U', $comment ) ) 109 106 ); 110 107 } 108 111 109 $list_items_markup .= '</footer>'; 110 112 111 if ( $attributes['displayExcerpt'] ) { 113 112 $list_items_markup .= '<div class="wp-block-latest-comments__comment-excerpt">' . wpautop( get_comment_excerpt( $comment ) ) . '</div>'; 114 113 } 114 115 115 $list_items_markup .= '</article></li>'; 116 116 } 117 117 } 118 118 119 119 $class = 'wp-block-latest-comments'; 120 120 121 if ( ! empty( $attributes['className'] ) ) { 121 122 $class .= ' ' . $attributes['className']; 122 123 } 124 123 125 if ( isset( $attributes['align'] ) ) { 124 126 $class .= " align{$attributes['align']}"; 125 127 } 128 126 129 if ( $attributes['displayAvatar'] ) { 127 130 $class .= ' has-avatars'; 128 131 } 132 129 133 if ( $attributes['displayDate'] ) { 130 134 $class .= ' has-dates'; 131 135 } 136 132 137 if ( $attributes['displayExcerpt'] ) { 133 138 $class .= ' has-excerpts'; 134 139 } 140 135 141 if ( empty( $comments ) ) { 136 142 $class .= ' no-comments'; 137 143 } 144 138 145 $classnames = esc_attr( $class ); 139 146 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 } 149 152 } 150 153 151 154 /**