WP_HTML_Open_Elements::walk_up()publicWP 6.4.0

Steps through the stack of open elements, starting with the bottom element (added last) and walking upwards to the one added first.

This generator function is designed to be used inside a "foreach" loop.

Example:

$html = '<em><strong><a>We are here';
foreach ( $stack->walk_up() as $node ) {
	echo "{$node->node_name} -> ";
}
> A -> STRONG -> EM ->

To start with the first added element and walk towards the bottom, see WP_HTML_Open_Elements::walk_down().

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$WP_HTML_Open_Elements = new WP_HTML_Open_Elements();
$WP_HTML_Open_Elements->walk_up( $above_this_node );
$above_this_node(?WP_HTML_Token)
Start traversing above this node, if provided and if the node exists.
По умолчанию: null

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

С версии 6.4.0 Введена.
С версии 6.5.0 Accepts $above_this_node to start traversal above a given node, if it exists.

Код WP_HTML_Open_Elements::walk_up() WP 6.6.2

public function walk_up( $above_this_node = null ) {
	$has_found_node = null === $above_this_node;

	for ( $i = count( $this->stack ) - 1; $i >= 0; $i-- ) {
		$node = $this->stack[ $i ];

		if ( ! $has_found_node ) {
			$has_found_node = $node === $above_this_node;
			continue;
		}

		yield $node;
	}
}