Import 10,000 Users into WordPress WITH a specific ID for each user

I have a website which has about 10,000 users. I am converting this site over to WordPress. The new site is ready to roll, but I have to bring over all the users.

There are a number of plugins available to importing users from a CSV file, and I’ve got the CSV file ready to go. The plugin that I’d like to use is the following:

Read More

Import Users from CSV

The reason I’d like to use this plugin is that it provides the option to import a CSV file containing user id’s. Unfortunately, the plugin is currently designed so that if ID’s are present in the CSV file, it assumes that these users already exist in your WordPress database and you’re trying to “UPDATE” those records.

I’m not. I’m trying to make NEW users in the database, but with specific ID’s (because these ID’s are tied to another system and I don’t want these losers to lose access to all of this other info as a result of an ID change from the old system to the new.

It seems that the plugin above maybe be piggy-backing off of the built-in WordPress functions for registering or updating users, so this may be the problem.

How can I accomplish my goal with as little time investment as possible?

BTW – I am pretty comfortable in phpmyadmin, so I don’t mind doing it there, the only problem is I want to make sure that all users receive an email notifying them and providing their new password (because I can’t move these over). Using the plugin, this is automatic. Without it, not to much.

Thanks for any assistance.

Related posts

Leave a Reply

3 comments

  1. I’m not familiar with the plugin, but this might be an option to work around it:

    1. Import the ids into the database directly using SQL (phpMyAdmin).
    2. Use the plugin to import the CSV and run the “update” on those now-existing users, so they receive their updated password email.
  2. This is the answer I alluded to above in my comment.

    First off, I should say that Andrew’s “maybe helpful” piece posted yesterday works, but I didn’t end up doing it that way.

    Either way, you’ve got to insert records into your wp_users table containing all the ID’s of the members you want to import (I also included usernames, but not sure if that’s necessary).

    Then, use the Import Users from CSV plugin I referenced in my initial question to import your users’ login, email and role (and any other fields you want to import. the plugin has instructions for this)

    To set them to a specific role on import, simply add a column to your CSV file called “role” and then within each record indicate in that column what their role should be: “subscriber”, “author”, etc.

    I believe your “roles” must be entered all lower-case. That’s the way I did it. Others indicated that if the first letter was capitalized, it didn’t work.

    Be sure that the ID’s are included in this CSV so that the plugin knows which records to update in the database with the new info.

    Here’s an example of a few records from my CSV file, so you can see how it’s structured:

    "ID","user_login","user_email","role","another_field","another_field_2"
    "5094","username5094","user5094@gmail.com","subscriber","another_field_value","another_field_2_value"
    "5095","username5095","user5095@gmail.com","subscriber","another_field_value","another_field_2_value"
    

    ++++++++++
    NOTICE
    ++++++++++

    When I initially posted this answer I neglected to indicate that I made a small modification to the “Import Users from CSV” plugin. In your WordPress admin, under the “plugins” section, choose the “Editor” link.
    Then, use the upper-right hand drop-down box to select the correct plugin (the Import Users from CSV plugin).

    About half-way down the php file there are a couple of lines separated by about 10-15 lines in between.

    The first is:

    if ( $update )
    

    I commented this line out and modified it so that the code for that line now looks like:

    /* if ( $update )   */
    if (1==0)
    

    Then, the second line you’re going to change (about 10-15 lines below the last one) is:

    if ( ! $update ) {
    

    Which I changed to:

    /* if ( ! $update ) {  */
    if ( 1==1 ) {
    

    What this does is guarantee that all of the users that you’re importing will get their welcome emails with the new username and password.

    +++++++++
    END NOTICE
    +++++++++

    I found that I could only import about 150 users at a time without getting a server error, which wasn’t ideal, since I have thousands of users to import. But, I don’t think this is so much a limitation of the plugin as it is the settings on my server and/or available memory.

    If you checked the appropriate boxes, each user that gets imported will receive a “new user” email from your WordPress including their username and password for login. So, you’ll need to get the passwords within their records encrypted right away, otherwise they won’t work when they try to login.

    Personally, I’d import some users, then run my encryption query. Then import some more users, then run my encryption query. That way there was never a lag of more than about a minute between the the “welcome email” that users would receive and the encryption of their password so that the login would work.

    Once you’ve got all or a portion of the users imported. Then, use Andrews solution above with “WHERE CHAR_LENGTH(wp_users.user_pass) = 12”. Since WordPress is going to assign all of your new users a 12 digit password when you import them with the plugin, these are the ones you’ll want to update with the encrypted version, and that’s what the “WHERE” portion of that query comes in. It’s possible your situation may not require the use of this “WHERE” portion, but it won’t hurt to leave it there, if you’re not sure.

    The next time these individuals login to your WordPress blog, WordPress will change the encryption on those passwords to the new encryption method. The user won’t know the difference.

    And, for those who are curious what method I actually used instead of Andrew’s, I created a PHP file containing the following code:

    <?php 
    require_once '/home/evaluate/public_html/members-blog/wp-config.php';
    
    $sql="SELECT user_pass,ID FROM wp_users WHERE CHAR_LENGTH(wp_users.user_pass) = 12";
    $find = mysql_query($sql) or die(mysql_error());
    
      while($row = mysql_fetch_array($find))
      {
    
      $current_password = $row['user_pass'];
      $current_id = $row['ID'];
      $hashed_password = wp_hash_password( $current_password );
    
      $update_sql= "UPDATE wp_users SET user_pass = '" . $hashed_password . "' WHERE ID = " . $current_id . "";
      $update = mysql_query($update_sql) or die(mysql_error());  
    
      echo $current_id . " " . $hashed_password;
      echo "<br />";
      }
    
     ?>
    

    Then, once I had some users imported through the plugin, I’d pull up the URL for this php file in my browser to start it running.

    This php file uses WordPress’ own encryption method by tying in to the WordPress config file (the “require_once” statement). This also connects it to the correct database. It grabs each user in the wp_users table that has an UNencrypted password (any password in the table that is only 12 characters is UNencrypted), encrypts the password and then updates that record with the new encrypted version of the password. Finally, it echos the ID of the user it just updated along with the encrypted version of the password.

    It continues looping through this process until all users in the database with an UNencrypted password have been encrypted. At the end, you’ll have a printout displayed on your screen which shows all the user ID’s that were updated and the encrypted version of the password (so that you’ve got proof of what was done).

    This is also nice because, if the script dies before completing all the records, all you do is refresh the page to rerun it. Since it only updates records that haven’t yet been encrypted, it just picks up where it left off.

    Hope this helps someone. If you have questions above the process, let me know. I’ll try to elaborate as best I can.

  3. This is how I did the job:

    • Use export CSV to export your members
    • Import into Excel
    • Check your new site’s last member ID
    • Select the ID column in your Excel sheet
    • Press the delete button
    • Re fill in “ID” on the first row
    • Second row type the first next ID number you want
    • Drag the bottom right corner a few down do that it shows a few ID’s for the first few members
    • Select those ID’s
    • Double click on the bottom right vorner of the last ID
    • Now all ID fields should be filled in correctly
    • Export to CSV once again
    • Import with Users CSV import, be sure to select the password nag option

    All done!