Make WordPress Core

Opened 22 months ago

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

Download all attachments as: .zip

Change History (10)

comment:1 @ocean9022 months ago

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

Related: #24309

@garhdez22 months ago

Added filter to the default return value

comment:2 @garhdez22 months ago

Fixed: just replaced the default return statement.

comment:3 @garhdez22 months ago

  • Keywords has-patch added; needs-patch removed

comment:4 @DrewAPicture22 months ago

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

@JustinSainton22 months ago

comment:5 @JustinSainton22 months ago

24849.1.diff includes $content as second arg.

@JustinSainton22 months ago

comment:6 @JustinSainton22 months ago

Refreshed against trunk.

comment:7 @wonderboymusic3 months 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.