Make WordPress Core

Opened 11 years ago

Closed 9 years ago

#24849 closed enhancement (maybelater)

filter in get_url_in_content($content) function

Reported by: ounziw's profile ounziw Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.6
Component: Media Keywords: has-patch
Focuses: Cc:


In WP 3.6 RC2, get_url_in_content($content) in wp-includes/formatting is

function get_url_in_content( $content ) {
	if ( empty( $content ) )
		return '';

	if ( preg_match( '/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches ) )
		return esc_url_raw( $matches[2] );

	return false;

I propose to add filter for the return value.

	return apply_filters( 'get_url_in_content', false);

This filter will be useful in cases like this;
"when no image found, I want to return a default image (site logo or something)"

Attachments (3)

24849.diff (411 bytes) - added by garhdez 11 years ago.
Added filter to the default return value
24849.1.diff (419 bytes) - added by JustinSainton 11 years ago.
24849.2.diff (421 bytes) - added by JustinSainton 11 years ago.

Download all attachments as: .zip

Change History (10)

#1 @ocean90
11 years ago

  • Component changed from Formatting to Media
  • Keywords needs-patch added
  • Type changed from feature request to enhancement

Related: #24309

11 years ago

Added filter to the default return value

#2 @garhdez
11 years ago

Fixed: just replaced the default return statement.

#3 @garhdez
11 years ago

  • Keywords has-patch added; needs-patch removed

#4 @DrewAPicture
11 years ago

+1 for the filter. We should also pass $content as a second arg.

#5 @JustinSainton
11 years ago

24849.1.diff includes $content as second arg.

#6 @JustinSainton
11 years ago

Refreshed against trunk.

#7 @wonderboymusic
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

Since get_url_in_content() is only ever used by themes, themes can check the return value and return what they want. Seems like this is from 3.6RC2 and would have been way more useful if Post Formats actually happened.

Note: See TracTickets for help on using tickets.