WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 6 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:

Description

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

Download all attachments as: .zip

Change History (10)

comment:1 @ocean902 years ago

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

Related: #24309

@garhdez2 years ago

Added filter to the default return value

comment:2 @garhdez2 years ago

Fixed: just replaced the default return statement.

comment:3 @garhdez2 years ago

  • Keywords has-patch added; needs-patch removed

comment:4 @DrewAPicture2 years ago

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

@JustinSainton2 years ago

comment:5 @JustinSainton2 years ago

24849.1.diff includes $content as second arg.

@JustinSainton2 years ago

comment:6 @JustinSainton2 years ago

Refreshed against trunk.

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