diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/blocks/latest-comments.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/wp/wp-includes/blocks/latest-comments.php Mon Oct 14 18:28:13 2019 +0200
@@ -0,0 +1,185 @@
+ $attributes['commentsToShow'],
+ 'status' => 'approve',
+ 'post_status' => 'publish',
+ )
+ )
+ );
+
+ $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 .= '
';
+ }
+ }
+
+ $class = 'wp-block-latest-comments';
+ if ( ! empty( $attributes['className'] ) ) {
+ $class .= ' ' . $attributes['className'];
+ }
+ if ( isset( $attributes['align'] ) ) {
+ $class .= " align{$attributes['align']}";
+ }
+ if ( $attributes['displayAvatar'] ) {
+ $class .= ' has-avatars';
+ }
+ if ( $attributes['displayDate'] ) {
+ $class .= ' has-dates';
+ }
+ if ( $attributes['displayExcerpt'] ) {
+ $class .= ' has-excerpts';
+ }
+ if ( empty( $comments ) ) {
+ $class .= ' no-comments';
+ }
+ $classnames = esc_attr( $class );
+
+ $block_content = ! empty( $comments ) ? sprintf(
+ '%2$s
',
+ $classnames,
+ $list_items_markup
+ ) : sprintf(
+ '%2$s
',
+ $classnames,
+ __( 'No comments to show.' )
+ );
+
+ return $block_content;
+}
+
+register_block_type(
+ 'core/latest-comments',
+ array(
+ 'attributes' => array(
+ 'align' => array(
+ 'type' => 'string',
+ 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
+ ),
+ 'className' => array(
+ 'type' => 'string',
+ ),
+ 'commentsToShow' => array(
+ 'type' => 'number',
+ 'default' => 5,
+ 'minimum' => 1,
+ 'maximum' => 100,
+ ),
+ 'displayAvatar' => array(
+ 'type' => 'boolean',
+ 'default' => true,
+ ),
+ 'displayDate' => array(
+ 'type' => 'boolean',
+ 'default' => true,
+ ),
+ 'displayExcerpt' => array(
+ 'type' => 'boolean',
+ 'default' => true,
+ ),
+ ),
+ 'render_callback' => 'render_block_core_latest_comments',
+ )
+);