Skip to content

HTML API: Make get_attribute_names_with_prefix() agree with enqueued attribute updates#12619

Open
irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:fix/64567-html-api-attribute-names-with-prefix
Open

HTML API: Make get_attribute_names_with_prefix() agree with enqueued attribute updates#12619
irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:fix/64567-html-api-attribute-names-with-prefix

Conversation

@irozum

@irozum irozum commented Jul 21, 2026

Copy link
Copy Markdown

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.

Copilot AI review requested due to automatic review settings July 21, 2026 02:52
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props irozum.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@irozum
irozum force-pushed the fix/64567-html-api-attribute-names-with-prefix branch from e5955cb to aaf85f9 Compare July 21, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants