-
-
Save kwcjr/c08bdbc3bf688c2079f535cabff05dee to your computer and use it in GitHub Desktop.
Force WP Password Reset
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
/** | |
* This snippet will update ALL Users including Administrators with a randomly generated hashed password | |
* that is 26 characters long, includes Special characters and Extra Special characters. A Password Reset Email | |
* is then sent to the user. | |
* | |
* @snippetType: Return info from Child Sites | |
*/ | |
// Load in WP Core files we need. | |
include_once(ABSPATH . WPINC . '/pluggable.php'); | |
include_once(ABSPATH . WPINC . '/user.php'); | |
// Grab All users. | |
$users = get_users(); | |
// Grab only `administrators` role | |
// $args = array( | |
// 'role' => 'administrator' | |
// ); | |
// $users = get_users( $args ); | |
// Build output. | |
echo '<ul>'; | |
foreach ( $users as $user ) { | |
// Generate random secure hashed password and store it. | |
$password = wp_generate_password( 26, true, true ); | |
wp_set_password( $password, $user->ID ); | |
// Send user Password Reset email. | |
retrieve_password($user->user_email); | |
// Display user list to screen for verification. | |
echo '<li>' . esc_html( $user->display_name ) . '[' . esc_html( $user->user_email ) . '] - Password Updated.</li>'; | |
} | |
echo '</ul>'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Comment out line #14 & Un-comment lines #17-20 to only grab
administrator
roles.