Make WordPress Available from any domain

2019-05-18 22:01发布

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.

I have filter hooks for option_siteurl and option_home which is proving to be useful in almost all cases.

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.

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;
}

Thanks!

1条回答
Fickle 薄情
2楼-- · 2019-05-18 22:42

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.

查看更多
登录 后发表回答