Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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);
//send the notification email
wp_new_user_notification($user_id, $newpass);
echo "."; //so we can see progress
echo "done";
add_action("init", "my_password_reset");
Copy link

This recipe is included in the blog post on "How to Mass Import Members into WordPress/PMPro" at Paid Memberships Pro here:

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