[wp-trac] [WordPress Trac] #59400: HTML API: Add matches_breadcrumbs() to HTML Processor for better querying

WordPress Trac noreply at wordpress.org
Tue Sep 19 21:22:14 UTC 2023


#59400: HTML API: Add matches_breadcrumbs() to HTML Processor for better querying
-------------------------+--------------------------------------
 Reporter:  dmsnell      |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  HTML API     |    Version:  trunk
 Severity:  normal       |   Keywords:  has-patch has-unit-tests
  Focuses:               |
-------------------------+--------------------------------------
 Inside a next_tag() loop it can be challenging to use breadcrumbs because
 they are only exposed inside the call to next_tag() via the $query arg.

 {{{#!php
 <?php
 while ( $processor->next_tag( array( 'breadcrumbs' => array( 'figure',
 'img' ) ) ) ) {
         …
 }
 }}}

 In this patch a new method, `matches_breadcrumbs()` is exposed which
 allows for querying within the `next_tag()` loop for more complicated
 queries.

 {{{#!php
 <?php
 while ( $processor->next_tag() ) {
         if ($processor->matches_breadcrumbs( array( 'figure', 'img' ) ) )
 {
                 …
         }
 }
 }}}

 This method exposes a wildcard `*` operator to allow matching any HTML tag
 that the currently-matched tag is a child or descendant of. It also
 exposes a `**` operator to allow matching from zero to any number of non-
 specific tags in the stack of open elements between the current breadcrumb
 and the next.

 {{{#!php
 <?php
 while ( $processor->next_tag() ) {
         // Detect A descendants of NAV elements.
         if ( $processor->matches_breadcrumbs( array( 'nav', '**', a' ) ) )
 {
                 …
         }
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59400>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list