WP_HTML_Open_Elements::has_element_in_specific_scope( string $tag_name, string[] $termination_list ): bool

Returns whether an element is in a specific scope.

Description

See also

Parameters

$tag_namestringrequired
Name of tag check.
$termination_liststring[]required
List of elements that terminate the search.

Return

bool Whether the element was found in a specific scope.

Source

public function has_element_in_specific_scope( string $tag_name, $termination_list ): bool {
	foreach ( $this->walk_up() as $node ) {
		$namespaced_name = 'html' === $node->namespace
			? $node->node_name
			: "{$node->namespace} {$node->node_name}";

		if ( $namespaced_name === $tag_name ) {
			return true;
		}

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

		if ( in_array( $namespaced_name, $termination_list, true ) ) {
			return false;
		}
	}

	return false;
}

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.