Indicates if the block delimiter represents a block of the given type.
Description
Since the “core” namespace may be implicit, it’s allowable to pass either the fully-qualified block type with namespace and block name as well as the shorthand version only containing the block name, if the desired block is in the “core” namespace.
Since freeform HTML content is non-block content, it has no block type.
Passing the wildcard “*” will, however, return true for all block types, even the implicit freeform content, though not for spans of inner HTML.
Example:
$is_core_paragraph = $processor->is_block_type( 'paragraph' );
$is_core_paragraph = $processor->is_block_type( 'core/paragraph' );
$is_formula = $processor->is_block_type( 'math-block/formula' );Parameters
$block_typestringrequired- Block type name for the desired block.
E.g. "paragraph", "core/paragraph", "math-blocks/formula".
Source
public function is_block_type( string $block_type ): bool {
if ( '*' === $block_type ) {
return true;
}
if ( $this->is_html() ) {
// This is a core/freeform text block, it’s special.
if ( 0 === ( $this->open_blocks_length[0] ?? null ) ) {
return (
'core/freeform' === $block_type ||
'freeform' === $block_type
);
}
// Otherwise this is innerHTML and not a block.
return false;
}
return $this->are_equal_block_types( $this->source_text, $this->namespace_at, $this->name_at - $this->namespace_at + $this->name_length, $block_type, 0, strlen( $block_type ) );
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.