Opened 9 days ago
Last modified 2 days ago
#66077 new defect (bug)
Unapproved comment preview renders oEmbed URL differently from the approved comment
| Reported by: | johnbillion | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Comments | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
In a block theme whose comments are inside a pattern block (eg. Twenty Twenty-Five), a pending comment containing an embeddable URL renders as an oEmbed in the comment moderation preview, but as a plain link once approved. The preview does not represent what will be published.
Steps to reproduce
- Twenty Twenty-Five theme, with comments set to require moderation.
- Logged out, comment on a post with a YouTube video URL on its own line.
- Observe that the comment preview shows an oEmbed of the video.
- Approve the comment and view the post. Observe a plain link renders.
The correct behaviour is that a plain link is shown.
An AI agent tells me that the fix is to run autoembed() on the source before do_blocks() in render_block_core_pattern() and _wp_apply_block_content_filters(), matching get_the_block_template_html() and the the_content filter order. Needs confirming, needs tests.
Change History (4)
This ticket was mentioned in PR #13508 on WordPress/wordpress-develop by @iamchitti.
4 days ago
#2
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
## Description
render_block_core_pattern() and _wp_apply_block_content_filters() called WP_Embed::autoembed() after do_blocks(), so it ran over rendered block output instead of the source. the_content (autoembed at 8, do_blocks() at 9), get_the_block_template_html() and render_block_core_block() all autoembed the source only.
This moves the autoembed() call before do_blocks() in both functions.
Trac ticket: https://core.trac.wordpress.org/ticket/66077
## Testing instructions
- Activate Twenty Twenty-Five and set comments to require moderation.
- Logged out, comment on a post with some text, a blank line, then a YouTube URL alone on the last line. Leave the cookie consent box unchecked. The leading text matters — the moderation notice is concatenated without a newline, so a URL on the comment's first line never matches autoembed.
- On the
?unapproved=…&moderation-hash=…preview, observe the YouTube player before the change and a plain URL after it. - Approve the comment and reload. It renders as a link in both cases.
## Screenshots
| Before | After |
|---|---|
| | |
## AI Usage
Model: Claude Code Opus 5
Used for: root cause analysis, the patch, and the unit tests.
#3
@
4 days ago
Raised related Gutenberg PR here - https://github.com/WordPress/gutenberg/pull/82860
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Reproduced, and the suggested fix works - with one correction:
autoembed()is already called in bothrender_block_core_pattern()and_wp_apply_block_content_filters(), just afterdo_blocks()rather than before. Moving it beforedo_blocks()resolves it.One addition to the steps: the comment needs some text before the URL. The moderation notice is concatenated without a newline, so a URL on the comment's first line shares a line with the notice's
</p>and autoembed never matches it.Also worth noting the preview still won't match the approved comment after this - unapproved renders the URL as plain unlinked text, approved renders a link. That's the
wp_kses( $comment_text, array() )stripping inrender_block_core_comment_content(), which looks deliberate.I'm working on a PR for it.