Skip to content

Instantly share code, notes, and snippets.

@kappuccino
Created January 24, 2020 10:22
Show Gist options
  • Save kappuccino/58b44eb8b3a5976f6361d9d3385c45a5 to your computer and use it in GitHub Desktop.
Save kappuccino/58b44eb8b3a5976f6361d9d3385c45a5 to your computer and use it in GitHub Desktop.
Import WP User from CVSV
<?php
$raw = file_get_contents(__DIR__.'/Clients.csv');
$lines = explode("\n", trim($raw));
unset($lines[0]);
foreach($lines as $i => $line){
list($nom, $prenom, $email) = explode(';', trim($line));
var_dump($nom);
var_dump($prenom);
var_dump($email);
$u = get_user_by('email', $email);
if(empty($u)){
$user_name = str_replace(' ', '', strtolower($nom.'-'.$prenom));
$random_password = wp_generate_password(12, false);
$user_id = wp_create_user($user_name, $random_password, $email);
var_dump($user_id);
if($user_id > 0){
update_user_meta($user_id, 'first_name', $prenom);
update_user_meta($user_id, 'last_name', $nom);
}
}
echo '--'.PHP_EOL;
#if($i > 10) die('--');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment