Skip to content

How To Remove Password Change Option From WordPress

I was looking into Visual Composer‘s demo WordPress website, and I noticed that the users were not allowed to change the password of the demo user. It does make sense to not give users ability to change password on your demo WordPress website. In this tutorial, I’ll show you how to remove password change option from your WordPress to prevent users from changing the password of their user accounts.

You don’t want some evil people to change password of the user to prevent others from logging into your demo WordPress website. So, we are going to simply remove the ability to change the password by hiding the fields.

Just add following snippet to your current theme’s functions.php file:

class Password_Reset_Removed
{

  function __construct() 
  {
    add_filter( 'show_password_fields', array( $this, 'disable' ) );
    add_filter( 'allow_password_reset', array( $this, 'disable' ) );
  }

  function disable() 
  {
    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;
  }

}

$pass_reset_removed = new Password_Reset_Removed();

We have just removed the fields to change password from the back-end of the WordPress. Now, some users will also try to reset the password using the Lost your password? form from the log-in page.

In order to prevent them from doing that, we will remove lost password link and disable the lost password form by adding following snippet:

function remove_lost_your_password($text)
  {
    return str_replace( array('Lost your password?', 'Lost your password'), '', trim($text, '?') );
  }
add_filter( 'gettext', 'remove_lost_your_password'  );

function disable_reset_lost_password()
  {
    return false;
  }
add_filter( 'allow_password_reset', 'disable_reset_lost_password');

1 thought on “How To Remove Password Change Option From WordPress”

Leave a Reply

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