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