Tutorial: Gravity Forms Automatically Login User After Registration

Wordpress Tutorial: Gravity Forms Automatically login user after registration

Tutorial: Gravity Forms Automatically Login User After Registration

In this tutorial we are going to show you how to make Gravity Forms Automatically login user after they register for an account. The default behavior in WordPress after registration is to require the user to login with the account information that they just created. This login requirement can be an annoying and extra step for the user and isn’t necessary.

In order for this to work it requires the User Registration Add-On  for Gravity Forms. Assuming this add-on is installed and activated, go ahead and navigate to your current themes functions.php file where we will be adding our code.

Don't Want To Touch Any Code?

Have one of our WordPress Experts add the following code snippets for you. Chill out while we do the hard work.

Get Help
Gravity Forms Automatically login user after registration

In order to get this function to work all you have to do is add the following code snippet to your current theme’s functions.php file. As usually, if you don’t have a child theme installed on your website we highly recommend you do that and paste it in the child themes functions.php. If you don’t have a child theme and would like to create one, here is a tutorial how to create a WordPress child theme.

add_action( 'gform_user_registered', 'wpc_gravity_registration_autologin',  10, 4 );
/**
 * Auto login after registration.
 */
function wpc_gravity_registration_autologin( $user_id, $user_config, $entry, $password ) {
	$user = get_userdata( $user_id );
	$user_login = $user->user_login;
	$user_password = $password;
       $user->set_role(get_option('default_role', 'subscriber'));

    wp_signon( array(
		'user_login' => $user_login,
		'user_password' =>  $user_password,
		'remember' => false

    ) );
}

That’s all there is to it! You just made Gravity Forms Automatically login user after they have filled out your registration form using the User Registration Add-On. 

We have plenty of other great Gravity Forms WordPress tutorials that you can check out here: Gravity Forms WordPress Tutorials. One of our recent tutorials we show you how to Create a Unique ID for Gravity Forms Entries.

Redirect User After Login

As an extra bonus we thought we would include this little hint as well just in case you’re new to Gravity Forms. Now that you have Gravity Forms Automatically login users after registration, what if you want to have them redirect to a specific page afterwards?

To configure the URL to which the user should be redirected to, you will simply need to go into the  Forms Settings and under Confirmations and Confirmations Type simply click Page and choose the desired page.

Gravity Forms Redirect After Login

Need Help with your Website?

Our Experts can handle any customization or developement at a reasonable price.

Get a Quote

Looking for more?

Here are some other articles that we think you will be interested in!