Question

I create user with wp_create_user,after succesfully creating a user I need to set his status to be logged in?How to set his status to be logged in ?

Was it helpful?

Solution

Use wp_signon(). Ex:

$creds = array();
$creds['user_login'] = 'example';
$creds['user_password'] = 'plaintextpw';
$creds['remember'] = true;

$user = wp_signon( $creds, false );

if ( is_wp_error($user) )
    echo $user->get_error_message();

See Codex for more details about wp_signon().

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top