WP_Block_Processor::get_printable_block_type
Allocates a printable substring for the block type and returns the fully-qualified name, including the namespace, if matched on a delimiter or freeform block, otherwise null.
This function is like {@see self::get_block_type()} but when paused on a freeform HTML block, will return “core/freeform” instead of null. The null behavior matches what \parse_blocks() returns but may not be as useful as having a string value.
This function allocates a substring for the given block type. This allocation will be small and likely fine in most cases, but it's preferable to call {@see self::is_block_type()} if only needing to know whether the delimiter is for a given block type, as that function is more efficient for this purpose and avoids the allocation.
Example:
// Avoid. 'core/paragraph' = $processor->get_printable_block_type();
// Prefer. $processor->is_block_type( 'core/paragraph' ); $processor->is_block_type( 'paragraph' ); $processor->is_block_type( 'core/freeform' );
// Freeform HTML content is given an implicit type. $processor = new WP_Block_Processor( 'non-block content' ); $processor->next_token(); 'core/freeform' === $processor->get_printable_block_type();
Метод класса: WP_Block_Processor{}
Хуков нет.
Возвращает
Строку|null. Fully-qualified block namespace and type, e.g. "core/paragraph", if matched on an explicit delimiter or freeform block, otherwise null.
Использование
$WP_Block_Processor = new WP_Block_Processor(); $WP_Block_Processor->get_printable_block_type(): ?string;
Заметки
- Смотрите: self::are_equal_block_types()
Список изменений
| С версии 6.9.0 | Введена. |
Код WP_Block_Processor::get_printable_block_type() WP Block Processor::get printable block type WP 6.9.1
public function get_printable_block_type(): ?string {
if (
self::READY === $this->state ||
self::COMPLETE === $this->state ||
self::INCOMPLETE_INPUT === $this->state
) {
return null;
}
// This is a core/freeform text block, it’s special.
if ( $this->is_html() ) {
return 1 === count( $this->open_blocks_at )
? 'core/freeform'
: '#innerHTML';
}
$block_type = substr( $this->source_text, $this->namespace_at, $this->name_at - $this->namespace_at + $this->name_length );
return self::normalize_block_type( $block_type );
}