wp/wp-includes/blocks/latest-posts.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
--- a/wp/wp-includes/blocks/latest-posts.php	Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-includes/blocks/latest-posts.php	Wed Sep 21 18:19:35 2022 +0200
@@ -11,6 +11,7 @@
  *
  * @var int
  */
+global $block_core_latest_posts_excerpt_length;
 $block_core_latest_posts_excerpt_length = 0;
 
 /**
@@ -58,6 +59,7 @@
 	$list_items_markup = '';
 
 	foreach ( $recent_posts as $post ) {
+		$post_link = esc_url( get_permalink( $post ) );
 
 		$list_items_markup .= '<li>';
 
@@ -75,16 +77,24 @@
 				$image_classes .= ' align' . $attributes['featuredImageAlign'];
 			}
 
+			$featured_image = get_the_post_thumbnail(
+				$post,
+				$attributes['featuredImageSizeSlug'],
+				array(
+					'style' => $image_style,
+				)
+			);
+			if ( $attributes['addLinkToFeaturedImage'] ) {
+				$featured_image = sprintf(
+					'<a href="%1$s">%2$s</a>',
+					$post_link,
+					$featured_image
+				);
+			}
 			$list_items_markup .= sprintf(
 				'<div class="%1$s">%2$s</div>',
 				$image_classes,
-				get_the_post_thumbnail(
-					$post,
-					$attributes['featuredImageSizeSlug'],
-					array(
-						'style' => $image_style,
-					)
-				)
+				$featured_image
 			);
 		}
 
@@ -94,7 +104,7 @@
 		}
 		$list_items_markup .= sprintf(
 			'<a href="%1$s">%2$s</a>',
-			esc_url( get_permalink( $post ) ),
+			$post_link,
 			$title
 		);
 
@@ -125,6 +135,10 @@
 
 			$trimmed_excerpt = get_the_excerpt( $post );
 
+			if ( post_password_required( $post ) ) {
+				$trimmed_excerpt = __( 'This content is password protected.' );
+			}
+
 			$list_items_markup .= sprintf(
 				'<div class="wp-block-latest-posts__post-excerpt">%1$s</div>',
 				$trimmed_excerpt
@@ -133,9 +147,16 @@
 
 		if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent']
 			&& isset( $attributes['displayPostContentRadio'] ) && 'full_post' === $attributes['displayPostContentRadio'] ) {
+
+			$post_content = wp_kses_post( html_entity_decode( $post->post_content, ENT_QUOTES, get_option( 'blog_charset' ) ) );
+
+			if ( post_password_required( $post ) ) {
+				$post_content = __( 'This content is password protected.' );
+			}
+
 			$list_items_markup .= sprintf(
 				'<div class="wp-block-latest-posts__post-full-content">%1$s</div>',
-				wp_kses_post( html_entity_decode( $post->post_content, ENT_QUOTES, get_option( 'blog_charset' ) ) )
+				$post_content
 			);
 		}
 
@@ -144,10 +165,7 @@
 
 	remove_filter( 'excerpt_length', 'block_core_latest_posts_get_excerpt_length', 20 );
 
-	$class = 'wp-block-latest-posts wp-block-latest-posts__list';
-	if ( isset( $attributes['align'] ) ) {
-		$class .= ' align' . $attributes['align'];
-	}
+	$class = 'wp-block-latest-posts__list';
 
 	if ( isset( $attributes['postLayout'] ) && 'grid' === $attributes['postLayout'] ) {
 		$class .= ' is-grid';
@@ -165,13 +183,11 @@
 		$class .= ' has-author';
 	}
 
-	if ( isset( $attributes['className'] ) ) {
-		$class .= ' ' . $attributes['className'];
-	}
+	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $class ) );
 
 	return sprintf(
-		'<ul class="%1$s">%2$s</ul>',
-		esc_attr( $class ),
+		'<ul %1$s>%2$s</ul>',
+		$wrapper_attributes,
 		$list_items_markup
 	);
 }