Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save strangerstudios/5773927 to your computer and use it in GitHub Desktop.
Save strangerstudios/5773927 to your computer and use it in GitHub Desktop.
Reset WordPress user passwords and send them a new user notification email. Read the comments. BE CAREFUL WITH THIS CODE!
/*
Place this code inside your active theme's functions.php or in a custom plugin
*/
function my_password_reset()
{
//get all users you just added
$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users WHERE ID > 1"); //change 1 here to the ID of the first imported user
//$user_ids = array(6,7); //if you want to test on a couple users first. enter ids for two test accounts you will get email from.
//now loop through the users
foreach($user_ids as $user_id)
{
//create a new password
$newpass = pmpro_getDiscountCode(); //returns a psuedo random 10 character code
//update the user's password
$userdata = array("ID" => $user_id, "password" => $newpass);
wp_update_user($userdata);
//send the notification email
wp_new_user_notification($user_id, $newpass);
echo "."; //so we can see progress
}
echo "done";
exit;
}
add_action("init", "my_password_reset");
@laurenhagan0306
Copy link

This recipe is included in the blog post on "How to Mass Import Members into WordPress/PMPro" at Paid Memberships Pro here: https://www.paidmembershipspro.com/how-to-mass-import-members-into-wordpresspmpro/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment