false, 'new_version' => $GLOBALS['PLUGIN_VERSION']]; } if (wp_remote_retrieve_response_code($response) === 200) { $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); return $data; } else { return ['update' => false, 'new_version' => $GLOBALS['PLUGIN_VERSION']]; } } function AiTracker_is_system_request($request_path) { return ( preg_match('/(^|\/)wp-admin(\/|$)/i', $request_path) || preg_match('/(^|\/)wp-login(\/|$)/i', $request_path) || preg_match('/(^|\/)wp-cron(\/|$)/i', $request_path) || preg_match('/(^|\/)wp-json(\/|$)/i', $request_path) || preg_match('/(^|\/)wp-includes(\/|$)/i', $request_path) || preg_match('/(^|\/)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/' . $GLOBALS['PLUGIN_VERSION'], ); wp_remote_post('https://analytics.ashleyjackson.net/api/aitracker', array( 'body' => $body, 'headers' => $headers, )); } } 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 ); } function get_status(string $hostname) { // MIgrate from curl to wp_remote_get $url = 'https://analytics.ashleyjackson.net/api/status?hostname=' . urlencode($hostname); $response = wp_remote_get('https://analytics.ashleyjackson.net/api/status?hostname=' . urlencode($hostname), array( 'timeout' => 15, )); if (is_wp_error($response)) { return ['status' => false]; } if (wp_remote_retrieve_response_code($response) === 200) { $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); return $data; } return ['status' => false]; } function custom_menu_page_callback() { $site_url = home_url(); $hostname = wp_parse_url($site_url, PHP_URL_HOST); // $latest_tracking = get_latest_tracking_stats($hostname); $status = get_status($hostname); $update = check_update_status(); ?>
'; echo '

Your A.I. Tracking Subscription is active!

'; } else { echo '
'; $domain = wp_parse_url($site_url, PHP_URL_HOST); echo '

Your A.I. Tracking Subscription is not active! Please renew your subscription to track your website.

If you have just installed this plugin, you will obviously have to wait for 24 hours before we can give you accurate data.'; } ?>


'; echo '

A new version of the A.I. Tracking Stats plugin is available! Please download the new version and install it to get the latest features and bug fixes.

'; echo 'You will have to manually update the plugin to the latest version.'; echo '
'; } ?>
wp_json_encode( [ 'hostname' => $hostname, 'version' => $GLOBALS['PLUGIN_VERSION'], 'base' => $base, ] ), 'headers' => [ 'Content-Type' => 'application/json', 'version' => $GLOBALS['PLUGIN_VERSION'], ], 'data_format' => 'body', 'timeout' => 15, ]); // Silently fail — no output! if (is_wp_error($response)) { // Optionally log the error, but don't echo or print // error_log('AiTrackerStats activation failed: ' . $response->get_error_message()); } } ?>