Last active
March 28, 2017 21:22
-
-
Save rmccue/ec6a7d79349ea7e9b206 to your computer and use it in GitHub Desktop.
WordPress test server - front controller for testing WP. *****NEVER USE THIS ON PRODUCTION******
This file contains hidden or 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 | |
/** | |
* WordPress Test Server | |
* | |
* This serves up a full WordPress site via the PHP test server (`php -S`), and | |
* is intended purely for serving WP for UI testing. Please do not ever use this | |
* in production. | |
*/ | |
// Path to WP install | |
$basedir = realpath( __DIR__ . '/../..' ); | |
$wpdir = $basedir . '/wordpress'; | |
// Ensure we can't load files outside of our WP install | |
ini_set( 'open_basedir', $basedir ); | |
$path = null; | |
if ( !empty( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] !== '/' ) { | |
$requested = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); | |
$search = array( | |
$basedir, // /wordpress/wp-includes/a.jpg | |
$wpdir, // /wp-includes/a.jpg | |
); | |
foreach ( $search as $dir ) { | |
$full = realpath( $dir . $requested ); | |
if ( file_exists( $full ) ) { | |
$path = $full; | |
} | |
} | |
} | |
if ( empty( $path ) ) { | |
require $basedir . '/index.php'; | |
return; | |
} | |
$info = new finfo( FILEINFO_SYMLINK ); | |
$mime_type = $info->file($path, FILEINFO_MIME_TYPE); | |
if ( $mime_type === 'text/x-php' ) { | |
include $path; | |
return; | |
} | |
$mime_header = $info->file($path, FILEINFO_MIME_ENCODING); | |
header( sprintf( 'Content-Type: %s', $mime_header ) ); | |
readfile( $path ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment