From 52801db5fc4304497de6acd1dd683af0fd9099d6 Mon Sep 17 00:00:00 2001
From: Mark Jaquith
Date: Thu, 27 Sep 2012 06:07:21 +0000
Subject: [PATCH] Make Multisite work when WordPress is installed in a
subdirectory. You can now have WordPress Multisite as an SVN external or a
Git submodule! props johnjamesjacoby, evansolomon, duck_, jakemgold, nacin,
markjaquith. see #19796
git-svn-id: https://develop.svn.wordpress.org/trunk@22042 602fd350-edb4-49c9-b593-d223f7449a82
---
wp-admin/network.php | 136 +++++++++++++---------------------
wp-admin/network/site-new.php | 4 +-
wp-includes/rewrite.php | 86 +++------------------
3 files changed, 64 insertions(+), 162 deletions(-)
diff --git a/wp-admin/network.php b/wp-admin/network.php
index af70da2704..51a617e329 100644
--- a/wp-admin/network.php
+++ b/wp-admin/network.php
@@ -51,8 +51,8 @@ function network_domain_check() {
* @return bool Whether subdomain install is allowed
*/
function allow_subdomain_install() {
- $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'siteurl' ) );
- if( false !== strpos( $domain, '/' ) || 'localhost' == $domain || preg_match( '|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|', $domain ) )
+ $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
+ if( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) )
return false;
return true;
@@ -144,13 +144,6 @@ include( ABSPATH . 'wp-admin/admin-header.php' );
function network_step1( $errors = false ) {
global $is_apache;
- if ( get_option( 'siteurl' ) != get_option( 'home' ) ) {
- echo '' . __('ERROR:') . ' ' . sprintf( __( 'Your WordPress address must match your Site address before creating a Network. See General Settings.' ), esc_url( admin_url( 'options-general.php' ) ) ) . '
';
- echo '';
- include ( ABSPATH . 'wp-admin/admin-footer.php' );
- die();
- }
-
if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
echo '' . __('ERROR:') . ' ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '
';
echo '';
@@ -314,11 +307,14 @@ function network_step1( $errors = false ) {
* @since 3.0.0
*/
function network_step2( $errors = false ) {
- global $base, $wpdb;
- $hostname = get_clean_basedomain();
+ global $wpdb;
- if ( ! isset( $base ) )
- $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
+ $hostname = get_clean_basedomain();
+ $slashed_home = trailingslashit( get_option( 'home' ) );
+ $base = parse_url( $slashed_home, PHP_URL_PATH );
+ $wp_dir_from_root = preg_replace( '#^' . preg_quote( $_SERVER['DOCUMENT_ROOT'], '#' ) . '#', '', ABSPATH );
+ $wp_siteurl_subdir = trailingslashit( '/' . preg_replace( '#^' . preg_quote( $base, '#' ) . '#', '', $wp_dir_from_root ) );
+ $rewrite_base = ! empty( $wp_siteurl_subdir ) ? ltrim( trailingslashit( $wp_siteurl_subdir ), '/' ) : '';
// Wildcard DNS message.
if ( is_wp_error( $errors ) )
@@ -344,6 +340,10 @@ function network_step2( $errors = false ) {
}
}
+ $subdir_match = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?';
+ $subdir_replacement_01 = $subdomain_install ? '' : '$1';
+ $subdir_replacement_12 = $subdomain_install ? '$1' : '$2';
+
if ( $_POST || ! is_multisite() ) {
?>
@@ -361,20 +361,21 @@ function network_step2( $errors = false ) {
?>
wp-config.php file in %s above the line reading /* That’s all, stop editing! Happy blogging. */:' ), ABSPATH ); ?>
-
'', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' );
foreach ( $keys_salts as $c => $v ) {
if ( defined( $c ) )
unset( $keys_salts[ $c ] );
}
+
if ( ! empty( $keys_salts ) ) {
$keys_salts_str = '';
$from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
@@ -399,10 +400,13 @@ define('BLOG_ID_CURRENT_SITE', 1);
+ $web_config_file = <<
@@ -414,49 +418,14 @@ define('BLOG_ID_CURRENT_SITE', 1);
if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
$web_config_file .= '
-
-
+
+
';
}
$web_config_file .= '
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-';
- } else {
- $web_config_file =
-'
-
-
-
-
-
-
-
- ';
- if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) {
- $web_config_file .= '
-
-
-
- ';
- }
- $web_config_file .= '
-
-
-
+
+
@@ -467,12 +436,12 @@ define('BLOG_ID_CURRENT_SITE', 1);
-
-
+
+
-
-
+
+
@@ -481,10 +450,11 @@ define('BLOG_ID_CURRENT_SITE', 1);
-';
- }
+
+EOF;
+
?>
- web.config file in %s, replacing other WordPress rules:' ), ABSPATH ); ?>
+ web.config file in %s, replacing other WordPress rules:' ), trailingslashit( str_replace( trailingslashit( $wp_siteurl_subdir ), '', ABSPATH ) ) ); ?>
' . __('Warning:') . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '
';
@@ -495,27 +465,27 @@ define('BLOG_ID_CURRENT_SITE', 1);
.htaccess file in %s, replacing other WordPress rules:' ), ABSPATH ); ?>
@@ -537,14 +507,12 @@ RewriteRule ^ - [L]';
if ( $_POST ) {
- $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
-
check_admin_referer( 'install-network-1' );
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
// create network tables
install_network();
- $hostname = get_clean_basedomain();
+ $base = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
$subdomain_install = allow_subdomain_install() ? !empty( $_POST['subdomain_install'] ) : false;
if ( ! network_domain_check() ) {
$result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), stripslashes( $_POST['sitename'] ), $base, $subdomain_install );
diff --git a/wp-admin/network/site-new.php b/wp-admin/network/site-new.php
index b3cc84e504..adf50db6b5 100644
--- a/wp-admin/network/site-new.php
+++ b/wp-admin/network/site-new.php
@@ -62,10 +62,10 @@ if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) {
if ( is_subdomain_install() ) {
$newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
- $path = $base;
+ $path = $current_site->path;
} else {
$newdomain = $current_site->domain;
- $path = $base . $domain . '/';
+ $path = $current_site->path . $domain . '/';
}
$password = 'N/A';
diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php
index 1cda6f979b..1797267092 100644
--- a/wp-includes/rewrite.php
+++ b/wp-includes/rewrite.php
@@ -1729,83 +1729,17 @@ class WP_Rewrite {
';
}
- if ( !is_multisite() ) {
- $rules .= '
-
-
-
-
-
-
-
- ';
- } else {
- if (is_subdomain_install()) {
- $rules .= '
-
-
-
- ';
- if ( get_site_option( 'ms_files_rewriting' ) ) {
- $rules .= '
-
-
-
- ';
- }
- $rules .= '
-
-
-
-
-
+
+ $rules .= '
+
+
+
+
+
-
-
-
-
-
- ';
- } else {
- $rules .= '
-
-
-
- ';
- if ( get_site_option( 'ms_files_rewriting' ) ) {
- $rules .= '
-
-
-
- ';
- }
- $rules .= '
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ';
- }
- }
+
+ ';
+
if ( $add_parent_tags ) {
$rules .= '