[wp-trac] [WordPress Trac] #23570: Add functions to extract a URL from an arbitrary string, HTML, or the current $post

WordPress Trac noreply at wordpress.org
Mon Mar 4 01:15:16 UTC 2013


#23570: Add functions to extract a URL from an arbitrary string, HTML, or the
current $post
----------------------------+------------------
 Reporter:  wonderboymusic  |       Owner:
     Type:  enhancement     |      Status:  new
 Priority:  normal          |   Milestone:  3.6
Component:  Post Formats    |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |
----------------------------+------------------

Old description:

> = Scenarios
>
> My post has a format of "link"
> - My post has format meta for URL
> - OR - My post content is a URL
> - OR - My post contains an <a> tag with an href
> - OR - My post content is a URL followed by new line(s) and commentary
>
> An arbitrary string might be only a URL, a URL with some commentary, or a
> blob of HTML that might contain an <a> with an href attribute
>
> Introduce `the_link()` and `get_the_link( $id = 0 )` which will
> arbitrarily extract a URL from a post's content.
>
> Introduce `get_content_link( &$content, $remove = false )` to find a URL
> in an arbitrary string meeting the above criteria and optionally remove
> the found URL if it wasn't embedded in HTML content.
>
> = Tested
>
> Theme doesn't support 'link' post format, but post has 'link' post
> format. `the_content()` is called.
> - Not in the post and has meta: only shows once
> - In the post and has meta: nothing changes, only shows once
> - URL in the post and has meta with a different URL: both links show, the
> meta url is formatted
> - In the post and has no meta: wrapped in an <a> tag with the
> `post_title` as anchor text, if present, only shows once
> - In the post as an href and has meta: nothing changes, only shows once
> - In the post as an href and has no meta: nothing changes, only shows
> once
>
> Theme doesn't support 'link' post format, but post has 'link' post
> format, and `the_link()` and `the_content()` are called in succession.
> - Not in the post and has meta: URL is output, content is output with a
> formatted link. Themer should use if / else.
> - In the post and has meta: URL is output, content is output unchanged.
> Themer should use if / else.
> - URL in the post and has meta with a different URL: meta URL is output,
> post URL remains, meta URL is formatted and added to post. Themer should
> use if / else.
> - In the post and has no meta: URL is output, content is output with a
> formatted link. Themer should use if / else.
> - In the post as an href and has meta: URL is output, content is
> unchanged. Themer should use if / else.
> - In the post as an href and has no meta: URL is output, content is
> unchanged. Themer should use if / else.
>
> Theme does support 'link' post format. `the_content()` is called.
> - Not in the post and has meta: Content is unchanged.
> - In the post and has meta: Content is unchanged.
> - URL in the post and has meta with a different URL: Content is
> unchanged.
> - In the post and has no meta: Content is unchanged.
> - In the post as an href and has meta: Content is unchanged.
> - In the post as an href and has no meta: Content is unchanged.
>
> Theme does support 'link' post format. `the_link()` and `the_content()`
> are called in succession.
> - Not in the post and has meta: URL is output, Content is unchanged.
> - In the post and has meta: URL is output, Content is unchanged.
> - URL in the post and has meta with a different URL: Meta URL is output,
> Content is unchanged.
> - In the post and has no meta: URL is output, Content is unchanged.
> - In the post as an href and has meta: URL is output, Content is
> unchanged.
> - In the post as an href and has no meta: URL is output, Content is
> unchanged.

New description:

 = Scenarios

 My post has a format of "link"
 - My post has format meta for URL
 - OR - My post content is a URL
 - OR - My post contains an <a> tag with an href
 - OR - My post content is a URL followed by new line(s) and commentary

 An arbitrary string might be only a URL, a URL with some commentary, or a
 blob of HTML that might contain an <a> with an href attribute

 Introduce `the_link()` and `get_the_link( $id = 0 )` which will
 arbitrarily extract a URL from a post's content.

 Introduce `get_content_link( &$content, $remove = false )` to find a URL
 in an arbitrary string meeting the above criteria and optionally remove
 the found URL if it wasn't embedded in HTML content.

--

Comment (by wonderboymusic):

 attachment:23570.2.diff​ is patch refreshed against trunk and tested
 compatibility for these 6 scenarios:

 - Post with the link as the content
 - Post with the link as the content, followed by commentary
 - Post with the link as the content AND has link meta value
 - Post with the link as the content AND has link meta value, followed by
 commentary
 - Post with the link as metadata, content is empty
 - Post with the link as metadata, followed by commentary

 If the theme supports structured-post-formats, nothing happens to the
 content.
 The themer can use: `the_link()`, `get_the_link()`, and `get_content_link(
 $content )` - all return a URL. `get_content_link( $content )` only works
 if the link is in the post's body.

 If the post has a post format of link, the compat runs whether the theme
 supports it or not.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/23570#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list