Last active
February 10, 2016 16:19
-
-
Save devfreddy/dc6796231dc003aaee99 to your computer and use it in GitHub Desktop.
Wordpress dynamically set site url for local development
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 | |
/* | |
* Still requires the nginx server_name to be set to one of these | |
* For names, still requires hosts file to be set | |
* Just updates one thing for you automatically so if your local ip changes you don't have to change so many things | |
* | |
*/ | |
$ip = $_SERVER['SERVER_ADDR']; | |
$identifiers = array( $_SERVER['HTTP_HOST'], $_SERVER['REMOTE_ADDR'], $_SERVER['SERVER_NAME'] ); | |
$aliases = array('local.site.org', $ip . '.xip.io', $ip, '127.0.0.1', '127.0.0.1.xip.io'); | |
foreach($identifiers as $key => $identity){ | |
if(!empty($identity) && in_array($identity, $aliases)){ | |
define('WP_HOME', 'https://' . $identity); | |
define('WP_SITEURL', 'https://' . $identity); | |
error_log("Setting to: " . WP_HOME); | |
break; | |
} | |
} | |
/* | |
* Nginx server block for the secure beta site | |
* Add these to the server name: | |
* 192.168.1.123.xip.io | |
* 192.168.1.123 | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment