wpgenie icon

block user login

wpgenie | PRO | 04/01/25 07:47:20 AM UTC | 0 ⭐ | 11109 👁️ | Never ⏰ | []
PHP |

680 B

|

None

|

0 👍

/

0 👎

/**
 * 
 * User login blocking without need for dedicated plugin.
 * 
 */
function wpgenie_check_attempted_login( $user, $username, $password ) {
 
    
    $blocked = array( 1, 2, 3 ); // user IDs you want to block
 
 
    if ( is_a ( $user, 'WP_User' ) ) {
 
        if ( !in_array( $user->ID, $blocked) ) {
                
            return $user;
 
        } else {
 
            $user = new WP_Error(
                'account_locked',
                'Your account has been locked. Please contact us for assistance.'
            );
            
            return $user;
        }
    }     
}
 
add_filter('authenticate', 'wpgenie_check_attempted_login', 100, 3);

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