gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

List block is allowed in excerpt but still stripped

Open JiveDig opened this issue 4 years ago • 8 comments

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 avatar Nov 29 '22 16:11 JiveDig

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

JiveDig avatar Nov 29 '22 16:11 JiveDig

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.

t-hamano avatar Nov 30 '22 13:11 t-hamano

TY!

JiveDig avatar Nov 30 '22 14:11 JiveDig

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

JiveDig avatar Oct 31 '23 15:10 JiveDig

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 );
});

JiveDig avatar Oct 31 '23 15:10 JiveDig

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

sergiu-radu avatar Jan 22 '24 16:01 sergiu-radu

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.

t-hamano avatar Jan 23 '24 02:01 t-hamano

I think we can close this issue in favor of the Trac ticket.

Mamaduka avatar Dec 10 '25 07:12 Mamaduka