← Back
Editing: class-cal-aiv-cdn-checker.php
<?php if (!defined('ABSPATH')) { exit; } class CAL_AIV_CDN_Checker { public static function render_warnings() { $warnings = array_merge( self::detect_cdn_headers(), self::detect_caching_plugins(), self::detect_htaccess_cache(), self::detect_headless() ); if (empty($warnings)) { return; } echo '<div class="awin-aiv-warnings">'; echo '<h3>' . esc_html('Caching & CDN Warnings') . '</h3>'; $unique = array(); foreach ($warnings as $warning) { $name = $warning['name']; if (isset($unique[$name])) { continue; } $unique[$name] = true; echo '<div class="awin-aiv-warning notice notice-warning inline">'; echo '<p><strong>' . esc_html(sprintf('Warning: %s Detected', $name)) . '</strong></p>'; echo '<p>' . esc_html('AI bot requests served from cache will not be tracked by this plugin.') . '</p>'; echo '<p>' . esc_html('For complete coverage, implement tracking at the CDN or cache layer.') . '</p>'; echo '</div>'; } echo '</div>'; } private static function detect_cdn_headers() { $cdn_signals = array( 'Cloudflare' => array('HTTP_CF_RAY', 'HTTP_CF_CACHE_STATUS'), 'Fastly' => array('HTTP_FASTLY_DEBUG_DIGEST', 'HTTP_X_SERVED_BY'), 'CloudFront' => array('HTTP_X_AMZ_CF_ID'), 'Akamai' => array('HTTP_X_AKAMAI_REQUEST_ID'), 'StackPath' => array('HTTP_X_STACKPATH_EDGE'), 'Generic CDN' => array('HTTP_X_CDN', 'HTTP_X_CACHE', 'HTTP_X_VARNISH'), ); $detected = array(); $via = isset($_SERVER['HTTP_VIA']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_VIA'])) : ''; if ($via !== '' && stripos($via, 'cloudfront') !== false) { $detected[] = array('name' => 'CloudFront'); } foreach ($cdn_signals as $name => $headers) { foreach ($headers as $header) { if (!empty($_SERVER[$header])) { $detected[] = array('name' => $name); break; } } } return $detected; } private static function detect_caching_plugins() { $detected = array(); if (function_exists('wp_cache_phase2') && defined('WPCACHEHOME')) { $detected[] = array('name' => 'WP Super Cache'); } if (function_exists('w3tc_pgcache_flush') || defined('W3TC')) { $detected[] = array('name' => 'W3 Total Cache'); } if (defined('WP_ROCKET_VERSION')) { $detected[] = array('name' => 'WP Rocket'); } if (defined('LSCWP_V') || class_exists('LiteSpeed_Cache')) { $detected[] = array('name' => 'LiteSpeed Cache'); } return $detected; } private static function detect_htaccess_cache() { $htaccess = ABSPATH . '.htaccess'; if (!is_readable($htaccess)) { return array(); } $contents = file_get_contents($htaccess); if ($contents === false) { return array(); } $patterns = array('WP Super Cache', 'W3TC', 'WP-Rocket', 'wp-rocket', 'LiteSpeed'); foreach ($patterns as $pattern) { if (stripos($contents, $pattern) !== false) { return array(array('name' => 'Page Cache (.htaccess rules)')); } } return array(); } private static function detect_headless() { $detected = array(); $nextjs_dirs = array(ABSPATH . '.next', ABSPATH . 'public/_next'); $gatsby_files = array(ABSPATH . 'public/page-data', ABSPATH . '.cache/default-html.html'); foreach (array_merge($nextjs_dirs, $gatsby_files) as $path) { if (file_exists($path)) { $detected[] = array('name' => 'Headless (Next.js/Gatsby)'); break; } } return $detected; } }
Save File
Cancel