Opened 2 years ago

Last modified 2 years ago

#16747 new defect (bug)

'feedtype_enclosure' hooks not triggered without custom field

Reported by: tcloninger Owned by:
Priority: normal Milestone: Awaiting Review
Component: Feeds Version: 3.1
Severity: trivial Keywords: has-patch
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 2 years ago.
Introduce 'rss_enclosures' and 'atom_enclosures' filters, pass $enclosure to singular filters, general code cleanup

Download all attachments as: .zip

Change History (2)

kawauso2 years ago

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

  • Keywords has-patch added
Note: See TracTickets for help on using tickets.