[Resolved] The auto login snippet doesn't work anymoe
This support ticket is created 4 years, 6 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.
Hello. Thank you for contacting the Toolset support.
I checked on your install and yes I confirm that the code you added with the help of Toolset form API hook cred_save_data for autologin the user is not working.
But the strange thing is that the same code I've added with my test site where I tried to create a user with the same subscriber role using Toolset form and it works without any issue on my test site.
You can create a new user with my test site using the following link: hidden link
- As soon as you create new user, it will be redirected to home page and it will autologin as well.
If you want backend access, you can use: hidden link
User: demo
pass: Admin@123
I've used the following code - which is added to "Custom Code" section of Toolset:
=> hidden link
add_action( 'cred_save_data', 'func_tssupp_cred_autologin', 10, 2);
function func_tssupp_cred_autologin( $post_id, $form_data ){
if ( $form_data['id'] == 1708 ) { // Edit as required
if ( !empty( $_POST['user_email'] ) && !empty( $_POST['user_pass'] ) ) {
$user = get_user_by( "email", $_POST['user_email'] );
// get the user credentials from the $_POST object
$user = array(
'user_login' => $user->user_login,
'user_password' => $_POST['user_pass'],
'remember' => true
);
$login = wp_signon( $user, false );
if ( is_wp_error($login) ) {
error_log( $login->get_error_message() );
}
}
}
}
As its working with the minimum setup where only Toolset plugins installed with the default theme, I suggest in order to minimize the cause of the issue:
Could you please try to resolve your issue by deactivating all third-party plugins as well as the default theme to check for any possible conflicts with any of the plugins or themes?
- Do you see any difference or found plugin/theme is causing the issue?
Thanks so much for your help with this. Have already tried disabling all plugins to no avail. I'm going to use your code and give it ago, will update shortly.
Ok fine - As I shared the link to my test site, it works as expected so there must be something going on with third-party plugin/theme or server. You need to check where the issue is.