Make WordPress Core

Opened 14 years ago

Last modified 6 years ago

#16747 new defect (bug)

'feedtype_enclosure' hooks not triggered without custom field

Reported by: tcloninger's profile tcloninger Owned by:
Milestone: Priority: normal
Severity: normal Version: 1.5
Component: Feeds Keywords: has-patch needs-refresh needs-unit-tests
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 14 years ago.
Introduce 'rss_enclosures' and 'atom_enclosures' filters, pass $enclosure to singular filters, general code cleanup

Download all attachments as: .zip

Change History (6)

@kawauso
14 years ago

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

#1 @kawauso
14 years ago

  • Keywords has-patch added

#2 @c3mdigital
11 years ago

  • Keywords needs-refresh added
  • Version changed from 3.1 to 1.5

#3 @chriscct7
9 years ago

  • Severity changed from trivial to normal

#4 @stevenkword
9 years ago

  • Keywords needs-unit-tests added

#5 @stevenkword
9 years ago

Relates to #33591

Note: See TracTickets for help on using tickets.