ID, false );
if ( $disabled ) {
return new WP_Error('ul_user_disabled', __('ERROR: This user account is disabled.', 'user-locker'));
}
$locked = get_user_option( 'ul_locked', $user->ID, false );
if ( $locked ) {
return new WP_Error('ul_user_locked', __('ERROR: This user account is locked for security reasons. Please use Lost Password option to unlock it.', 'user-locker'));
}
return $user;
}
// Set password check flag
function check_password( $check ) {
$this->pass_check = true;
return $check;
}
// Increment bad attempt counter and finally lock account
function wp_login_failed( $username ) {
if ( !$this->pass_check ) {
// Function called too early
return;
}
$user = get_userdatabylogin($username);
if ( !$user || ($user->user_login != $username) ) {
// Invalid username
return;
}
$disabled = get_user_option( 'ul_disabled', $user->ID, false );
$locked = get_user_option( 'ul_locked', $user->ID, false );
if ( !$disabled && !$locked ) {
$cnt = get_user_option( 'ul_bad_attempts', $user->ID, false );
if ( $cnt === false ) {
$cnt = 1;
} else {
++$cnt;
}
update_user_option( $user->ID, 'ul_bad_attempts', $cnt, false );
if ( $cnt >= get_option( 'userlocker_max_attempts' ) ) {
$this->locked = true;
update_user_option( $user->ID, 'ul_locked', true, false );
}
}
}
// Reset account lock on pass reset
function password_reset( $user ) {
$this->unlock_user( $user->ID );
}
// Reset account lock on valid login
function wp_login( $username ) {
$user = get_userdatabylogin( $username );
$this->unlock_user( $user->ID );
}
// Unlock account for given user
function unlock_user( $user_id ) {
update_user_option( $user_id, 'ul_bad_attempts', 0, false );
update_user_option( $user_id, 'ul_locked', false, false );
}
// Add info about account lock
function login_errors( $errors ) {
if ( $this->locked ) {
$errors .= __('ERROR: This user account has been locked for security reasons. Please use Lost Password option to unlock it.', 'user-locker') . "
\n";
}
return $errors;
}
function edit_user_profile() {
if ( !current_user_can( 'edit_users' ) ) {
return;
}
global $user_id;
// User cannot disable itself
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
if ( $current_user_id == $user_id ) {
return;
}
?>
', $message, '