PluginProbe
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites / 1.2.1
BlockSpare – Gutenberg Blocks for News, Magazine, Blog & Business Websites v1.2.1
4.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.1.2 2.5.0 2.5.3 2.6.1 All 38 releases
← All changes | src/blocks/latest-posts-grid/index.php +54 -30 1.2.31.2.1 View file →
@@ -194,38 +194,27 @@
194 194 );
195 195
196 196
197 197 /* Get the excerpt */
198 -
199 - $post_id = get_the_ID();
200 -
201 - $excerpt = apply_filters('the_excerpt',
202 - get_post_field(
203 - 'post_excerpt',
204 - $post_id,
205 - 'display'
206 - )
207 - );
208 -
209 - if(empty($excerpt) && isset($attributes['excerptLength'])) {
210 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound, PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket -- Running the_excerpt directly, Previous rule doesn't take without the_excerpt being moved up a line
211 - $excerpt = apply_filters('the_excerpt',
212 - wp_trim_words(
213 - preg_replace(
214 - array(
215 - '/\<figcaption>.*\<\/figcaption>/',
216 - '/\[caption.*\[\/caption\]/',
217 - ),
218 - '',
219 - get_the_content()
220 - ),
221 - $attributes['excerptLength']
222 - )
223 - );
198 +
199 + global $post;
200 +
201 +
202 + $excerpt = blockspare_post_excerpt($post_id, $post);
203 +
204 + if (!$excerpt) {
205 + $excerpt = null;
224 206 }
225 -
226 - if(!$excerpt) {
227 - $excerpt = null;
207 +
208 + if (!empty($excerpt)) {
209 + $excerpt = explode(' ', $excerpt);
210 + $trim_to_length = (int)$attributes['excerptLength'] ? (int)$attributes['excerptLength'] : 55;
211 + if (count($excerpt) > $trim_to_length) {
212 + $excerpt = implode(' ', array_slice($excerpt, 0, $trim_to_length)) . '...';
213 + } else {
214 + $excerpt = implode(' ', $excerpt);
215 + }
216 +
228 217 }
229 218
230 219
231 220 if ((isset($attributes['displayPostExcerpt']) && $excerpt != null) || isset($attributes['displayPostLink'])) {
@@ -239,9 +228,9 @@
239 228 );
240 229
241 230 if (isset($attributes['displayPostExcerpt']) && $attributes['displayPostExcerpt']) {
242 231 $blockspare_content_markup .= sprintf(
243 - '<div class="blockspare-block-post-grid-excerpt-content">%1$s</div>',
232 + '<div class="blockspare-block-post-grid-excerpt-content">%s</div>',
244 233 wp_kses_post($excerpt)
245 234 );
246 235 }
247 236
@@ -425,8 +414,43 @@
425 414 }
426 415
427 416 add_action('init', 'blockspare_blocks_register_block_core_latest_posts_grid');
428 417
418 +
419 +if (!function_exists('blockspare_post_excerpt')) {
420 + /**
421 + * Get the post excerpt.
422 + *
423 + * @since 1.7
424 + */
425 + function blockspare_post_excerpt($object)
426 + {
427 + return blockspare_get_excerpt($object['id']);
428 + }
429 +}
430 +
431 +if (!function_exists('blockspare_get_excerpt')) {
432 + /**
433 + * Get the excerpt.
434 + *
435 + * @since 1.7
436 + */
437 + function blockspare_get_excerpt($post_id, $post = null)
438 + {
439 + $excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id, 'display'));
440 + if (!empty($excerpt)) {
441 + return $excerpt;
442 + }
443 +
444 + $max_excerpt = 100; // WP default is 55.
445 +
446 + if (!empty($post['post_content'])) {
447 + return apply_filters('the_excerpt', wp_trim_words($post['post_content'], $max_excerpt));
448 + }
449 + $post_content = apply_filters('the_content', get_post_field('post_content', $post_id));
450 + return apply_filters('the_excerpt', wp_trim_words($post_content, $max_excerpt));
451 + }
452 +}
429 453
430 454
431 455
432 456