Comments: add the embed block - #53032
Open
arcangelini wants to merge 13 commits into
Open
arcangelini wants to merge 13 commits into
arcangelini wants to merge 13 commits into
Conversation
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Contributor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
|
…s, settle a closed route into a link
…nt, add rel to the link fallback
This branch has not been deployed
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.
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.
core/embedin 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.wpcom/v2/comments/embedpreview 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'soembed/1.0/proxyneedsedit_posts, which commenters do not have.figureanddivthrough with the one class each.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.jetpack_comments_block_editor_embedsfilter turns embeds off while leaving the rest of the editor on.editorsettings object.Two things reviewers will notice:
&as&in the embed'surlattribute. A pass at priority 11 puts it back, so the stored attribute matches the markup and the comment re-opens cleanly in the editor.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_hotnessfilter or the sticker):https://www.youtube.com/watch?v=dQw4w9WgXcQon its own line. It should turn into an embed block with a preview./embedoffers the block too.https://example.com/page. It should settle back into a plain link./wp-json/wpcom/v2/comments/embed?url=https://www.youtube.com/watch?v=dQw4w9WgXcQreturns oEmbed data;?url=https://example.com/returns a 404. Repeat with 30 fresh URLs to hit the 429.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.