Skip to content

Auto-link URLs in plain text content - #314

Merged
pfefferle merged 4 commits into
trunkfrom
fix/303-autolink-urls-in-plain-text
Nov 15, 2026
Merged

pfefferle merged 4 commits into
trunkfrom
fix/303-autolink-urls-in-plain-text

Conversation

@pfefferle

@pfefferle pfefferle commented Jan 11, 2026 •

Copy link
Copy Markdown
Member

Auto-links URLs in Micropub posts, using make_clickable().

The first version linked the URLs on save, so the links ended up in post_content. That breaks editing: q=source returns post_content as plain text, so a client gets the <a> markup back and on the next update it gets escaped into the post. Now the content is stored as the client sent it, and the URLs are linked in the_content, only for Micropub posts.

The links have no rel="nofollow", because they are the author's own links. This uses the make_clickable_rel filter, which exists since WordPress 5.3. On older versions the links still get nofollow.

Trade-off: bare URLs in HTML content get linked too now, not only plain text. make_clickable() skips existing links and <code>/<pre> blocks, so I think this is fine.

Fixes #303

@pfefferle
pfefferle requested a review from Copilot January 11, 2026 22:35
@pfefferle pfefferle self-assigned this Jan 11, 2026
@pfefferle
pfefferle requested a review from dshanske January 11, 2026 22:36
@pfefferle
pfefferle force-pushed the fix/303-autolink-urls-in-plain-text branch from af535dd to da50f52 Compare January 11, 2026 22:38

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

This pull request adds automatic URL linking functionality to plain text content submitted via the Micropub endpoint. When users submit posts with plain text content containing URLs, those URLs will now be automatically converted to clickable HTML links using WordPress's make_clickable() function.

Changes:

  • Modified the content processing logic to apply make_clickable() to plain text content after HTML escaping
  • Added comprehensive test coverage for both plain text auto-linking and HTML content preservation scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
includes/rest/class-endpoint-controller.php Updated mp_to_wp() method to apply make_clickable() to plain text content while preserving HTML content as-is
tests/test_endpoint.php Added 6 new test cases covering plain text URL auto-linking, multiple URLs, and verification that HTML content remains unchanged

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

Use WordPress's make_clickable() function to automatically convert
URLs in plain text content to clickable links. This only applies
to plain text content, not HTML content which is preserved as-is.

Fixes #303
@pfefferle
pfefferle force-pushed the fix/303-autolink-urls-in-plain-text branch from da50f52 to c02afb0 Compare July 8, 2026 10:44
Apply make_clickable() to the content value fallback as well, so plain
text is auto-linked consistently whether it arrives as a string or as
an array with a value property. Guard the html key access while at it:
a value-only content array previously triggered an undefined array key
warning on PHP 8.
@pfefferle
pfefferle requested review from a team and snarfed July 8, 2026 10:53
@pfefferle
pfefferle merged commit 62b79f8 into trunk Nov 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Auto-link URLs in plain text content

3 participants