Following on from the comments thread...
Here's a method I've used for a long time for handling the 'not ideal' scenario of different configurations between environments. The following is a heavily cut-down representation of wp-config.php
but it demonstrates the idea...
<?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
As you can see I prefer to assume that 'else' means the live settings, just for safety's sake.
I have also used versions of this method where the definition of the environment is actually in a separate file that is included e.g. replacing define('BCUK_SITE_ENV', 'LOCAL');
with an include statement that pulls in a file (something like 'environment_config.inc.php') in which there is just one line that is used to change the environment constant. That way you can always push your wp-config.php between environments without actually affecting which environment is currently configured.
In all the above, you could easily adapt it to either base your logic directly on the value of $_SERVER['HTTP_HOST']
or to configure your environment variable/constant on the value of $_SERVER['HTTP_HOST']
.
Hope that all makes sense. It's definitely not the only way, but hopefully it demonstrates that it is definitely a robust and workable method. Whether it works for your particular plugin development scenario only you will know.
SITE_ENVIRONMENT
constant forlocal | staging | live
and have variable settings dependent on the environment. Ideally you would define the constant elsewhere (and then include/fetch it) so that you can still push your wp-config between environments without overwriting the environment value. Note: Some hosts - especially dedicated Wordpress managed hosts - don't let you manage wp-config. They always supply workarounds though.