Make WordPress Core

Changeset 60939


Ignore:
Timestamp:
10/15/2025 09:51:35 PM (2 months ago)
Author:
dmsnell
Message:

Blocks: Introduce WP_Block_Processor for efficiently parsing blocks.

The Block Processor follows the HTML API in providing a streaming, near-zero-overhead, lazy, re-entrant parser for traversing block structure. This class provides an alternate interface to parse_blocks() which is more amenable to a number of common server-side operations on posts, especially those needing to operate on only a part of a full post.

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

Props dmsnell, gziolo, jonsurrell, soean, tjnowell, westonruter.
Fixes #61401.

Location:
trunk
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpcs.xml.dist

    r60768 r60939  
    230230    SELECTIVE EXCLUSIONS
    231231    Exclude specific files for specific sniffs and/or exclude sub-groups in sniffs.
    232    
     232
    233233    These exclusions are listed ordered by alphabetic sniff name.
    234234    #############################################################################
     
    267267        <!-- Goto is an effective way to handle errors in decoders which expect valid bytes
    268268             without impacting the fast path while avoiding bloating the code with redundant
    269              and risky handling code. Exclude forbidding goto in UTF-8 fallback code. -->
     269             and risky handling code. Exclude forbidding goto in parser code. -->
    270270        <exclude-pattern>/wp-includes/compat-utf8\.php</exclude-pattern>
     271        <exclude-pattern>/wp-includes/class-wp-block-processor\.php</exclude-pattern>
    271272    </rule>
    272273
  • trunk/src/wp-includes/blocks.php

    r60809 r60939  
    23772377 * Parses blocks out of a content string.
    23782378 *
     2379 * Given an HTML document, this function fully-parses block content, producing
     2380 * a tree of blocks and their contents, as well as top-level non-block content,
     2381 * which will appear as a block with no `blockName`.
     2382 *
     2383 * This function can be memory heavy for certain documents, particularly those
     2384 * with deeply-nested blocks or blocks with extensive attribute values. Further,
     2385 * this function must parse an entire document in one atomic operation.
     2386 *
     2387 * If the entire parsed document is not necessary, consider using {@see WP_Block_Processor}
     2388 * instead, as it provides a streaming and low-overhead interface for finding blocks.
     2389 *
    23792390 * @since 5.0.0
    23802391 *
  • trunk/src/wp-settings.php

    r60793 r60939  
    269269require ABSPATH . WPINC . '/html-api/class-wp-html-processor-state.php';
    270270require ABSPATH . WPINC . '/html-api/class-wp-html-processor.php';
     271require ABSPATH . WPINC . '/class-wp-block-processor.php';
    271272require ABSPATH . WPINC . '/class-wp-http.php';
    272273require ABSPATH . WPINC . '/class-wp-http-streams.php';
Note: See TracChangeset for help on using the changeset viewer.