Make WordPress Core

Changeset 61294


Ignore:
Timestamp:
11/24/2025 09:52:17 PM (3 weeks ago)
Author:
dmsnell
Message:

Block Processor: Rename extract_block() method for clearer documentation.

In testing during the release candidacy for WordPress 6.9 it was found
that the extract_block() method may do more work than is expected
based off of its name.

This change renames the method to extract_full_block_and_advance() to
communicate that it does move the Block Processor forward and to hint at
the fact that it also encompasses all inner blocks during that advance.

Developed in https://github.com/WordPress/wordpress-develop/pull/10538
Discussed in https://core.trac.wordpress.org/ticket/61401

Follow-up to [60939].

Props dlh, dmsnell, jonsurrell, westonruter.

See #61401.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-processor.php

    r61036 r61294  
    195195 * while skipping over the parse of the rest of the document.
    196196 *
    197  * {@see self::extract_block()} will scan forward from the current block opener
     197 * {@see self::extract_full_block_and_advance()} will scan forward from the current block opener
    198198 * and build the parsed block structure until the current block is closed. It will
    199199 * include all inner HTML and inner blocks, and parse all of the inner blocks. It
     
    208208 *
    209209 *     $gallery_at    = $processor->get_span()->start;
    210  *     $gallery_block = $processor->extract_block();
     210 *     $gallery_block = $processor->extract_full_block_and_advance();
    211211 *     $after_gallery = $processor->get_span()->start;
    212212 *     return (
     
    12241224     *
    12251225     *     $gallery_at  = $processor->get_span()->start;
    1226      *     $gallery     = $processor->extract_block();
     1226     *     $gallery     = $processor->extract_full_block_and_advance();
    12271227     *     $ends_before = $processor->get_span();
    12281228     *     $ends_before = $ends_before->start ?? strlen( $post_content );
     
    12551255     * }
    12561256     */
    1257     public function extract_block(): ?array {
     1257    public function extract_full_block_and_advance(): ?array {
    12581258        if ( $this->is_html() ) {
    12591259            $chunk = $this->get_html_content();
     
    12921292             */
    12931293            if ( $this->opens_block() ) {
    1294                 $inner_block             = $this->extract_block();
     1294                $inner_block             = $this->extract_full_block_and_advance();
    12951295                $block['innerBlocks'][]  = $inner_block;
    12961296                $block['innerContent'][] = null;
  • trunk/tests/phpunit/tests/block-processor/wpBlockProcessor-BlockProcessing.php

    r60939 r61294  
    8787        $extracted = array();
    8888        while ( $processor->next_block( '*' ) ) {
    89             $extracted[] = $processor->extract_block();
     89            $extracted[] = $processor->extract_full_block_and_advance();
    9090        }
    9191
Note: See TracChangeset for help on using the changeset viewer.