Skip Navigation

[Resolved] Redirect issue after successful login

This thread is resolved. Here is a description of the problem and solution.

Problem:
Trying to redirect to sign-up page to display custom message after login.

Solution:
Solution here: https://toolset.com/forums/topic/redirect-issue-after-successful-login/#post-563668

OR If you just want to redirect user after login without any special action, you can use this Views builtin shortcode in your page or where needed:

[wpv-login-form redirect_url="https://www.google.com"] 

Screenshot here: http://bit.ly/2vsvOWL

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 10 replies, has 3 voices.

Last updated by henryH 7 years, 3 months ago.

Assisted by: Noman.

Author
Posts
#563489

I am trying to redirect to sign-up page to display custom message after login, if that user is having 'inactive' state(custom field) but it is redirecting me to home page..
I expected to see custom message on sign-up page..
Form is created using [wpv-login-form]

function show_message_inactive_user( $redirect_to, $request, $user ) {
    
	if( !isset( $user->user_login ) ){ // we only want this to run when credentials have been supplied
        return $redirect_to;
    }
    $all_meta_for_user = get_user_meta($user->ID);
    if($all_meta_for_user['wpcf-user-state'][0] == 4)
    {
        return home_url('/sign-in/?username='.$user->data->user_email.'&fail_reason=inactive_account');
    } else {
        return $redirect_to;
    }
}

add_filter( 'login_redirect', 'show_message_inactive_user', 10, 3 );
#563505

Please follow this correction for above post.
I am trying to redirect to sign-in page to display custom message after login, if that user is having 'inactive' state(custom field) but it is redirecting me to home page..
I expected to see custom message on sign-in page..
Form is created using [wpv-login-form]

#563544

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

login form redirect.png

Hi Marc,

Thank you for contacting Toolset Support. Redirect URL field is already available if you insert the shortcode with Fields and Views button, see attached screenshot.

Its shortcode is like:

 [wpv-login-form redirect_url="<em><u>hidden link</u></em>"] 

Perhaps you may need to use redirect_url attribute in your condition or code.
Thank you

#563549

Hi Noman,

[wpv-login-form redirect_url="<em><u>hidden link</u></em>"]

I have already provided that url in my short code but, I am trying to achieve is once user's email and password is correct I am checking for custom field status as I have mentioned earlier...if that status is 4 I would like to redirect him on sign-in page itself with message "you should contact the supportdesk".

Please check my code above for the same.

Thanks

#563563

I debug the code again and came to know that redirection is not working for my site urls..If I give any other site url like hidden link..it works fine

#563581

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Okay just to be more clear please confirm if this correct:
You want to Redirect Inactive Users >> to Sign-up page (and show a message on the page) >> after they are logged-in?

I think code needs some changes, please provide temporary website WP-admin and FTP info for your site to debug further and to help in resolving this. Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please add the Login page link and redirect page link as well where you want to redirect the Inactive User.

Thank you

#563609

You can login using below details for inactive user

Email : nirali.prajapati@agileinfoways.com
Password : 6YshCZ6I

Thanks

#563668

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

I have made minor updates to the code:

function show_message_inactive_user( $redirect_to, $request, $user ) {
    
	if( !isset( $user->user_login ) ){ // we only want this to run when credentials have been supplied
        return $redirect_to;
    }
    $all_meta_for_user = get_user_meta($user->ID);
    if($all_meta_for_user['wpcf-user-state'][0] == 4)
    { 
        $url = home_url('/sign-in/?username='.$user->data->user_email.'&fail_reason=inactive_account');
		return $url;
    } else {
        return $redirect_to;
    }
}

add_filter( 'login_redirect', 'show_message_inactive_user', 10, 3 );

The main problem is this hook or code below, this is duplicated action and you can’t add double redirects like this. I have commented following action, this is what causing the issue.

function logout_inactive_user()
{
    if (is_user_logged_in()) 
    {
        $all_meta_for_user = get_user_meta(get_current_user_id());
        if($all_meta_for_user['wpcf-user-state'][0] == 4)
        {
            wp_logout();
            wp_redirect(home_url());
            exit;
        }
    }
}
//add_action('init', 'logout_inactive_user');

I have created some new test user “delegate3” with same user and pass, tested with your given user. Redirect is working fine now: hidden link

I don’t think that you need add_action('init', 'logout_inactive_user'); hook because inactive_user is already blocked by the other code.

Thanks

#563787

Hi Noman,

As you have mentioned above for the add_action('init', 'logout_inactive_user'); hook is not required..But I need that because I have functionality that If I am logged in as active user and on the other side admin is changed my status from "active" to "inactive"...so now I am "inactive" user and I am trying to open a page which is accessible if I am active user. so I am not an "active" user so I will be automatically logged out and can not see that page.

For above mentioned functionality I have added that add_action('init', 'logout_inactive_user') hook.I need that hook to achieve above goal..

We need both hook for my below cases

Inactive user:
• A user with an inactive account will automatically be logged out.
Hook : add_action('init', 'logout_inactive_user');

• If a user logs in with an inactive account the user gets a notification that is stating that
they should contact the supportdesk .
Hook : add_filter( 'login_redirect', 'show_message_inactive_user', 10, 3 );

How we are going make both the cases work perfectly fine??

Thanks

#563837

Thanks,I got solution for both cases

#1070271

Hi marcB-6,

How you implement that? Can you please share your code. Same functionality i want to implement