|
12 | 12 |
|
13 | 13 | // ** MySQL settings - included in the Pantheon Environment ** //
|
14 | 14 | /** The name of the database for WordPress */
|
15 |
| -define('DB_NAME', $_ENV['DB_NAME']); |
| 15 | +define( 'DB_NAME', $_ENV['DB_NAME'] ); |
16 | 16 |
|
17 | 17 | /** MySQL database username */
|
18 |
| -define('DB_USER', $_ENV['DB_USER']); |
| 18 | +define( 'DB_USER', $_ENV['DB_USER'] ); |
19 | 19 |
|
20 | 20 | /** MySQL database password */
|
21 |
| -define('DB_PASSWORD', $_ENV['DB_PASSWORD']); |
| 21 | +define( 'DB_PASSWORD', $_ENV['DB_PASSWORD'] ); |
22 | 22 |
|
23 | 23 | /** MySQL hostname; on Pantheon this includes a specific port number. */
|
24 |
| -define('DB_HOST', $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT']); |
| 24 | +define( 'DB_HOST', $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT'] ); |
25 | 25 |
|
26 | 26 | /** Database Charset to use in creating database tables. */
|
27 |
| -define('DB_CHARSET', 'utf8mb4'); |
| 27 | +define( 'DB_CHARSET', 'utf8mb4' ); |
28 | 28 |
|
29 | 29 | /** The Database Collate type. Don't change this if in doubt. */
|
30 |
| -define('DB_COLLATE', ''); |
| 30 | +define( 'DB_COLLATE', '' ); |
31 | 31 |
|
32 | 32 | /**#@+
|
33 | 33 | * Authentication Unique Keys and Salts.
|
|
39 | 39 | *
|
40 | 40 | * @since 2.6.0
|
41 | 41 | */
|
42 |
| -define('AUTH_KEY', $_ENV['AUTH_KEY']); |
43 |
| -define('SECURE_AUTH_KEY', $_ENV['SECURE_AUTH_KEY']); |
44 |
| -define('LOGGED_IN_KEY', $_ENV['LOGGED_IN_KEY']); |
45 |
| -define('NONCE_KEY', $_ENV['NONCE_KEY']); |
46 |
| -define('AUTH_SALT', $_ENV['AUTH_SALT']); |
47 |
| -define('SECURE_AUTH_SALT', $_ENV['SECURE_AUTH_SALT']); |
48 |
| -define('LOGGED_IN_SALT', $_ENV['LOGGED_IN_SALT']); |
49 |
| -define('NONCE_SALT', $_ENV['NONCE_SALT']); |
| 42 | +define( 'AUTH_KEY', $_ENV['AUTH_KEY'] ); |
| 43 | +define( 'SECURE_AUTH_KEY', $_ENV['SECURE_AUTH_KEY'] ); |
| 44 | +define( 'LOGGED_IN_KEY', $_ENV['LOGGED_IN_KEY'] ); |
| 45 | +define( 'NONCE_KEY', $_ENV['NONCE_KEY'] ); |
| 46 | +define( 'AUTH_SALT', $_ENV['AUTH_SALT'] ); |
| 47 | +define( 'SECURE_AUTH_SALT', $_ENV['SECURE_AUTH_SALT'] ); |
| 48 | +define( 'LOGGED_IN_SALT', $_ENV['LOGGED_IN_SALT'] ); |
| 49 | +define( 'NONCE_SALT', $_ENV['NONCE_SALT'] ); |
50 | 50 | /**#@-*/
|
51 | 51 |
|
52 |
| -/** A couple extra tweaks to help things run well on Pantheon. **/ |
53 |
| -if (isset($_SERVER['HTTP_HOST'])) { |
54 |
| - // HTTP is still the default scheme for now. |
55 |
| - $scheme = 'http'; |
56 |
| - // If we have detected that the end use is HTTPS, make sure we pass that |
57 |
| - // through here, so <img> tags and the like don't generate mixed-mode |
58 |
| - // content warnings. |
59 |
| - if (isset($_SERVER['HTTP_USER_AGENT_HTTPS']) && $_SERVER['HTTP_USER_AGENT_HTTPS'] == 'ON') { |
60 |
| - $scheme = 'https'; |
61 |
| - $_SERVER['HTTPS'] = 'on'; |
62 |
| - } |
63 |
| - define('WP_HOME', $scheme . '://' . $_SERVER['HTTP_HOST']); |
64 |
| - define('WP_SITEURL', $scheme . '://' . $_SERVER['HTTP_HOST']); |
| 52 | +/** A couple extra tweaks to help things run well on Pantheon. */ |
| 53 | +if ( isset( $_SERVER['HTTP_HOST'] ) ) { |
| 54 | + // HTTP is still the default scheme for now. |
| 55 | + $scheme = 'http'; |
| 56 | + // If we have detected that the end use is HTTPS, make sure we pass that |
| 57 | + // through here, so <img> tags and the like don't generate mixed-mode |
| 58 | + // content warnings. |
| 59 | + if ( isset( $_SERVER['HTTP_USER_AGENT_HTTPS'] ) && $_SERVER['HTTP_USER_AGENT_HTTPS'] == 'ON' ) { |
| 60 | + $scheme = 'https'; |
| 61 | + $_SERVER['HTTPS'] = 'on'; |
| 62 | + } |
| 63 | + define( 'WP_HOME', $scheme . '://' . $_SERVER['HTTP_HOST'] ); |
| 64 | + define( 'WP_SITEURL', $scheme . '://' . $_SERVER['HTTP_HOST'] ); |
65 | 65 | }
|
66 | 66 | // Don't show deprecations; useful under PHP 5.5
|
67 |
| -error_reporting(E_ALL ^ E_DEPRECATED); |
| 67 | +error_reporting( E_ALL ^ E_DEPRECATED ); |
68 | 68 | /** Define appropriate location for default tmp directory on Pantheon */
|
69 |
| -define('WP_TEMP_DIR', sys_get_temp_dir()); |
| 69 | +define( 'WP_TEMP_DIR', sys_get_temp_dir() ); |
70 | 70 |
|
71 | 71 | // FS writes aren't permitted in test or live, so we should let WordPress know to disable relevant UI
|
72 |
| -if (in_array($_ENV['PANTHEON_ENVIRONMENT'], array( 'test', 'live' )) && ! defined('DISALLOW_FILE_MODS')) { |
73 |
| - define('DISALLOW_FILE_MODS', true); |
| 72 | +if ( in_array( $_ENV['PANTHEON_ENVIRONMENT'], array( 'test', 'live' ) ) && ! defined( 'DISALLOW_FILE_MODS' ) ) { |
| 73 | + define( 'DISALLOW_FILE_MODS', true ); |
74 | 74 | }
|
75 | 75 |
|
76 | 76 | /**
|
77 | 77 | * Set WP_ENVIRONMENT_TYPE according to the Pantheon Environment
|
78 | 78 | */
|
79 |
| -if (getenv('WP_ENVIRONMENT_TYPE') === false) { |
80 |
| - switch ($_ENV['PANTHEON_ENVIRONMENT']) { |
81 |
| - case 'live': |
82 |
| - putenv('WP_ENVIRONMENT_TYPE=production'); |
83 |
| - break; |
84 |
| - case 'test': |
85 |
| - putenv('WP_ENVIRONMENT_TYPE=staging'); |
86 |
| - break; |
87 |
| - default: |
88 |
| - putenv('WP_ENVIRONMENT_TYPE=development'); |
89 |
| - break; |
90 |
| - } |
| 79 | +if ( getenv( 'WP_ENVIRONMENT_TYPE' ) === false ) { |
| 80 | + switch ( $_ENV['PANTHEON_ENVIRONMENT'] ) { |
| 81 | + case 'live': |
| 82 | + putenv( 'WP_ENVIRONMENT_TYPE=production' ); |
| 83 | + break; |
| 84 | + case 'test': |
| 85 | + putenv( 'WP_ENVIRONMENT_TYPE=staging' ); |
| 86 | + break; |
| 87 | + default: |
| 88 | + putenv( 'WP_ENVIRONMENT_TYPE=development' ); |
| 89 | + break; |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +/** |
| 94 | + * Decode secrets.json and convert key/value pairs into environment variables. |
| 95 | + */ |
| 96 | +if ( file_exists( __DIR__ . '/wp-content/uploads/private/secrets.json' ) && isset( $_ENV['PANTHEON_ENVIRONMENT'] ) ) { |
| 97 | + // Decode as associative array... |
| 98 | + $json = json_decode( file_get_contents( __DIR__ . '/wp-content/uploads/private/secrets.json' ), true ); |
| 99 | + |
| 100 | + if ( ! empty( $json ) && ! empty( $_ENV['PANTHEON_ENVIRONMENT'] ) ) { |
| 101 | + // Loop over key/value pairs... |
| 102 | + foreach ( $json as $key => $value ) { |
| 103 | + // Define environment variable if one doesn't already exists... |
| 104 | + if ( ! isset( $_ENV[ $key ] ) ) { |
| 105 | + putenv( "{$key}={$value}" ); |
| 106 | + } |
| 107 | + } |
| 108 | + } |
91 | 109 | }
|
0 commit comments