From 01a15007cb4e86151654daf3d743e850b63db3cd Mon Sep 17 00:00:00 2001 From: Malin Date: Mon, 9 Mar 2026 20:35:14 +0100 Subject: [PATCH] fix: surface flush() errors in admin connection status When WP-Cron's automatic queue flush fails (network error, wrong token, non-200 response), update connection_ok=false and last_error with the reason so the admin dot turns red and shows the exact failure message. Previously failures were silent. Co-Authored-By: Claude Sonnet 4.6 --- honeypot-fields.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/honeypot-fields.php b/honeypot-fields.php index 30c94d8..0b23275 100644 --- a/honeypot-fields.php +++ b/honeypot-fields.php @@ -349,11 +349,27 @@ class SmartHoneypotAPIClient { ] ); - if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) { - update_option(self::OPT_QUEUE, $queue, false); - $s['last_sync'] = time(); - $s['sent_total'] = ($s['sent_total'] ?? 0) + count($batch); + if (is_wp_error($response)) { + $s['connection_ok'] = false; + $s['last_error'] = 'Flush failed: ' . $response->get_error_message(); update_option(self::OPT_SETTINGS, $s); + error_log('[Honeypot] flush() wp_error: ' . $response->get_error_message()); + return; + } + + $code = wp_remote_retrieve_response_code($response); + if ($code === 200) { + update_option(self::OPT_QUEUE, $queue, false); + $s['last_sync'] = time(); + $s['sent_total'] = ($s['sent_total'] ?? 0) + count($batch); + $s['last_error'] = ''; + $s['connection_ok'] = true; + update_option(self::OPT_SETTINGS, $s); + } else { + $s['connection_ok'] = false; + $s['last_error'] = "Flush failed: API returned HTTP {$code}. Check URL and token."; + update_option(self::OPT_SETTINGS, $s); + error_log("[Honeypot] flush() API returned HTTP {$code}"); } }