@@ -12,10 +12,6 @@ function s24_load_environment_config() {
12
12
/**
13
13
* Setup environment
14
14
*/
15
-
16
- // We need to set $argv as global to be able to access it
17
- global $ argv ;
18
-
19
15
// Set env if set via environment variable
20
16
if (getenv ('WP_ENV ' ) !== false ) {
21
17
define ('WP_ENV ' , preg_replace ('/[^a-z]/ ' , '' , getenv ('WP_ENV ' )));
@@ -24,10 +20,13 @@ function s24_load_environment_config() {
24
20
// Set env via --env=<environment> argument if running via WP-CLI
25
21
if (!defined ('WP_ENV ' ) && PHP_SAPI == "cli " && defined ('WP_CLI_ROOT ' )) {
26
22
23
+ // We need to set $argv as global to be able to access it
24
+ global $ argv ;
25
+
27
26
if (isset ($ argv )) {
28
27
foreach ($ argv as $ arg ) {
29
28
if (preg_match ('/--env=(.+)/ ' , $ arg , $ m )) {
30
- define ('WP_ENV ' , $ m [1 ]);
29
+ define ('WP_ENV ' , preg_replace ( ' /[^a-z]/ ' , '' , $ m [1 ]) );
31
30
break ;
32
31
}
33
32
}
@@ -54,6 +53,10 @@ function s24_load_environment_config() {
54
53
// Load environments
55
54
require __DIR__ . '/wp-config.env.php ' ;
56
55
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
+
57
60
// Set environment constants
58
61
if (defined ('WP_ENV ' )) {
59
62
if (isset ($ env [WP_ENV ])) {
@@ -76,7 +79,7 @@ function s24_load_environment_config() {
76
79
$ match = '/ ' . str_replace ('* ' , '([^.]+) ' , preg_quote ($ domain , '/ ' )) . '/ ' ;
77
80
if (preg_match ($ match , $ hostname , $ m )) {
78
81
if (!defined ('WP_ENV ' )) {
79
- define ('WP_ENV ' , $ environment );
82
+ define ('WP_ENV ' , preg_replace ( ' /[^a-z]/ ' , '' , $ environment) );
80
83
}
81
84
define ('WP_ENV_DOMAIN ' , str_replace ('* ' , $ m [1 ], $ domain ));
82
85
if (isset ($ env_vars ['ssl ' ])) {
@@ -94,7 +97,7 @@ function s24_load_environment_config() {
94
97
foreach ($ domain as $ domain_name ) {
95
98
if ($ hostname === $ domain_name ) {
96
99
if (!defined ('WP_ENV ' )) {
97
- define ('WP_ENV ' , $ environment );
100
+ define ('WP_ENV ' , preg_replace ( ' /[^a-z]/ ' , '' , $ environment) );
98
101
}
99
102
define ('WP_ENV_DOMAIN ' , $ domain_name );
100
103
if (isset ($ env_vars ['ssl ' ])) {
@@ -112,11 +115,6 @@ function s24_load_environment_config() {
112
115
if (!defined ('WP_ENV ' )) {
113
116
throw new Exception ("Cannot determine current environment " );
114
117
}
115
-
116
- /**
117
- * Define WordPress Site URLs
118
- */
119
-
120
118
if (!defined ('WP_ENV_DOMAIN ' )) {
121
119
throw new Exception ("Cannot determine current environment domain, make sure this is set in wp-config.env.php " );
122
120
}
@@ -126,6 +124,10 @@ function s24_load_environment_config() {
126
124
if (WP_ENV_SSL && (!defined ('FORCE_SSL_ADMIN ' ))) {
127
125
define ('FORCE_SSL_ADMIN ' , true );
128
126
}
127
+
128
+ /**
129
+ * Define WordPress Site URLs
130
+ */
129
131
$ protocol = (WP_ENV_SSL ) ? 'https:// ' : 'http:// ' ;
130
132
$ path = (defined ('WP_ENV_PATH ' )) ? '/ ' . trim (WP_ENV_PATH , '/ ' ) : '' ;
131
133
0 commit comments