Before doing anything, make sure that the user account doesn’t already exist. This is really easy to do with the username_exists function.
if( null == username_exists( $username ) ) {
echo "user not exist";
}
use the above code and see what happen
then do as below
$user_id = wp_create_user ( $email_address, $password, $email_address );
all code like
if( null == username_exists( $username) ) {
// Generate the password and create the user
$password = wp_generate_password( 12, false );
$user_id = wp_create_user( $username, $password, $email_address );
// Set the nickname
wp_update_user(
array(
'ID' => $user_id,
'nickname' => $email_address
)
);
// Set the role
$user = new WP_User( $user_id );
$user->set_role( 'contributor' );
// Email the user
wp_mail( $email_address, 'Welcome!', 'Your Password: ' . $password );
} // end if
if even not work than do like below
codes func :-
//function wp_create_user($username, $password, $email="") {
//$user_login = esc_sql( $username );
//$user_email = esc_sql( $email );
//$user_pass = $password;
//$userdata = compact('user_login', 'user_email', 'user_pass');
//return wp_insert_user($userdata);
//}
user it will too. use like this codex func.
$user_id = username_exists( $user_name );
if ( !$user_id and email_exists($user_email) == false ) {
$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
$user_id = wp_create_user( $user_name, $random_password, $user_email );
} else {
$random_password = __('User already exists. Password inherited.');
}
i hope its work well