context['postId'] ) ) { return ''; } $more_text = isset( $attributes['moreText'] ) ? '' . $attributes['moreText'] . '' : ''; $filter_excerpt_length = function() use ( $attributes ) { return isset( $attributes['wordCount'] ) ? $attributes['wordCount'] : 55; }; add_filter( 'excerpt_length', $filter_excerpt_length ); $classes = ''; if ( isset( $attributes['textAlign'] ) ) { $classes .= 'has-text-align-' . $attributes['textAlign']; } $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) ); $content = '

' . get_the_excerpt( $block->context['postId'] ); if ( ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'] ) { $content .= '

' . $more_text . '

'; } else { $content .= " $more_text

"; } remove_filter( 'excerpt_length', $filter_excerpt_length ); return sprintf( '
%2$s
', $wrapper_attributes, $content ); } /** * Registers the `core/post-excerpt` block on the server. */ function register_block_core_post_excerpt() { register_block_type_from_metadata( __DIR__ . '/post-excerpt', array( 'render_callback' => 'render_block_core_post_excerpt', ) ); } add_action( 'init', 'register_block_core_post_excerpt' );