Migrating WP users to WPMU

by c

This technique will migrate:

  • Usernames
  • Email
  • Password

It does not concern itself with

  • User meta
  • Anything else

It assumes

  • Admin on WPMU has already been created.
  • Admin on original WP install is user id #1
  • All new users are subscribers on blog #1 in WPMU

Firstly, run this sql in your mysql install:

select concat('Array(', concat_ws(', ', quote(user_login), quote(user_email), quote(user_pass)), '),') from wp_users where id != 1

Now drop this script into the base directory of your WPMU install. Paste the results from above where noted.

<?

$users = Array(
	// Array('example user', 'user email', 'user password hash'),
	// PASTE RESULTS FROM MYSQL HERE
);

require_once("wp-config.php");
require_once("wp-includes/registration.php");

foreach ($users as $v) { add_user($v[0], $v[1], $v[2]); }

echo "Done.";

function add_user($user_login, $user_email, $password)
{
	global $user, $wpdb, $allowedtags, $blog_id;

	$wpdb->show_errors();

	if (username_exists($user_login))
		return;

	if (email_exists($user_email))
		return;

	echo "$user_login..";

	if ( ! $user_id = wpmu_create_user($user_login, 'temp', $user_email) )
	{
		print_r(new WP_Error('create_user', __('Could not create user'), $user_id));
		exit;
	}

	add_user_to_blog(1, $user_id, 'subscriber');
	update_usermeta($user_id, 'source_domain', 'YOURDOMAIN.COM');
	do_action('wpmu_activate_user', $user_id, $password, Array());
	$wpdb->query("UPDATE wp_users SET user_pass = '$password' WHERE ID = '$user_id'");
}

?>

The end.