• Hello I have a PHP page in a plugin that creates a wordpress user using

    $status = wp_create_user($username, $random_password, $email);'
    
    //I tried to use this code after the wp_create_user function
    
    '$creds = array();
    	$creds["user_login"] = $username;
    	$creds["user_password"] = $random_password;
    	$creds["remember"] = true;
    	$user = wp_signon( $creds, false );
    	$userID = $user->ID;
    
    wp_set_current_user( $userID, $username );
    wp_set_auth_cookie( $userID, true, false );
    do_action( "wp_login", $username );
    
    echo  is_user_logged_in();

    it shows is_user_logged_in as “1”

    as soon as I click on another page the user is not logged in.

    how can I log a user in right after creating them? and stay logged in?

    This is making me tear my hair out

    thanks for any advise.

    Paul

  • The topic ‘How to wp_create_user and auto login right after creation’ is closed to new replies.