我在Wordpress中使用带有插件wp最快缓存的缓存系统。它的工作正常,但我有一些自定义要求。我的网站上有一些特定地区的数据。我们可以从右上角的下拉菜单切换区域。它可以在安装了WordPress的子域上使用。
基本上,我在wp-config.php
文件中添加了几行代码,代码为
function define_network_constant() {
$servername = $_SERVER['SERVER_NAME'];
$protocol = $_SERVER['REQUEST_SCHEME'];
$host = explode('.', $servername);
$maindomain = null;
$subdomain = 'us';
if (count($host) >= 3) {
$subdomain = $host[0];
$maindomain = $host[1];
} else {
$maindomain = $host[0];
}
global $region_config;
setcookie('WP_REGION', $subdomain, time() + (1000), "/"); // 86400 = 1 day
define('WP_HOME', "{$protocol}://{$servername}");
define('WP_SITEURL', "{$protocol}://{$servername}");
define('WP_REGION', $subdomain);
$region_config = ['protocol' => $protocol, 'subdomain' => $subdomain, 'maindomain' => get_main_domain($servername)];
}
它从网址中获取子域名,例如fr
za
等,并设置常量WP_REGION
和WP_SITEURL
。
如果我不使用缓存,一切都是完美的。但是,当我启用缓存时,它不会更改下拉菜单中的区域。所以基本上我想从缓存中绕开这些常量。
我也尝试过使用Cookies并设置管理员的排除规则,但是不起作用。
可以存档吗? 谢谢您的提前。