Friday, August 14, 2015

Wordpress- hook to auto login after registration


Wordpress- auto login after registration

function _new_user_auto_log_in($user_id){
  if(!is_user_logged_in()){
    $secure_cookie = is_ssl();
    $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, array());
    global $auth_secure_cookie;
    $auth_secure_cookie = $secure_cookie;
   
    wp_set_auth_cookie($user_id, true, $secure_cookie);
    $user_info = get_userdata($user_id);
    do_action('wp_login', $user_info->user_login, $user_info);

  }
}

add_action('user_register', '_new_user_auto_log_in');

1 comment :