WP_Block_Processor::next_delimiter( string|null $block_name = null ): bool
- Since
- 6.9.0
- Source
wp-includes/class-wp-block-processor.php:682
Description
Delimiters may include invalid JSON. This parser does not attempt to parse the JSON attributes until requested; when invalid, the attributes will be null. This matches the behavior of parse_blocks(). To visit freeform HTML content, pass the wildcard “*” as the block type.
Use this function to walk through the block delimiters in a document.
Example delimiters:
<!-- wp:paragraph {"dropCap": true} -->
<!-- wp:separator /-->
<!-- /wp:paragraph -->
// If the wildcard * is provided as the block type, freeform content is matched.
<⃨h⃨2⃨>⃨M⃨y⃨ ⃨s⃨y⃨n⃨o⃨p⃨s⃨i⃨s⃨<⃨/⃨h⃨2⃨>⃨\⃨n⃨<!-- wp:my/table-of-contents /-->
// Inner HTML is never freeform content, and will not be matched even with the wildcard.
...</ul><⃨!⃨-⃨-⃨ ⃨/⃨w⃨p⃨:⃨l⃨i⃨s⃨t⃨ ⃨-⃨-⃨>⃨<!-- wp:paragraph --><p> Example:
$html = '<!-- wp:void /-->\n<!-- wp:void /-->';
$processor = new WP_Block_Processor( $html );
while ( $processor->next_delimiter() {
// Runs twice, seeing both void blocks of type “core/void.”
}
$processor = new WP_Block_Processor( $html );
while ( $processor->next_delimiter( '*' ) ) {
// Runs thrice, seeing the void block, the newline span, and the void block.
}Compatibility
- WordPress
- since 6.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 3 of the 5 tracked releases, added in 6.9.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$block_namestring|nulloptional- Keep searching until a block of this name is found.
Defaults to visit every block regardless of type.Default:null
Return value
bool- Whether a block delimiter was matched.
Performance profile
How much work a call to WP_Block_Processor::next_delimiter() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Scales with input
- Instructions
- 7–11
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 21.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Block_Processor::next_delimiter() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!->next_token() | 7–8 | ->next_token() |
isset($block_name) && ->next_token() && ->is_block_type() | 11 | ->next_token(), ->is_block_type() |
!isset($block_name) && ->next_token() && !->is_html() | 11 | ->next_token(), ->is_html() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 21 | 7–11 | 5 | |
| 8.5 | 21 | 7–11 | 5 | |
| 8.4 | 21 | 7–11 | 5 | |
| 8.3 | 21 | 7–11 | 5 | |
| 8.2 | 21 | 7–11 | 5 | 1 more instruction than PHP 8.1 |
| 8.1 | 20 | 7–11 | 5 | |
| 7.4 | 20 | 7–11 | 5 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 3
- WP_Block_Processor::next_token()Advance to the next block delimiter or HTML span in a document, indicating if one was found.
- WP_Block_Processor::is_html()Indicates if the matched delimiter is an HTML span.
- WP_Block_Processor::is_block_type()Indicates if the block delimiter represents a block of the given type.
Used by · 1
- WP_Block_Processor::next_block()Advance to the next block delimiter which opens a block, indicating if one was found.
Source code
public function next_delimiter( ?string $block_name = null ): bool { if ( ! isset( $block_name ) ) { while ( $this->next_token() ) { if ( ! $this->is_html() ) { return true; } } return false; } while ( $this->next_token() ) { if ( $this->is_block_type( $block_name ) ) { return true; } } return false; }Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.
Signature, return type and hooks compared across 3 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-block-processor.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.