Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#25207 closed defect (bug) (wontfix)

Restore the ability to short-circuit core redirects

Reported by: DrewAPicture Owned by:
Priority: normal Milestone:
Component: General Version: 3.1
Severity: normal Keywords: has-patch
Cc: Focuses:

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 13 years ago.

Download all attachments as: .zip

Change History (5)

@DrewAPicture
13 years ago

#1 @johnbillion
13 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
13 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 on a case by case basis.

Version 0, edited 13 years ago by SergeyBiryukov (next)

#3 in reply to: ↑ 2 @DrewAPicture
13 years ago

  • Milestone Awaiting Review
  • Resolution → wontfix
  • Status new → 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
13 years ago

Filter docs for wp_redirect(): #25215

Note: See TracTickets for help on using tickets.