Make WordPress Core


Ignore:
Timestamp:
07/06/2021 03:31:48 PM (2 years ago)
Author:
desrosj
Message:

Posts: Prevent an empty excerpt when groups and nested column blocks are present.

This improves the logic within excerpt_remove_blocks() to better handle innerBlocks. This prevents an empty excerpt from being returned when core/columns, core/column, and core/group blocks are present.

This issue has been surfaced in the Query Loop block, where excerpts can be set to display.

Props aristath.
Fixes #53604.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/getTheExcerpt.php

    r46586 r51348  
    146146        $this->assertSame( 'Bar', $found );
    147147    }
     148
     149    /**
     150     * @ticket 53604
     151     */
     152    public function test_inner_blocks_excerpt() {
     153        $content_1 = '<!-- wp:group -->
     154<div class="wp-block-group"><!-- wp:columns -->
     155<div class="wp-block-columns"><!-- wp:column -->
     156<div class="wp-block-column"><!-- wp:paragraph -->
     157<p>Column 1</p>
     158<!-- /wp:paragraph --></div>
     159<!-- /wp:column -->
     160
     161<!-- wp:column -->
     162<div class="wp-block-column"><!-- wp:paragraph -->
     163<p>Column 2</p>
     164<!-- /wp:paragraph --></div>
     165<!-- /wp:column --></div>
     166<!-- /wp:columns --></div>
     167<!-- /wp:group -->
     168
     169<!-- wp:paragraph -->
     170<p></p>
     171<!-- /wp:paragraph -->';
     172
     173        $content_2 = '<!-- wp:group -->
     174<div class="wp-block-group"><!-- wp:paragraph -->
     175<p>Paragraph inside group block</p>
     176<!-- /wp:paragraph --></div>
     177<!-- /wp:group -->
     178
     179<!-- wp:paragraph -->
     180<p></p>
     181<!-- /wp:paragraph -->';
     182
     183        $post_1 = self::factory()->post->create_and_get(
     184            array(
     185                'post_content' => $content_1,
     186                'post_excerpt' => '',
     187            )
     188        );
     189
     190        $post_2 = self::factory()->post->create_and_get(
     191            array(
     192                'post_content' => $content_2,
     193                'post_excerpt' => '',
     194            )
     195        );
     196
     197        $this->assertSame(
     198            'Column 1 Column 2',
     199            get_the_excerpt( ( new WP_Query( array( 'p' => $post_1->ID ) ) )->posts[0] )
     200        );
     201
     202        $this->assertSame(
     203            'Paragraph inside group block',
     204            get_the_excerpt( ( new WP_Query( array( 'p' => $post_2->ID ) ) )->posts[0] )
     205        );
     206    }
    148207}
Note: See TracChangeset for help on using the changeset viewer.