WP_Block_Processor::next_delimiter
Advance to the next block delimiter in a document, indicating if one was found.
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.
}
Метод класса: WP_Block_Processor{}
Хуков нет.
Возвращает
true|false. Whether a block delimiter was matched.
Использование
$WP_Block_Processor = new WP_Block_Processor(); $WP_Block_Processor->next_delimiter( ?string $block_name ): bool;
- ?string $block_name
- .
По умолчанию:null
Список изменений
| С версии 6.9.0 | Введена. |
Код WP_Block_Processor::next_delimiter() WP Block Processor::next delimiter WP 6.9.1
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;
}