WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 8 months ago

#16747 new defect (bug)

'feedtype_enclosure' hooks not triggered without custom field

Reported by: tcloninger Owned by:
Milestone: Awaiting Review Priority: normal
Severity: trivial Version: 1.5
Component: Feeds Keywords: has-patch needs-refresh
Focuses: Cc:

Description

file: wp-includes/feed.php, functions: atom_enclosure() and rss_enclosure()

If a "enclosure" custom field is not provided, the atom_enclosure and rss_enclosure filters are never triggered (because they're inside an if statement).

Wouldn't it make sense to replace this ...

function atom_enclosure() {
	if ( post_password_required() )
		return;

	foreach ( (array) get_post_custom() as $key => $val ) {
		if ($key == 'enclosure') {
			foreach ( (array) $val as $enc ) {
				$enclosure = split("\n", $enc);
				echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
			}
		}
	}
}

... with this ...

function atom_enclosure() {
	if ( post_password_required() )
		return;

	$output = '';
	foreach ( (array) get_post_custom() as $key => $val ) {
		if ($key == 'enclosure') {
			foreach ( (array) $val as $enc ) {
				$enclosure = split("\n", $enc);
				$output = '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . '\n';
			}
		}
	}
	echo apply_filters('atom_enclosure',$output);
}

... so that those functions can be hooked via plugins, even if the custom field doesn't exist?

In my particular case, I wanted to use a different--already existing--custom field name to pull the url from, but I couldn't hook atom_enclosure() because apply_filters() is only triggered if the "enclosure" custom field name exists.

Attachments (1)

16747.diff (3.9 KB) - added by kawauso 3 years ago.
Introduce 'rss_enclosures' and 'atom_enclosures' filters, pass $enclosure to singular filters, general code cleanup

Download all attachments as: .zip

Change History (3)

kawauso3 years ago

Introduce 'rss_enclosures' and 'atom_enclosures' filters, pass $enclosure to singular filters, general code cleanup

comment:1 kawauso3 years ago

  • Keywords has-patch added

comment:2 c3mdigital8 months ago

  • Keywords needs-refresh added
  • Version changed from 3.1 to 1.5
Note: See TracTickets for help on using tickets.