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) {

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

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

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' ) );

add_action( 'gform_user_registered', 'my_auto_login' );
  • 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 May 24 '11 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 May 24 '11 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 May 25 '11 at 7:47
  • This will no longer work: Cannot modify header information - headers already sent by (output started at /...activate.php:35) – Simon Jan 28 '18 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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