Make WordPress Core

Opened 20 months ago

Closed 4 weeks ago

#24849 closed enhancement (maybelater)

filter in get_url_in_content($content) function

Reported by: 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 20 months ago.
Added filter to the default return value
24849.1.diff (419 bytes) - added by JustinSainton 20 months ago.
24849.2.diff (421 bytes) - added by JustinSainton 20 months ago.

Download all attachments as: .zip

Change History (10)

comment:1 @ocean9020 months ago

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

Related: #24309

@garhdez20 months ago

Added filter to the default return value

comment:2 @garhdez20 months ago

Fixed: just replaced the default return statement.

comment:3 @garhdez20 months ago

  • Keywords has-patch added; needs-patch removed

comment:4 @DrewAPicture20 months ago

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

@JustinSainton20 months ago

comment:5 @JustinSainton20 months ago

24849.1.diff includes $content as second arg.

@JustinSainton20 months ago

comment:6 @JustinSainton20 months ago

Refreshed against trunk.

comment:7 @wonderboymusic4 weeks 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.