Create users via PHP

I'd like to update my users list with some user from a csv file generated by another database (witch i can access too) i'd like to create dynamically a user (with username, password and so on) and other custom fields (such as language, status, and other personal variables).

I've fetched my csv (that works), but when i try to create user with wp_insert_user, nothing happens :/

here's the code:

function clients_csv($file){

$csv = array_map('str_getcsv', file($file));
for($i=0;$icount($csv);$i++){

if(!email_exists($csv[7]) ){
print "CREATE USER";
$user_id=wp_insert_user(
array(
'user_login' = $csv[4],
'user_pass' = wp_generate_password(12,false),
'first_name' = $csv[4],
'user_email' = $csv[7],
'role' = 'sbscrbr_subscriber'
)
);
update_user_meta( $user_id, 'lingua', $csv[1] );
}
for($j=0;$jcount($csv[$i]);$j++){
print $csv[$i][$j];
}
add_user_meta($csv[0],'lingua',$csv[1]);
print "
";
}
}

just for trial purpose, i call the function in the index file.

Thanks in advance

Topic wp-create-user admin users customization Wordpress

Category Web


I found out the problem. i used wp_update_user to create the user, instead of wp_create_user.

my bad :/

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.