WP_HTML_Open_Elements::pop_untilpublicWP 6.4.0

Pops nodes off of the stack of open elements until an HTML tag with the given name has been popped.

Method of the class: WP_HTML_Open_Elements{}

No Hooks.

Returns

true|false. Whether a tag of the given name was found and popped off of the stack of open elements.

Usage

$WP_HTML_Open_Elements = new WP_HTML_Open_Elements();
$WP_HTML_Open_Elements->pop_until( $html_tag_name ): bool;
$html_tag_name(string) (required)
Name of tag that needs to be popped off of the stack of open elements.

Notes

Changelog

Since 6.4.0 Introduced.

WP_HTML_Open_Elements::pop_until() code WP 6.8.1

public function pop_until( string $html_tag_name ): bool {
	foreach ( $this->walk_up() as $item ) {
		$this->pop();

		if ( 'html' !== $item->namespace ) {
			continue;
		}

		if (
			'(internal: H1 through H6 - do not use)' === $html_tag_name &&
			in_array( $item->node_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true )
		) {
			return true;
		}

		if ( $html_tag_name === $item->node_name ) {
			return true;
		}
	}

	return false;
}