Skip to content

fix: use wp_kses_post() instead of esc_url() for HTML output in distributor_the_original_site_link()#1379

Merged
peterwilsoncc merged 1 commit into
10up:developfrom
thisismyurl:fix/esc-url-original-site-link
Jun 17, 2026
Merged

fix: use wp_kses_post() instead of esc_url() for HTML output in distributor_the_original_site_link()#1379
peterwilsoncc merged 1 commit into
10up:developfrom
thisismyurl:fix/esc-url-original-site-link

Conversation

@thisismyurl

@thisismyurl thisismyurl commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Description of the Change

Summary

distributor_the_original_site_link() wraps the return value of distributor_get_original_site_link() in esc_url() before echoing it. distributor_get_original_site_link() returns a fully-formed <a href="...">...</a> anchor tag — not a bare URL — with esc_url() and esc_html() already applied internally.

Wrapping HTML in esc_url() encodes angle brackets, quotes, and ampersands. The rendered output is escaped text rather than a clickable link.

This PR replaces esc_url() with wp_kses_post(), which permits the safe HTML subset the getter already produces.

Before:

echo esc_url( distributor_get_original_site_link( $post_id ) );

After:

echo wp_kses_post( distributor_get_original_site_link( $post_id ) );

Fixes #1378


Developed and tested with AI assistance (Claude + internal review pipeline). Changes were verified against the function's return value before implementation.

How to test the Change

  1. Link two sites, either internal or external
  2. Create a post on the source site
  3. Distribute the post to the destination site
  4. On the destination site, check the post ID on the edit post list page
  5. Run the WP CLI command wp eval --url=[destination site] "distributor_the_original_site_link([post id]);" replacing the placeholders as appropriate
  6. Ensure the link tag is shown in the output

Changelog Entry

Fixed - Correct escaping of distributor_the_original_site_link()

Credits

Props @thisismyurl

Checklist:

Replace esc_url() with wp_kses_post() in distributor_the_original_site_link().
distributor_get_original_site_link() returns a complete <a> tag with esc_url()
and esc_html() already applied internally. Wrapping HTML in esc_url() encodes
angle brackets and breaks the rendered link.

Fixes 10up#1378
Copilot AI review requested due to automatic review settings June 15, 2026 13:53
@thisismyurl thisismyurl requested a review from a team as a code owner June 15, 2026 13:53
@thisismyurl thisismyurl requested review from peterwilsoncc and removed request for a team June 15, 2026 13:53

Copilot AI left a comment

Copy link
Copy Markdown

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 output escaping for the “original site link” template tag so HTML returned by the getter is safely rendered instead of being incorrectly treated as a URL.

Changes:

  • Replace esc_url() with wp_kses_post() when echoing the original site link markup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@peterwilsoncc

Copy link
Copy Markdown
Collaborator

@thisismyurl thank you for the pull request.

I've taken the liberty of reformatting your PR description using the repository template. Are you able to review the test details I've provided to ensure you are happy with them.

We also require contributors to review and agree to the repos code of conduct, are you able to read through them and check the checkbox "I agree to follow this project's Code of Conduct." in the PR's description if you are happy with them.

Once I hear back, I'll approve and merge the pull request.

@thisismyurl

Copy link
Copy Markdown
Contributor Author

Hi @peterwilsoncc — I've read through the Code of Conduct and checked the box.

Your test steps look right to me: the bug shows up any time distributor_the_original_site_link() is called with content that has been distributed, and the WP CLI wp eval command is a clean way to verify the output without needing a front-end template. The reproduction steps you documented match how I verified the fix locally.

Thanks for reformatting the description and for the detailed test case.

@peterwilsoncc peterwilsoncc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM and tests well, thank you!

@peterwilsoncc peterwilsoncc merged commit bcbf377 into 10up:develop Jun 17, 2026
11 of 18 checks passed
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.

distributor_the_original_site_link() wraps HTML output in esc_url(), breaking rendered link

3 participants