#23570 closed enhancement (fixed)
Add functions to extract a URL from an arbitrary string, HTML, or the current $post
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 3.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Post Formats | Keywords: | has-unit-tests needs-codex |
Focuses: | Cc: |
Description (last modified by )
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.
Attachments (8)
Change History (33)
#4
@
12 years ago
- Description modified (diff)
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.
#5
@
12 years ago
I tested the 23570.2 patch as part of #23619 and there was a very small issue with the get_content_link
when the content is HTML. The regular expression for detecting the link was incorrect (it's (.+?)
instead of (.?)
).
So here's the .2 patch with this very small change.
#7
@
12 years ago
- Keywords needs-unit-tests added
get_content_link() really super needs unit tests for all of the scenarios covered. This is a textbook case where tests can drive development.
#10
follow-up:
↓ 11
@
12 years ago
I think we should use esc_url()
instead of esc_url_raw()
in get_content_link()
, because second function is not safe to use for displaying the URL.
#11
in reply to:
↑ 10
@
12 years ago
Replying to Mamaduka:
I think we should use
esc_url()
instead ofesc_url_raw()
inget_content_link()
, because second function is not safe to use for displaying the URL.
Function could be used for purposes other than display. the_link() could probably stand to do esc_url(), though.
#14
@
12 years ago
What about filters? What if I have an existing postmeta key that stores URLs. Would be nice to be able to filter get_the_url()
and have that old data considered.
#15
@
12 years ago
- Keywords needs-patch has-unit-tests added; has-patch needs-unit-tests removed
Yeah, let's definitely get some filters in.
#16
@
12 years ago
23570.5.diff adds a filter to get_the_url()
, corrects a little doc, and checks for the quote format as well as link. Do we need anything in get_content_url()
? I guess I could see somebody wanting that.
#18
@
12 years ago
Leaving open - have a suspicion some things might shift when we actually start practical integration into Twenty Thirteen.
#24
@
12 years ago
In 1261/tests:
#25
@
12 years ago
In 1330/tests:
Sort of Template, sort of Post Formats. Putting it in Post Formats for easy tracking of the feature dev.