Support » Plugin: Nginx Helper » Call to undefined function wp_sanitize_redirect

  • Resolved heshiming

    (@heshiming)


    With nginx-helper plugin installed, I get the error Call to undefined function wp_sanitize_redirect when visiting /wp-admin/ without logging in first. And the page dies without redirection. I guess this problem might appear elsewhere too.

    After some digging, I discovered that wp_sanitize_redirect, along with functions such as is_user_logged_in are so called ‘pluggable’ functions. That means plugin definition takes precedence, and when no plugins defined such functions, it falls back to wordpress’ pluggable definition.

    The problem with nginx-helper is that near line 340 of nginx-helper.php, you’ve overridden wp_redirect and used wp_sanitize_redirect. It gets called by wordpress to redirect the user to the login page when visiting /wp-admin/ (this could be my particular situation, I’m using a customized login page, and I’ve got other pages that will redirect if the user isn’t logged on). When this redirection happens, pluggable.php isn’t loaded yet.

    To avoid this warning, may I propose the this patch to nginx-helper.php:

    @@ -340,7 +340,8 @@
    $status = 302;
    }

    – $location = wp_sanitize_redirect( $location );
    + if (function_exists(‘wp_sanitize_redirect’))
    + $location = wp_sanitize_redirect( $location );
    header( ‘Location: ‘ . $location, true, $status );
    }

    It’s simple. It doesn’t sanitize the redirection when the function is not defined. Ideally, you could define your own copy of wp_sanitize_redirect, but I think it’ll be too much of a hassle.

    I’m wondering if you could include this change in your future releases?

    http://wordpress.org/extend/plugins/nginx-helper/

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Call to undefined function wp_sanitize_redirect’ is closed to new replies.