function redirect_us_users() { if ( is_admin() ) return; // Lista botów do ignorowania $excluded_bots = [ // Wyszukiwarki 'Googlebot', 'GPTBot', 'ChatGPT-User', 'bingbot', 'Slurp', 'DuckDuckBot', 'Baiduspider', 'YandexBot', 'Sogou', 'Exabot', // Social Media 'facebookexternalhit', 'Facebot', 'Twitterbot', 'LinkedInBot', 'Pinterest', 'WhatsApp', 'TelegramBot', 'Slackbot', 'Discordbot', // AI i inne Crawlery 'ClaudeBot', 'CCBot', 'anthropic-ai', 'Applebot', // Narzędzia SEO 'AhrefsBot', 'SemrushBot', 'DotBot', 'MJ12bot' ]; $user_agent = $_SERVER['HTTP_USER_AGENT'] ?? ''; foreach ( $excluded_bots as $bot ) { if ( stripos( $user_agent, $bot ) !== false ) { return; // To bot, wpuszczamy bez przekierowania } } // Reszta logiki bez zmian if ( session_status() == PHP_SESSION_NONE ) : session_start(); endif; if ( ! isset( $_SESSION['country_code'] ) ) : $ip_address = $_SERVER['REMOTE_ADDR']; $geolocation_data = wp_remote_get( "http://ip-api.com/json/{$ip_address}", [ 'timeout' => 2 ] ); if ( is_wp_error( $geolocation_data ) ) : return; endif; $body = json_decode( wp_remote_retrieve_body( $geolocation_data ), true ); $_SESSION['country_code'] = $body['countryCode'] ?? ''; endif; if ( $_SESSION['country_code'] === 'US' ) : wp_redirect( home_url( '/us/' ) ); exit; endif; } add_action( 'template_redirect', 'redirect_us_users' );