-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp_contacts_importer.php
74 lines (58 loc) · 1.8 KB
/
wp_contacts_importer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
set_time_limit(0);
require( dirname(__FILE__) . '/wp-load.php' );
$file = "csv/" . $_REQUEST['file'] . ".csv";
$missed = "csv/eq_contact_errors.txt";
$remaining = file($missed, FILE_IGNORE_NEW_LINES);
$errors = array();
if(file_exists($file)) {
$source = fopen($file, 'r') or die("Problem open file");
$head = fgetcsv($source, 1000, ",");
$created = 0;
while (($data = fgetcsv($source, 1000, ",")) !== FALSE) {
if(! in_array($data[0], $remaining)) {
continue;
}
$password = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 7);
// $parts = explode("@", $data[0]);
// $username = $parts[0];
$username = $data[1] . "14";
$email = $data[0];
$fname = $data[1];
$lname = $data[2];
$user_data = array(
"user_login" => esc_sql($username),
"user_pass" => esc_sql($password),
"user_email" => esc_sql($email),
"first_name" => esc_sql($fname),
"last_name" => esc_sql($lname)
);
$user_id = wp_insert_user($user_data);
if(gettype($user_id)=="integer") {
++$created;
for ($j=3; $j<count($head); $j++) {
$meta_key = str_replace(" ", "_", $head[$j]);
add_user_meta( $user_id, $meta_key, $data[$j] );
}
$msg = "Hi {$data[1]} {$data[2]},";
$msg .= "<br><br>Your account has been created at <a href='http://eq.org/'>EQ.ORG</a>. Here are the account details:<br>";
$msg .= "<br>Username: {$username}";
$msg .= "<br>Password: {$password}";
wp_mail( $email, "You account has been created at EQ.ORG", $msg);
} else {
foreach($user_id->errors as $error) {
$errors[] = array("Error"=>$error[0], "Email"=>$email);
}
}
}
} else {
echo $file . " not found!";
exit();
}
?>
<html>
<body>
<p><?php echo $created ;?> users created!</p>
<p><?php var_dump($errors);?></p>
</body>
</html>