[wp-trac] [WordPress Trac] #59209: HTML API: Add class name utilities has_class() and class_list()
WordPress Trac
noreply at wordpress.org
Sat Aug 26 03:10:43 UTC 2023
#59209: HTML API: Add class name utilities has_class() and class_list()
-------------------------+-----------------------------
Reporter: dmsnell | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: HTML API | Version: trunk
Severity: normal | Keywords: has-patch
Focuses: |
-------------------------+-----------------------------
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' )`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59209>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list