WordPress AutoLogin


/ Published in: PHP
Save to your folder(s)

Code snippet that allows the user to be automatically logged in on account creation, this works with s2Member since they allow the user to create their own password.


Copy this code and paste it in your HTML
  1. function auto_login($userID) {
  2. if (!is_user_logged_in()) {
  3.  
  4. $user = get_userdata($userID);
  5. $user_id = $user->ID;
  6. $user_login = $user->user_login;
  7.  
  8. //login
  9. wp_set_current_user($user_id, $user_login);
  10. wp_set_auth_cookie($user_id);
  11. do_action('wp_login', $user_login);
  12. }
  13. }
  14. add_action('user_register', 'auto_login');

Report this snippet


Comments


You need to login to view comments.