GeoAI_404 class handles 404 error monitoring and logging for the GEO AI plugin.
Overview
This class provides opt-in 404 error tracking with configurable retention controls. It logs broken URLs, referrers, and IP addresses to help identify and fix site issues. Namespace:GeoAI\CoreFile:
includes/class-geoai-404.php
Class Methods
get_instance()
Get the singleton instance of the 404 monitor.GeoAI_404 — Singleton instance
log_404()
Logs a 404 error to the database if monitoring is enabled.template_redirect
Behavior:
- Only runs on 404 pages (
is_404()) - Checks if monitoring is enabled in settings
- Logs URL, referrer, IP address, and timestamp
- Automatically cleans up old logs based on retention settings
get_client_ip()
Retrieves the client IP address with proxy support.string — Sanitized IP address
Detection Order:
HTTP_CLIENT_IP(proxy)HTTP_X_FORWARDED_FOR(load balancer)REMOTE_ADDR(direct connection)
cleanup_old_logs()
Removes 404 logs older than the configured retention period.Configurable via:
geoai_404_settings['retention']
Called automatically after each new 404 log entry.
Configuration
Enable 404 monitoring via Settings → GEO AI → Redirects & 404. Option Key:geoai_404_settings
Usage Examples
Check if monitoring is enabled
Query recent 404s
Get 404 count by URL
Manually trigger cleanup
Privacy Considerations
Best Practices:- Set reasonable retention periods (7-30 days)
- Disclose IP logging in your privacy policy
- Consider anonymizing IPs for GDPR compliance
- Disable monitoring if not actively using the data
Performance
The 404 monitor is designed for minimal overhead:- Single database INSERT per 404 (less than 5ms)
- No queries on successful page loads
- Automatic cleanup prevents table bloat
- Indexed timestamp column for fast queries
Related
Redirects
Redirect manager class documentation
404 Monitor Feature
User guide for 404 monitoring
Admin Class
Settings management for 404 options
Architecture
Plugin structure and database schema