Created
April 29, 2016 13:25
-
-
Save g105b/7575e736458cedd37807d18605a87ff3 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Serve Wordpress locally without having to configure a web server. | |
* | |
* You need to have the database served as configured in wp-config.php, then | |
* run php -S 0.0.0.0:8080 wp-router.php to serve, and access localhost:8080 or | |
* your.computers.ip:8080 in a browser. | |
* | |
* Make sure in the database that within the `wp_options` table, the `siteurl` | |
* and `home` values are both "/". | |
*/ | |
// Work from the server's document root directory. | |
$rootDir = $_SERVER["DOCUMENT_ROOT"]; | |
chdir($rootDir); | |
// Extract path component of incoming request. | |
$urlComponents = parse_url($_SERVER["REQUEST_URI"]); | |
$requestedPath = "/" . trim($urlComponents["path"], "/"); | |
// Allow child scripts to use current directory as include path. | |
set_include_path(implode(":", [ | |
get_include_path(), | |
__DIR__ | |
])); | |
$diskPath = rtrim("$rootDir/$requestedPath", "/"); | |
if(file_exists($diskPath)) { | |
if(is_dir($diskPath) && $requestedPath === "/") { | |
$requestedPath = rtrim($requestedPath, "/") . "/index.php"; | |
} | |
if(strstr($requestedPath, ".php")) { | |
$diskPath = rtrim("$rootDir/$requestedPath", "/"); | |
require_once($diskPath); | |
} | |
else { | |
return false; | |
} | |
} | |
else { | |
require_once("index.php"); | |
} |
Hi past Greg! Working with a Wordpress thing again today - psh!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because sometimes, you have to work with a Wordpress project 👎