wp/wp-includes/blocks/latest-comments.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
   135 	if ( empty( $comments ) ) {
   135 	if ( empty( $comments ) ) {
   136 		$class .= ' no-comments';
   136 		$class .= ' no-comments';
   137 	}
   137 	}
   138 	$classnames = esc_attr( $class );
   138 	$classnames = esc_attr( $class );
   139 
   139 
   140 	$block_content = ! empty( $comments ) ? sprintf(
   140 	return ! empty( $comments ) ? sprintf(
   141 		'<ol class="%1$s">%2$s</ol>',
   141 		'<ol class="%1$s">%2$s</ol>',
   142 		$classnames,
   142 		$classnames,
   143 		$list_items_markup
   143 		$list_items_markup
   144 	) : sprintf(
   144 	) : sprintf(
   145 		'<div class="%1$s">%2$s</div>',
   145 		'<div class="%1$s">%2$s</div>',
   146 		$classnames,
   146 		$classnames,
   147 		__( 'No comments to show.' )
   147 		__( 'No comments to show.' )
   148 	);
   148 	);
   149 
       
   150 	return $block_content;
       
   151 }
   149 }
   152 
   150 
   153 register_block_type(
   151 /**
   154 	'core/latest-comments',
   152  * Registers the `core/latest-comments` block.
   155 	array(
   153  */
   156 		'attributes'      => array(
   154 function register_block_core_latest_comments() {
   157 			'align'          => array(
   155 	register_block_type_from_metadata(
   158 				'type' => 'string',
   156 		__DIR__ . '/latest-comments',
   159 				'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
   157 		array(
   160 			),
   158 			'render_callback' => 'render_block_core_latest_comments',
   161 			'className'      => array(
   159 		)
   162 				'type' => 'string',
   160 	);
   163 			),
   161 }
   164 			'commentsToShow' => array(
   162 
   165 				'type'    => 'number',
   163 add_action( 'init', 'register_block_core_latest_comments' );
   166 				'default' => 5,
       
   167 				'minimum' => 1,
       
   168 				'maximum' => 100,
       
   169 			),
       
   170 			'displayAvatar'  => array(
       
   171 				'type'    => 'boolean',
       
   172 				'default' => true,
       
   173 			),
       
   174 			'displayDate'    => array(
       
   175 				'type'    => 'boolean',
       
   176 				'default' => true,
       
   177 			),
       
   178 			'displayExcerpt' => array(
       
   179 				'type'    => 'boolean',
       
   180 				'default' => true,
       
   181 			),
       
   182 		),
       
   183 		'render_callback' => 'render_block_core_latest_comments',
       
   184 	)
       
   185 );