Last active
June 23, 2020 14:26
-
-
Save uaibo/650e079568f17a524daa048a769b2f92 to your computer and use it in GitHub Desktop.
wp-config sample for easy access of the site from localhost as well as 192.168...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//production by default | |
$ENV_KEY = 'prod'; | |
$localDir = ''; | |
//host vars | |
if ( defined('WP_CLI') ) { | |
$_SERVER['HTTP_HOST'] = 'localhost'; | |
} | |
$hostName = $_SERVER['HTTP_HOST']; | |
$hostURL = 'http://'.$hostName; | |
//hosts that represent local environment | |
$local_matches = array('localhost', '192.168.'); | |
//check if current host matches any localhost | |
function isLocal(){ | |
global $hostName, $local_matches; | |
foreach($local_matches as $k => $v){ | |
if(stristr( $hostName, $v )){ return true;} | |
} | |
return false; | |
} | |
if ( isLocal() ) { | |
$ENV_KEY = 'local'; | |
$localDir = str_replace('wp-admin', '', dirname( __FILE__ )); | |
} | |
$env = array( | |
'local' => array( | |
'ENV_LOCAL' => TRUE, | |
'DB_NAME' => 'database_table', | |
'DB_USER' => 'database_user', | |
'DB_PASSWORD' => 'database_password', | |
'DB_HOST' => 'localhost', | |
'WP_SITEURL' => $hostURL . $localDir, | |
'WP_HOME' => $hostURL . $localDir, | |
'WP_CACHE' => FALSE, | |
'SCRIPT_DEBUG' => TRUE, | |
'WP_DEBUG' => TRUE | |
), | |
'prod' => array( | |
'DB_NAME' => 'database_table', | |
'DB_USER' => 'database_user', | |
'DB_PASSWORD' => 'database_password', | |
'DB_HOST' => 'localhost', | |
'WP_SITEURL' => $hostURL . $localDir, | |
'WP_HOME' => $hostURL . $localDir, | |
'WP_CACHE' => TRUE, | |
'SCRIPT_DEBUG' => FALSE, | |
'WP_DEBUG' => FALSE | |
) | |
); | |
foreach($env[$ENV_KEY] as $key => $val){ | |
define( $key, $val ); | |
} | |
// Default: If server isn't defined, do this. | |
// Put the details for your production server here. | |
!defined('ENV_LOCAL') ? define('ENV_LOCAL', FALSE) : null; | |
!defined('DB_NAME') ? define('DB_NAME', '') : null; | |
!defined('DB_USER') ? define('DB_USER', '') : null; | |
!defined('DB_PASSWORD') ? define('DB_PASSWORD', '') : null; | |
!defined('DB_HOST') ? define('DB_HOST', 'localhost') : null; | |
!defined('DB_CHARSET') ? define('DB_CHARSET', 'utf8mb4') : null; | |
!defined('DB_COLLATE') ? define('DB_COLLATE', 'utf8mb4_unicode_ci') : null; | |
!defined('WP_SITEURL') ? define('WP_SITEURL', 'http://mysite.com/') : null; | |
!defined('WP_HOME') ? define('WP_HOME', 'http://mysite.com/') : null; | |
!defined('SCRIPT_DEBUG') ? define('SCRIPT_DEBUG', FALSE) : null; | |
!defined('WP_DEBUG') ? define('WP_DEBUG', FALSE) : null; | |
!defined('WP_CACHE') ? define('WP_CACHE', TRUE) : null; | |
!defined('WPLANG') ? define('WPLANG', 'en_US') : null; | |
/**#@+ | |
* Authentication Unique Keys and Salts. | |
* | |
* Change these to different unique phrases! | |
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} | |
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. | |
* | |
* @since 2.6.0 | |
*/ | |
define( 'AUTH_KEY', 'put your unique phrase here' ); | |
define( 'SECURE_AUTH_KEY', 'put your unique phrase here' ); | |
define( 'LOGGED_IN_KEY', 'put your unique phrase here' ); | |
define( 'NONCE_KEY', 'put your unique phrase here' ); | |
define( 'AUTH_SALT', 'put your unique phrase here' ); | |
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' ); | |
define( 'LOGGED_IN_SALT', 'put your unique phrase here' ); | |
define( 'NONCE_SALT', 'put your unique phrase here' ); | |
$table_prefix = 'wp_'; | |
/* That's all, stop editing! Happy publishing. */ | |
/** 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