post-excerpt.php in Gutenberg 8.2
File
vendor/gutenberg/block-library/blocks/post-excerpt.php
View source
<?php
function gutenberg_render_block_core_post_excerpt($attributes, $content, $block) {
if (!isset($block->context['postId'])) {
return '';
}
$more_text = isset($attributes['moreText']) ? '<a href="' . esc_url(get_the_permalink($block->context['postId'])) . '">' . $attributes['moreText'] . '</a>' : '';
$filter_excerpt_length = function () use ($attributes) {
return isset($attributes['wordCount']) ? $attributes['wordCount'] : 55;
};
add_filter('excerpt_length', $filter_excerpt_length);
$output = '<p>' . get_the_excerpt($block->context['postId']);
if (!isset($attributes['showMoreOnNewLine']) || $attributes['showMoreOnNewLine']) {
$output .= '</p>' . '<p>' . $more_text . '</p>';
}
else {
$output .= ' ' . $more_text . '</p>';
}
remove_filter('excerpt_length', $filter_excerpt_length);
return $output;
}
function gutenberg_register_block_core_post_excerpt() {
register_block_type_from_metadata(__DIR__ . '/post-excerpt', array(
'render_callback' => 'gutenberg_render_block_core_post_excerpt',
));
}
add_action('init', 'gutenberg_register_block_core_post_excerpt', 20);