Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#25207 closed defect (bug) (wontfix)

Restore the ability to short-circuit core redirects

Reported by: drewapicture's profile DrewAPicture 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)

25207.diff (63.1 KB) - added by DrewAPicture 11 years ago.

Download all attachments as: .zip

Change History (5)

@DrewAPicture
11 years ago

#1 @johnbillion
11 years ago

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().

#2 follow-up: @SergeyBiryukov
11 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.

Last edited 11 years ago by SergeyBiryukov (previous) (diff)

#3 in reply to: ↑ 2 @DrewAPicture
11 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.

#4 @DrewAPicture
11 years ago

Filter docs for wp_redirect(): #25215

Note: See TracTickets for help on using tickets.