Skip to content

Comments: add the embed block - #53032

Open
arcangelini wants to merge 13 commits into
trunkfrom
add/comments-embed-block
Open

arcangelini wants to merge 13 commits into
trunkfrom
add/comments-embed-block

Conversation

@arcangelini

@arcangelini arcangelini commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Proposed changes

Follow-up to #52971. The comment editor gets an embed block, limited to the providers WordPress itself trusts, and kept to the bare minimum: a URL in, an embed out.

  • Register core/embed in the comment editor with a small edit and save of our own. The block holds one attribute, the URL, and saves <figure class="wp-block-embed"><div class="wp-block-embed__wrapper">URL</div></figure>. Core's edit needs the site data store, which the comment bundle leaves out. Pasting a link on its own line becomes an embed block. A link the site will not embed turns back into a plain link paragraph on its own, since most links in a comment are just links.
  • Add a wpcom/v2/comments/embed preview route, registered the same way as the identity routes, so one definition works on self-hosted, Atomic and Simple. It is open to anyone, rate limits lookups per IP, answers with a public cache header, and runs with oEmbed discovery off, so the only outbound requests go to a trusted provider's own endpoint. Core's oembed/1.0/proxy needs edit_posts, which commenters do not have.
  • On save, rebuild each embed block from its URL. A URL outside the trusted provider list becomes a paragraph holding the link. kses lets figure and div through with the one class each.
  • On render, draw the embed through WP_Embed, which shares core's embed cache with the site's posts and with the comment autoembed WordPress.com and Jetpack's shortcodes already run at priority 1. Only approved comments on the front end draw a provider's iframe. Pending comments and wp-admin show the link.
  • A jetpack_comments_block_editor_embeds filter turns embeds off while leaving the rest of the editor on.
  • The block's strings are core's, in the default domain, translated the way every other string in the editor is: PHP pulls them from core's language files and hands them over. The i18n check now expects that domain for this package, and the editor's only string of its own, the toolbar name, moves with the route into one editor settings object.

Two things reviewers will notice:

  • WordPress 7.x runs kses over block attribute values, which writes & as &amp; in the embed's url attribute. A pass at priority 11 puts it back, so the stored attribute matches the markup and the comment re-opens cleanly in the editor.
  • Phan did not run locally. The package has no PHPUnit harness yet, so a WorDBless script covering save, kses, render and the route was the automated check. Happy to turn it into tests in a follow-up.

Related product discussion/links

Does this pull request change what data or activity we track or use?

No.

Testing instructions

On a site with the new comment form enabled (jetpack_comments_new_hotness filter or the sticker):

  • Open a post and click into the comment box so the block editor loads.
  • Paste https://www.youtube.com/watch?v=dQw4w9WgXcQ on its own line. It should turn into an embed block with a preview. /embed offers the block too.
  • Paste a link from a site WordPress does not embed, such as https://example.com/page. It should settle back into a plain link.
  • Post the comment. While pending it shows the link. Approve it and reload: the figure holds the iframe.
  • Open the comment in wp-admin. The list and edit screen show the link, not the iframe, and the edit screen's block editor loads the embed block.
  • Call the route directly: /wp-json/wpcom/v2/comments/embed?url=https://www.youtube.com/watch?v=dQw4w9WgXcQ returns oEmbed data; ?url=https://example.com/ returns a 404. Repeat with 30 fresh URLs to hit the 429.
  • Add add_filter( 'jetpack_comments_block_editor_embeds', '__return_false' ); and reload: the embed block is gone from the editor and existing embeds render as links.

@arcangelini arcangelini added the [Status] Needs Review This PR is ready for review. label Oct 1, 2026
@arcangelini arcangelini self-assigned this Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the add/comments-embed-block branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/comments-embed-block
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/comments-embed-block

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control

jp-launch-control Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php 38/503 (7.55%) -0.03% 2 ❤️‍🩹

Full summary · PHP report · JS report

@arcangelini
arcangelini requested a review from a team October 1, 2026 14:31

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Comments [Package] Jetpack mu wpcom WordPress.com Features [Status] Needs Review This PR is ready for review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant