Skip to content

Commit 1c1670c

Browse files
committed
Added Autologin User
Gravity Forms automatically login user after registration
0 parents  commit 1c1670c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

gforms-autologin.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/* Gravity Forms Login User After Registration */
4+
5+
remove_action("gform_post_submission", array("GFUser", "gf_create_user"));
6+
add_action("gform_after_submission", array("GFUser", "gf_create_user"), 10, 2);
7+
8+
add_action("gform_user_registered", "gforms_autologin", 10, 4);
9+
function gforms_autologin($user_id, $config, $entry, $password) {
10+
11+
$form = RGFormsModel::get_form_meta($entry['form_id']);
12+
13+
$user_login = apply_filters("gform_username_{$form['id']}",
14+
apply_filters('gform_username', GFUser::get_meta_value('username', $config, $form, $entry), $config, $form, $entry),
15+
$config, $form, $entry);
16+
17+
$redirect_url = rgars($form, 'confirmation/url') ? rgars($form, 'confirmation/url') : get_bloginfo('home');
18+
19+
//pass the above to the wp_signon function
20+
$result = wp_signon(array('user_login' => $user_login, 'user_password' => $password, 'remember' => false));
21+
22+
if(!is_wp_error($result))
23+
wp_redirect($redirect_url);
24+
25+
}

0 commit comments

Comments
 (0)