WP_HTML_Processor::get_breadcrumbs()publicWP 6.4.0

Computes the HTML breadcrumbs for the currently-matched node, if matched.

Breadcrumbs start at the outermost parent and descend toward the matched element. They always include the entire path from the root HTML node to the matched element.

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

Хуков нет.

Возвращает

Строку[]|null. Array of tag names representing path to matched node, if matched, otherwise NULL.

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

$WP_HTML_Processor = new WP_HTML_Processor();
$WP_HTML_Processor->get_breadcrumbs();

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

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

Код WP_HTML_Processor::get_breadcrumbs() WP 6.6.1

public function get_breadcrumbs() {
	$breadcrumbs = array();

	foreach ( $this->state->stack_of_open_elements->walk_down() as $stack_item ) {
		$breadcrumbs[] = $stack_item->node_name;
	}

	if ( ! $this->is_virtual() ) {
		return $breadcrumbs;
	}

	foreach ( $this->element_queue as $queue_item ) {
		if ( $this->current_element->token->bookmark_name === $queue_item->token->bookmark_name ) {
			break;
		}

		if ( 'context-node' === $queue_item->token->bookmark_name ) {
			break;
		}

		if ( 'real' === $queue_item->provenance ) {
			break;
		}

		if ( WP_HTML_Stack_Event::PUSH === $queue_item->operation ) {
			$breadcrumbs[] = $queue_item->token->node_name;
		} else {
			array_pop( $breadcrumbs );
		}
	}

	if ( null !== parent::get_token_name() && ! parent::is_tag_closer() ) {
		array_pop( $breadcrumbs );
	}

	// Add the virtual node we're at.
	if ( WP_HTML_Stack_Event::PUSH === $this->current_element->operation ) {
		$breadcrumbs[] = $this->current_element->token->node_name;
	}

	return $breadcrumbs;
}