Skip to content

Instantly share code, notes, and snippets.

@ryanshoover
Created November 21, 2022 17:46
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 ryanshoover/8c10debb76b9e9f20dfb9517bd26e136 to your computer and use it in GitHub Desktop.
Save ryanshoover/8c10debb76b9e9f20dfb9517bd26e136 to your computer and use it in GitHub Desktop.
Retrofit WPMS blogs.dir structure
<?php
/**
* Sunrise - load very early.
*/
/**
* If the request is for a file, send it to the legacy ms-files.php for processing.
*
* File requests follow the pattern `multisite.com/sitename/files/2022/06/filename.jpg`
*/
function maybe_redirect_ms_files() {
$path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
$is_file = preg_match( '/[\w-]*\/files\/(.*)/', $path, $matches );
// If this is a file request, send it to ms-files.
if ( $is_file ) {
$_GET['file'] = $matches[1];
require_once ABSPATH . WPINC . '/ms-files.php';
die;
}
}
// Wait for all the multisite code to be loaded, then check if we should process this as a file.
add_action( 'ms_loaded', 'maybe_redirect_ms_files' );
// Load sunrise.php file early.
define( 'SUNRISE', true );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment