From 1d2849b176c41dc1cd2203939218eeefb4fbe382 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Tue, 2 Sep 2025 13:09:42 +0200 Subject: [PATCH 1/3] Excerpts: extract content from inside lists In #53604, we made some changes so when automatically generating an excerpt from post content, we would better consider content inside inner blocks. r51382 added support for two main wrappers used in Core to house inner blocks: columns and groups. This commit adds support for another commonly used wrapper in core: lists. This way, content from lists would be pulled in excerpts when possible. Trac ticket: https://core.trac.wordpress.org/ticket/63909 --- src/wp-includes/blocks.php | 3 ++- tests/phpunit/tests/post/getTheExcerpt.php | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 170d7c0fbf10a..64b603955a60c 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -2169,7 +2169,7 @@ function excerpt_remove_blocks( $content ) { 'core/freeform', 'core/heading', 'core/html', - 'core/list', + 'core/list-item', 'core/media-text', 'core/paragraph', 'core/preformatted', @@ -2183,6 +2183,7 @@ function excerpt_remove_blocks( $content ) { 'core/columns', 'core/column', 'core/group', + 'core/list', ); /** diff --git a/tests/phpunit/tests/post/getTheExcerpt.php b/tests/phpunit/tests/post/getTheExcerpt.php index 49fae7b69587b..c73c7572da407 100644 --- a/tests/phpunit/tests/post/getTheExcerpt.php +++ b/tests/phpunit/tests/post/getTheExcerpt.php @@ -148,6 +148,7 @@ public function test_should_respect_post_parameter_in_the_loop_when_falling_back /** * @ticket 53604 + * @ticket 63909 */ public function test_inner_blocks_excerpt() { $content_1 = ' @@ -176,6 +177,16 @@ public function test_inner_blocks_excerpt() { + +

+'; + + $content_3 = ' + + +

'; @@ -194,6 +205,13 @@ public function test_inner_blocks_excerpt() { ) ); + $post_3 = self::factory()->post->create_and_get( + array( + 'post_content' => $content_3, + 'post_excerpt' => '', + ) + ); + $this->assertSame( 'Column 1 Column 2', get_the_excerpt( ( new WP_Query( array( 'p' => $post_1->ID ) ) )->posts[0] ) @@ -203,5 +221,10 @@ public function test_inner_blocks_excerpt() { 'Paragraph inside group block', get_the_excerpt( ( new WP_Query( array( 'p' => $post_2->ID ) ) )->posts[0] ) ); + + $this->assertSame( + 'List item inside a list.', + get_the_excerpt( ( new WP_Query( array( 'p' => $post_3->ID ) ) )->posts[0] ) + ); } } From ac26ae4c1e333f1bfcdc497c4c4c2565581e083f Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 7 Aug 2026 17:35:10 +0200 Subject: [PATCH 2/3] Update src/wp-includes/blocks.php Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> --- src/wp-includes/blocks.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 64b603955a60c..2efc9253d8d75 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -2169,6 +2169,7 @@ function excerpt_remove_blocks( $content ) { 'core/freeform', 'core/heading', 'core/html', + 'core/list', 'core/list-item', 'core/media-text', 'core/paragraph', From bd01d0f271156b978dcea1a72e324b4bcbaab6b6 Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Fri, 7 Aug 2026 17:39:17 +0200 Subject: [PATCH 3/3] Excerpts: cover legacy List blocks in tests Legacy List blocks keep their items as raw HTML rather than inner blocks, so they take a different path through excerpt_remove_blocks() than the current markup does. Nothing pinned that behaviour down, and it is exactly what breaks if core/list stops being an allowed inner block. Add a test for a legacy list on its own and nested inside a quote. Removing core/list from the allowed inner blocks fails the nested case, which is the regression we want to hear about. --- tests/phpunit/tests/post/getTheExcerpt.php | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/phpunit/tests/post/getTheExcerpt.php b/tests/phpunit/tests/post/getTheExcerpt.php index c73c7572da407..8dbaef5a82de1 100644 --- a/tests/phpunit/tests/post/getTheExcerpt.php +++ b/tests/phpunit/tests/post/getTheExcerpt.php @@ -227,4 +227,47 @@ public function test_inner_blocks_excerpt() { get_the_excerpt( ( new WP_Query( array( 'p' => $post_3->ID ) ) )->posts[0] ) ); } + + /** + * Legacy List blocks store their items as raw HTML instead of inner blocks. + * They should still contribute to the excerpt, both on their own and when + * nested inside another block. + * + * @ticket 63909 + */ + public function test_legacy_list_block_excerpt() { + $content_1 = ' +
  • Legacy list item.
+'; + + $content_2 = ' +
+
  • Quoted legacy list item.
+
+'; + + $post_1 = self::factory()->post->create_and_get( + array( + 'post_content' => $content_1, + 'post_excerpt' => '', + ) + ); + + $post_2 = self::factory()->post->create_and_get( + array( + 'post_content' => $content_2, + 'post_excerpt' => '', + ) + ); + + $this->assertSame( + 'Legacy list item.', + get_the_excerpt( ( new WP_Query( array( 'p' => $post_1->ID ) ) )->posts[0] ) + ); + + $this->assertSame( + 'Quoted legacy list item.', + get_the_excerpt( ( new WP_Query( array( 'p' => $post_2->ID ) ) )->posts[0] ) + ); + } }