Skip to content

Instantly share code, notes, and snippets.

@kwcjr
Last active November 18, 2022 01:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwcjr/c08bdbc3bf688c2079f535cabff05dee to your computer and use it in GitHub Desktop.
Save kwcjr/c08bdbc3bf688c2079f535cabff05dee to your computer and use it in GitHub Desktop.
Force WP Password Reset
/**
* 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>';
@kwcjr
Copy link
Author

kwcjr commented Nov 18, 2022

Comment out line #14 & Un-comment lines #17-20 to only grab administrator roles.

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