#25207 closed defect (bug) (wontfix)
Restore the ability to short-circuit core redirects
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1 |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
When the wp_redirect
filter was added in [4407], the point was to make it possible to "cancel" a redirect by filtering the location. However, following [16847], exit;
calls for wp_redirect()
were added all over core.
The problem with adding exit
in the way we did in [16847], was that it thereafter prevented short-circuiting a redirect because exit
is called whether the redirect is canceled or not.
So in that vein, rather than doing:
<?php wp_redirect( admin_url( 'something' ) ); exit;
We should take a cue from [24996] and check for a successful redirect before exiting.
<?php if ( wp_redirect( admin_url( 'something' ) ) ) exit;
Patch attached.
Attachments (1)
Change History (5)
#2
follow-up:
↓ 3
@
12 years ago
Yes, there are probably a lot of instances where the redirect should never be canceled.
If there are redirects that can be canceled for a valid use case, I'd suggest to deal with them on a case by case basis.
#3
in reply to:
↑ 2
@
12 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
Replying to SergeyBiryukov:
Yes, there are probably a lot of instances where the redirect should never be canceled.
If there are redirects that can be canceled for a valid use case, I'd suggest to deal with them on a case by case basis.
Fair enough.
My original use-case was to cancel the redirect to media-new.php from post-new.php?post_type=attachment (which I quickly found was impossible).
I guess we should remove the "allows the wp_redirect filter to cancel a redirect" bit in wp_redirect()
then. No longer possible post-3.1. I'll create a separate ticket.
Surely this introduces unexpected behaviour all over the place if you start cancelling redirects? The scripts will continue processing after the cancelled redirect, when they'd normally be stopped with
exit()
.