Skip to content

Commit fadeab4

Browse files
committed
Clean up, add filters where WP_ENV set
1 parent f5834bc commit fadeab4

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

wp-config.load.php

+14-12
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ function s24_load_environment_config() {
1212
/**
1313
* Setup environment
1414
*/
15-
16-
// We need to set $argv as global to be able to access it
17-
global $argv;
18-
1915
// Set env if set via environment variable
2016
if (getenv('WP_ENV') !== false) {
2117
define('WP_ENV', preg_replace('/[^a-z]/', '', getenv('WP_ENV')));
@@ -24,10 +20,13 @@ function s24_load_environment_config() {
2420
// Set env via --env=<environment> argument if running via WP-CLI
2521
if (!defined('WP_ENV') && PHP_SAPI == "cli" && defined('WP_CLI_ROOT')) {
2622

23+
// We need to set $argv as global to be able to access it
24+
global $argv;
25+
2726
if (isset($argv)) {
2827
foreach ($argv as $arg) {
2928
if (preg_match('/--env=(.+)/', $arg, $m)) {
30-
define('WP_ENV', $m[1]);
29+
define('WP_ENV', preg_replace('/[^a-z]/', '', $m[1]));
3130
break;
3231
}
3332
}
@@ -54,6 +53,10 @@ function s24_load_environment_config() {
5453
// Load environments
5554
require __DIR__ . '/wp-config.env.php';
5655

56+
if (!isset($env) || !is_array($env)) {
57+
throw new Exception('$env array not detected, you must set this in wp-config.env.php');
58+
}
59+
5760
// Set environment constants
5861
if (defined('WP_ENV')) {
5962
if (isset($env[WP_ENV])) {
@@ -76,7 +79,7 @@ function s24_load_environment_config() {
7679
$match = '/' . str_replace('*', '([^.]+)', preg_quote($domain, '/')) . '/';
7780
if (preg_match($match, $hostname, $m)) {
7881
if (!defined('WP_ENV')) {
79-
define('WP_ENV', $environment);
82+
define('WP_ENV', preg_replace('/[^a-z]/', '', $environment));
8083
}
8184
define('WP_ENV_DOMAIN', str_replace('*', $m[1], $domain));
8285
if (isset($env_vars['ssl'])) {
@@ -94,7 +97,7 @@ function s24_load_environment_config() {
9497
foreach ($domain as $domain_name) {
9598
if ($hostname === $domain_name) {
9699
if (!defined('WP_ENV')) {
97-
define('WP_ENV', $environment);
100+
define('WP_ENV', preg_replace('/[^a-z]/', '', $environment));
98101
}
99102
define('WP_ENV_DOMAIN', $domain_name);
100103
if (isset($env_vars['ssl'])) {
@@ -112,11 +115,6 @@ function s24_load_environment_config() {
112115
if (!defined('WP_ENV')) {
113116
throw new Exception("Cannot determine current environment");
114117
}
115-
116-
/**
117-
* Define WordPress Site URLs
118-
*/
119-
120118
if (!defined('WP_ENV_DOMAIN')) {
121119
throw new Exception("Cannot determine current environment domain, make sure this is set in wp-config.env.php");
122120
}
@@ -126,6 +124,10 @@ function s24_load_environment_config() {
126124
if (WP_ENV_SSL && (!defined('FORCE_SSL_ADMIN'))) {
127125
define('FORCE_SSL_ADMIN', true);
128126
}
127+
128+
/**
129+
* Define WordPress Site URLs
130+
*/
129131
$protocol = (WP_ENV_SSL) ? 'https://' : 'http://';
130132
$path = (defined('WP_ENV_PATH')) ? '/' . trim(WP_ENV_PATH, '/') : '';
131133

0 commit comments

Comments
 (0)