WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.49k stars 4.19k forks source link

Post excerpt block does not call 'the_excerpt' filter #28214

Open chvillanuevap opened 3 years ago

chvillanuevap commented 3 years ago

Description

The post excerpt block does not call the the_excerpt filter before rendering the block. In contrast, the post content block does call the the_content filter before rendering.

Step-by-step reproduction instructions

  1. Open file wp-content/plugins/gutenberg/build/block-library/blocks/post-excerpt.php
  2. Go to line 37.
  3. Compare with wp-content/plugins/gutenberg/build/block-library/blocks/post-content.php, line 25.

Expected behaviour

I would expect that the block that renders the excerpt calls the the_excerpt filter.

Actual behaviour

The block does not call the the_excerpt filter.

Code snippet (optional)

In post-excerpt.php:

$output = sprintf( '<div %1$s>', $wrapper_attributes ) . '<p class="wp-block-post-excerpt__excerpt">' . get_the_excerpt( $block->context['postId'] );

In post-content.php:

return (
    '<div ' . $wrapper_attributes . '>' .
        apply_filters( 'the_content', str_replace( ']]>', ']]&gt;', get_the_content( null, false, $block->context['postId'] ) ) ) .
    '</div>'
);

WordPress information

Device information

ntsekouras commented 3 years ago

Hey @chvillanuevap 👋 - As you can see in the source code of get_the_excerpt here: https://developer.wordpress.org/reference/functions/get_the_excerpt/#source, the filter is applied

return apply_filters( 'get_the_excerpt', $post->post_excerpt, $post );

Can you test it by adding a filter like the below?

function filter_function_name( $excerpt ) {
    return "Filtered -- $excerpt";
  }
add_filter( 'get_the_excerpt', 'filter_function_name' );
chvillanuevap commented 3 years ago

I saw that, but get_the_excerpt and the_excerpt are two different filters. And there are plugins, like Jetpack's Sharing module, that utilize the_excerpt rather than get_the_excerpt. I think that for backwards compatibility, the_excerpt filter should be applied, even if it's a bit redundant.

galbaras commented 2 years ago

+1

mrfoxtalbot commented 6 months ago

It looks like we have a clear path to fixing this (applying the the_excerpt filter to the block). It would be good for backwards compatibility and it should not take too long to fix.

What would be the best place to include this in the next sprint/release, @priethor? Thank you!

priethor commented 4 months ago

Added it to the Polish board to mark it as long-hanging fruit (the board name can be confusing, as it also includes this kind of bugfixes)