HTML API: Make get_attribute_names_with_prefix() agree with enqueued attribute updates#12619
HTML API: Make get_attribute_names_with_prefix() agree with enqueued attribute updates#12619irozum wants to merge 1 commit into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
This PR updates WP_HTML_Tag_Processor::get_attribute_names_with_prefix() so it reflects enqueued attribute changes (from set_attribute(), remove_attribute(), add_class(), remove_class()) even before get_updated_html() is called, aligning its behavior with get_attribute() and fixing stale results (Trac #64567).
Changes:
- Reconcile pending class-name updates into attribute updates before collecting attribute names.
- Include newly-added attribute names from enqueued lexical updates (and exclude attributes enqueued for removal) when filtering by prefix.
- Add PHPUnit coverage for added/removed attributes and class mutations without requiring a prior
get_updated_html()call, including a serialized-order assertion for multiple new attributes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/phpunit/tests/html-api/wpHtmlTagProcessor.php | Adds regression tests covering stale prefix lookups across set/remove attribute and add/remove class flows, including ordering behavior. |
| src/wp-includes/html-api/class-wp-html-tag-processor.php | Updates get_attribute_names_with_prefix() to account for enqueued updates and adds helper to surface newly-added attribute names in serialized order. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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. |
…attribute updates.
e5955cb to
aaf85f9
Compare
get_attribute_names_with_prefix() only looked at the parsed attributes for a tag, so it returned stale data once attributes were set or removed via set_attribute(), remove_attribute(), add_class(), or remove_class(), without first calling get_updated_html(). This brings it in line with get_attribute(), which already reconciles enqueued lexical updates before returning.
Trac ticket: https://core.trac.wordpress.org/ticket/64567
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Implementation, debugging (including finding and fixing an attribute-ordering edge case for multiple newly-added attributes), and test coverage.
All changes were reviewed and directed by me throughout.