How to remove password reset option from users’ profiles

We have already shown you how to reset a password in WordPress. In today’s article, we will show you a simple function which will remove the option to change a password directly from users’ profiles.

If you have left everything as it is, every user registered to your website will have the option to log in and access his or her profile page. Once there, users can easily enter their old passwords and generate a new one. If you want to remove this option for any reason, you can do that with the following code:

  1. Open function.php file
  2. Copy and paste the following code:
  3. function disable_password_reset_dashboard()
    {
    if ( is_admin() ) {
    $userdata = wp_get_current_user();
    $user = new WP_User($userdata->ID);
    if ( !empty( $user->roles ) && is_array( $user->roles ) && $user->roles[0] == 'administrator' )
    return true;
    }
    return false;
    }
    add_filter( 'show_password_fields', 'disable_password_reset_dashboard' );
    
  4. Save changes.

After you have made the changes, you can go on and try to change a password. If you log in with your admin account, everything will work as it should and you will be able to change your password easily from the profile menu. But if you log in with any non-admin account, you will notice that the password reset feature is missing.

Take note that this function only removes the option from the dashboard. Your users will still be able to change/restore their password from the login menu. Well, they will be unless you deny access to the Password Reset page as well.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *