Make WordPress Core

Changeset 63340


Ignore:
Timestamp:
08/23/2026 06:07:11 AM (3 months ago)
Author:
audrasjb
Message:

Editor: Extract content from inside lists to generate post excerpts.

[51382] added support for two main wrappers used in Core to house inner blocks: columns and groups. This resulted in the content of these wrapper blocks being taken into account in the generation of post excerpts.

This changeset adds support for another commonly used wrapper in core: lists. This way, content from lists would be pulled in excerpts when possible.

Follow-up to #53604 / [51382].

Props jeherve, audrasjb, mukesh27, huzaifaalmesbah, wildworks, gaisma22, huzaifaalmesbah.
Fixes #63909.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r63320 r63340  
    22552255                'core/html',
    22562256                'core/list',
     2257                'core/list-item',
    22572258                'core/media-text',
    22582259                'core/paragraph',
    … …  
    22682269                'core/column',
    22692270                'core/group',
     2271                'core/list',
    22702272        );
    22712273
  • trunk/tests/phpunit/tests/post/getTheExcerpt.php

    r51348 r63340  
    149149        /**
    150150         * @ticket 53604
     151         * @ticket 63909
    151152         */
    152153        public function test_inner_blocks_excerpt() {
    … …  
    181182<!-- /wp:paragraph -->';
    182183
     184                $content_3 = '<!-- wp:list -->
     185<ul class="wp-block-list"><!-- wp:list-item -->
     186<li>List item inside a list.</li>
     187<!-- /wp:list-item --></ul>
     188<!-- /wp:list -->
     189
     190<!-- wp:paragraph -->
     191<p></p>
     192<!-- /wp:paragraph -->';
     193
    183194                $post_1 = self::factory()->post->create_and_get(
    184195                        array(
    … …  
    191202                        array(
    192203                                'post_content' => $content_2,
     204                                'post_excerpt' => '',
     205                        )
     206                );
     207
     208                $post_3 = self::factory()->post->create_and_get(
     209                        array(
     210                                'post_content' => $content_3,
    193211                                'post_excerpt' => '',
    194212                        )
    … …  
    204222                        get_the_excerpt( ( new WP_Query( array( 'p' => $post_2->ID ) ) )->posts[0] )
    205223                );
     224
     225                $this->assertSame(
     226                        'List item inside a list.',
     227                        get_the_excerpt( ( new WP_Query( array( 'p' => $post_3->ID ) ) )->posts[0] )
     228                );
     229        }
     230
     231        /**
     232         * Legacy List blocks store their items as raw HTML instead of inner blocks.
     233         * They should still contribute to the excerpt, both on their own and when
     234         * nested inside another block.
     235         *
     236         * @ticket 63909
     237         */
     238        public function test_legacy_list_block_excerpt() {
     239                $content_1 = '<!-- wp:list -->
     240<ul class="wp-block-list"><li>Legacy list item.</li></ul>
     241<!-- /wp:list -->';
     242
     243                $content_2 = '<!-- wp:quote -->
     244<blockquote class="wp-block-quote"><!-- wp:list -->
     245<ul class="wp-block-list"><li>Quoted legacy list item.</li></ul>
     246<!-- /wp:list --></blockquote>
     247<!-- /wp:quote -->';
     248
     249                $post_1 = self::factory()->post->create_and_get(
     250                        array(
     251                                'post_content' => $content_1,
     252                                'post_excerpt' => '',
     253                        )
     254                );
     255
     256                $post_2 = self::factory()->post->create_and_get(
     257                        array(
     258                                'post_content' => $content_2,
     259                                'post_excerpt' => '',
     260                        )
     261                );
     262
     263                $this->assertSame(
     264                        'Legacy list item.',
     265                        get_the_excerpt( ( new WP_Query( array( 'p' => $post_1->ID ) ) )->posts[0] )
     266                );
     267
     268                $this->assertSame(
     269                        'Quoted legacy list item.',
     270                        get_the_excerpt( ( new WP_Query( array( 'p' => $post_2->ID ) ) )->posts[0] )
     271                );
    206272        }
    207273}
Note: See TracChangeset for help on using the changeset viewer.