有没有办法可以移动我的 Wordpress 域配置设置:
- 网址
- 家
从数据库 wp-options 表到 wp-config.php?
为了开发目的,我有时希望能够将我的实时数据库与我的本地主机同步,但是每次都必须更改数据库中的这些设置很烦人。
我正在使用 git,并且在我的存储库中有一个 wp-config.production.php 和 wp-config.testing.php,它们在部署时与 Capistrano 进行符号链接,所以理想情况下我想将我的域设置分别添加到这些文件中.
有没有办法可以移动我的 Wordpress 域配置设置:
从数据库 wp-options 表到 wp-config.php?
为了开发目的,我有时希望能够将我的实时数据库与我的本地主机同步,但是每次都必须更改数据库中的这些设置很烦人。
我正在使用 git,并且在我的存储库中有一个 wp-config.production.php 和 wp-config.testing.php,它们在部署时与 Capistrano 进行符号链接,所以理想情况下我想将我的域设置分别添加到这些文件中.
我想出了以下解决方案,似乎可以正常工作:
将以下内容添加到 wp-config.php
/** Domain settings (No trailing slash!)*/
define ('SITEURL', 'http://domain.dev');
define ('HOME', 'http://domain.dev');
然后在function.php中添加:
<?php
update_domain_settings();
/**
* update_domain_settings
*/
function update_domain_settings()
{
$domain_updated = false;
if(get_option('siteurl') != SITEURL) {
update_option('siteurl', SITEURL);
$domain_updated = true;
}
if(get_option('home') != HOME) {
update_option('home', HOME);
$domain_updated = true;
}
if($domain_updated === true) {
header("Location: " . home_url());
exit;
}
}
省略 SITEURL 和 HOME 中的尾部斜杠很重要,否则您最终会遇到递归重定向问题。