• Resolved Mariette

    (@mariette-jackson)


    I would like to prevent a particular custom user role being able to

    1. change their own password and

    2. use the email instead of username to log in

    Is this possible?

    many thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Caseproof

    (@caseproof)

    Hi Mariette,

    1. Here is the code that you can insert at the end of your theme’s functions.php file to disable password change for a particular role:

    
    add_filter('allow_password_reset', 'disable_password');
     
    function disable_password() 
      {
        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 false;
        }
        return true;
      }

    In this case it is Administrator but you can change it.

    2. I’m not sure if this is possible because when the user is not logged in, WordPress doesn’t know the role this user has.

    Cheers

    Thread Starter Mariette

    (@mariette-jackson)

    Thank you very much for the code, that’s great. Haha – hadn’t thought of that for number 2! No worries.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide password reset for role’ is closed to new replies.