Skip Navigation

[Resolved] Automatic Login after Email only registration

This support ticket is created 2 years, 7 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

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

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 2 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2344289

Hi there,

I've created an email only registration here: hidden link

Could you please give me the snippet for automatically logging in after signup?

I've tried this: https://toolset.com/forums/topic/auto-log-in-after-sign-up-with-user-form/

Best regards

#2344497
user-form-password-field.png

Hi,

Thank you for contacting us and I'd be happy to assist.

The code from the other ticket is not working because your form is set to generate the user password automatically and there is no password field in the form. You'll see that the code will work if you'll include the password field in the form, by unchecking the option "Auto-generate Password".

To make sure that the user only sees the email field, you can automatically populate a password in the password field, using the following steps:

1. You'll need a custom shortcode that can generate a random password:


add_shortcode('random-password', 'random_password_func');
function random_password_func() {

	$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	$charactersLength = strlen( $characters );
	$randomString = '';
	for ( $i = 0; $i < 12; $i ++ ) {
		$randomString .= $characters[ rand( 0, $charactersLength - 1 ) ];
	}

	return $randomString;

}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

2. Next, add "random-password" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

3. In the password field in the form, include this shortcode [random-password] as a default value and make sure that the option "Do not force users to confirm their password" is selected.
( example screenshot attached )

4. At this point, the password field will be visible in the form, with the random password automatically populated in it. You can include the following custom CSS code in the form's CSS editor, to hide this password field:


label[for*="_user_pass"],
div[data-item_name*="password-user_pass"]{
  display:none;
}

After these changes, the custom code from the other ticket, for automatic login will work.

regards,
Waqar