-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.php
151 lines (135 loc) · 4.42 KB
/
config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
define('_ROOT_FOLDER_', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('ENV_FOLDER', __DIR__ . DIRECTORY_SEPARATOR . 'env' . DIRECTORY_SEPARATOR);
//Add Composer Autoloader
require __DIR__ . '/' . 'vendor/autoload.php';
//load .env
if (file_exists(ENV_FOLDER . '.env')) {
$dotenv = \Dotenv\Dotenv::createImmutable(ENV_FOLDER);
$dotenv->load();
try {
$dotenv->required([
'DB_NAME',
'DB_USER',
'DB_PREFIX',
])->notEmpty();
$dotenv->required('APP_ENV')->allowedValues(['local', 'dev', 'stag', 'prod']);
$dotenv->required('ENABLE_HTTPS')->allowedValues(['ON', 'OFF']);
$dotenv->required('IN_MAINTENANCE')->allowedValues(['ON', 'OFF']);
} catch (\Dotenv\Exception\ValidationException $error) {
die($error->getMessage());
//if we don't handle it, we end up with server error 500, which is extra steps to inspect server log
}
} else {
die('there was an error finding the .env file at /path/to/env/.env');
}
//load helper ENV files to prevent repeating code
if (file_exists(ENV_FOLDER . $_ENV['APP_ENV'] . '.php')) {
require_once ENV_FOLDER . $_ENV['APP_ENV'] . '.php';
} else {
die('there was an error finding a php ENV file at at /path/to/env/{env}.php');
}
/** IS MAINTENANCE MODE */
define('IN_MAINTENANCE', $_ENV['IN_MAINTENANCE']);
/**
* Set the WordPress global environment via constant WP_ENVIRONMENT_TYPE
* Allowed values: 'local', 'development', 'staging', 'production'
*
* reference:
* - https://make.wordpress.org/core/2020/07/24/new-wp_get_environment_type-function-in-wordpress-5-5/
*
* This environment is fetch via the inbuilt WP function:
* - wp_get_environment_type()
*
* This function is found in: wp-includes/load.php
*/
switch ($_ENV['APP_ENV']) {
case 'prod':
define('WP_ENVIRONMENT_TYPE', 'production');
break;
case 'stag':
define('WP_ENVIRONMENT_TYPE', 'staging');
break;
case 'dev':
define('WP_ENVIRONMENT_TYPE', 'development');
break;
case 'local':
define('WP_ENVIRONMENT_TYPE', 'local');
break;
default:
define('WP_ENVIRONMENT_TYPE', 'production');
}
/**
* Authentication Unique Keys and Salts.
*
* TODO: Change in env/.env file
* Generate from here https://api.wordpress.org/secret-key/1.1/salt/
*/
define('AUTH_KEY', $_ENV['AUTH_KEY']);
define('SECURE_AUTH_KEY', $_ENV['SECURE_AUTH_KEY']);
define('LOGGED_IN_KEY', $_ENV['LOGGED_IN_KEY']);
define('NONCE_KEY', $_ENV['NONCE_KEY']);
define('AUTH_SALT', $_ENV['AUTH_SALT']);
define('SECURE_AUTH_SALT', $_ENV['SECURE_AUTH_SALT']);
define('LOGGED_IN_SALT', $_ENV['LOGGED_IN_SALT']);
define('NONCE_SALT', $_ENV['NONCE_SALT']);
/**
* Database credentials
*/
define('DB_NAME', $_ENV['DB_NAME']); //TODO: change in env/.env
define('DB_USER', $_ENV['DB_USER']); //TODO: change in env/.env
define('DB_PASSWORD', $_ENV['DB_PASSWORD']); //TODO: change in env/.env
$table_prefix = $_ENV['DB_PREFIX']; //TODO: change in env/.env
/**
* HTTPS Status | Enable via .env file, set constant ENABLE_HTTPS
*/
$http_scheme = 'http';
if ((isset($_ENV['ENABLE_HTTPS']) && ($_ENV['ENABLE_HTTPS'] == 'ON'))) {
$http_scheme = 'https';
$_SERVER['HTTPS'] = 'on';
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
}
define('SITE_URL', $http_scheme . '://' . $_SERVER['HTTP_HOST']); //TODO: If this does not work for you, put it manually
define('WP_HOME', SITE_URL);
define('WP_SITEURL', SITE_URL . '/wp/');
// Change placement of wp-content
define('WP_CONTENT_DIR', dirname(__FILE__) . '/public/wp-content');
define('WP_CONTENT_URL', SITE_URL . '/wp-content');
define('FS_CHMOD_FILE', 0644);
define('FS_CHMOD_DIR', 0755);
/**
* A convenience function to output values of Variables and/or Arrays in a more readable manner
*
* @param $array
* @param bool $die
* @param bool $print
*
* @return string
*/
function pp($array, $print = true, $die = false) //print or echo
{
$result = '<pre>';
$result .= print_r($array, true);
$result .= '</pre><br/>';
if ($print) {
echo $result;
if ($die) {
die;
}
}
return $result;
}
/**
* @param $array
* @param mixed $print
*/
function ppd($array, $print = true) //print and die
{
pp($array, $print, true);
}
// That's all, stop editing! Happy blogging.
/** Absolute path to the WordPress directory. */
if (!defined('ABSPATH')) {
define('ABSPATH', dirname(__FILE__) . '/');
}