Skip to content

Interactivity API: Add server-side processing for the data-wp-html directive - #14012

Closed
DAreRodz wants to merge 6 commits into
WordPress:trunkfrom
DAreRodz:data-wp-html-directive-processor
Closed

DAreRodz wants to merge 6 commits into
WordPress:trunkfrom
DAreRodz:data-wp-html-directive-processor

Conversation

@DAreRodz

@DAreRodz DAreRodz commented Oct 5, 2026

Copy link
Copy Markdown

Adds server-side processing for the new data-wp-html directive, whose client implementation was merged in WordPress/gutenberg#83092, so that trusted HTML produced in PHP is present in the server-rendered page, including inside data-wp-each items.

What it adds

  • wp_interactivity_as_dangerous_html( string $html ): returns an opaque WP_Interactivity_Dangerous_HTML token. The token holds no HTML; the server records the HTML against the token's identity for the current request.
  • A data-wp-html directive processor. When the reference resolves to a token, the element's content is replaced with its HTML, byte for byte. The element keeps its tag and attributes, and its other directives are processed as usual.

Behavior

  • Only tokens render. Strings (sanitized or not), clones, and unserialized or reconstructed objects never render.
  • The HTML is neither sanitized nor validated, and directives inside it are not processed on the server.
  • Neither the token nor its HTML is written to the Interactivity data printed for the client.
  • When the directive does not render, the element keeps its existing content. A _doing_it_wrong() notice is raised when the value is not a token, when the element cannot hold content (void elements and script, style, textarea, title, iframe, noembed, noframes, xmp), or when the element also carries data-wp-text or is a template with data-wp-each. null or unresolved values are silent.

Implementation notes

The processor writes an inert placeholder comment as the element's content, and process_directives() swaps the trusted HTML in with a single strtr() pass once processing has finished. Core therefore never tokenizes the trusted HTML, and the processing loop, data-wp-each, and the balanced-tag helper are unchanged. A new set_raw_content_between_balanced_tags() helper writes the placeholder without escaping.

Testing

PHPUnit only; hydration in the browser is covered by the Gutenberg PR.

npm run test:php -- --group interactivity-api

New test classes: Tests_Interactivity_API_WpInteractivityAsDangerousHtml, Tests_WP_Interactivity_API_WP_HTML, Tests_WP_Interactivity_API_Client_Data_WP_HTML, plus new cases in wpInteractivityAPIDirectivesProcessor.php.

Trac ticket: https://core.trac.wordpress.org/ticket/66246

Use of AI Tools

AI assistance: Yes
Tool(s): OpenCode, running an autonomous multi-agent pipeline (Radical Pipelines) that wrote and reviewed each stage separately
Model(s): Claude Opus 5.5, Claude Sonnet 5.5, GPT-6 Astra, GPT-6.1 Sol
Used for: This pull request was authored by AI end to end: specification and design (Claude Opus 5.5), implementation plan (Claude Opus 5.5), implementation and PHPUnit tests (GPT-6.1 Sol), inline documentation (Claude Sonnet 5.5), and the reviews of every stage (GPT-6 Astra and GPT-6.1 Sol). Orchestration used Claude Opus 5.5. I have reviewed the result and take responsibility for it.


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.

@github-actions

github-actions Bot commented Oct 5, 2026

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.

@DAreRodz
DAreRodz requested a review from luisherranz October 5, 2026 13:33
@DAreRodz
DAreRodz marked this pull request as ready for review October 7, 2026 13:08
@github-actions

github-actions Bot commented Oct 7, 2026

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 darerodz.

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

@DAreRodz

Copy link
Copy Markdown
Author

Superseded by #14301, which reworks this change after review: the token keeps its HTML in a private property instead of a static registry, unserializing a token leaves it inert with a notice instead of throwing, data-wp-style is left as in trunk, and token paths reached through state are announced in derivedStateClosures.

@DAreRodz DAreRodz closed this Oct 15, 2026
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.

1 participant