0

I'm using this function in functions.php to auto log in users after the sign up in the front-end

function auto_login_new_user( $user_id ) {
   wp_set_current_user($user_id);
   wp_set_auth_cookie($user_id); 
   wp_redirect('http://mydomain.com/confirmation/');
   exit;
}
add_action( 'user_register', 'auto_login_new_user' );

This works great for auto login in users but for some reason this also causes the automatic confirmation email not being sent to users anymore. I have no idea why though, any suggestions would be really helpful.

Thanks

2 Answers 2

1

You're short-circuiting the registration process when you redirect and exit script execution, the user_register action isn't the last step of the process. You can try to call wp_new_user_notification manually, but I'm not sure what other side-effects that may have.

2
  • Thanks a lot for the tip. I added this line before the exit command. This sends an email to admin but it doesn't send an email to the registered user, is there a way to get the email to the user as well? Commented Jun 14, 2014 at 8:58
  • Okay I get it to work by removing the exit command from the function, but I'm getting the admin email twice for some reason for each user Commented Jun 14, 2014 at 11:16
0

may be the wp_redirect causing the problem. you must call wp_new_user_notification before the redirect.

May be a problem here - see the note on wordpress codex and the example in the codex

<?php wp_new_user_notification( $user_id, $plaintext_pass ) ?>

Note: If password is not passed to function, the newly registered user will not receive their welcome email.

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.