I have a form that creates a new user by using:
wp_create_user()
This works, but after this I want to auto log in the user.
I tried using:
$creds = array();
$creds['user_login'] = 'username';
$creds['user_password'] = 'password';
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ) {
$msg = $user->get_error_message();
die($msg);
} else {
$output_form = true;
}
But this creates a “headers already sent” error message because it’s not at the top of the page.
Is there a way to auto log in the user after I have created the user?