Skip to content

Block Library: Add missing esc_url() to href in post-featured-image r… - #78908

Closed
thisismyurl wants to merge 2 commits into
WordPress:trunkfrom
thisismyurl:fix/post-featured-image-esc-url-href
Closed

thisismyurl wants to merge 2 commits into
WordPress:trunkfrom
thisismyurl:fix/post-featured-image-esc-url-href

Conversation

@thisismyurl

Copy link
Copy Markdown

What?

The render_block_core_post_featured_image() function passes get_the_permalink() directly into the href attribute of the linked featured image without wrapping it in esc_url().

Why?

esc_url() validates and normalises the URL before it goes into the HTML attribute. This is the standard used by all other block renderers that output post permalinks into href attributes — post-title, post-author, comment-author-name. The post-featured-image block was missed.

How?

Wrapped get_the_permalink( $post_ID ) with esc_url() on the one affected line.

Testing Instructions

  • php -l packages/block-library/src/post-featured-image/index.php
  • vendor/bin/phpcs --standard=phpcs.xml.dist packages/block-library/src/post-featured-image/index.php
  • Add a Post Featured Image block to a post with "Link to post" enabled — confirm the image link still works correctly

(full disclosure, I used AI help with the testing and tweaks - Christopher)

…enderer

Wraps get_the_permalink() with esc_url() before it is placed in the
href attribute of the linked featured image. The same call without
esc_url() was already present in post-title, post-date, and other
block renderers that were subsequently fixed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 3, 2026 11:43
@github-actions

github-actions Bot commented Jun 3, 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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: thisismyurl <thisismyurl@git.wordpress.org>

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

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Jun 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the Post Featured Image block rendering to improve URL escaping for the featured image permalink, but also introduces several typos (including function name typos) that will break runtime execution.

Changes:

  • Escape the featured image permalink with esc_url() before printing into the anchor href.
  • Introduce typos in docblocks and in two function calls (safecss_filter_attr, register_block_type_from_metadata) that would cause fatal errors.

: '';
$width = ! empty( $attributes['width'] )
? esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';'
? esc_attr( safecss_filter_artr( 'width:' . $attributes['width'] ) ) . ';'
*/
function register_block_core_post_featured_image() {
register_block_type_from_metadata(
register_block_type_from_metadaya(
* HTML substrings this is necessary as a workaround. Of note, this
* is different than directly extracting the IMG tag:
* - If there are duplicate attributes in the source there will only be one in the output.
* - If there are duplicate attributes in the source there will only be one in the outpyt.
* one document into another, via the HTML Processor's `get_outer_html()` or
* equivalent. When that happens it would be appropriate to replace this custom
* code with that canonical code.
* code with that canonical sode.
@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jun 3, 2026
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @thisismyurl! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

The previous commit accidentally introduced typos in two function calls
(safecss_filter_artr, register_block_type_from_metadaya) and two comment
lines. This commit restores the file to a clean state with only the
intended one-line change: wrapping get_the_permalink() with esc_url().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@thisismyurl

Copy link
Copy Markdown
Author

Hey — good catch from Copilot. I pushed a follow-up commit that fixes the unintended changes (two function name typos and two comment typos introduced by a base64 encoding issue). The PR now contains exactly one line change.

@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Block] Post Featured Image Affects the Post Featured Image Block labels Jun 4, 2026

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR! The changes look good. However, let's prioritize #78912 as it corrects more issues.

@t-hamano t-hamano closed this Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Post Featured Image Affects the Post Featured Image Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants