WP_HTML_Open_Elements::walk_up()
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().
Method of the class: WP_HTML_Open_Elements{}
No Hooks.
Returns
null
. Nothing (null).
Usage
$WP_HTML_Open_Elements = new WP_HTML_Open_Elements(); $WP_HTML_Open_Elements->walk_up( ?WP_HTML_Token $above_this_node );
- ?WP_HTML_Token $above_this_node **
- -
Default: null
Changelog
Since 6.4.0 | Introduced. |
Since 6.5.0 | Accepts $above_this_node to start traversal above a given node, if it exists. |
WP_HTML_Open_Elements::walk_up() WP HTML Open Elements::walk up code WP 6.8.1
public function walk_up( ?WP_HTML_Token $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; } }