#9455 closed enhancement (wontfix)
Change template_redirect from action to filter in template-loader.php
| Reported by: | mikeschinkel | Owned by: | mikeschinkel |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Permalinks | Version: | 2.8 |
| Severity: | normal | Keywords: | template_redirect template-loader.php urls permalinks url-routing |
| Cc: | Focuses: |
Description
As per the discussion here [1] where scribu gave a +1, this patch will convert "template_redirect" from an action to a filter in template-loader.php. This allows the plugin developer to return false instead of execute exit (but exit works the same way) in the case that he or she wants to indicate to terminate if-else processing of the WordPress URL routing. Also this will follow a more expected pattern for developers making it easier for new developers to discover and use "template_redirect" for the purpose of overriding URLs.
[1] http://www.nabble.com/Addition-to-template-loader.php-td22866661.html
Attachments (1)
Change History (11)
#1
@
17 years ago
Note that any plugin which uses the template_redirect as a action currently, and doesnt die (its common) will cause this filter not to work as expected (Unless the filtering function is hooked after/later every other other action is hooked)
(Thats because when the filter has actions hooked to it, it returns null.)
#2
@
17 years ago
I don't see why we should break backwards compatibility like this.
If a plugin wants to use the action as the place to do it's output as an alternative to a themes template file then it should just exit after doing so.
#3
@
17 years ago
Yes, "template_redirect" is frequently used for different purposes, like script loading using wp_enqueue_script() and others. Why is it that way?
#4
follow-up:
↓ 5
@
17 years ago
Why is it that way?
Its one of the easiest filters to use after WP has loaded and parsed everything, and is ready to start outputting. when this action fires, Plugins have everything at their disposal, and the theme hasnt displayed anything yet, Very useful time to inspect and redirect if need be, or to enqueue stuff that'll be needed (since you can see the posts now)
#5
in reply to: ↑ 4
@
17 years ago
Replying to DD32:
Its one of the easiest filters to use after WP has loaded and parsed everything, and is ready to start outputting. when this action fires, Plugins have everything at their disposal, and the theme hasnt displayed anything yet, Very useful time to inspect and redirect if need be, or to enqueue stuff that'll be needed (since you can see the posts now)
Thanks for the explanation.
#6
@
17 years ago
I agree with westi, if this patch is committed, lots of plugin which rely on that as an action will break.
#8
@
17 years ago
I've since done deeper testing and recognized the problems you identified, but that takes me back to the original issue. I will submit a new ticket and a new patch for it.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
DIFF/Patch file for template-loader.php