Users & Login PHP Intermediate

Turn Off Password Resets for Administrators

Block the "Lost your password?" reset for administrator accounts, so a hacked email inbox can't be used to take over the site.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 6 lines
add_filter( 'allow_password_reset', function ( $allow, int $user_id ) {
	if ( user_can( $user_id, 'manage_options' ) ) {
		return new WP_Error( 'nahnu_no_reset', 'Password reset is turned off for this account. Please contact the site owner.' );
	}
	return $allow;
}, 10, 2 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

If an attacker gets into an administrator’s email, the “Lost your password?” link gives them the site too. Turning off resets for admin accounts closes that path. Admins reset each other’s passwords from the Users screen instead.

How it works

Before sending a reset email, WordPress asks allow_password_reset whether the user may reset. The snippet returns an error for anyone with manage_options, which shows on the lost password form. Other users can still reset as normal.

Things to watch

  • Make sure every administrator knows their password, or that another admin can reset it for them. If you’re the only admin, you’d need database or hosting access to recover.
  • Admins can still change their password while logged in, on their profile.

How to test it

Log out, click “Lost your password?” and enter an admin’s email. You should see the error message and no email should be sent.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only