application.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * Your base production configuration goes in this file. Environment-specific
  4. * overrides go in their respective config/environments/{{WP_ENV}}.php file.
  5. *
  6. * A good default policy is to deviate from the production config as little as
  7. * possible. Try to define as much of your configuration in this file as you
  8. * can.
  9. */
  10. use Roots\WPConfig\Config;
  11. /**
  12. * Directory containing all of the site's files
  13. *
  14. * @var string
  15. */
  16. $root_dir = dirname(__DIR__);
  17. /**
  18. * Document Root
  19. *
  20. * @var string
  21. */
  22. $webroot_dir = $root_dir . '/web';
  23. /**
  24. * Expose global env() function from oscarotero/env
  25. */
  26. Env::init();
  27. /**
  28. * Use Dotenv to set required environment variables and load .env file in root
  29. */
  30. $dotenv = Dotenv\Dotenv::createImmutable($root_dir);
  31. if (file_exists($root_dir . '/.env')) {
  32. $dotenv->load();
  33. $dotenv->required(['WP_HOME', 'WP_SITEURL']);
  34. if (!env('DATABASE_URL')) {
  35. $dotenv->required(['DB_NAME', 'DB_USER', 'DB_PASSWORD']);
  36. }
  37. }
  38. /**
  39. * Set up our global environment constant and load its config first
  40. * Default: production
  41. */
  42. define('WP_ENV', env('WP_ENV') ?: 'production');
  43. /**
  44. * URLs
  45. */
  46. Config::define('WP_HOME', env('WP_HOME'));
  47. Config::define('WP_SITEURL', env('WP_SITEURL'));
  48. /**
  49. * Custom Content Directory
  50. */
  51. Config::define('CONTENT_DIR', '/app');
  52. Config::define('WP_CONTENT_DIR', $webroot_dir . Config::get('CONTENT_DIR'));
  53. Config::define('WP_CONTENT_URL', Config::get('WP_HOME') . Config::get('CONTENT_DIR'));
  54. /**
  55. * DB settings
  56. */
  57. Config::define('DB_NAME', env('DB_NAME'));
  58. Config::define('DB_USER', env('DB_USER'));
  59. Config::define('DB_PASSWORD', env('DB_PASSWORD'));
  60. Config::define('DB_HOST', env('DB_HOST') ?: 'localhost');
  61. Config::define('DB_CHARSET', 'utf8mb4');
  62. Config::define('DB_COLLATE', '');
  63. $table_prefix = env('DB_PREFIX') ?: 'wp_';
  64. if (env('DATABASE_URL')) {
  65. $dsn = (object) parse_url(env('DATABASE_URL'));
  66. Config::define('DB_NAME', substr($dsn->path, 1));
  67. Config::define('DB_USER', $dsn->user);
  68. Config::define('DB_PASSWORD', isset($dsn->pass) ? $dsn->pass : null);
  69. Config::define('DB_HOST', isset($dsn->port) ? "{$dsn->host}:{$dsn->port}" : $dsn->host);
  70. }
  71. /**
  72. * Authentication Unique Keys and Salts
  73. */
  74. Config::define('AUTH_KEY', env('AUTH_KEY'));
  75. Config::define('SECURE_AUTH_KEY', env('SECURE_AUTH_KEY'));
  76. Config::define('LOGGED_IN_KEY', env('LOGGED_IN_KEY'));
  77. Config::define('NONCE_KEY', env('NONCE_KEY'));
  78. Config::define('AUTH_SALT', env('AUTH_SALT'));
  79. Config::define('SECURE_AUTH_SALT', env('SECURE_AUTH_SALT'));
  80. Config::define('LOGGED_IN_SALT', env('LOGGED_IN_SALT'));
  81. Config::define('NONCE_SALT', env('NONCE_SALT'));
  82. /**
  83. * Custom Settings
  84. */
  85. Config::define('AUTOMATIC_UPDATER_DISABLED', true);
  86. Config::define('DISABLE_WP_CRON', env('DISABLE_WP_CRON') ?: false);
  87. // Disable the plugin and theme file editor in the admin
  88. Config::define('DISALLOW_FILE_EDIT', true);
  89. // Disable plugin and theme updates and installation from the admin
  90. Config::define('DISALLOW_FILE_MODS', true);
  91. /**
  92. * Debugging Settings
  93. */
  94. Config::define('WP_DEBUG_DISPLAY', false);
  95. Config::define('WP_DEBUG_LOG', env('WP_DEBUG_LOG') ?? false);
  96. Config::define('SCRIPT_DEBUG', false);
  97. ini_set('display_errors', '0');
  98. /**
  99. * Allow WordPress to detect HTTPS when used behind a reverse proxy or a load balancer
  100. * See https://codex.wordpress.org/Function_Reference/is_ssl#Notes
  101. */
  102. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
  103. $_SERVER['HTTPS'] = 'on';
  104. }
  105. $env_config = __DIR__ . '/environments/' . WP_ENV . '.php';
  106. if (file_exists($env_config)) {
  107. require_once $env_config;
  108. }
  109. Config::apply();
  110. /**
  111. * Bootstrap WordPress
  112. */
  113. if (!defined('ABSPATH')) {
  114. define('ABSPATH', $webroot_dir . '/wp/');
  115. }