1

I am trying to hook in to automatically sign-in the user after registration. (using a GravityForms registration form).

None of the hooks seem to be working. I've tried: gform_user_registered, user_register, a filtered 'update_user_metadata'....

Why would this not kill the script after a registration happens?

add_action("user_register", "my_auto_login");
function my_auto_login($user_id) {
    die('x');
}

Login after registration seems like it should not be that complicated.

1
  • Isn't there a support forum at the gravity forms site? It's a commercial plugin...
    – kaiser
    Commented May 23, 2011 at 23:26

1 Answer 1

0

Use the Gravity forms gform_user_registered hook. It fires after the registration and will return the $user_id.

function my_auto_login( $user_id ) {
wp_set_auth_cookie( $user_id, false, is_ssl() );
wp_redirect( admin_url( 'profile.php' ) );
exit;
}

add_action( 'gform_user_registered', 'my_auto_login' );
4
  • Perhaps the order of the action and function matter? It seems that they are reversed in a lot of examples. Either way, I've never seen wp_set_auth_cookie() used like that to make this work. Thanks A TON Chris !
    – J_B
    Commented May 24, 2011 at 0:25
  • @J_B I guess it worked pretty cool. There is also wp_set_current_user($user_id); but I guess it's not needed here.
    – Chris_O
    Commented May 24, 2011 at 0:47
  • yes, it did work. One attempt of mine was using wp_set_current_user along with a set cookie function.. but your suggestion was the only one that seemed to do anything. I would still like to know why putting die() had no effect.. Thanks again.
    – J_B
    Commented May 25, 2011 at 7:47
  • This will no longer work: Cannot modify header information - headers already sent by (output started at /...activate.php:35)
    – Simon
    Commented Jan 28, 2018 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.