Repository navigation
Conversation
`get_attribute_names_with_prefix()` flushes enqueued `add_class()` and `remove_class()` calls only when they could add or remove the `class` attribute. It decided whether the tag has a `class` attribute from the input document alone and ignored an enqueued `set_attribute()` or `remove_attribute()` for `class`, so two kinds of sequence gave the wrong answer: - The input has a `class` attribute, `remove_attribute( 'class' )` or `set_attribute( 'class', false )` enqueues its removal, and `add_class()` follows. The method did not flush, found the removal, and omitted `class`, while `get_updated_html()` produces a `class` attribute. - The input has no `class` attribute, `set_attribute( 'class', ... )` enqueues one, and `remove_class()` removes every class in it. The method did not flush, found the addition, and reported `class`, while `get_updated_html()` produces no `class` attribute. The method now uses the enqueued `class` attribute update, when one exists, to decide whether the attribute exists. Every sequence of up to three calls to `add_class()`, `remove_class()`, `remove_attribute( 'class' )` and `set_attribute( 'class', ... )` was compared, on tags with no, an empty, a boolean, a single and a duplicated `class` attribute, against a new Tag Processor's reading of `get_updated_html()`. Before this change 254 of 5,550 sequences disagreed; after it, none do. `get_attribute( 'class' )` agreed in every sequence before and after. Follow-up to [62960]. Props jonsurrell. See #65967.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
get_attribute_names_with_prefix()can disagree withget_updated_html()about theclassattribute whenadd_class()orremove_class()follows an enqueuedset_attribute( 'class', ... )orremove_attribute( 'class' )on the same tag. This is in released WordPress since r62960 (7.1.0), which made the method read enqueued updates.remove_class( 'a' )remove_attribute( 'class' )get_attribute_names_with_prefix( '' )array( 'class' )array()get_updated_html()<div class="b"><div class="b">The reverse also happens: on
<div>,set_attribute( 'class', 'a' )thenremove_class( 'a' )reportsclass, and the output has noclassattribute.The method flushes class name updates only when they could add or remove the
classattribute: a removal when the tag has the attribute, an addition when it does not. It decided whether the tag has the attribute from the input document alone. It now uses the enqueuedclassattribute update when one exists, which is the valueclass_name_updates_to_attributes_updates()starts from.Every sequence of up to three calls to
add_class(),remove_class(),remove_attribute( 'class' )andset_attribute( 'class', ... ), on tags with no, an empty, a boolean, a single and a duplicatedclassattribute, was compared with a new Tag Processor's reading ofget_updated_html(). On trunk 254 of 5,550 sequences disagree; with this change none do, and none of 55,550 sequences of up to four calls.get_attribute( 'class' )agrees in every sequence on both. The new data provider test has a case for each kind of mismatch.Trac ticket: https://core.trac.wordpress.org/ticket/65967
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Diagnosis, the sequence comparison, tests, implementation and description drafting.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.