WP_HTML_Open_Elements::has_element_in_specific_scope()
Returns whether an element is in a specific scope.
HTML Support
This function skips checking for the termination list because there are no supported elements which appear in the termination list.
Method of the class: WP_HTML_Open_Elements{}
No Hooks.
Return
true|false
. Whether the element was found in a specific scope.
Usage
$WP_HTML_Open_Elements = new WP_HTML_Open_Elements(); $WP_HTML_Open_Elements->has_element_in_specific_scope( $tag_name, $termination_list );
- $tag_name(string) (required)
- Name of tag check.
- $termination_list(string[]) (required)
- List of elements that terminate the search.
Notes
Changelog
Since 6.4.0 | Introduced. |
WP_HTML_Open_Elements::has_element_in_specific_scope() WP HTML Open Elements::has element in specific scope code WP 6.6.2
public function has_element_in_specific_scope( $tag_name, $termination_list ) { foreach ( $this->walk_up() as $node ) { if ( $node->node_name === $tag_name ) { return true; } if ( '(internal: H1 through H6 - do not use)' === $tag_name && in_array( $node->node_name, array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ), true ) ) { return true; } switch ( $node->node_name ) { case 'HTML': return false; } if ( in_array( $node->node_name, $termination_list, true ) ) { return false; } } return false; }