Created
March 14, 2016 23:15
-
-
Save josheby/2b47583083d7fe0f99de to your computer and use it in GitHub Desktop.
Nested WordPress Networks Using WP Multi Network
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
# BEGIN WordPress | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^index\.php$ - [L] | |
# add a trailing slash to /wp-admin | |
RewriteRule ^([_0-9a-zA-Z-]+/)+?wp-admin$ $1wp-admin/ [R=301,L] | |
RewriteCond %{REQUEST_FILENAME} -f [OR] | |
RewriteCond %{REQUEST_FILENAME} -d | |
RewriteRule ^ - [L] | |
RewriteRule ^([_0-9a-zA-Z-]+/)+?(wp-(content|admin|includes).*) $2 [L] | |
RewriteRule ^([_0-9a-zA-Z-]+/)+?(.*\.php)$ $2 [L] | |
RewriteRule . index.php [L] | |
</IfModule> | |
# END WordPress |
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 | |
if ( ! defined( 'SUNRISE_LOADED' ) ) | |
define( 'SUNRISE_LOADED', 1 ); | |
if ( ! defined( 'COOKIE_DOMAIN' ) ) { | |
define('COOKIE_DOMAIN', $_SERVER[ 'HTTP_HOST' ] ); | |
} else { | |
die("Error COOKIE DOMAIN"); | |
} | |
$sites = $wpdb->get_results("SELECT * FROM {$wpdb->site} ORDER BY CHAR_LENGTH(path) DESC"); | |
foreach ( $sites as $site ) { | |
if ( false !== strpos( $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ] . '/', $site->domain . $site->path ) ) { | |
$site_id = $site->id; | |
$current_site = $site; | |
$wpdb->siteid = $site->id; | |
break; | |
} | |
} | |
$blogs = $wpdb->get_results("SELECT * FROM {$wpdb->blogs} WHERE site_id = {$site_id} ORDER BY CHAR_LENGTH(path) DESC"); | |
foreach ( $blogs as $blog ) { | |
if ( false !== strpos( str_replace( $site->domain, '', $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ] . '/' ), $blog->path) ) { | |
$blog_id = $blog->blog_id; | |
$current_blog = $blog; | |
$wpdb->blogid = $blod->id; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment