1

My WordPress site is setup so that all visitors have to login to view any page or post.

I have a redirection setup so that after a user with the role of 'reader' log in they are redirected to a page called http:/www.example.com/readersetup

function my_login_redirect( $url, $request, $user ){
    if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
        if( $user->has_cap( 'reader' ) ) {
            $url = home_url('/readersetup');
        }
    }
    return $url;
}
add_filter('login_redirect', 'my_login_redirect', 10, 3 );

This is working well, now what I would like to do is pass through a URL to the /readersetup page as a variable so that if somebody follows this...

  • User goes to www.example.com/mypost
  • Site redirects them to www.example.com/wp-login.php
  • User Logs In and is redirect to www.example.com/readersetup
  • www.example.com/mypost is saved as a variable and is available on www.example.com/readersetup

Whats the best way of achieving it?

  • 1
    You could pass the URL as a 'GET' variable, but you'd have to be careful to escape the URL correctly. My preference (not necessarily the best idea) is to pass the MIME-encode of the URL as a GET variable, so you don't have to worry about proper escaping. – barrycarter Jan 22 '16 at 1:34
  • Are you still experiencing this issue? – Ethan Jinks O'Sullivan Aug 23 '16 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.