Indicates if the matched delimiter is an opening or void delimiter of the given type, if a type is provided, otherwise if it opens any block or implicit freeform HTML content.
Description
This is a helper method to ease handling of code inspecting where blocks start, and for checking if the blocks are of a given type. The function is variadic to allow for checking if the delimiter opens one of many possible block types. To advance to the start of a block self::next_block(). Example: $processor = new WP_Block_Processor( $html );
while ( $processor->next_delimiter() ) {
if ( $processor->opens_block( 'core/code', 'syntaxhighlighter/code' ) ) {
echo "Found code!";
continue;
}
if ( $processor->opens_block( 'core/image' ) ) {
echo "Found an image!";
continue;
}
if ( $processor->opens_block() ) {
echo "Found a new block!";
}
}
Parameters
$block_typestring[]
Is the matched block type one of these? If none are provided, will not test block type.
Return
bool
Whether the matched block delimiter opens a block, and whether it opens a block of one of the given block types, if provided.
Uses · 3
array_any()Polyfill for `array_any()` function added in PHP 8.4.
WP_Block_Processor::extract_full_block_and_advance()Extracts a block object, and all inner content, starting at a matched opening block delimiter, or at a matched top-level HTML span as freeform HTML content.
1581publicfunctionopens_block(string...$block_type):bool{1582// HTML spans only open implicit freeform content at the top level.1583if(self::HTML_SPAN===$this->state&&1!==count($this->open_blocks_at)){1584returnfalse;1585}15861587/*1588 * Because HTML spans are discovered after the next delimiter is found,1589 * the delimiter type when visiting HTML spans refers to the type of the1590 * following delimiter. Therefore the HTML case is handled by checking1591 * the state and depth of the stack of open block.1592 */1593if(self::CLOSER===$this->type&&!$this->is_html()){1594returnfalse;1595}15961597if(count($block_type)===0){1598returntrue;1599}16001601returnarray_any($block_type,fn($block)=>$this->is_block_type($block));1602}
History
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.