WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 years ago

#23570 closed enhancement

Add functions to extract a URL from an arbitrary string, HTML, or the current $post — at Initial Version

Reported by: wonderboymusic Owned by:
Milestone: 3.6 Priority: normal
Severity: normal Version:
Component: Post Formats Keywords: has-unit-tests needs-codex
Focuses: Cc:

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.

Change History (1)

@wonderboymusic3 years ago

Note: See TracTickets for help on using tickets.