This support ticket is created Il y a 7 années et 3 mois. 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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
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 );
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]
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.
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".
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.
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.
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??