Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,7 @@ function excerpt_remove_blocks( $content ) {
'core/heading',
'core/html',
'core/list',
'core/list-item',
Comment thread
jeherve marked this conversation as resolved.
'core/media-text',
'core/paragraph',
'core/preformatted',
Expand All @@ -2269,6 +2270,7 @@ function excerpt_remove_blocks( $content ) {
'core/columns',
'core/column',
'core/group',
'core/list',
);

/**
Expand Down
66 changes: 66 additions & 0 deletions tests/phpunit/tests/post/getTheExcerpt.php
Comment thread
jeherve marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<!-- wp:group -->
Expand Down Expand Up @@ -176,6 +177,16 @@ public function test_inner_blocks_excerpt() {
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->';

$content_3 = '<!-- wp:list -->
<ul class="wp-block-list"><!-- wp:list-item -->
<li>List item inside a list.</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->';
Expand All @@ -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] )
Expand All @@ -203,5 +221,53 @@ 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] )
);
}

/**
* 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 = '<!-- wp:list -->
<ul class="wp-block-list"><li>Legacy list item.</li></ul>
<!-- /wp:list -->';

$content_2 = '<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:list -->
<ul class="wp-block-list"><li>Quoted legacy list item.</li></ul>
<!-- /wp:list --></blockquote>
<!-- /wp:quote -->';

$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] )
);
}
}
Loading