Skip to content

Commit

Permalink
Add at method to open elements
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Jul 17, 2024
1 parent d28d9ec commit 2eb1e01
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/wp-includes/html-api/class-wp-html-open-elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,33 @@ public function set_push_handler( Closure $handler ) {
$this->push_handler = $handler;
}

/**
* Returns the name of the node at the nth position on the stack
* of open elements, or `null` if no such position exists.
*
* Note that this uses a 1-based index, which represents the
* "nth item" on the stack, counting from the top, where the
* top-most element is the 1st, the second is the 2nd, etc...
*
* @todo Skip over "marker" entries on the stack, if appropriate.
*
* @since 6.7.0
*
* @param int $nth Retrieve the nth item on the stack, with 1 being
* the top element, 2 being the second, etc...
* @return string|null Name of the node on the stack at the given location,
* or `null` if the location isn't on the stack.
*/
public function at( int $nth ): ?string {
foreach ( $this->walk_down() as $item ) {
if ( 0 === --$nth ) {
return $item->node_name;
}
}

return null;
}

/**
* Reports if a node of a given name is in the stack of open elements.
*
Expand Down

0 comments on commit 2eb1e01

Please sign in to comment.