PluginProbe
Gutenberg / 8.5.1
Gutenberg v8.5.1
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | build/block-library/blocks/latest-posts.php +25 -43 12.6.0 → 8.5.1 View file →
@@ -10,9 +10,8 @@
10 10 * set at render time and used by the block itself.
11 11 *
12 12 * @var int
13 13 */
14 -global $block_core_latest_posts_excerpt_length;
15 14 $block_core_latest_posts_excerpt_length = 0;
16 15
17 16 /**
18 17 * Callback for the excerpt_length filter used by
@@ -58,15 +57,9 @@
58 57
59 58 $list_items_markup = '';
60 59
61 60 foreach ( $recent_posts as $post ) {
62 - $post_link = esc_url( get_permalink( $post ) );
63 - $title = get_the_title( $post );
64 61
65 - if ( ! $title ) {
66 - $title = __( '(no title)' );
67 - }
68 -
69 62 $list_items_markup .= '<li>';
70 63
71 64 if ( $attributes['displayFeaturedImage'] && has_post_thumbnail( $post ) ) {
72 65 $image_style = '';
@@ -81,33 +74,28 @@
81 74 if ( isset( $attributes['featuredImageAlign'] ) ) {
82 75 $image_classes .= ' align' . $attributes['featuredImageAlign'];
83 76 }
84 77
85 - $featured_image = get_the_post_thumbnail(
86 - $post,
87 - $attributes['featuredImageSizeSlug'],
88 - array(
89 - 'style' => esc_attr( $image_style ),
90 - )
91 - );
92 - if ( $attributes['addLinkToFeaturedImage'] ) {
93 - $featured_image = sprintf(
94 - '<a href="%1$s" aria-label="%2$s">%3$s</a>',
95 - esc_url( $post_link ),
96 - esc_attr( $title ),
97 - $featured_image
98 - );
99 - }
100 78 $list_items_markup .= sprintf(
101 79 '<div class="%1$s">%2$s</div>',
102 - esc_attr( $image_classes ),
103 - $featured_image
80 + $image_classes,
81 + get_the_post_thumbnail(
82 + $post,
83 + $attributes['featuredImageSizeSlug'],
84 + array(
85 + 'style' => $image_style,
86 + )
87 + )
104 88 );
105 89 }
106 90
91 + $title = get_the_title( $post );
92 + if ( ! $title ) {
93 + $title = __( '(no title)' );
94 + }
107 95 $list_items_markup .= sprintf(
108 96 '<a href="%1$s">%2$s</a>',
109 - esc_url( $post_link ),
97 + esc_url( get_permalink( $post ) ),
110 98 $title
111 99 );
112 100
113 101 if ( isset( $attributes['displayAuthor'] ) && $attributes['displayAuthor'] ) {
@@ -118,9 +106,9 @@
118 106
119 107 if ( ! empty( $author_display_name ) ) {
120 108 $list_items_markup .= sprintf(
121 109 '<div class="wp-block-latest-posts__post-author">%1$s</div>',
122 - $byline
110 + esc_html( $byline )
123 111 );
124 112 }
125 113 }
126 114
@@ -127,9 +115,9 @@
127 115 if ( isset( $attributes['displayPostDate'] ) && $attributes['displayPostDate'] ) {
128 116 $list_items_markup .= sprintf(
129 117 '<time datetime="%1$s" class="wp-block-latest-posts__post-date">%2$s</time>',
130 118 esc_attr( get_the_date( 'c', $post ) ),
131 - get_the_date( '', $post )
119 + esc_html( get_the_date( '', $post ) )
132 120 );
133 121 }
134 122
135 123 if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent']
@@ -136,12 +124,8 @@
136 124 && isset( $attributes['displayPostContentRadio'] ) && 'excerpt' === $attributes['displayPostContentRadio'] ) {
137 125
138 126 $trimmed_excerpt = get_the_excerpt( $post );
139 127
140 - if ( post_password_required( $post ) ) {
141 - $trimmed_excerpt = __( 'This content is password protected.' );
142 - }
143 -
144 128 $list_items_markup .= sprintf(
145 129 '<div class="wp-block-latest-posts__post-excerpt">%1$s</div>',
146 130 $trimmed_excerpt
147 131 );
@@ -148,18 +132,11 @@
148 132 }
149 133
150 134 if ( isset( $attributes['displayPostContent'] ) && $attributes['displayPostContent']
151 135 && isset( $attributes['displayPostContentRadio'] ) && 'full_post' === $attributes['displayPostContentRadio'] ) {
152 -
153 - $post_content = html_entity_decode( $post->post_content, ENT_QUOTES, get_option( 'blog_charset' ) );
154 -
155 - if ( post_password_required( $post ) ) {
156 - $post_content = __( 'This content is password protected.' );
157 - }
158 -
159 136 $list_items_markup .= sprintf(
160 137 '<div class="wp-block-latest-posts__post-full-content">%1$s</div>',
161 - wp_kses_post( $post_content )
138 + wp_kses_post( html_entity_decode( $post->post_content, ENT_QUOTES, get_option( 'blog_charset' ) ) )
162 139 );
163 140 }
164 141
165 142 $list_items_markup .= "</li>\n";
@@ -166,9 +143,12 @@
166 143 }
167 144
168 145 remove_filter( 'excerpt_length', 'gutenberg_block_core_latest_posts_get_excerpt_length', 20 );
169 146
170 - $class = 'wp-block-latest-posts__list';
147 + $class = 'wp-block-latest-posts wp-block-latest-posts__list';
148 + if ( isset( $attributes['align'] ) ) {
149 + $class .= ' align' . $attributes['align'];
150 + }
171 151
172 152 if ( isset( $attributes['postLayout'] ) && 'grid' === $attributes['postLayout'] ) {
173 153 $class .= ' is-grid';
174 154 }
@@ -184,13 +164,15 @@
184 164 if ( isset( $attributes['displayAuthor'] ) && $attributes['displayAuthor'] ) {
185 165 $class .= ' has-author';
186 166 }
187 167
188 - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $class ) );
168 + if ( isset( $attributes['className'] ) ) {
169 + $class .= ' ' . $attributes['className'];
170 + }
189 171
190 172 return sprintf(
191 - '<ul %1$s>%2$s</ul>',
192 - $wrapper_attributes,
173 + '<ul class="%1$s">%2$s</ul>',
174 + esc_attr( $class ),
193 175 $list_items_markup
194 176 );
195 177 }
196 178