Skip to content

Instantly share code, notes, and snippets.

@phillipadsmith
Created May 8, 2012 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipadsmith/2640373 to your computer and use it in GitHub Desktop.
Save phillipadsmith/2640373 to your computer and use it in GitHub Desktop.
Diff file from the original Worpress CSV User Import to one that supports more user fields
diff --git a/Users/phillipadsmith/Downloads/csv-user-import/csv-user-import.php b/wp-content/plugins/csv-user-import/csv-user-import.php
index ea2e26f..2ef4fa5 100644
--- a/Users/phillipadsmith/Downloads/csv-user-import/csv-user-import.php
+++ b/wp-content/plugins/csv-user-import/csv-user-import.php
@@ -37,17 +37,27 @@ function csvuserimport_page1() {
if (is_array($arr_rows)) {
foreach ($arr_rows as $row) {
- // split into values
- $arr_values = split(",", $row);
+ // More effective way to split a CSV string into an array of values
+ $arr_values = str_getcsv( $row, $delimiter=',', $enclosure='"', $escape='\\' );
- // firstname, lastname, username, password
+ // firstname, lastname, username, password, email, description, website, aim, jabber
+ // yim, facebook, twitter, google
$firstname = $arr_values[0];
$lastname = $arr_values[1];
$username = trim($arr_values[2]);
$password = trim($arr_values[3]);
$user_email = trim($arr_values[4]);
if (!$user_email) { $username."@donotreply.com"; }
- $user_nicename = sanitize_title($username);
+ $user_nicename = sanitize_title($username);
+ $description = $arr_values[5]; // Let's add some user meta information, like a bio
+ $website = $arr_values[6]; // Website
+ $aim = $arr_values[7]; // AIM
+ $jabber = $arr_values[8]; // Jabber (WTF uses it?)
+ $yim = $arr_values[9]; // Yahoo IM
+ $user_fb = $arr_values[10]; // Facebook
+ $user_tw = $arr_values[11]; // Twitter
+ $google_profile = $arr_values[12]; // Google Plus
+
// add the new user
$arr_user = array( 'user_login' => $username,
@@ -55,7 +65,9 @@ function csvuserimport_page1() {
'user_email' => $user_email,
'user_registered' => date( 'Y-m-d H:i:s' ),
'user_status' => "0",
- 'display_name' => $username
+ 'user_url' => $website,
+ // TODO This should be an option on the import screen
+ 'display_name' => $firstname . ' ' . $lastname
);
$wpdb->insert( $wpdb->users, $arr_user );
$user_id = $wpdb->insert_id;
@@ -67,10 +79,24 @@ function csvuserimport_page1() {
'rich_editing' => "true",
'comment_shortcuts' => "false",
'admin_color' => "fresh",
- $wpdb->prefix . 'capabilities' => 'a:1:{s:10:"subscriber";b:1;}',
+ // TODO Would be sensible to put the capability options
+ // into a hash table and accept a key from the import screen
+ // Contributor: a:1:{s:11:"contributor";s:1:"1";}
+ // Subscriber: a:1:{s:10:"subscriber";b:1;}
+ // Author: a:1:{s:6:"author";s:1:"1";}
+ // Editor: a:1:{s:6:"editor";s:1:"1";}
+ // Admin: a:1:{s:13:"administrator";s:1:"1";}
+ $wpdb->prefix . 'capabilities' => 'a:1:{s:11:"contributor";s:1:"1";}',
'first_name' => $firstname,
'last_name' => $lastname,
- 'default_password_nag' => "1"
+ 'default_password_nag' => "1",
+ 'description' => $description,
+ 'aim' => $aim,
+ 'jabber' => $jabber,
+ 'yim' => $yim,
+ 'user_fb' => $user_fb,
+ 'user_tw' => $user_tw,
+ 'google_profile' => $google_profile
);
foreach ($arr_meta_values as $key => $value) {
@@ -112,12 +138,20 @@ function csvuserimport_page1() {
<td>lastname,</td>
<td>username,</td>
<td>password (plain text),</td>
- <td>email address</td>
+ <td>bio/descripton,</td>
+ <td>website,</td>
+ <td>AIM,</td>
+ <td>jabber,</td>
+ <td>YIM,</td>
+ <td>Facebook,</td>
+ <td>Twitter,</td>
+ <td>Google</td>
</tr>
</table>
+ <p>You can find an example <a href="https://gist.github.com/2640242">here</a>.</p>
<p style="color: red">Please make sure you back up your database before proceeding!</p>
</div>
<?php
} // end of 'function csvuserimport_page1()'
-?>
\ No newline at end of file
+?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment