WordPress / gutenberg

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

List block is allowed in excerpt but still stripped #46167

Open JiveDig opened 1 year ago

JiveDig commented 1 year ago

Description

The excerpt_remove_blocks() filter has core/list in the $allowed_inner_blocks array but it's still stripped from get_the_excerpt().

I'm pretty sure this is because the list block is actually nested list-item blocks, so this:

    $allowed_inner_blocks = array(
        // Classic blocks have their blockName set to null.
        null,
        'core/freeform',
        'core/heading',
        'core/html',
        'core/list',
        'core/media-text',
        'core/paragraph',
        'core/preformatted',
        'core/pullquote',
        'core/quote',
        'core/table',
        'core/verse',
    );

    $allowed_wrapper_blocks = array(
        'core/columns',
        'core/column',
        'core/group',
    );

Needs to become this:

    $allowed_inner_blocks = array(
        // Classic blocks have their blockName set to null.
        null,
        'core/freeform',
        'core/heading',
        'core/html',
        'core/list-item', // Changed from list to list-item
        'core/media-text',
        'core/paragraph',
        'core/preformatted',
        'core/pullquote',
        'core/quote',
        'core/table',
        'core/verse',
    );

    $allowed_wrapper_blocks = array(
        'core/columns',
        'core/column',
        'core/group',
        'core/list', // Added as wrapper block
    );

Inner blocks is changed to list-item while wrapper blocks has list added.

Step-by-step reproduction instructions

  1. Add a List block as the first part of your content.
  2. Display the excerpt however you want, as long as it uses get_the_excerpt() function.
  3. Notice the list block content is stripped.

Screenshots, screen recording, code snippet

No response

Environment info

WP 6.1.1, not using Gutenberg plugin, only tested in WP core.

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

JiveDig commented 1 year ago

Realizing I may have posted this in the wrong place. Let me know if it should be moved.

t-hamano commented 1 year ago

Thanks for the report.

I think your suggestion makes sense. I have submitted a ticket (#57235) regarding this issue and a PR (#3710).

Once the issue is resolved in core, close this issue as well.

JiveDig commented 1 year ago

TY!

JiveDig commented 11 months ago

Any update on this? I'm still using excerpt_allowed_wrapper_blocks and excerpt_allowed_blocks filters to fix this one.

JiveDig commented 11 months ago

For anyone that hits this, here are the filters I'm using:

/**
 * REMOVE AFTER WP UPDATE FIXES THIS.
 * Allows list blocks to be used in excerpts.
 * 
 * @link https://github.com/WordPress/wordpress-develop/pull/3710
 * @link https://github.com/WordPress/gutenberg/issues/46167
 * 
 * @param array $blocks The allowed blocks.
 * 
 * @return array
 */
add_filter( 'excerpt_allowed_wrapper_blocks', function( $blocks ) {
    $blocks[] = 'core/list';
    return array_unique( $blocks );
});

/**
 * REMOVE AFTER WP UPDATE FIXES THIS.
 * Allows list-item blocks to be used in excerpts.
 * 
 * @link https://github.com/WordPress/wordpress-develop/pull/3710
 * @link https://github.com/WordPress/gutenberg/issues/46167
 * 
 * @param array $blocks The allowed blocks.
 * 
 * @return array
 */
add_filter( 'excerpt_allowed_blocks', function( $blocks ) {
    $blocks[] = 'core/list-item';
    return array_unique( $blocks );
});
sergiu-radu commented 8 months ago

Hi @t-hamano, Any updates on this? Do you know if PR will be merged in the next update?

t-hamano commented 8 months ago

Hi @sergiu-radu,

have already submitted a PR, but this issue is more complicated than I expected. Please see this comment. I don't have the time to continue working on this issue at the moment, but if you have any ideas, I welcome them.