sanitize_text_field($username), 'ip' => $ip, 'time' => $timestamp, ]; $logs = get_option('aegis_shield_failed_logins', []); $logs[] = $log_entry; if (count($logs) > 100) { $logs = array_slice($logs, -100); } update_option('aegis_shield_failed_logins', $logs); }); // 404 throttling add_action('template_redirect', function () { if (is_404()) { $ip = isset($_SERVER['REMOTE_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])) : ''; $ip = filter_var($ip, FILTER_VALIDATE_IP); if (!$ip) { return; } $key = 'aegis_404_' . md5($ip); $timestamps = get_transient($key) ?: []; $now = time(); $timestamps[] = $now; $timestamps = array_filter($timestamps, fn($t) => ($now - $t) < 60); if (count($timestamps) > 10) { aegis_shield_block_ip($ip); aegis_shield_save_blocked_ips_fallback(array_merge(aegis_shield_get_blocked_ips_fallback(), [$ip])); } set_transient($key, $timestamps, 2 * MINUTE_IN_SECONDS); } }); // Block IPs via .htaccess or fallback function aegis_shield_block_ip($ip) { if (!filter_var($ip, FILTER_VALIDATE_IP)) return false; $blocked_ips = aegis_shield_get_blocked_ips_fallback(); if (!in_array($ip, $blocked_ips, true)) { $blocked_ips[] = $ip; aegis_shield_save_blocked_ips_fallback($blocked_ips); } return true; }