4

I have a spreadsheet (XLS) of names, email addresses, and passwords from another content management system. Is there a way to import these folks as users (I think subscriber level, but some may be Editors as well) into WordPress?

4 Answers 4

6

A new file, import.php:

<?php

define('WP_INSTALLING', true); // this is required. i forget why!

include '/path/to/wordpress/wp-load.php';
include ABSPATH . WPINC . '/registration.php'; // wp_insert_user()

$userdata = array('user_login' => 'jdoe', 'user_pass' => 'foobar');
$user_id = wp_insert_user($userdata);

Check wp_insert_user() for other possible fields. Run update_usermeta() for any additional needed meta fields. (Including user level, though there may be convenience functions.)

Note that here at work we redefine the wp_authenticate() function (it's in pluggable.php, so it can be replaced by defining it in your own plugin) and creating user accounts on-demand if they don't exist at login time.

2
  • I had not heard of wp_insert_user() - nice!
    – artlung
    Aug 11, 2010 at 20:55
  • Double-nice because you can use it on existing users (just pass $userdata['ID']). I recommend being familiar with both wp_insert_user() and wp_update_user(). Aug 12, 2010 at 1:45
1

I would use a plugin for that. When done, remove the plugin.

This one by Dagon Design seems to do the trick, but it was not updated for wordpress 3. Don't know if it will work, so you migth want to try it on a sample wordpress.

0

You can also directly import them using the SQL databases, running an SQL query using the code from the downloaded SQL file from the previous server which contains all the users. That's what I would do, it is very easy.

3
  • 1
    Using a SQL query, you wouldn't be able to import the passwords. WordPress doesn't use the MySQL PASSWORD() function, it uses PHPass. Aug 16, 2012 at 18:51
  • @PHPass I never said import them using an sql query. There is no such thing. You import them from another SQL file in the import screen. Your comment is irrelevant and should be ignored. Maybe you commented on the wrong answer?
    – wordpress
    Mar 21, 2015 at 7:29
  • Your answer seemed like you were suggesting that OP turn his XLS into SQL statements, or import (e.g. as CSV using phpmyadmin or similar) directly into the database. That's a great suggestion, but OP wouldn't be able to import the passwords as-is, which is what I was noting, and for which my comment is relevant. If you're instead suggesting (as it sounds from your comment) that OP import from his old non-WP database to his WP database, that would not work. In that case, my comment is not relevant, but neither is your answer. Mar 23, 2015 at 1:24
0

You can easily migrate users using the free plugin Import export WordPress users

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.