[WordPress] and issue with wp_insert_user() and wp_signon()


<?php

// a short version of wp_insert_user(), no difference at all.
$new_user = wp_create_user( $username, $password, $email );

if( ! is_wp_error( $new_user ) )
{
	$creds = array();
	$creds['user_login'] = $username;
	$creds['user_password'] = $pass;
	$creds['remember'] = true;

	$signon = wp_signon( $creds, false );

	if ( is_wp_error( $signon ) )
	{
		// signed in, carry on
	}
	else
	{
		// echos out the errors, if any, from the login
		echo $signon->get_error_message();
	}
}
else
{
	// echos out the errors, if any, from the user insertion
	echo $new_user->get_error_message();
}

?>

above is a simplified code of my actual ones, not changed anything but stripped out the stuff that not necessary to debug :slight_smile:

the script inserts the user fine, but when it comes to login, it fails echoing out a message like “Username and password dont match” or something. The vars $username and $password and $email are defined earlier in the code.