Conversation
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
af535dd to
da50f52
Compare
There was a problem hiding this comment.
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.
| @@ -831,7 +831,8 @@ protected function mp_to_wp( $mf2 ) { | |||
| $args['post_content'] = $content['html'] ? $content['html'] : | |||
| \htmlspecialchars( $content['value'] ); | |||
There was a problem hiding this comment.
When the content array contains HTML with an empty 'html' key (falsy value like empty string or null), this code will fall back to htmlspecialchars of the 'value' field without applying make_clickable. This creates an inconsistency where some plain text content gets auto-linked (line 835) but plain text content coming from the 'value' field in an array doesn't get auto-linked. Consider applying make_clickable to the fallback case as well to ensure consistent behavior.
| \htmlspecialchars( $content['value'] ); | |
| \make_clickable( \htmlspecialchars( $content['value'] ) ); |
| ); | ||
| $post = self::check_create( self::create_json_request( $input ) ); | ||
| // URLs in pre blocks should not be auto-linked. | ||
| $this->assertEquals( '<pre>curl https://example.com/api</pre>', $post->post_content ); |
There was a problem hiding this comment.
Consider adding a test case for content with an array structure where the 'html' key is empty or falsy, forcing fallback to the 'value' field. This would verify that URLs in plain text content are consistently auto-linked regardless of whether content is provided as a string or as an array with a 'value' field.
Summary
make_clickable()function to automatically convert URLs in plain text content to clickable linksFixes #303