From d28d9eca339e317e291e8cf7f18bcea2c803fe2b Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 17 Jul 2024 10:59:32 +0200 Subject: [PATCH] Add contains method to open elements From https://github.com/WordPress/wordpress-develop/pull/6972 --- .../html-api/class-wp-html-open-elements.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/wp-includes/html-api/class-wp-html-open-elements.php b/src/wp-includes/html-api/class-wp-html-open-elements.php index df6ba8158b085..d300143b48542 100644 --- a/src/wp-includes/html-api/class-wp-html-open-elements.php +++ b/src/wp-includes/html-api/class-wp-html-open-elements.php @@ -101,6 +101,24 @@ public function set_push_handler( Closure $handler ) { $this->push_handler = $handler; } + /** + * Reports if a node of a given name is in the stack of open elements. + * + * @since 6.7.0 + * + * @param string $node_name Name of node for which to check. + * @return bool Whether a node of the given name is in the stack of open elements. + */ + public function contains( string $node_name ): bool { + foreach ( $this->walk_up() as $item ) { + if ( $node_name === $item->node_name ) { + return true; + } + } + + return false; + } + /** * Reports if a specific node is in the stack of open elements. *