[wp-trac] [WordPress Trac] #59209: HTML API: Add class name utilities has_class() and class_list()

WordPress Trac noreply at wordpress.org
Tue Sep 26 09:15:36 UTC 2023


#59209: HTML API: Add class name utilities has_class() and class_list()
---------------------------------------------+-----------------------------
 Reporter:  dmsnell                          |       Owner:  Bernhard
                                             |  Reiter
     Type:  enhancement                      |      Status:  closed
 Priority:  normal                           |   Milestone:  6.4
Component:  HTML API                         |     Version:  trunk
 Severity:  normal                           |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests commit  |     Focuses:
---------------------------------------------+-----------------------------
Changes (by Bernhard Reiter):

 * owner:  (none) => Bernhard Reiter
 * status:  new => closed
 * resolution:   => fixed


Comment:

 In [changeset:"56703" 56703]:
 {{{
 #!CommitTicketReference repository="" revision="56703"
 HTML API: Add class name utilities `has_class()` and `class_list()`.

 This patch adds two new public methods to the HTML Tag Processor:
  - `has_class()` indicates if a matched tag contains a given CSS class
 name.
  - `class_list()` returns a generator to iterate over all the class names
 in a matched tag.

 Included in this patch is a refactoring of the internal logic when
 matching
 a tag to reuse the new `has_class()` function. Previously it was relying
 on
 optimized code in the `matches()` function which performed byte-for-byte
 class name comparison. With the change in this patch it will perform class
 name matching on the decoded value, which might differ if a class
 attribute
 contains character references.

 These methods may be useful for running more complicated queries based
 on the presence or absence of CSS class names. The use of these methods
 avoids the need to manually decode the class attribute as reported by
 `$process->get_attribute( 'class' )`.

 Props dmsnell.
 Fixes #59209.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59209#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list