Index: wp-admin/network.php
--- wp-admin/network.php
+++ wp-admin/network.php
@@ -51,8 +51,8 @@
* @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 @@
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,21 +307,25 @@
* @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' ) );
+ $slashed_siteurl = trailingslashit( get_option( 'siteurl' ) );
+ $wp_siteurl_subdir = '/' . str_replace( $slashed_home, '', $slashed_siteurl );
+ $rewrite_base = ! empty( $wp_siteurl_subdir ) ? trailingslashit( $wp_siteurl_subdir ) : '';
+ $base = parse_url( $slashed_home, PHP_URL_PATH );
// Wildcard DNS message.
if ( is_wp_error( $errors ) )
echo '' . $errors->get_error_message() . '
';
- if ( $_POST ) {
- if ( allow_subdomain_install() )
+ if ( ! empty( $_POST ) ) {
+ if ( allow_subdomain_install() ) {
$subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
- else
+ } else {
$subdomain_install = false;
+ }
} else {
if ( is_multisite() ) {
$subdomain_install = is_subdomain_install();
@@ -344,7 +341,7 @@
}
}
- if ( $_POST || ! is_multisite() ) {
+ if ( ! empty( $_POST ) || ! is_multisite() ) {
?>
@@ -369,20 +366,22 @@
+define('BLOG_ID_CURRENT_SITE', 1);
+define('WP_SITEURL_SUBDIR', '');
'', '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 ) )
+ 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/' );
+ $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
if ( is_wp_error( $from_api ) ) {
foreach ( $keys_salts as $c => $v ) {
$keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
@@ -465,11 +464,11 @@
-
+
-
+
@@ -504,13 +503,14 @@
RewriteRule ^ - [L]';
// @todo custom content dir.
- if ( ! $subdomain_install )
- $htaccess_file .= "\nRewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]\nRewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]";
+ if ( ! $subdomain_install ) {
+ $htaccess_file .= "\nRewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $rewrite_base$1 [L]\nRewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $rewrite_base$1 [L]";
+ }
$htaccess_file .= "\nRewriteRule . index.php [L]";
?>
- .htaccess file in %s
, replacing other WordPress rules:' ), ABSPATH ); ?>
+ .htaccess file in %s
, replacing other WordPress rules:' ), trailingslashit( str_replace( trailingslashit( $wp_siteurl_subdir ), '', ABSPATH ) ) ); ?>
@@ -523,24 +523,26 @@
}
}
-if ( $_POST ) {
+if ( ! empty( $_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 );
if ( is_wp_error( $result ) ) {
- if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() )
+ if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() ) {
network_step2( $result );
- else
+ } else {
network_step1( $result );
+ }
} else {
network_step2();
}
Index: wp-admin/network/site-new.php
--- wp-admin/network/site-new.php
+++ wp-admin/network/site-new.php
@@ -62,10 +62,10 @@
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';
Index: wp-includes/link-template.php
--- wp-includes/link-template.php
+++ wp-includes/link-template.php
@@ -2129,7 +2129,7 @@
if ( 'relative' == $scheme )
$url = $current_site->path;
else
- $url = $scheme . '://' . $current_site->domain . $current_site->path;
+ $url = $scheme . '://' . $current_site->domain . $current_site->wp_siteurl_subdir;
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
$url .= ltrim($path, '/');
Index: wp-includes/ms-default-constants.php
--- wp-includes/ms-default-constants.php
+++ wp-includes/ms-default-constants.php
@@ -47,7 +47,7 @@
* @since 1.5.0
*/
if ( !defined( 'SITECOOKIEPATH' ) )
- define( 'SITECOOKIEPATH', $current_site->path );
+ define( 'SITECOOKIEPATH', $current_site->wp_siteurl_subdir );
/**
* @since 2.6.0
Index: wp-includes/ms-functions.php
--- wp-includes/ms-functions.php
+++ wp-includes/ms-functions.php
@@ -1142,7 +1142,7 @@
$wpdb->suppress_errors(false);
- $url = get_blogaddress_by_id($blog_id);
+ $homeurl = $siteurl = untrailingslashit( get_blogaddress_by_id( $blog_id ) );
// Set everything up
make_db_current_silent( 'blog' );
@@ -1150,10 +1150,12 @@
populate_roles();
$wp_roles->_init();
- $url = untrailingslashit( $url );
- // fix url.
- update_option('siteurl', $url);
- update_option('home', $url);
+ // Maybe fix url
+ if ( defined( 'WP_SITEURL_SUBDIR' ) && WP_SITEURL_SUBDIR )
+ $siteurl = trailingslashit( $siteurl ) . WP_SITEURL_SUBDIR;
+
+ update_option('siteurl', $siteurl);
+ update_option('home', $homeurl);
update_option('fileupload_url', $url . "/files" );
update_option('upload_path', UPLOADBLOGSDIR . "/$blog_id/files");
update_option('blogname', stripslashes( $blog_title ) );
@@ -1161,10 +1163,9 @@
$wpdb->update( $wpdb->options, array('option_value' => ''), array('option_name' => 'admin_email') );
// remove all perms
- $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix.'user_level' ) );
+ $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix . 'user_level' ) );
+ $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix . 'capabilities' ) );
- $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix.'capabilities' ) );
-
$wpdb->suppress_errors( false );
}
Index: wp-includes/ms-load.php
--- wp-includes/ms-load.php
+++ wp-includes/ms-load.php
@@ -142,6 +142,12 @@
$current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
$current_site->domain = DOMAIN_CURRENT_SITE;
$current_site->path = $path = PATH_CURRENT_SITE;
+
+ if( defined( 'WP_SITEURL_SUBDIR' ) )
+ $current_site->wp_siteurl_subdir = WP_SITEURL_SUBDIR;
+ else
+ $current_site->wp_siteurl_subdir = $current_site->path;
+
if ( defined( 'BLOG_ID_CURRENT_SITE' ) )
$current_site->blog_id = BLOG_ID_CURRENT_SITE;
elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated.