Reset WordPress user passwords and send them a new user notification email. Read the comments. BE CAREFUL WITH THIS CODE!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/