On past few days, I was working on User Registration Add-on for Gravity Form and my task is to customize or add new functionality in User Registration Gravity Form Add-on, the functionality to add is to auto login user after registration, and I want to share you how I did it or add it.
First Step
In user registration add-on plugin directory open
userregistration.php
and locate line #1606 or function gf_create_user()
.gf_create_user()
is use to create new user and we’re going to insert the code to auto login user after registration.Second Step
Our next step is to create a function, this functions is use to login user, copy and paste the snippet below just after
gf_create_user()
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
// use to auto signon user by rys[.]dead2009[@]gmail[.]com
public static function ryans_signon($username, $password)
{
$user = array();
$user['user_login'] = $username;
$user['user_password'] = $password;
$user_verify = wp_signon( $user, false );
if ( is_wp_error($user_verify) ) {
return;
} else {
wp_set_current_user($user_verify->ID);
}
}
|
So now, the login function is ready.
Third Step
let’s add
ryans_signon()
function at the very last line of the gf_create_user()
function.
see below for example where to add the function.
1
2
3
4
5
|
do_action(‘gform_user_registered’, $user_id, $user_config, $entry, $password);
// we’re calling our new created function for auto sign on.
self::ryans_signon($user_name, $password);
}
|
That’s it, now after the user registered it will automatically login, no re-login or double login needed.
0 comments:
Post a Comment