wp/wp-includes/blocks/latest-comments.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    39  * @param array $attributes The block attributes.
    39  * @param array $attributes The block attributes.
    40  *
    40  *
    41  * @return string Returns the post content with latest comments added.
    41  * @return string Returns the post content with latest comments added.
    42  */
    42  */
    43 function render_block_core_latest_comments( $attributes = array() ) {
    43 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(
    44 	$comments = get_comments(
       
    45 		// This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php.
    46 		apply_filters(
    46 		apply_filters(
    47 			'widget_comments_args',
    47 			'widget_comments_args',
    48 			array(
    48 			array(
    49 				'number'      => $attributes['commentsToShow'],
    49 				'number'      => $attributes['commentsToShow'],
    50 				'status'      => 'approve',
    50 				'status'      => 'approve',
   114 			}
   114 			}
   115 			$list_items_markup .= '</article></li>';
   115 			$list_items_markup .= '</article></li>';
   116 		}
   116 		}
   117 	}
   117 	}
   118 
   118 
   119 	$class = 'wp-block-latest-comments';
   119 	$classnames = array();
   120 	if ( ! empty( $attributes['className'] ) ) {
       
   121 		$class .= ' ' . $attributes['className'];
       
   122 	}
       
   123 	if ( isset( $attributes['align'] ) ) {
       
   124 		$class .= " align{$attributes['align']}";
       
   125 	}
       
   126 	if ( $attributes['displayAvatar'] ) {
   120 	if ( $attributes['displayAvatar'] ) {
   127 		$class .= ' has-avatars';
   121 		$classnames[] = 'has-avatars';
   128 	}
   122 	}
   129 	if ( $attributes['displayDate'] ) {
   123 	if ( $attributes['displayDate'] ) {
   130 		$class .= ' has-dates';
   124 		$classnames[] = 'has-dates';
   131 	}
   125 	}
   132 	if ( $attributes['displayExcerpt'] ) {
   126 	if ( $attributes['displayExcerpt'] ) {
   133 		$class .= ' has-excerpts';
   127 		$classnames[] = 'has-excerpts';
   134 	}
   128 	}
   135 	if ( empty( $comments ) ) {
   129 	if ( empty( $comments ) ) {
   136 		$class .= ' no-comments';
   130 		$classnames[] = 'no-comments';
   137 	}
   131 	}
   138 	$classnames = esc_attr( $class );
   132 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) );
   139 
   133 
   140 	return ! empty( $comments ) ? sprintf(
   134 	return ! empty( $comments ) ? sprintf(
   141 		'<ol class="%1$s">%2$s</ol>',
   135 		'<ol %1$s>%2$s</ol>',
   142 		$classnames,
   136 		$wrapper_attributes,
   143 		$list_items_markup
   137 		$list_items_markup
   144 	) : sprintf(
   138 	) : sprintf(
   145 		'<div class="%1$s">%2$s</div>',
   139 		'<div %1$s>%2$s</div>',
   146 		$classnames,
   140 		$wrapper_attributes,
   147 		__( 'No comments to show.' )
   141 		__( 'No comments to show.' )
   148 	);
   142 	);
   149 }
   143 }
   150 
   144 
   151 /**
   145 /**