Block the "Lost your password?" reset for administrator accounts, so a hacked email inbox can't be used to take over the site.
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 );
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.
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.
Log out, click “Lost your password?” and enter an admin’s email. You should see the error message and no email should be sent.