1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
global $locale; |
|
|
|
|
4
|
|
|
|
5
|
|
|
$root_dir = dirname( dirname( __DIR__ ) ); |
6
|
|
|
|
7
|
|
|
// ** Use root_dir to define ABSPATH if it has not been defined yet ** // |
8
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
9
|
|
|
define( 'ABSPATH', sprintf( '%s/public', $root_dir ) ); |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
// ** Load .env file and require DB and URL-related settings to be set ** // |
13
|
|
|
$dotenv = sprintf( '%s/.env', $root_dir ); |
14
|
|
|
if ( ! file_exists( $dotenv ) ) { |
15
|
|
|
die( sprintf( 'Please make sure you have created "%s" file containing WordPress settings', $dotenv ) ); |
16
|
|
|
} |
17
|
|
|
$dotenv = new Dotenv\Dotenv( $root_dir ); |
18
|
|
|
$dotenv->load(); |
19
|
|
|
$dotenv->required( [ 'DB_NAME', 'DB_USER', 'DB_PASSWORD', 'WP_HOME', 'WP_SITEURL' ] )->notEmpty(); |
20
|
|
|
|
21
|
|
|
// ** Authentication Unique Keys and Salts ** // |
22
|
|
|
define( 'AUTH_KEY', getenv( 'AUTH_KEY' ) ); |
23
|
|
|
define( 'SECURE_AUTH_KEY', getenv( 'SECURE_AUTH_KEY' ) ); |
24
|
|
|
define( 'LOGGED_IN_KEY', getenv( 'LOGGED_IN_KEY' ) ); |
25
|
|
|
define( 'NONCE_KEY', getenv( 'NONCE_KEY' ) ); |
26
|
|
|
define( 'AUTH_SALT', getenv( 'AUTH_SALT' ) ); |
27
|
|
|
define( 'SECURE_AUTH_SALT', getenv( 'SECURE_AUTH_SALT' ) ); |
28
|
|
|
define( 'LOGGED_IN_SALT', getenv( 'LOGGED_IN_SALT' ) ); |
29
|
|
|
define( 'NONCE_SALT', getenv( 'NONCE_SALT' ) ); |
30
|
|
|
|
31
|
|
|
// ** Load additional settings & tweaks conditionnaly, using current WordPress environment ** // |
32
|
|
|
define( 'WP_ENV', getenv( 'WP_ENV' ) ?: 'development' ); |
33
|
|
|
$dotenv_file = sprintf( '%s/environments/%s.php', __DIR__, WP_ENV ); |
34
|
|
|
if ( file_exists( $dotenv_file ) ) { |
35
|
|
|
require_once $dotenv_file; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// ** URLs ** // |
39
|
|
|
define( 'WP_HOME', getenv( 'WP_HOME' ) ); |
40
|
|
|
define( 'WP_SITEURL', getenv( 'WP_SITEURL' ) ); |
41
|
|
|
|
42
|
|
|
// ** Primary language ** // |
43
|
|
|
if ( empty( getenv( 'WPLANG' ) ) ) { |
44
|
|
|
define( 'WPLANG', $locale ); |
45
|
|
|
} else { |
46
|
|
|
define( 'WPLANG', getenv( 'WPLANG' ) ); |
47
|
|
|
$locale = WPLANG; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// ** If true, includes the wp-content/advanced-cache.php script ** // |
51
|
|
|
define( 'WP_CACHE', getenv( 'WP_CACHE' ) ); |
52
|
|
|
|
53
|
|
|
// ** MariaDB / MySQL server settings ** // |
54
|
|
|
define( 'DB_HOST', getenv( 'DB_HOST' ) ?: 'localhost' ); |
55
|
|
|
define( 'DB_NAME', getenv( 'DB_NAME' ) ); |
56
|
|
|
define( 'DB_USER', getenv( 'DB_USER' ) ); |
57
|
|
|
define( 'DB_PASSWORD', getenv( 'DB_PASSWORD' ) ); |
58
|
|
|
define( 'DB_CHARSET', getenv( 'DB_CHARSET' ) ?: 'utf8mb4' ); |
59
|
|
|
define( 'DB_COLLATE', '' ); |
60
|
|
|
|
61
|
|
|
$table_prefix = getenv( 'DB_PREFIX' ) ?: 'wp_'; |
62
|
|
|
|
63
|
|
|
// ** Defines a default theme for new sites, also used as fallback for a broken theme. ** // |
64
|
|
|
define( 'WP_DEFAULT_THEME', getenv( 'WP_DEFAULT_THEME' ) ?: 'mr-press-child-theme' ); |
65
|
|
|
|
66
|
|
|
// ** Performance tweaks ** // |
67
|
|
|
define( 'WP_MEMORY_LIMIT', getenv( 'WP_MEMORY_LIMIT' ) ); |
68
|
|
|
define( 'WP_MAX_MEMORY_LIMIT', getenv( 'WP_MAX_MEMORY_LIMIT' ) ); |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Disable WP_CRON unless running thtough WordPress cron job |
72
|
|
|
* For further details read this article: https://www.lucasrolff.com/wordpress/why-wp-cron-sucks |
73
|
|
|
*/ |
74
|
|
|
define( 'DISABLE_WP_CRON', getenv( 'DISABLE_WP_CRON' ) ?: ( ! isset( $argv[ 1 ] ) || 'DOING_CRON' !== $argv[ 1 ] ) ); |
75
|
|
|
|
76
|
|
|
// ** Additional settings ** // |
77
|
|
|
define( 'DISALLOW_FILE_EDIT', getenv( 'DISALLOW_FILE_EDIT' ) ?: true ); |
78
|
|
|
define( 'WP_ALLOW_REPAIR', getenv( 'WP_ALLOW_REPAIR' ) ?: false ); |
79
|
|
|
define( 'AUTOMATIC_UPDATER_DISABLED', getenv( 'AUTOMATIC_UPDATER_DISABLED' ) ?: true ); |
80
|
|
|
|
81
|
|
|
// ** Redefine default WordPress content (themes, plugins etc) folder location ** // |
82
|
|
|
define( 'WP_CONTENT_DIR', sprintf( '%s/%s', $root_dir, 'wp-content' ) ); |
83
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.