Monthly Archives: May 2025

国内限制访问

// 添加到主题的functions.php文件 add_action(‘init’, ‘restrict_chinese_access’); function restrict_chinese_access() { // 跳过管理员后台 if (is_admin()) { // 获取访客IP $visitor_ip = $_SERVER[‘REMOTE_ADDR’]; // 江苏IP段示例(需要替换为实际江苏IP段) $jiangsu_ips = [ ‘58.208.0.0-58.223.255.255’, ‘114.212.0.0-114.215.255.255’, // 添加更多江苏IP段 ]; $allowed = false; foreach ($jiangsu_ips as $ip_range) { if (ip_in_range($visitor_ip, $ip_range)) { $allowed = true; break; } } // 非江苏IP禁止访问后台 if (!$allowed) { wp_die(‘Access Denied’, 403); } return; […]