#34259 closed enhancement (fixed)
Dynamic 'do_feed_{$feed}' action should have a static equivalent
Reported by: | slimndap | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 4.3.1 |
Component: | Feeds | Keywords: | has-patch |
Focuses: | template | Cc: |
Description
There should be a static do_feed
action in do_feed()
.
This way developers can generate content based on the feed name. This is not possible with the current 'do_feed_{$feed}' action.
Example:
I have an events plugin and I want my users to set up different feeds with date and category filters. They can do this on an admin options page.
The hook could look like this:
do_action( 'do_feed', $feed, $wp_query->is_comment_feed );
Attachments (2)
Change History (15)
#2
@
9 years ago
Yes, that is exactly the point. The plugin needs to check the value of $feed
to know which feed to show.
This is not possible with the existing dynamic hook, nor with the callback function that you set with add_feed()
.
$feed
is not available.
So for example:
- My users sets up a feed that always shows events for the coming week. He creates a new feed named 'Events this week'. He then sets 'Next Monday' as the start date and 'Next Monday + 1 week' as the end date.
- My plugin uses
add_feed(sanitize_title($feed['name']), 'my_plugin_add_feed'))
to add the feed. - The
my_plugin_add_feed()
function will render the feed.
The problem is that my_plugin_add_feed()
needs to know which feed it is supposed to show in order to use the proper start and end dates. This information is not available. Currently you need to dig into the query vars to figure it out.
#4
@
9 years ago
- Milestone changed from Awaiting Review to Future Release
Got it. Thanks for the info.
With dynamic hook names like this, the dynamic portion of the hook name is often passed as an argument to help with situations just like this. For example {type}_template
, add_option_{option}
, etc.
So, $feed
should be added as a parameter to the do_feed_{feed}
action. I don't think there's need for a new action here.
#5
@
9 years ago
- Keywords has-patch added; needs-patch needs-docs removed
- Milestone changed from Future Release to 4.4
34259.diff adds the $feed
parameter and includes the patch on #34264.
Thanks for the ticket, slimndap.
Can you explain a little more about how this hook would help your plugin? As far as I can tell, your plugin still needs to check the value of
$feed
, otherwise it risks outputting data when it shouldn't, for example with custom feeds provided by other plugins (a JSON feed being a good example), especially ones that don't output XML.