function custom_login_failed($username) {
$ip = $_SERVER['REMOTE_ADDR'];
$transient_name = 'login_attempts_' . $ip;
$attempts = get_transient($transient_name);
if (!$attempts) {
$attempts = 1;
} else {
$attempts++;
}
set_transient($transient_name, $attempts, 15 * MINUTE_IN_SECONDS); // Store for 15 minutes
if ($attempts >= 3) {
set_transient('locked_' . $ip, true, 30 * MINUTE_IN_SECONDS); // Lock for 30 minutes
}
}
add_action('wp_login_failed', 'custom_login_failed');
function block_login_form_if_locked() {
$ip = $_SERVER['REMOTE_ADDR'];
if (get_transient('locked_' . $ip)) {
wp_die('You have entered the wrong password more than 3 times. Please try again after 30 minutes.');
}
}
add_action('login_form', 'block_login_form_if_locked');
UNM - Kuliahjen.com