List block is allowed in excerpt but still stripped
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
- Add a List block as the first part of your content.
- Display the excerpt however you want, as long as it uses
get_the_excerpt()function. - 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
Realizing I may have posted this in the wrong place. Let me know if it should be moved.
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.
TY!
Any update on this? I'm still using excerpt_allowed_wrapper_blocks and excerpt_allowed_blocks filters to fix this one.
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 );
});
Hi @t-hamano, Any updates on this? Do you know if PR will be merged in the next update?
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.
I think we can close this issue in favor of the Trac ticket.