问题描述
我正在尝试创建一个插件,允许从任何域访问 WordPress,当然前提是该域指向它.
I'm trying to create a plugin that will allow WordPress to be accessed from any domain, of course provided that the domain is pointed to it.
我有用于 option_siteurl 和 option_home 的过滤器钩子,事实证明这在几乎所有情况下都很有用.
I have filter hooks for option_siteurl and option_home which is proving to be useful in almost all cases.
但是,它似乎不适用于附加到帖子的图像,也不适用于主题的标题图像.看起来对于这些,它采用 options -> siteurl 的数据库值.
However, it doesn't appear to be working for images that are attached to a post nor for header images of themes. It looks like for these, it's taking the database value of options -> siteurl.
我尝试过 update_option,但这也没有奏效.
I've tried update_option, but that hasn't done the trick either.
我正在使用以下代码获取主机:
I'm using the following code to get the host:
public function getGoodURL() {
$scheme = ($_SERVER["SERVER_PORT"] == 80 ? "http://" : "https://");
$host = $_SERVER["HTTP_HOST"];
return $scheme.$host;
}
谢谢!
推荐答案
可能想尝试将站点 url 配置放在配置文件中,即:
Might want to try putting the site url configuration in the config file i.e.:
$domain = sprintf('%s://%s',
$_SERVER['SERVER_PORT'] == 80 ? 'http' : 'https',
$_SERVER['SERVER_NAME']);
define('WP_SITEURL', $domain);
define('WP_HOME', $domain);
这样,您的网站将始终接受当前域.
That way, your site will always accept the current domain.
这篇关于使任何域都可以使用 WordPress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!