slug) && 'aitrackerstats' === $item->slug) { return true; } return $update; } function AiTracker_is_system_request($request_path) { // Consolidated regex for better performance (single check instead of 6) return (bool) preg_match('/(^|\/)(wp-admin|wp-login|wp-cron|wp-json|wp-includes|wp-content)(\/|$)/i', $request_path); } function push_to_analytics() { $request_path = isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : false; if (empty($_SERVER['HTTP_USER_AGENT'])) { return; } if (!AiTracker_is_system_request($request_path)) { $site_url = home_url(); $hostname = wp_parse_url($site_url, PHP_URL_HOST); $body = wp_json_encode(array( 'hostname' => $hostname, 'path' => $request_path, 'useragent' => sanitize_text_field($_SERVER['HTTP_USER_AGENT']), 'version' => $GLOBALS['PLUGIN_VERSION'], )); $headers = array( 'Content-Type' => 'application/x-www-form-urlencoded', 'user-agent' => 'AiTrackerStats/' . $hostname . '/WordPress/' . $GLOBALS['PLUGIN_VERSION'], ); // Non-blocking request to prevent server delays $response = wp_remote_post('https://aitrackerstats.com/api/aitracker', array( 'body' => $body, 'headers' => $headers, 'blocking' => false, // Non-blocking: don't wait for response 'sslverify' => true, // Maintain security )); // Log errors for debugging (non-blocking requests can still fail during initiation) if (is_wp_error($response)) { error_log('AiTrackerStats tracking error: ' . $response->get_error_message()); } } } function aitrackerstats_enqueue_styles() { wp_enqueue_style( 'aitrackerstats-admin-styles', plugins_url('admin-styles.css', __FILE__) ); } add_action('admin_enqueue_scripts', 'aitrackerstats_enqueue_styles'); function aitrackerstats_sidebar_menu() { add_menu_page( 'A.I. Tracking Stats', 'A.I. Tracking Stats', 'manage_options', 'ai-tracking-stats', 'custom_menu_page_callback', plugins_url('ai.svg', __FILE__), 200 ); add_submenu_page( 'ai-tracking-stats', 'Verification Code', 'Verification Code', 'manage_options', 'ai-tracking-verification-code', 'show_verification_code' ); } function show_verification_code() { $site_url = home_url(); $hostname = wp_parse_url($site_url, PHP_URL_HOST); $base = base64_encode($hostname); echo '
Your Domain is : ' . esc_html($hostname) . '
'; echo 'Your verification code is: ' . esc_html($base) . '
'; echo 'Please use these when registering your site on https://aitrackerstats.com/app/login.
'; echo '