WordPress Mass Account Import
Posted by rob in General, Internet, PHP, Wordpress, web funWhile working on a couple of WordPress projects for two sites I host (www.cambridgerepeaters.net & www.cambridgeshire-raynet.net) I had the need to do mass account creation. These were 30+ accounts at a time, not a thrilling prospect to do that via the normal admin interface. Searching the net was nearly useless, until I found a WP plugin called “Import Users Plugin for WordPress”. This worked, but was very simple and didn’t suit my needs.
So, after looking at the script and figuring out how it worked (I’m not PHP coder but I can get by in a pinch), I managed to hack the script to do what I wanted. The script as provided above only allows for the email address and login name, the 2 required bits of info to create a new account on a WP system. However, I needed to be able to specify:
- first name
- last name
- password
Another nice thing to have on the import is being able to set the WordPress user role (access level), so I shoved that in as well. On the plugin page I posted a comment about my updates and a link to the new modified script:
I’d like to submit another modified version of this great script. The changes I’ve made to the script allows for adding first and last names, setting a password and setting the role for the imports. I’m also using the more powerful method of account creation, “wp_insert_user” this allows a lot more in the way of adding nice things to the script and new account.
The import file or manually entered format is:
username|firstname|lastname|password|email|role
All fields except username and email are optional, but all fields must be delimited, ie:
fred|Fred|Rivers|mypassw0rd|fred@rivers.com|Editor
sam|Sam||sam@mypress.com|Fred has everything assigned while Sam will be emailed his generated password and his role will be set to whatever was selected from the drop down box on the form.
I’d be interested in any comments on my changes. There have been quite a few changes, I suggest a diff of mine and the latest modified one.
My modified version can be found at:
http://www.gammaray-tech.com/scripts/dd-import-users-mod_wp27.txt
I hope people find this useful, I think it’s a function that’s needed by far more people then you might expect. In my mind, it’s something that should be part of the core code for WordPress. I can see more modifications coming to this script as my projects progress. While looking into changes for the script I’ve found other things that would be nice to have at the time of import too…
Watch this space…
Updated script
2009.06.17 @ 2013GMT
Version 1.1.13 – Added user URL to be imported into user details (not the default assigned blog for WPMU)
dd-import-users-mod_wp27_v1.1.13.txt
Note the new format when using this version:
The import file or manually entered format is:
username|firstname|lastname|password|email|role|URL
All fields except username and email are optional, but all fields must be delimited, ie:
fred|Fred|Rivers|mypassw0rd|fred@rivers.com|Editor|http://blah.com
sam|Sam||sam@mypress.com||


