Skip to content

Instantly share code, notes, and snippets.

@stracker-phil
Last active May 1, 2019 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stracker-phil/c7b741645c2903d03be48d6ef81b2aaf to your computer and use it in GitHub Desktop.
Save stracker-phil/c7b741645c2903d03be48d6ef81b2aaf to your computer and use it in GitHub Desktop.
Template for a wp-config.php file with included environment detection
<?php
/**
* The base configuration for WordPress
*
* @link https://codex.wordpress.org/Editing_wp-config.php
*
* @package WordPress
*/
// Defines the environment (prod|stage|dev)
if ( file_exists( __DIR__ . '/.env' ) ) {
$env = trim( file_get_contents( __DIR__ . '/.env' ) );
define( 'ENVIRONMENT', $env );
} else {
echo 'Please add the <strong>.env</strong> file';
exit;
}
// Setup environment specific database connection.
if ( 'prod' === ENVIRONMENT ) {
define( 'DB_NAME', 'live_sitename' );
define( 'DB_USER', 'live_user' );
define( 'DB_PASSWORD', 'live_password' );
define( 'DB_HOST', 'localhost' );
} elseif ( 'stage' === ENVIRONMENT ) {
define( 'DB_NAME', 'stage_sitename' );
define( 'DB_USER', 'stage_user' );
define( 'DB_PASSWORD', 'stage_password' );
define( 'DB_HOST', 'localhost' );
} else {
define( 'DB_NAME', 'local_sitename' );
define( 'DB_USER', 'local_user' );
define( 'DB_PASSWORD', 'local_password' );
define( 'DB_HOST', 'localhost' );
}
define( 'DB_CHARSET', 'utf8' );
define( 'DB_COLLATE', '' );
$table_prefix = 'abcd_';
/**
* Authentication Unique Keys and Salts.
*
* @link https://api.wordpress.org/secret-key/1.1/salt/
* @since 2.6.0
*/
define( 'AUTH_KEY', $env . '(secret salt here)' );
define( 'SECURE_AUTH_KEY', $env . '(secret salt here)' );
define( 'LOGGED_IN_KEY', $env . '(secret salt here)' );
define( 'NONCE_KEY', $env . '(secret salt here)' );
define( 'AUTH_SALT', $env . '(secret salt here)' );
define( 'SECURE_AUTH_SALT', $env . '(secret salt here)' );
define( 'LOGGED_IN_SALT', $env . '(secret salt here)' );
define( 'NONCE_SALT', $env . '(secret salt here)' );
// Environment specific configuration.
if ( 'prod' === ENVIRONMENT ) {
// Production settings.
define( 'FORCE_SSL_ADMIN', true );
define( 'WP_DEBUG', false );
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_CORE', false );
define( 'WP_DEBUG_LOG', true );
} else {
// Development and stage settings.
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', true );
define( 'WP_DEBUG_CORE', false );
define( 'WP_DEBUG_LOG', true );
}
// Global configuration, identical for all environments.
define( 'DISALLOW_FILE_EDIT', true );
define( 'DISALLOW_FILE_MODS', false );
define( 'WP_CRON_LOCK_TIMEOUT', '60' );
define( 'EMPTY_TRASH_DAYS', '30' );
define( 'WP_CACHE', true );
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) )
define( 'ABSPATH', dirname( __FILE__ ) . '/' );
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment