Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent new WordPress users from logging in until manually "activated"?

I'm developing a plugin for WordPress which has 3 groups of users. I need to disable some users and prevent them from login. what I mean isn't preventing them to access the backend. I want to prevent them from is log in. For example, when they want to login they should see a message like this account isn't active yet. thank you guys.

like image 812
Alireza Seyedzade Avatar asked Dec 24 '22 19:12

Alireza Seyedzade


1 Answers

after some search and see similar problems I solved this problam like this : first add a user meta for user status so we can checking if user is active or not then we can disable or enable users.

add_filter( 'authenticate', 'chk_active_user',100,2);
function chk_active_user ($user,$username) 
   {
     $user_data = $user->data;
     $user_id = $user_data->ID;
     $user_sts = get_user_meta($user_id,"user_active_status",true);
     if ($user_sts==="no")
     {
        return new WP_Error( 'disabled_account','this account is disabled');

      }
      else
      {
       return $user;
      }
        return $user;
     }
like image 169
Alireza Seyedzade Avatar answered Dec 26 '22 17:12

Alireza Seyedzade