From 9bdb5c9648dfc2db11b8af45f84946201b5cdcad Mon Sep 17 00:00:00 2001 From: Jeff Spicher Date: Mon, 30 Mar 2026 22:21:27 -0400 Subject: [PATCH] Fix fatal error from undefined AjaxTracker::isUserAgentAIBot() method AIBotTracking::is_doing_ai_bot_tracking_this_request() calls AjaxTracker::isUserAgentAIBot() which does not exist in the bundled MatomoTracker library. This causes a fatal error (HTTP 500) on every frontend page load, even when AI bot tracking is disabled. Two changes: - Move the is_ai_bot_tracking_enabled() / is_tracking_enabled() check above the isUserAgentAIBot() call so the method returns early when the feature is off (which is the default) - Add a method_exists() guard around isUserAgentAIBot() as a safety net for when the feature is enabled but the method is still missing --- classes/WpMatomo/AIBotTracking.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/classes/WpMatomo/AIBotTracking.php b/classes/WpMatomo/AIBotTracking.php index 1e6ccb732..bb1965a48 100644 --- a/classes/WpMatomo/AIBotTracking.php +++ b/classes/WpMatomo/AIBotTracking.php @@ -195,6 +195,15 @@ private function is_doing_ai_bot_tracking_this_request() { return true; } + // Check settings early to avoid calling methods that may not exist + // in the bundled MatomoTracker library (e.g. isUserAgentAIBot). + if ( + ! $this->settings->is_ai_bot_tracking_enabled() + || ! $this->settings->is_tracking_enabled() + ) { + return false; + } + if ( ! $this->should_track_current_page() ) { return false; } @@ -206,13 +215,8 @@ private function is_doing_ai_bot_tracking_this_request() { $tracker = $this->get_tracker(); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase - if ( ! AjaxTracker::isUserAgentAIBot( $tracker->userAgent ) ) { - return false; - } - - if ( - ! $this->settings->is_ai_bot_tracking_enabled() - || ! $this->settings->is_tracking_enabled() + if ( ! method_exists( AjaxTracker::class, 'isUserAgentAIBot' ) + || ! AjaxTracker::isUserAgentAIBot( $tracker->userAgent ) ) { return false; }