Monday, August 19, 2013

wordpress wp_insert_user cannot login?

its a weird behaviour.
after running these code below, i wasn't able to login.
but when i request for password, the password reset works.
so, work around is, running wp_set_password after insert user:
Example:


$user = array(
          'user_login'          => $email,
          'user_password'       => $password,
          'user_email'          => $email,
          'first_name'          => $first_name,
          'last_name'           => $last_name,
          'user_registered'     => $row->updated_at
);

$user_id = wp_insert_user($user);

$customer = get_user_by('id', $user_id);

$customer->add_role( 'customer' );

//workaround below
wp_set_password( $password, $user_id );

No comments: