-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace regex with tag processor for duotone class render #49212
Conversation
Flaky tests detected in 9c30a2c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4472838415
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this with some posts with Duotone applied and it seemed to work. Code looks good based on what I know about this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if ( $tags->next_tag() ) { | ||
$tags->add_class( $filter_id ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like add_class
gets a free pass and the if statement isn't necessary/desired here.
if ( $tags->next_tag() ) { | |
$tags->add_class( $filter_id ); | |
} | |
$tags->add_class( $filter_id ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The $tags->next_tag()
returns a boolean if it finds a tag or not, so the if
statement is checking to make sure that we have an element to add the class to, not that the class already exists on the element. The only reason I think it might return false
is if you have an empty string or malformed HTML.
For reference, I based this off of how it was used in #46625.
What?
Updates duotone to use
WP_HTML_Tag_Processor
instead ofpreg_replace
.Why?
WP_HTML_Tag_Processor
is a more robust solution for adding a class in PHP.Fixes #49169
How?
Replaces regex code with
WP_HTML_Tag_Processor
for adding the duotone filter class.Testing Instructions