Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am a newbie to Wordpress. I am currently working on registration and login. I have a page restrict url let http://xyz.com/abc. Login/registration is required for this url.

I need that when a user register or login then it should be redirected on this previous url.

In login I have added the following hook :

add_filter('login_redirect', 'redirect_previous_page', 10);

function redirect_previous_page(){

    global $user;
    $request = $_SERVER["HTTP_REFERER"];

    if ( in_array( $user->roles[0], array( 'administrator') ) ) {

        return admin_url();
        return $redirect_to;

    } elseif ( in_array( $user->roles[0], array( 'subscriber') ) ) {

        return $request;
        return $redirect_to;

    } 

}

It is working for me, but I am not getting how can I redirect on this url after successful registration. I have registration link on the login page

share|improve this question
    
You can't have two return one after the other. Your functions ends on the first return it meets. You also need arguments in your function. Read the codex for an example. –  RRikesh Aug 6 '13 at 11:48
    
@RRikesh then is it possible that I can send the value of that url along with the register url, and if then how, I am using theme-my-plugin ... –  lord_linus Aug 6 '13 at 11:53

1 Answer 1

You used in_array wrong. There might be some redundancy in your function too(depending on what you're doing). You could use something like this to redirect your users:

add_filter('login_redirect', 'redirect_previous_page', 10);

function redirect_previous_page(){
    global $user;
    if ( in_array( 'administrator', $user->roles ) ) {
        return admin_url();
    } else {
        return 'http://localhost/'; //add your link here
    } 
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.