/templates/gatsby-wordpress/files/wordpress/wp-config.php

https://gitlab.com/pepek4kintil/template-builder · PHP · 126 lines · 78 code · 20 blank · 28 comment · 17 complexity · 31569ea2739dfe45639e904cd5501e93 MD5 · raw file

  1. <?php
  2. use Platformsh\ConfigReader\Config;
  3. require __DIR__.'/../vendor/autoload.php';
  4. // Create a new config object to ease reading the Platform.sh environment variables.
  5. // You can alternatively use getenv() yourself.
  6. $config = new Config();
  7. // Set default scheme and hostname.
  8. $site_scheme = 'http';
  9. $site_host = 'localhost';
  10. // Update scheme and hostname for the requested page.
  11. if (isset($_SERVER['HTTP_HOST'])) {
  12. $site_host = $_SERVER['HTTP_HOST'];
  13. $site_scheme = !empty($_SERVER['HTTPS']) ? 'https' : 'http';
  14. }
  15. if ($config->isValidPlatform()) {
  16. if ($config->hasRelationship('database')) {
  17. // This is where we get the relationships of our application dynamically
  18. // from Platform.sh.
  19. // Avoid PHP notices on CLI requests.
  20. if (php_sapi_name() === 'cli') {
  21. session_save_path("/tmp");
  22. }
  23. // Get the database credentials
  24. $credentials = $config->credentials('database');
  25. // We are using the first relationship called "database" found in your
  26. // relationships. Note that you can call this relationship as you wish
  27. // in your `.platform.app.yaml` file, but 'database' is a good name.
  28. define( 'DB_NAME', $credentials['path']);
  29. define( 'DB_USER', $credentials['username']);
  30. define( 'DB_PASSWORD', $credentials['password']);
  31. define( 'DB_HOST', $credentials['host']);
  32. define( 'DB_CHARSET', 'utf8' );
  33. define( 'DB_COLLATE', '' );
  34. // Check whether a route is defined for this application in the Platform.sh
  35. // routes. Use it as the site hostname if so (it is not ideal to trust HTTP_HOST).
  36. if ($config->routes()) {
  37. $routes = $config->routes();
  38. foreach ($routes as $url => $route) {
  39. if ($route['type'] === 'upstream' && $route['upstream'] === $config->applicationName) {
  40. // Pick the first hostname, or the first HTTPS hostname if one exists.
  41. $host = parse_url($url, PHP_URL_HOST);
  42. $scheme = parse_url($url, PHP_URL_SCHEME);
  43. if ($host !== false && (!isset($site_host) || ($site_scheme === 'http' && $scheme === 'https'))) {
  44. $site_host = $host;
  45. $site_scheme = $scheme ?: 'http';
  46. }
  47. }
  48. }
  49. }
  50. // Debug mode should be disabled on Platform.sh. Set this constant to true
  51. // in a wp-config-local.php file to skip this setting on local development.
  52. if (!defined( 'WP_DEBUG' )) {
  53. define( 'WP_DEBUG', false );
  54. }
  55. // Set all of the necessary keys to unique values, based on the Platform.sh
  56. // entropy value.
  57. if ($config->projectEntropy) {
  58. $keys = [
  59. 'AUTH_KEY',
  60. 'SECURE_AUTH_KEY',
  61. 'LOGGED_IN_KEY',
  62. 'NONCE_KEY',
  63. 'AUTH_SALT',
  64. 'SECURE_AUTH_SALT',
  65. 'LOGGED_IN_SALT',
  66. 'NONCE_SALT',
  67. ];
  68. $entropy = $config->projectEntropy;
  69. foreach ($keys as $key) {
  70. if (!defined($key)) {
  71. define( $key, $entropy . $key );
  72. }
  73. }
  74. }
  75. }
  76. }
  77. else {
  78. // Local configuration file should be in project root.
  79. if (file_exists(dirname(__FILE__, 2) . '/wp-config-local.php')) {
  80. include(dirname(__FILE__, 2) . '/wp-config-local.php');
  81. }
  82. }
  83. // Do not put a slash "/" at the end.
  84. // https://codex.wordpress.org/Editing_wp-config.php#WP_HOME
  85. define( 'WP_HOME', $site_scheme . '://' . $site_host );
  86. // Do not put a slash "/" at the end.
  87. // https://codex.wordpress.org/Editing_wp-config.php#WP_SITEURL
  88. define( 'WP_SITEURL', WP_HOME );
  89. define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/wp-content' );
  90. define( 'WP_CONTENT_URL', WP_HOME . '/wp-content' );
  91. // Since you can have multiple installations in one database, you need a unique
  92. // prefix.
  93. $table_prefix = 'wp_';
  94. // Default PHP settings.
  95. ini_set('session.gc_probability', 1);
  96. ini_set('session.gc_divisor', 100);
  97. ini_set('session.gc_maxlifetime', 200000);
  98. ini_set('session.cookie_lifetime', 2000000);
  99. ini_set('pcre.backtrack_limit', 200000);
  100. ini_set('pcre.recursion_limit', 200000);
  101. /** Absolute path to the WordPress directory. */
  102. if ( ! defined( 'ABSPATH' ) ) {
  103. define( 'ABSPATH', dirname( __FILE__ ) . '/' );
  104. }
  105. /** Sets up WordPress vars and included files. */
  106. require_once(ABSPATH . 'wp-settings.php');