Opened 14 years ago
Last modified 6 years ago
#16747 new defect (bug)
'feedtype_enclosure' hooks not triggered without custom field
Reported by: | 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)
Change History (6)
Note: See
TracTickets for help on using
tickets.
Introduce 'rss_enclosures' and 'atom_enclosures' filters, pass
$enclosure
to singular filters, general code cleanup