| @@ -29,9 +29,9 @@ | ||
| 29 | 29 | $title = get_the_title( $post ); |
| 30 | 30 | if ( empty( $title ) ) { |
| 31 | 31 | $title = __( '(no title)' ); |
| 32 | 32 | } |
| 33 | - return $title; | |
| 33 | + return esc_html( $title ); | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Renders the `core/latest-comments` block on server. |
| @@ -40,10 +40,10 @@ | ||
| 40 | 40 | * |
| 41 | 41 | * @return string Returns the post content with latest comments added. |
| 42 | 42 | */ |
| 43 | 43 | function gutenberg_render_block_core_latest_comments( $attributes = array() ) { |
| 44 | + // This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php. | |
| 44 | 45 | $comments = get_comments( |
| 45 | - /** This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php */ | |
| 46 | 46 | apply_filters( |
| 47 | 47 | 'widget_comments_args', |
| 48 | 48 | array( |
| 49 | 49 | 'number' => $attributes['commentsToShow'], |
| @@ -48,10 +48,9 @@ | ||
| 48 | 48 | array( |
| 49 | 49 | 'number' => $attributes['commentsToShow'], |
| 50 | 50 | 'status' => 'approve', |
| 51 | 51 | 'post_status' => 'publish', |
| 52 | - ), | |
| 53 | - array() | |
| 52 | + ) | |
| 54 | 53 | ) |
| 55 | 54 | ); |
| 56 | 55 | |
| 57 | 56 | $list_items_markup = ''; |
| @@ -116,30 +115,36 @@ | ||
| 116 | 115 | $list_items_markup .= '</article></li>'; |
| 117 | 116 | } |
| 118 | 117 | } |
| 119 | 118 | |
| 120 | - $classnames = array(); | |
| 119 | + $class = 'wp-block-latest-comments'; | |
| 120 | + if ( ! empty( $attributes['className'] ) ) { | |
| 121 | + $class .= ' ' . $attributes['className']; | |
| 122 | + } | |
| 123 | + if ( isset( $attributes['align'] ) ) { | |
| 124 | + $class .= " align{$attributes['align']}"; | |
| 125 | + } | |
| 121 | 126 | if ( $attributes['displayAvatar'] ) { |
| 122 | - $classnames[] = 'has-avatars'; | |
| 127 | + $class .= ' has-avatars'; | |
| 123 | 128 | } |
| 124 | 129 | if ( $attributes['displayDate'] ) { |
| 125 | - $classnames[] = 'has-dates'; | |
| 130 | + $class .= ' has-dates'; | |
| 126 | 131 | } |
| 127 | 132 | if ( $attributes['displayExcerpt'] ) { |
| 128 | - $classnames[] = 'has-excerpts'; | |
| 133 | + $class .= ' has-excerpts'; | |
| 129 | 134 | } |
| 130 | 135 | if ( empty( $comments ) ) { |
| 131 | - $classnames[] = 'no-comments'; | |
| 136 | + $class .= ' no-comments'; | |
| 132 | 137 | } |
| 133 | - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) ); | |
| 138 | + $classnames = esc_attr( $class ); | |
| 134 | 139 | |
| 135 | 140 | return ! empty( $comments ) ? sprintf( |
| 136 | - '<ol %1$s>%2$s</ol>', | |
| 137 | - $wrapper_attributes, | |
| 141 | + '<ol class="%1$s">%2$s</ol>', | |
| 142 | + $classnames, | |
| 138 | 143 | $list_items_markup |
| 139 | 144 | ) : sprintf( |
| 140 | - '<div %1$s>%2$s</div>', | |
| 141 | - $wrapper_attributes, | |
| 145 | + '<div class="%1$s">%2$s</div>', | |
| 146 | + $classnames, | |
| 142 | 147 | __( 'No comments to show.' ) |
| 143 | 148 | ); |
| 144 | 149 | } |
| 145 | 150 | |