London/Stansted, UNITED KINGDOM
Entries (RSS)
I think there’s a problem with the link… It’s generating an error as printed below:
Fatal error: Call to undefined function add_action() in /var/www/virtual/gammaray/www.gammaray-tech.com/scripts/dd-import-users-mod_wp27.php.txt on line 316
You are correct, thanks for that.. I’ve corrected the link on the site..
Cheers!!!
I think this is what I’ve been looking for, but, since I’m no expert, I have two questions:
1- As I understand it, I have to install dagon design’plugin first, and then modify the php file. Am I right?
2- Will this work foe WordPress 2.7?
You will need to install the plugin as any other plugin. No changes are needed to either the original script or my modified one. Once you install it you’ll see instructions for how to use it.
Yes, it’s very much ready for 2.7, especially the changes I’ve made to it. Once installed you’ll find it under the Tools menu on the dashboard.
Cheers!!!
Wow! You did an excellent work! Thank you very much! I installed as per your instructions and it worked perfectly! Thanks for sharing your modified script!
Thanks very much. Glad it worked for you. It’s only fair I share the changes.. it came from the wild, it should be returned to the wild..
Rob, thanks a lot! Thats exactly what i need to import about 200 users. It works perfectly with WP 2.7.1
)
Oh hooray! And thanks. I have to add around 350 subscribers and this has just worked perfectly with 4 names on my development blog.
This is *exactly* what I needed. It’s much appreciated.
Cheers,
Miraz
I need to be able to automate this (i.e. via cron).
Would that be straightforward?
Your plugin works wonderfully…thanks so much..you saved me a LOT of grief!!
I am trying to import hundreds of users on my current blog to a new blog and I dont want to be spamming them with WP’s user/password emails. Would you happen to know how I am might temporarily disable that functionality??
@ Ankush, I am looking to do the same thing. I have read elsewhere that the mailout function is done by WPs core code. So to stop it, we’d have to edit there and not just this nifty plugin.
For the moment, I am stuck. I have phplist, which I have used in the past to do messages to my clients / subscribers, but since I have moved my site to a WP powered one, I don’t want to have two databases of users or force them to use two accounts to change their profiles.
I’ll check back and post any solutions I find.
Link to script is broken, any chance you can upload it back up?
GiladG, Thanks for that. I’ve put the directory back. It seems to have gotten shuffled around when I was cleaning up. You always miss something when cleaning up don’t you
Thanks Rob.
But I have the same problem that Ankush has.
I want to import 3000+ users, but don’t want to email them, is tehre any chando to do that?
Thanks a lot.
This is a great Plugin – Thank you! However, I’ve realized that it doesn’t apply the Dashboard Blog assigned in options. If I manually add a new user through the WPMU interface then the Dashboard Blog is assigned. Any ideas on how this can be fixed?
I don’t actually use WPMU so not sure about that feature. I’ve just has a fast look at registration.php from WPMU, perhaps the option you want to add is for user_url .. just hack the script and add that into
$user_id = wp_insert_user(array(
“user_login” => $ud['username'],
“first_name” => $ud['firstname'],
“last_name” => $ud['lastname'],
“user_pass” => $password,
“user_email” => $ud['email'],
“user_url” => $ud['url']) // <– here
);
I'm not sure if that's the option or not for you. Try this new script with the changes adding user_url..
http://www.gammaray-tech.com/scripts/dd-import-users-mod_wpmu27.txt
Please be sure to try this on a dev system and NOT a live system!! I HAVE NOT TESTED THIS VERSION IN ANY WAY!!
Please, re-read the last line again!!!
Thanks for your quick response Robert!
The script had 2 syntax errors. The line above ud['url'] needed a “)” removed and required a “,”. Once that was fixed it ran fine. However, the variable user_url adds a url for the user’s website under contact information. What I’m looking for is to specify a default blog for the users imported. I’m not sure what variable would fix this as I’m not a programmer and am a newb to wpmu. Thanks again for your help.
Pablo,
I’m not sure it can be done without making some changes to the wp code. The actual function that’s called does the email along with the rest of the account creation, and there’s no option to “not send emails” in that function.
It might be something to suggest to the WP code gods, add an option to not send emails just for scripts like this one, or even just as a one off check box, there are times when creating an account that you don’t need an email going out (ie: creating a test account).
Thanks for that, I’ve corrected the script. It was just a crazy fast cut/paste job.
I’ve been looking at the WPMU registration process, I don’t think it will be an easy hack to make the script work with it, but I’ll have a play and see what I can do to it
As the “new” script I posted is NOT for WPMU as it stands, I’ll actually just update the old script to the new one and include the changes.
Ok, been playing with WPMU a little bit. Hacking the script to work specifically with MU looks like it will be .. well, non-trivial. However, take that as coming from someone that has crap PHP skills.
While it’s not a “fix” it is a work around for doing imports into MU. It’s not really ideal but could be useful.
1) Put the plugin into the /wp-content/mu-plugins/ directory, Deactivate and remove it from /wp-content/plugins/ first, it will barf on you
2) Login into one of the blog sites myblog..com/wp-admin/ as an admin of that blog. Under Tools you’ll see the DDImport option.
Accounts imported via the blog it self will be linked to that blog.
Like I said it’s not idea and may not even be useful for some, but it will work. This will allow the blog owners the ability to import the users themselves, or mass create new accounts. This might be useful for the blog admin
In the mean time I’ll keep poking around at the script and see if I can make it more MU friendly .. haha but it’s not gonna be easy, that I can see.
I am running WP 2.8, and i am getting the following error:
Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home/thewood3/public_html/wp-content/plugins/Users-Import/Dagon Import users modifed Rob.php:320) in /home/thewood3/public_html/wp-content/plugins/wp-e-commerce/wp-shopping-cart.php on line 166
Warning: Cannot modify header information – headers already sent by (output started at /home/thewood3/public_html/wp-content/plugins/Users-Import/Dagon Import users modifed Rob.php:320) in /home/thewood3/public_html/wp-content/plugins/sidebar-login/sidebar-login.php on line 258