wpgenie

block user login

Apr 1st, 2025
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. /**
  2.  *
  3.  * User login blocking without need for dedicated plugin.
  4.  *
  5.  */
  6. function wpgenie_check_attempted_login( $user, $username, $password ) {
  7.  
  8.    
  9.     $blocked = array( 1, 2, 3 ); // user IDs you want to block
  10.  
  11.  
  12.     if ( is_a ( $user, 'WP_User' ) ) {
  13.  
  14.         if ( !in_array( $user->ID, $blocked) ) {
  15.                
  16.             return $user;
  17.  
  18.         } else {
  19.  
  20.             $user = new WP_Error(
  21.                 'account_locked',
  22.                 'Your account has been locked. Please contact us for assistance.'
  23.             );
  24.            
  25.             return $user;
  26.         }
  27.     }    
  28. }
  29.  
  30. add_filter('authenticate', 'wpgenie_check_attempted_login', 100, 3);
Advertisement
Add Comment
Please, Sign In to add comment