Make WordPress Core


Ignore:
Timestamp:
10/15/2025 09:51:35 PM (4 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 *
Note: See TracChangeset for help on using the changeset viewer.