$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://aitrackerstats.com/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 ); 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 '
'; 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 '
'; } 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); ?>
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()); } } ?>