WP_Block_Processor::get_breadcrumbspublicWP 6.9.0

Returns an array containing the names of the currently-open blocks, in order from outermost to innermost, with HTML spans indicated as “#html”.

Example:

// Freeform HTML content is an HTML span.
$processor = new WP_Block_Processor( 'Just text' );
$processor->next_token();
array( '#text' ) === $processor->get_breadcrumbs();
$processor = new WP_Block_Processor( '<!-- wp:a --><!-- wp:b --><!-- wp:c /--><!-- /wp:b --><!-- /wp:a -->' );
$processor->next_token();
array( 'core/a' ) === $processor->get_breadcrumbs();
$processor->next_token();
array( 'core/a', 'core/b' ) === $processor->get_breadcrumbs();
$processor->next_token();
// Void blocks are only open while visiting them.
array( 'core/a', 'core/b', 'core/c' ) === $processor->get_breadcrumbs();
$processor->next_token();
// Blocks are closed before visiting their closing delimiter.
array( 'core/a' ) === $processor->get_breadcrumbs();
$processor->next_token();
array() === $processor->get_breadcrumbs();
// Inner HTML is also an HTML span.
$processor = new WP_Block_Processor( '<!-- wp:a -->Inner HTML<!-- /wp:a -->' );
$processor->next_token();
$processor->next_token();
array( 'core/a', '#html' ) === $processor->get_breadcrumbs();

Метод класса: WP_Block_Processor{}

Хуков нет.

Возвращает

Строку[].

Использование

$WP_Block_Processor = new WP_Block_Processor();
$WP_Block_Processor->get_breadcrumbs(): array;

Список изменений

С версии 6.9.0 Введена.

Код WP_Block_Processor::get_breadcrumbs() WP 6.9.1

public function get_breadcrumbs(): array {
	$breadcrumbs = array_fill( 0, count( $this->open_blocks_at ), null );

	/*
	 * Since HTML spans can only be at the very end, set the normalized block name for
	 * each open element and then work backwards after creating the array. This allows
	 * for the elimination of a conditional on each iteration of the loop.
	 */
	foreach ( $this->open_blocks_at as $i => $at ) {
		$block_type        = substr( $this->source_text, $at, $this->open_blocks_length[ $i ] );
		$breadcrumbs[ $i ] = self::normalize_block_type( $block_type );
	}

	if ( isset( $i ) && 0 === $this->open_blocks_length[ $i ] ) {
		$breadcrumbs[ $i ] = '#html';
	}

	return $breadcrumbs;
}