下面是评论线程。。。
这里有一种方法我已经使用了很长时间,用于处理不同环境之间不同配置的“不理想”场景。以下是对wp-config.php
但它证明了这个想法。。。
<?php
/**
* The base configurations of the WordPress.
*
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
* by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
*
* This file is used by the wp-config.php creation script during the
* installation. You don\'t have to use the web site, you can just copy this file
* to "wp-config.php" and fill in the values.
*
* @package WordPress
*/
/** Environment: LOCAL || STAGING || LIVE **/
define(\'BCUK_SITE_ENV\', \'LOCAL\');
/** System/CMS defaults **/
e.g. settings that are common across all environments
if (BCUK_SITE_ENV == "LOCAL"):
e.g. different db settings, memory limits, paths, etc.
elseif (BCUK_SITE_ENV == "STAGING"):
e.g. different db settings, memory limits, paths, etc.
else:
e.g. different db settings, memory limits, paths, etc.
endif;
// Remaining wp-config bits go here e.g. salts, lang settings, etc
正如你所看到的,为了安全起见,我宁愿假设“else”是指现场设置。
我还使用了此方法的版本,其中环境的定义实际上包含在单独的文件中,例如替换define(\'BCUK_SITE_ENV\', \'LOCAL\');
使用include语句拉入一个文件(类似于“environment\\u config.股份有限公司.php”),其中只有一行用于更改环境常量。这样,您就可以随时推送您的wp配置。环境之间的php,而不影响当前配置的环境。
综上所述,您可以轻松地将其调整为直接基于$_SERVER[\'HTTP_HOST\']
或在以下值上配置环境变量/常量$_SERVER[\'HTTP_HOST\']
.
希望一切都有意义。这肯定不是唯一的方法,但希望它能证明这绝对是一种健壮且可行的方法。它是否适用于特定的插件开发场景,只有您自己知道。