Indicates if the currently-matched tag matches the given breadcrumbs.
Description
A "*" represents a single tag wildcard, where any tag matches, but not no tags. At some point this function <em>may</em> 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' ) );
Parameters
$breadcrumbsstring[]
DOM sub-path at which element is found, e.g. array( 'FIGURE', 'IMG' ). May also contain the wildcard * which matches a single element, e.g. array( 'SECTION', '*' ).
Return
bool
Whether the currently-matched tag is found at the given nested structure.
920publicfunctionmatches_breadcrumbs($breadcrumbs):bool{921// Everything matches when there are zero constraints.922if(0===count($breadcrumbs)){923returntrue;924}925926// Start at the last crumb.927$crumb=end($breadcrumbs);928929if('*'!==$crumb&&$this->get_tag()!==strtoupper($crumb)){930returnfalse;931}932933for($i=count($this->breadcrumbs)-1;$i>=0;$i--){934$node=$this->breadcrumbs[$i];935$crumb=strtoupper(current($breadcrumbs));936937if('*'!==$crumb&&$node!==$crumb){938returnfalse;939}940941if(false===prev($breadcrumbs)){942returntrue;943}944}945946returnfalse;947}
History
Introduced in 6.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/html-api/class-wp-html-processor.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.