I’m migrating a whole slew of users between two self-hosted WordPress sites, and I’m trying to find a way to bring them across without resetting their passwords. The current site has everyone’s passwords, naturally, all nicely hashed. Currently the two methods I could see to import these users (wp_insert_user() and wp_create_user()) both require the passwords to be in clear text. Is there something I’m missing, or can this just not be done with current methods?
Leave a Reply
You must be logged in to post a comment.
You have 3 options. Run a custom database query, copy and modify
wp_insert_user()
, or runwp_insert_user()
twice.Copy and modify
wp_insert_user()
Below is a custom
wp_insert_user
function. All I’ve done is removed the line that hashes the PW.Running
wp_insert_user
twiceIf you run
wp_insert_user()
user_pass
is expected to be a plain string. If you include an ID parameter however you need to use a hashed password instead.You could run
wp_insert_user()
with a random password to insert the user. This will return an ID. You could then run the same function again including the ID and the hashed password.As I pointed out above this is inefficient and not something I’d suggest but it would be possible. Here’s an example:
This is not a complete solution. If you were to use it you’d want to include some error checking, etc. You’re much better off with one of the two other solutions posed.