1 comment

  1. I think this may be a WordPress bug. According to the documentation, wp_signon() is the correct function to log a user in.

    In your script, you are using is_user_logged_in() to verify the user was correctly logged in after your call to wp_signon(). is_user_logged_in() uses the global $current_user variable which doesn’t appear to get set when using wp_signon().

    wp_set_current_user() sets the global $current_user, but does not create the auth cookie needed to keep the user logged in.

    Try the following:

    $user = wp_signon();
    wp_set_current_user( $user->ID );
    is_user_logged_in();
    

    This way, you are logging the user in (creating the auth cookie) and setting the current user before attempting to verify using is_user_logged_in().

Comments are closed.