0, 'relay' => 0, 'server_degraded' => 0, 'direct_blocked' => 0, 'direct_ok' => 0, 'no_fp_cookie' => 0, ]; } // Increment route bucket. if ($route === 'direct') { $stats[$today]['direct']++; } else { $stats[$today]['relay']++; } // Increment reason buckets. if ($reason === 'server_degraded') { $stats[$today]['server_degraded']++; } elseif (in_array($reason, ['direct_blocked', 'direct_blocked_no_fp_cookie'], true)) { $stats[$today]['direct_blocked']++; } elseif (in_array($reason, ['direct_ok', 'direct_ok_no_fp_cookie'], true)) { $stats[$today]['direct_ok']++; } elseif ($reason === 'no_fp_cookie') { $stats[$today]['no_fp_cookie']++; } ksort($stats); if (count($stats) > 30) { $stats = array_slice($stats, -30, 30, true); } update_option('acceptrics_adaptive_daily', $stats, false); status_header(204); exit; } function acceptrics_record_detect_handler() { if (!get_option('acceptrics_blocker_detect_enabled', false)) { status_header(204); exit; } $raw = isset($_POST['blocked']) ? intval($_POST['blocked']) : -1; if ($raw !== 0 && $raw !== 1) { status_header(400); exit; } $blocked = ($raw === 1); $today = gmdate('Y-m-d'); $stats = (array) get_option('acceptrics_detect_daily', []); if (!isset($stats[$today])) { $stats[$today] = ['blocked' => 0, 'unblocked' => 0]; } if ($blocked) { $stats[$today]['blocked']++; } else { $stats[$today]['unblocked']++; } // Keep only the most recent 30 days. ksort($stats); if (count($stats) > 30) { $stats = array_slice($stats, -30, 30, true); } // autoload=false: this option is read only on the Report tab, not on every request. update_option('acceptrics_detect_daily', $stats, false); status_header(204); exit; }