Make WordPress Core

Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#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)

template-loader.php.diff (509 bytes ) - added by mikeschinkel 17 years ago.
DIFF/Patch file for template-loader.php

Download all attachments as: .zip

Change History (11)

@mikeschinkel
17 years ago

DIFF/Patch file for template-loader.php

#1 @DD32
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 @westi
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 @scribu
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: @DD32
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 @scribu
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 @GamerZ
17 years ago

I agree with westi, if this patch is committed, lots of plugin which rely on that as an action will break.

#7 @ryan
17 years ago

  • Resolutionwontfix
  • Status newclosed

#8 @mikeschinkel
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.

#9 @mikeschinkel
17 years ago

BTW, one problem with using template_redirect for a custom URL is that by then 404 is already set as are noncache headers. Ticket #9460 is the follow up for this ticket.

#10 @Denis-de-Bernardy
17 years ago

  • Milestone Unassigned
Note: See TracTickets for help on using tickets.