Indicates if the currently-matched tag matches the given breadcrumbs.
A "*" represents a single tag wildcard, where any tag matches, but not no tags.
At some point this function may support a ** syntax for matching any number of unspecified tags in the breadcrumb stack. This has been intentionally left out, however, to keep this function simple and to avoid introducing backtracking, which could open up surprising performance breakdowns.
Example:
$processor = WP_HTML_Processor::create_fragment( '<div><span><figure><img></figure></span></div>' );
$processor->next_tag( 'img' );
true === $processor->matches_breadcrumbs( array( 'figure', 'img' ) );
true === $processor->matches_breadcrumbs( array( 'span', 'figure', 'img' ) );
false === $processor->matches_breadcrumbs( array( 'span', 'img' ) );
true === $processor->matches_breadcrumbs( array( 'span', '*', 'img' ) );$breadcrumbsstring[]required
array( 'FIGURE', 'IMG' ).* which matches a single element, e.g. array( 'SECTION', '*' ). *
* @todo In some cases, probably related to the adoption agency
* algorithm, this call to step() doesn't create any new
* events. Calling it again creates them. Figure out why
* this is and if it's inherent or if it's a bug. Looping
* until there are events or until there are no more
* tokens works in the meantime and isn't obviously wrong.
*/
if ( empty( $this->element_queue ) && $this->step() ) {
return $this->next_token();
}
// Process the next event on the queue.
$this->current_element = array_shift( $this->element_queue );
if ( ! isset( $this->current_element ) ) {
// There are no tokens left, so close all remaining open elements.
while ( $this->state->stack_of_open_elements->pop() ) {
continue;
}
return empty( $this->element_queue ) ? false : $this->next_token();
}
$is_pop = WP_HTML_Stack_Event::POP === $this->current_element->operation;
/*
* The root node only exists in the fragment parser, and closing it
| Version | Description |
|---|---|
| 6.4.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_html_processor/matches_breadcrumbs