[wp-trac] [WordPress Trac] #41036: wp_redirect and wp_safe_redirect calls fails in WP 4.8
WordPress Trac
noreply at wordpress.org
Wed Jun 14 08:36:01 UTC 2017
#41036: wp_redirect and wp_safe_redirect calls fails in WP 4.8
-------------------------------+------------------------------
Reporter: dkurth | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version: 4.8
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+------------------------------
Comment (by dkurth):
Replying to [comment:1 dd32]:
> Hi @dkurth and welcome to Trac,
>
> Can you please provide some extra details as to the problem you're
running into?
>
> Based on your comment in #41006 it sounds like calling
`wp_redirect()`/`wp_safe_redirect()` isn't performing a redirect at all -
would that be correct?
>
> In testing, I can't find any issues - which makes me think this may not
be `wp_redirect()` failing (although it could be) but possibly related to
the code you're using to trigger it.
>
> Can you provide a small bit of code to reproduce what you're seeing?
> Can you verify it against a clean no-plugins WordPress install?
> Is it triggered specifically by a plugin? (If so, what one?)
What was happening previously was the wp_redirect($RedirectURL) would
return a 1, indicating it was successful, however no forwarding would
occur. This was a quick plugin I wrote specifically for a single client,
who had different requirements for displaying content. It only point was
to test if a user was successfully logged in and had a subscription. If
not, it redirects the user to a notice. In this situation, the code had
been working great until this last upgrade.
I will admit that it is a bit of a mystery. I had disabled almost all
plugins, reverted the Theme backwards and the problem still existed. This
left only the wordpress upgrade to 4.8
I did finally find a solution, but it involved not using the wp_redirect
call, replacing it with a header call instead. This skips the filters and
then the plugin started to work again. You can see the code snippet below,
with comments to the right on what was there originally and what I just
changed.
$user_id = get_current_user_id();
if($user_id == 0)
{
// No one logged in
$RedirectURL = 'https://www.spdressage.com/notloggedin/';
//$status = wp_redirect($RedirectURL); <----- commented
out this
$location = wp_sanitize_redirect($RedirectURL); <----- added
this instead
header("Location: $location", true, 302); <----- added
this instead
$status=0; <----- added
this instead
mmd_ca_DebugLine('User Not Logged in', $RedirectURL, $status);
return;
}
Could there have been something with the filters in the upgrade?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41036#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list