Site icon Hip-Hop Website Design and Development

wp_insert_user at all times tries the identical consumer title

The web page title with my type is “Register”, which suggests the slug is “register”. That’s the first piece of information that’s tied to my principle about my error.

Once I run wp_insert_user I get successful the primary time, however the consumer title is “register”. So subsequent submissions attempt to create the consumer “register”, so it errors out with a “Person with that consumer title exists” error.

I’ve checked my knowledge time and again to confirm that I am not submitting a type with the consumer title “register”, but it surely at all times tries with that consumer title.

This is my code:

$first_name = $knowledge['first_name'];
$last_name = $knowledge['last_name'];
$user_name = $knowledge['user_name'];
$type_of_user = $knowledge['type_of_user'];
$nickname = $first_name . " " . $last_name;
$electronic mail = $knowledge['email_address'];
$password = wp_generate_password();

$address1 = $knowledge['address_1'];
$address2 = $knowledge['address_2'];
$metropolis = $knowledge['city'];
$state = $knowledge['state'];
$zipcode = $knowledge['zipcode'];

$user_photo = $knowledge['user_photo'];

$args = array (
        'user_login'        =>  $user_name,
    'user_email'    =>  $electronic mail,
    'user_pass'     =>  $password,
    'user_url'      =>  $web site,
    'first_name'    =>  $first_name,
    'last_name'     =>  $last_name,
    'nickname'      =>  $nickname,
        'function'                  =>  $type_of_user
) ;

$user_id = wp_insert_user($args);

May one thing within the put up loop be moving into my type and the way do I repair it. I’ve tried troubleshooting this for awhile now, however I am undecided what else to strive.

EDIT 1: Subsequent check case.

$username = "spock";
$password = wp_generate_password();
$email_address = "spock@blah.com";
if( null == username_exists( $username) ) {

// Generate the password and create the consumer
$password = wp_generate_password( 12, false );
$user_id = wp_create_user( $username, $password, $email_address );

if ( $user_id && !is_wp_error( $user_id ) ) {

  // Set the nickname
  wp_update_user(
    array(
      'ID'          =>    $user_id,
      'nickname'    =>    $email_address
    )
  );

  // Set the function
  $consumer = new WP_User( $user_id );
  $user->set_role( 'contributor' );

  // Electronic mail the consumer
  wp_mail( $email_address, 'Welcome!', 'Your Password: ' . $password );
} else {
  wp_mail("my@electronic mail.com", "Person Reg Error", "Username tried: " . $username . " . and Error: " . $user_id->get_error_message() . json_encode($user_id));
}

} // finish if

This code creates the next on the primary run.

After which on the subsequent run returns the error of “Sorry, that username already exists!”, because it tries to create a consumer with the username “register” once more.

EDIT 2: The Workaround (nonetheless want a solution)

The workaround is that I simply let it create the consumer title “register” after which shortly replace the consumer title with the provided consumer, however there isn’t any cause why it will be utilizing this consumer title. May one thing be filtering the wp_insert_user perform? Is there a WP hook that filters that?

EDIT 3: Tried one other web page/web page slug

I created a brand new web page known as “check” with the slug “check” and obtained the identical error so it has nothing to do with that.