Viewing 7 replies - 1 through 7 (of 7 total)
  • if ($user) { // user already exists - try to log them in															
    
    				$user = wp_authenticate($username, $password);
    				wp_set_current_user($user->ID); //Here is where we update the global user variables
    				wp_set_auth_cookie($user->ID);
    				do_action('wp_login',$userdata->ID);
    
    				if (isset($_REQUEST['redirect_to'])){
    					wp_redirect($_REQUEST['redirect_to']);
    				} else {
    					wp_redirect(get_bloginfo('url'));
    				}
    
    				exit;
    
    			} else {
    Thread Starter Tatichka

    (@tatichka)

    why would I use wp_authenticate since there is a hook to this function in the plugin?

    I am new to wordpress plug-ins and so I am not sure *why* this works but the code above works for me. Since you were having the same problem, I thought I would share what I found.

    Maybe you can take that line out and let us know if it works for you? Or post another solution if you have one?

    Thread Starter Tatichka

    (@tatichka)

    it was actually a genuine question, no offense ??
    what about the case where the user doesnt exist in the wordpress DB?

    I am trying to play with the wp_redirect, because now I have the WP cookies but they are read after the page is loaded, so I get redirected to wp-login.php?redirect-to=blablabla.php and when I delete wp-login… and replace by blablabla.php, I am logged in…

    mystery..

    Thread Starter Tatichka

    (@tatichka)

    I tried your piece of code but get an infinite loop of redirection between wp-login and wp-admin.

    Thread Starter Tatichka

    (@tatichka)

    nevermind mate….it worked!!!!! I had to change a bit the code you gave me to that

    ` wp_set_current_user($user->ID); //Here is where we update the global user variables
    wp_set_auth_cookie($user->ID);
    do_action(‘wp_login’,$user->ID);

    if (isset($_REQUEST[‘redirect_to’])){
    wp_redirect($_REQUEST[‘redirect_to’]);
    }`

    thanks a lot!

    I am glad that you were able to get it working!

    I posted the full copy of my class on this thread.

    I mention it so you can see where users that don’t exist in the wordpress database get added and then logged in. Please note you will need to pass uid (in the plugin) instead of wp_userid as the documentation indicates.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Plugin doesn't log me in to WP’ is closed to new replies.