2010-01-31 06:55:39 -05:00
< ? php
/**
2010-03-03 02:43:32 -05:00
* Network installation administration panel .
2010-01-31 06:55:39 -05:00
*
* A multi - step process allowing the user to enable a network of WordPress sites .
*
* @ since 3.0 . 0
*
* @ package WordPress
* @ subpackage Administration
*/
2011-10-05 20:21:24 -04:00
define ( 'WP_INSTALLING_NETWORK' , true );
2010-05-29 16:35:19 -04:00
2010-01-31 06:55:39 -05:00
/** WordPress Administration Bootstrap */
require_once ( './admin.php' );
if ( ! is_super_admin () )
2010-03-03 02:43:32 -05:00
wp_die ( __ ( 'You do not have sufficient permissions to manage options for this site.' ) );
2010-11-18 00:29:03 -05:00
if ( is_multisite () ) {
if ( ! is_network_admin () ) {
wp_redirect ( network_admin_url ( 'setup.php' ) );
exit ;
}
if ( ! defined ( 'MULTISITE' ) )
wp_die ( __ ( 'The Network creation panel is not for WordPress MU networks.' ) );
2010-11-18 00:37:00 -05:00
}
2010-03-11 18:53:03 -05:00
2010-02-23 14:58:53 -05:00
// We need to create references to ms global tables to enable Network.
foreach ( $wpdb -> tables ( 'ms_global' ) as $table => $prefixed_table )
$wpdb -> $table = $prefixed_table ;
2010-03-10 03:46:05 -05:00
/**
2010-03-11 17:33:52 -05:00
* Check for an existing network .
2010-03-10 03:46:05 -05:00
*
* @ since 3.0 . 0
2010-03-11 17:33:52 -05:00
* @ return Whether a network exists .
2010-03-10 03:46:05 -05:00
*/
function network_domain_check () {
global $wpdb ;
if ( $wpdb -> get_var ( " SHOW TABLES LIKE ' $wpdb->site ' " ) )
return $wpdb -> get_var ( " SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1 " );
return false ;
}
2010-04-01 22:04:25 -04:00
/**
* Allow subdomain install
*
* @ since 3.0 . 0
2010-05-04 16:48:28 -04:00
* @ return bool Whether subdomain install is allowed
2010-04-01 22:04:25 -04:00
*/
function allow_subdomain_install () {
2012-09-27 02:07:21 -04:00
$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 ) )
2010-04-01 22:04:25 -04:00
return false ;
return true ;
}
2010-05-08 11:25:33 -04:00
/**
2010-05-25 11:16:31 -04:00
* Allow subdirectory install
2010-05-08 11:25:33 -04:00
*
* @ since 3.0 . 0
2010-05-25 11:16:31 -04:00
* @ return bool Whether subdirectory install is allowed
2010-05-08 11:25:33 -04:00
*/
2010-05-25 11:16:31 -04:00
function allow_subdirectory_install () {
2010-05-08 11:25:33 -04:00
global $wpdb ;
2010-05-25 11:16:31 -04:00
if ( apply_filters ( 'allow_subdirectory_install' , false ) )
2010-05-08 11:25:33 -04:00
return true ;
2010-06-11 12:38:11 -04:00
if ( defined ( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL )
return true ;
2010-05-08 11:25:33 -04:00
$post = $wpdb -> get_row ( " SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish' " );
if ( empty ( $post ) )
return true ;
return false ;
}
2010-03-10 03:46:05 -05:00
/**
* Get base domain of network .
*
* @ since 3.0 . 0
2010-03-11 17:33:52 -05:00
* @ return string Base domain .
2010-03-10 03:46:05 -05:00
*/
function get_clean_basedomain () {
2010-03-11 17:33:52 -05:00
if ( $existing_domain = network_domain_check () )
2010-03-10 03:46:05 -05:00
return $existing_domain ;
$domain = preg_replace ( '|https?://|' , '' , get_option ( 'siteurl' ) );
2010-03-11 17:33:52 -05:00
if ( $slash = strpos ( $domain , '/' ) )
$domain = substr ( $domain , 0 , $slash );
2010-03-10 03:46:05 -05:00
return $domain ;
}
2010-03-09 14:10:07 -05:00
if ( ! network_domain_check () && ( ! defined ( 'WP_ALLOW_MULTISITE' ) || ! WP_ALLOW_MULTISITE ) )
wp_die ( __ ( 'You must define the <code>WP_ALLOW_MULTISITE</code> constant as true in your wp-config.php file to allow creation of a Network.' ) );
2010-11-18 00:24:13 -05:00
if ( is_network_admin () ) {
$title = __ ( 'Network Setup' );
$parent_file = 'settings.php' ;
} else {
$title = __ ( 'Create a Network of WordPress Sites' );
$parent_file = 'tools.php' ;
}
2010-01-31 06:55:39 -05:00
2011-11-29 11:58:58 -05:00
$network_help = '<p>' . __ ( 'This screen allows you to configure a network as having subdomains (<code>site1.example.com</code>) or subdirectories (<code>example.com/site1</code>). Subdomains require wildcard subdomains to be enabled in Apache and DNS records, if your host allows it.' ) . '</p>' .
2010-05-27 17:20:23 -04:00
'<p>' . __ ( 'Choose subdomains or subdirectories; this can only be switched afterwards by reconfiguring your install. Fill out the network details, and click install. If this does not work, you may have to add a wildcard DNS record (for subdomains) or change to another setting in Permalinks (for subdirectories).' ) . '</p>' .
2011-06-01 11:37:04 -04:00
'<p>' . __ ( 'The next screen for Network Setup will give you individually-generated lines of code to add to your wp-config.php and .htaccess files. Make sure the settings of your FTP client make files starting with a dot visible, so that you can find .htaccess; you may have to create this file if it really is not there. Make backup copies of those two files.' ) . '</p>' .
2012-09-11 18:22:20 -04:00
'<p>' . __ ( 'Add the designated lines of code to wp-config.php (just before <code>/*...stop editing...*/</code>) and <code>.htaccess</code> (replacing the existing WordPress rules).' ) . '</p>' .
2011-12-08 11:49:16 -05:00
'<p>' . __ ( 'Once you add this code and refresh your browser, multisite should be enabled. This screen, now in the Network Admin navigation menu, will keep an archive of the added code. You can toggle between Network Admin and Site Admin by clicking on the Network Admin or an individual site name under the My Sites dropdown in the Toolbar.' ) . '</p>' .
2011-11-29 11:58:58 -05:00
'<p>' . __ ( 'The choice of subdirectory sites is disabled if this setup is more than a month old because of permalink problems with “/blog/” from the main site. This disabling will be addressed in a future version.' ) . '</p>' .
'<p><strong>' . __ ( 'For more information:' ) . '</strong></p>' .
'<p>' . __ ( '<a href="http://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>' ) . '</p>' .
'<p>' . __ ( '<a href="http://codex.wordpress.org/Tools_Network_Screen" target="_blank">Documentation on the Network Screen</a>' ) . '</p>' ;
get_current_screen () -> add_help_tab ( array (
'id' => 'network' ,
'title' => __ ( 'Network' ),
'content' => $network_help ,
) );
2011-11-02 01:33:53 -04:00
2011-11-02 17:32:16 -04:00
get_current_screen () -> set_help_sidebar (
2010-05-27 17:20:23 -04:00
'<p><strong>' . __ ( 'For more information:' ) . '</strong></p>' .
2010-12-16 22:32:46 -05:00
'<p>' . __ ( '<a href="http://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>' ) . '</p>' .
2011-04-28 11:24:49 -04:00
'<p>' . __ ( '<a href="http://codex.wordpress.org/Tools_Network_Screen" target="_blank">Documentation on the Network Screen</a>' ) . '</p>' .
2010-06-03 17:00:39 -04:00
'<p>' . __ ( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
2010-05-27 17:20:23 -04:00
);
2010-01-31 06:55:39 -05:00
2010-11-18 00:24:13 -05:00
include ( ABSPATH . 'wp-admin/admin-header.php' );
2010-01-31 06:55:39 -05:00
?>
< div class = " wrap " >
2010-11-18 00:24:13 -05:00
< ? php screen_icon ( 'tools' ); ?>
2010-01-31 06:55:39 -05:00
< h2 >< ? php echo esc_html ( $title ); ?> </h2>
< ? php
/**
2010-03-03 02:43:32 -05:00
* Prints step 1 for Network installation process .
2010-01-31 06:55:39 -05:00
*
2010-03-03 02:43:32 -05:00
* @ todo Realistically , step 1 should be a welcome screen explaining what a Network is and such . Navigating to Tools > Network
2010-03-10 22:15:09 -05:00
* should not be a sudden " Welcome to a new install process! Fill this out and click here. " See also contextual help todo .
2010-01-31 06:55:39 -05:00
*
* @ since 3.0 . 0
*/
2010-03-10 20:51:24 -05:00
function network_step1 ( $errors = false ) {
2010-05-27 22:52:40 -04:00
global $is_apache ;
2010-01-31 06:55:39 -05:00
2010-10-29 18:44:05 -04:00
if ( defined ( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
2011-09-30 13:18:35 -04:00
echo '<div class="error"><p><strong>' . __ ( 'ERROR:' ) . '</strong> ' . __ ( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '</p></div>' ;
2010-10-29 18:44:05 -04:00
echo '</div>' ;
2010-12-01 16:32:40 -05:00
include ( ABSPATH . 'wp-admin/admin-footer.php' );
2010-10-29 18:44:05 -04:00
die ();
}
2010-03-03 02:43:32 -05:00
$active_plugins = get_option ( 'active_plugins' );
if ( ! empty ( $active_plugins ) ) {
2010-05-29 08:12:48 -04:00
echo '<div class="updated"><p><strong>' . __ ( 'Warning:' ) . '</strong> ' . sprintf ( __ ( 'Please <a href="%s">deactivate your plugins</a> before enabling the Network feature.' ), admin_url ( 'plugins.php?plugin_status=active' ) ) . '</p></div><p>' . __ ( 'Once the network is created, you may reactivate your plugins.' ) . '</p>' ;
2010-05-14 08:34:48 -04:00
echo '</div>' ;
2010-12-01 16:32:40 -05:00
include ( ABSPATH . 'wp-admin/admin-footer.php' );
2010-03-03 02:43:32 -05:00
die ();
}
2010-01-31 06:55:39 -05:00
2010-03-03 02:43:32 -05:00
$hostname = get_clean_basedomain ();
2010-03-09 17:01:49 -05:00
$has_ports = strstr ( $hostname , ':' );
2010-05-03 15:23:37 -04:00
if ( ( false !== $has_ports && ! in_array ( $has_ports , array ( ':80' , ':443' ) ) ) ) {
2011-09-30 13:18:35 -04:00
echo '<div class="error"><p><strong>' . __ ( 'ERROR:' ) . '</strong> ' . __ ( 'You cannot install a network of sites with your server address.' ) . '</p></div>' ;
2010-05-08 11:25:33 -04:00
echo '<p>' . sprintf ( __ ( 'You cannot use port numbers such as <code>%s</code>.' ), $has_ports ) . '</p>' ;
2010-05-03 14:16:22 -04:00
echo '<a href="' . esc_url ( admin_url () ) . '">' . __ ( 'Return to Dashboard' ) . '</a>' ;
2010-05-14 08:34:48 -04:00
echo '</div>' ;
2010-12-01 16:32:40 -05:00
include ( ABSPATH . 'wp-admin/admin-footer.php' );
2010-03-03 02:43:32 -05:00
die ();
2010-01-31 06:55:39 -05:00
}
2010-05-15 02:49:16 -04:00
echo '<form method="post" action="">' ;
2010-03-10 20:51:24 -05:00
wp_nonce_field ( 'install-network-1' );
$error_codes = array ();
if ( is_wp_error ( $errors ) ) {
echo '<div class="error"><p><strong>' . __ ( 'ERROR: The network could not be created.' ) . '</strong></p>' ;
foreach ( $errors -> get_error_messages () as $error )
echo " <p> $error </p> " ;
echo '</div>' ;
$error_codes = $errors -> get_error_codes ();
}
$site_name = ( ! empty ( $_POST [ 'sitename' ] ) && ! in_array ( 'empty_sitename' , $error_codes ) ) ? $_POST [ 'sitename' ] : sprintf ( _x ( '%s Sites' , 'Default network name' ), get_option ( 'blogname' ) );
$admin_email = ( ! empty ( $_POST [ 'email' ] ) && ! in_array ( 'invalid_email' , $error_codes ) ) ? $_POST [ 'email' ] : get_option ( 'admin_email' );
2010-01-31 06:55:39 -05:00
?>
2010-03-03 02:43:32 -05:00
< p >< ? php _e ( 'Welcome to the Network installation process!' ); ?> </p>
2010-04-11 06:41:54 -04:00
< p >< ? php _e ( 'Fill in the information below and you’ll be on your way to creating a network of WordPress sites. We will create configuration files in the next step.' ); ?> </p>
2010-01-31 06:55:39 -05:00
< ? php
2010-03-20 18:44:07 -04:00
if ( isset ( $_POST [ 'subdomain_install' ] ) ) {
2010-03-10 20:51:24 -05:00
$subdomain_install = ( bool ) $_POST [ 'subdomain_install' ];
} elseif ( apache_mod_loaded ( 'mod_rewrite' ) ) { // assume nothing
$subdomain_install = true ;
2010-05-25 11:16:31 -04:00
} elseif ( ! allow_subdirectory_install () ) {
2010-05-08 11:25:33 -04:00
$subdomain_install = true ;
2010-01-31 06:55:39 -05:00
} else {
2010-03-10 20:51:24 -05:00
$subdomain_install = false ;
2010-05-27 22:58:21 -04:00
if ( $got_mod_rewrite = got_mod_rewrite () ) // dangerous assumptions
2010-04-11 06:41:54 -04:00
echo '<div class="updated inline"><p><strong>' . __ ( 'Note:' ) . '</strong> ' . __ ( 'Please make sure the Apache <code>mod_rewrite</code> module is installed as it will be used at the end of this installation.' ) . '</p>' ;
2010-05-27 22:52:40 -04:00
elseif ( $is_apache )
2010-03-20 18:44:07 -04:00
echo '<div class="error inline"><p><strong>' . __ ( 'Warning!' ) . '</strong> ' . __ ( 'It looks like the Apache <code>mod_rewrite</code> module is not installed.' ) . '</p>' ;
2010-05-27 22:58:21 -04:00
if ( $got_mod_rewrite || $is_apache ) // Protect against mod_rewrite mimicry (but ! Apache)
2010-05-27 22:52:40 -04:00
echo '<p>' . __ ( 'If <code>mod_rewrite</code> is disabled, ask your administrator to enable that module, or look at the <a href="http://httpd.apache.org/docs/mod/mod_rewrite.html">Apache documentation</a> or <a href="http://www.google.com/search?q=apache+mod_rewrite">elsewhere</a> for help setting it up.' ) . '</p></div>' ;
2010-01-31 06:55:39 -05:00
}
2010-05-25 11:16:31 -04:00
if ( allow_subdomain_install () && allow_subdirectory_install () ) : ?>
2010-03-03 02:43:32 -05:00
< h3 >< ? php esc_html_e ( 'Addresses of Sites in your Network' ); ?> </h3>
< p >< ? php _e ( 'Please choose whether you would like sites in your WordPress network to use sub-domains or sub-directories. <strong>You cannot change this later.</strong>' ); ?> </p>
2010-04-11 06:41:54 -04:00
< p >< ? php _e ( 'You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality.' ); ?> </p>
2010-03-20 18:44:07 -04:00
< ? php // @todo: Link to an MS readme? ?>
2010-03-03 02:43:32 -05:00
< table class = " form-table " >
< tr >
2010-05-18 00:41:08 -04:00
< th >< label >< input type = 'radio' name = 'subdomain_install' value = '1' < ? php checked ( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
2010-03-24 22:49:23 -04:00
< td >< ? php printf ( _x ( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>' , 'subdomain examples' ), $hostname ); ?> </td>
2010-03-03 02:43:32 -05:00
</ tr >
< tr >
2010-05-18 00:41:08 -04:00
< th >< label >< input type = 'radio' name = 'subdomain_install' value = '0' < ? php checked ( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
2010-03-24 22:49:23 -04:00
< td >< ? php printf ( _x ( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>' , 'subdirectory examples' ), $hostname ); ?> </td>
2010-03-03 02:43:32 -05:00
</ tr >
</ table >
2010-01-31 06:55:39 -05:00
2010-03-09 13:58:05 -05:00
< ? php
endif ;
2010-03-09 01:14:42 -05:00
2012-09-11 18:22:20 -04:00
if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' && ( allow_subdirectory_install () || ! allow_subdomain_install () ) )
echo '<div class="error inline"><p><strong>' . __ ( 'Warning!' ) . '</strong> ' . __ ( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>' ;
2010-03-10 20:51:24 -05:00
$is_www = ( 0 === strpos ( $hostname , 'www.' ) );
2010-03-03 02:43:32 -05:00
if ( $is_www ) :
?>
< h3 >< ? php esc_html_e ( 'Server Address' ); ?> </h3>
2011-07-31 18:16:19 -04:00
< p >< ? php printf ( __ ( 'We recommend you change your siteurl to <code>%1$s</code> before enabling the network feature. It will still be possible to visit your site using the <code>www</code> prefix with an address like <code>%2$s</code> but any links will not have the <code>www</code> prefix.' ), substr ( $hostname , 4 ), $hostname ); ?> </p>
2010-01-31 06:55:39 -05:00
< table class = " form-table " >
< tr >
< th scope = 'row' >< ? php esc_html_e ( 'Server Address' ); ?> </th>
< td >
2010-04-11 06:41:54 -04:00
< ? php printf ( __ ( 'The internet address of your network will be <code>%s</code>.' ), $hostname ); ?>
2010-01-31 06:55:39 -05:00
</ td >
</ tr >
</ table >
2010-03-03 02:43:32 -05:00
< ? php endif ; ?>
2010-01-31 06:55:39 -05:00
2010-03-03 02:43:32 -05:00
< h3 >< ? php esc_html_e ( 'Network Details' ); ?> </h3>
2010-01-31 06:55:39 -05:00
< table class = " form-table " >
2010-03-09 01:14:42 -05:00
< ? php if ( 'localhost' == $hostname ) : ?>
< tr >
< th scope = " row " >< ? php esc_html_e ( 'Sub-directory Install' ); ?> </th>
2010-05-25 11:16:31 -04:00
< td >< ? php
_e ( 'Because you are using <code>localhost</code>, the sites in your WordPress network must use sub-directories. Consider using <code>localhost.localdomain</code> if you wish to use sub-domains.' );
// Uh oh:
if ( ! allow_subdirectory_install () )
echo ' <strong>' . __ ( 'Warning!' ) . ' ' . __ ( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>' ;
?> </td>
2010-03-09 01:14:42 -05:00
</ tr >
2010-04-01 22:04:25 -04:00
< ? php elseif ( ! allow_subdomain_install () ) : ?>
< tr >
< th scope = " row " >< ? php esc_html_e ( 'Sub-directory Install' ); ?> </th>
2010-05-25 11:16:31 -04:00
< td >< ? php
_e ( 'Because your install is in a directory, the sites in your WordPress network must use sub-directories.' );
// Uh oh:
if ( ! allow_subdirectory_install () )
2010-05-25 22:42:15 -04:00
echo ' <strong>' . __ ( 'Warning!' ) . ' ' . __ ( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>' ;
2010-05-25 11:16:31 -04:00
?> </td>
2010-04-01 22:04:25 -04:00
</ tr >
2010-05-25 11:16:31 -04:00
< ? php elseif ( ! allow_subdirectory_install () ) : ?>
2010-05-08 11:43:00 -04:00
< tr >
< th scope = " row " >< ? php esc_html_e ( 'Sub-domain Install' ); ?> </th>
2010-05-25 11:16:31 -04:00
< td >< ? php _e ( 'Because your install is not new, the sites in your WordPress network must use sub-domains.' );
echo ' <strong>' . __ ( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>' ;
?> </td>
2010-05-08 11:43:00 -04:00
</ tr >
2010-03-09 01:14:42 -05:00
< ? php endif ; ?>
2010-03-03 02:43:32 -05:00
< ? php if ( ! $is_www ) : ?>
2010-01-31 06:55:39 -05:00
< tr >
2010-03-03 02:43:32 -05:00
< th scope = 'row' >< ? php esc_html_e ( 'Server Address' ); ?> </th>
< td >
2010-04-11 06:41:54 -04:00
< ? php printf ( __ ( 'The internet address of your network will be <code>%s</code>.' ), $hostname ); ?>
2010-03-03 02:43:32 -05:00
</ td >
</ tr >
< ? php endif ; ?>
< tr >
< th scope = 'row' >< ? php esc_html_e ( 'Network Title' ); ?> </th>
2010-01-31 06:55:39 -05:00
< td >
2010-03-10 20:51:24 -05:00
< input name = 'sitename' type = 'text' size = '45' value = '<?php echo esc_attr( $site_name ); ?>' />
2010-03-03 02:43:32 -05:00
< br />< ? php _e ( 'What would you like to call your network?' ); ?>
2010-01-31 06:55:39 -05:00
</ td >
</ tr >
< tr >
2010-03-03 02:43:32 -05:00
< th scope = 'row' >< ? php esc_html_e ( 'Admin E-mail Address' ); ?> </th>
2010-01-31 06:55:39 -05:00
< td >
2010-03-10 20:51:24 -05:00
< input name = 'email' type = 'text' size = '45' value = '<?php echo esc_attr( $admin_email ); ?>' />
2010-01-31 06:55:39 -05:00
< br />< ? php _e ( 'Your email address.' ); ?>
</ td >
</ tr >
</ table >
2010-10-28 17:56:43 -04:00
< ? php submit_button ( __ ( 'Install' ), 'primary' , 'submit' ); ?>
2010-05-15 02:49:16 -04:00
</ form >
2010-10-28 17:56:43 -04:00
< ? php
2010-02-06 21:13:20 -05:00
}
/**
2010-03-03 02:43:32 -05:00
* Prints step 2 for Network installation process .
2010-02-06 21:13:20 -05:00
*
* @ since 3.0 . 0
*/
2010-03-10 20:51:24 -05:00
function network_step2 ( $errors = false ) {
2012-09-27 02:07:21 -04:00
global $wpdb ;
2010-03-10 20:51:24 -05:00
2012-09-27 02:07:21 -04:00
$hostname = get_clean_basedomain ();
$slashed_home = trailingslashit ( get_option ( 'home' ) );
$base = parse_url ( $slashed_home , PHP_URL_PATH );
2013-01-10 03:08:14 -05:00
$document_root_fix = str_replace ( '\\' , '/' , realpath ( $_SERVER [ 'DOCUMENT_ROOT' ] ) );
$abspath_fix = str_replace ( '\\' , '/' , ABSPATH );
$home_path = 0 === strpos ( $abspath_fix , $document_root_fix ) ? $document_root_fix . $base : str_replace ( '\\' , '/' , get_home_path () );
$wp_siteurl_subdir = preg_replace ( '#^' . preg_quote ( $home_path , '#' ) . '#' , '' , $abspath_fix );
2012-09-27 02:07:21 -04:00
$rewrite_base = ! empty ( $wp_siteurl_subdir ) ? ltrim ( trailingslashit ( $wp_siteurl_subdir ), '/' ) : '' ;
2011-01-16 16:50:45 -05:00
2012-12-02 22:42:02 -05:00
2012-12-02 21:54:29 -05:00
$location_of_wp_config = ABSPATH ;
if ( ! file_exists ( ABSPATH . 'wp-config.php' ) && file_exists ( dirname ( ABSPATH ) . '/wp-config.php' ) )
2012-12-02 21:59:04 -05:00
$location_of_wp_config = trailingslashit ( dirname ( ABSPATH ) );
2012-12-02 21:54:29 -05:00
2010-03-10 20:51:24 -05:00
// Wildcard DNS message.
if ( is_wp_error ( $errors ) )
echo '<div class="error">' . $errors -> get_error_message () . '</div>' ;
2010-03-10 03:17:07 -05:00
if ( $_POST ) {
2010-11-18 00:37:00 -05:00
if ( allow_subdomain_install () )
$subdomain_install = allow_subdirectory_install () ? ! empty ( $_POST [ 'subdomain_install' ] ) : true ;
else
$subdomain_install = false ;
2010-03-10 03:17:07 -05:00
} else {
if ( is_multisite () ) {
2010-05-04 16:48:28 -04:00
$subdomain_install = is_subdomain_install ();
2010-03-10 03:17:07 -05:00
?>
2010-11-18 00:24:13 -05:00
< p >< ? php _e ( 'The original configuration steps are shown here for reference.' ); ?> </p>
< ? php
} else {
2010-05-04 16:48:28 -04:00
$subdomain_install = ( bool ) $wpdb -> get_var ( " SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install' " );
2010-03-10 03:17:07 -05:00
?>
2010-03-09 13:58:05 -05:00
< div class = " error " >< p >< strong >< ? php _e ( 'Warning:' ); ?> </strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div>
< p >< ? php _e ( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?> </p>
2010-03-10 03:34:42 -05:00
< ? php
}
}
2012-12-02 22:42:02 -05:00
$subdir_match = $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?' ;
2012-09-27 02:07:21 -04:00
$subdir_replacement_01 = $subdomain_install ? '' : '$1' ;
$subdir_replacement_12 = $subdomain_install ? '$1' : '$2' ;
2010-03-10 03:34:42 -05:00
if ( $_POST || ! is_multisite () ) {
?>
2010-03-03 02:43:32 -05:00
< h3 >< ? php esc_html_e ( 'Enabling the Network' ); ?> </h3>
2010-03-06 15:01:32 -05:00
< p >< ? php _e ( 'Complete the following steps to enable the features for creating a network of sites.' ); ?> </p>
2010-05-27 22:41:01 -04:00
< div class = " updated inline " >< p >< ? php
2012-12-02 22:42:02 -05:00
if ( file_exists ( $home_path . '.htaccess' ) )
2010-12-14 12:02:29 -05:00
printf ( __ ( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.' ), '.htaccess' );
2012-12-02 22:42:02 -05:00
elseif ( file_exists ( $home_path . 'web.config' ) )
2010-12-14 12:02:29 -05:00
printf ( __ ( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.' ), 'web.config' );
2010-05-27 22:41:01 -04:00
else
2010-12-14 12:02:29 -05:00
_e ( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> file.' );
2010-05-27 22:41:01 -04:00
?> </p></div>
2010-03-09 17:42:36 -05:00
< ? php
2010-03-10 03:17:07 -05:00
}
2010-03-09 17:42:36 -05:00
?>
2010-01-31 06:55:39 -05:00
< ol >
2012-12-02 21:54:29 -05:00
< li >< p >< ? php printf ( __ ( 'Add the following to your <code>wp-config.php</code> file in <code>%s</code> <strong>above</strong> the line reading <code>/* That’s all, stop editing! Happy blogging. */</code>:' ), $location_of_wp_config ); ?> </p>
2012-09-27 02:07:21 -04:00
< textarea class = " code " readonly = " readonly " cols = " 100 " rows = " 6 " >
2012-02-20 11:35:03 -05:00
define ( 'MULTISITE' , true );
define ( 'SUBDOMAIN_INSTALL' , < ? php echo $subdomain_install ? 'true' : 'false' ; ?> );
define ( 'DOMAIN_CURRENT_SITE' , '<?php echo $hostname; ?>' );
define ( 'PATH_CURRENT_SITE' , '<?php echo $base; ?>' );
define ( 'SITE_ID_CURRENT_SITE' , 1 );
2012-09-27 02:07:21 -04:00
define ( 'BLOG_ID_CURRENT_SITE' , 1 );
</ textarea >
2010-03-06 16:01:58 -05:00
< ? php
$keys_salts = array ( 'AUTH_KEY' => '' , '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 ] );
}
2012-09-27 02:07:21 -04:00
2010-12-13 16:21:50 -05:00
if ( ! empty ( $keys_salts ) ) {
2010-12-06 10:26:30 -05:00
$keys_salts_str = '' ;
2010-03-06 16:01:58 -05:00
$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 ) {
2010-12-06 10:26:30 -05:00
$keys_salts_str .= " \n define( ' $c ', ' " . wp_generate_password ( 64 , true , true ) . " ' ); " ;
2010-03-06 16:01:58 -05:00
}
} else {
$from_api = explode ( " \n " , wp_remote_retrieve_body ( $from_api ) );
foreach ( $keys_salts as $c => $v ) {
2010-12-06 10:26:30 -05:00
$keys_salts_str .= " \n define( ' $c ', ' " . substr ( array_shift ( $from_api ), 28 , 64 ) . " ' ); " ;
2010-03-06 16:01:58 -05:00
}
}
$num_keys_salts = count ( $keys_salts );
?>
< p >< ? php
echo _n ( 'This unique authentication key is also missing from your <code>wp-config.php</code> file.' , 'These unique authentication keys are also missing from your <code>wp-config.php</code> file.' , $num_keys_salts ); ?> <?php _e( 'To make your installation more secure, you should also add:' ) ?></p>
2010-12-06 10:26:30 -05:00
< textarea class = " code " readonly = " readonly " cols = " 100 " rows = " <?php echo $num_keys_salts ; ?> " >< ? php echo esc_textarea ( $keys_salts_str ); ?> </textarea>
2010-03-17 12:27:25 -04:00
< ? php
2010-03-06 16:01:58 -05:00
}
?>
</ li >
2010-01-31 06:55:39 -05:00
< ? php
2010-05-27 22:41:01 -04:00
if ( iis7_supports_permalinks () ) :
2012-09-27 02:07:21 -04:00
// IIS doesn't support RewriteBase, all your RewriteBase are belong to us
$iis_subdir_match = ltrim ( $base , '/' ) . $subdir_match ;
$iis_rewrite_base = ltrim ( $base , '/' ) . $rewrite_base ;
$iis_subdir_replacement = $subdomain_install ? '' : '{R:1}' ;
2010-05-27 22:41:01 -04:00
2012-12-13 17:54:36 -05:00
$web_config_file = ' < ? xml version = " 1.0 " encoding = " UTF-8 " ?>
2010-05-25 01:12:47 -04:00
< configuration >
< system . webServer >
< rewrite >
< rules >
< rule name = " WordPress Rule 1 " stopProcessing = " true " >
< match url = " ^index \ .php $ " ignoreCase = " false " />
< action type = " None " />
2012-09-11 18:22:20 -04:00
</ rule > ' ;
if ( is_multisite () && get_site_option ( 'ms_files_rewriting' ) ) {
$web_config_file .= '
< rule name = " WordPress Rule for Files " stopProcessing = " true " >
2012-12-13 17:54:36 -05:00
< match url = " ^' . $iis_subdir_match . 'files/(.+) " ignoreCase = " false " />
< action type = " Rewrite " url = " ' . $iis_rewrite_base . 'wp-includes/ms-files.php?file= { R:1} " appendQueryString = " false " />
2012-09-11 18:22:20 -04:00
</ rule > ' ;
}
$web_config_file .= '
< rule name = " WordPress Rule 2 " stopProcessing = " true " >
2012-12-13 17:54:36 -05:00
< match url = " ^' . $iis_subdir_match . 'wp-admin $ " ignoreCase = " false " />
< action type = " Redirect " url = " ' . $iis_subdir_replacement . 'wp-admin/ " redirectType = " Permanent " />
2010-05-25 01:12:47 -04:00
</ rule >
2012-09-11 18:22:20 -04:00
< rule name = " WordPress Rule 3 " stopProcessing = " true " >
2010-05-25 01:12:47 -04:00
< match url = " ^ " ignoreCase = " false " />
< conditions logicalGrouping = " MatchAny " >
< add input = " { REQUEST_FILENAME} " matchType = " IsFile " ignoreCase = " false " />
< add input = " { REQUEST_FILENAME} " matchType = " IsDirectory " ignoreCase = " false " />
</ conditions >
< action type = " None " />
</ rule >
2012-09-11 18:22:20 -04:00
< rule name = " WordPress Rule 4 " stopProcessing = " true " >
2012-12-13 17:54:36 -05:00
< match url = " ^' . $iis_subdir_match . '(wp-(content|admin|includes).*) " ignoreCase = " false " />
< action type = " Rewrite " url = " ' . $iis_rewrite_base . ' { R:1} " />
2010-05-25 01:12:47 -04:00
</ rule >
2012-09-11 18:22:20 -04:00
< rule name = " WordPress Rule 5 " stopProcessing = " true " >
2012-12-13 17:54:36 -05:00
< match url = " ^' . $iis_subdir_match . '([_0-9a-zA-Z-]+/)?(.* \ .php) $ " ignoreCase = " false " />
< action type = " Rewrite " url = " ' . $iis_rewrite_base . ' { R:2} " />
2010-05-25 01:12:47 -04:00
</ rule >
2012-09-11 18:22:20 -04:00
< rule name = " WordPress Rule 6 " stopProcessing = " true " >
2010-05-25 01:12:47 -04:00
< match url = " . " ignoreCase = " false " />
< action type = " Rewrite " url = " index.php " />
</ rule >
</ rules >
</ rewrite >
</ system . webServer >
2012-12-13 17:54:36 -05:00
</ configuration > ' ;
2012-09-27 02:07:21 -04:00
2010-05-25 01:12:47 -04:00
?>
2012-12-02 22:42:02 -05:00
< li >< p >< ? php printf ( __ ( 'Add the following to your <code>web.config</code> file in <code>%s</code>, replacing other WordPress rules:' ), $home_path ); ?> </p>
2012-09-11 18:22:20 -04:00
< ? php
if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
echo '<p><strong>' . __ ( 'Warning:' ) . ' ' . __ ( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>' ;
?>
< textarea class = " code " readonly = " readonly " cols = " 100 " rows = " 20 " >< ? php echo esc_textarea ( $web_config_file ); ?>
2010-05-25 01:12:47 -04:00
</ textarea ></ li >
</ ol >
2010-05-27 22:41:01 -04:00
< ? php else : // end iis7_supports_permalinks(). construct an htaccess file instead:
2012-09-27 02:07:21 -04:00
$ms_files_rewriting = '' ;
2012-09-11 18:22:20 -04:00
if ( is_multisite () && get_site_option ( 'ms_files_rewriting' ) ) {
2012-09-27 02:07:21 -04:00
$ms_files_rewriting = " \n # uploaded files \n RewriteRule ^ " ;
$ms_files_rewriting .= $subdir_match . " files/(.+) { $rewrite_base } wp-includes/ms-files.php?file= { $subdir_replacement_12 } [L] " . " \n " ;
2012-09-11 18:22:20 -04:00
}
2010-05-25 22:42:15 -04:00
2012-09-27 02:07:21 -04:00
$htaccess_file = <<< EOF
RewriteEngine On
RewriteBase { $base }
RewriteRule ^ index\ . php $ - [ L ]
{ $ms_files_rewriting }
# add a trailing slash to /wp-admin
RewriteRule ^ { $subdir_match } wp - admin $ { $subdir_replacement_01 } wp - admin / [ R = 301 , L ]
2010-05-25 22:42:15 -04:00
2012-09-27 02:07:21 -04:00
RewriteCond % { REQUEST_FILENAME } - f [ OR ]
2010-05-25 19:55:32 -04:00
RewriteCond % { REQUEST_FILENAME } - d
2012-09-27 02:07:21 -04:00
RewriteRule ^ - [ L ]
RewriteRule ^ { $subdir_match }( wp - ( content | admin | includes ) .* ) { $rewrite_base }{ $subdir_replacement_12 } [ L ]
RewriteRule ^ { $subdir_match }( .* \ . php ) $ { $rewrite_base } $subdir_replacement_12 [ L ]
RewriteRule . index . php [ L ]
EOF ;
2010-05-25 22:42:15 -04:00
2010-05-25 01:12:47 -04:00
?>
2012-12-02 22:42:02 -05:00
< li >< p >< ? php printf ( __ ( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), $home_path ); ?> </p>
2012-09-11 18:22:20 -04:00
< ? php
if ( ! $subdomain_install && WP_CONTENT_DIR != ABSPATH . 'wp-content' )
echo '<p><strong>' . __ ( 'Warning:' ) . ' ' . __ ( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '</strong></p>' ;
?>
< textarea class = " code " readonly = " readonly " cols = " 100 " rows = " <?php echo substr_count( $htaccess_file , " \n " ) + 1; ?> " >
2010-11-17 12:12:01 -05:00
< ? php echo esc_textarea ( $htaccess_file ); ?> </textarea></li>
2010-03-03 02:43:32 -05:00
</ ol >
2010-05-27 22:41:01 -04:00
< ? php endif ; // end IIS/Apache code branches.
2010-05-25 01:12:47 -04:00
if ( ! is_multisite () ) { ?>
2010-05-08 11:25:33 -04:00
< p >< ? php printf ( __ ( 'Once you complete these steps, your network is enabled and configured. You will have to log in again.' ) ); ?> <a href="<?php echo esc_url( site_url( 'wp-login.php' ) ); ?>"><?php _e( 'Log In' ); ?></a></p>
2010-03-03 02:43:32 -05:00
< ? php
2010-03-09 17:42:36 -05:00
}
2010-01-31 06:55:39 -05:00
}
2010-03-09 13:58:05 -05:00
if ( $_POST ) {
2010-12-01 16:32:40 -05:00
2010-03-09 13:58:05 -05:00
check_admin_referer ( 'install-network-1' );
2010-01-31 06:55:39 -05:00
2010-03-09 13:58:05 -05:00
require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
// create network tables
install_network ();
2012-09-27 02:07:21 -04:00
$base = parse_url ( trailingslashit ( get_option ( 'home' ) ), PHP_URL_PATH );
2011-10-24 15:13:23 -04:00
$subdomain_install = allow_subdomain_install () ? ! empty ( $_POST [ 'subdomain_install' ] ) : false ;
2010-03-10 20:51:24 -05:00
if ( ! network_domain_check () ) {
2010-05-24 15:18:30 -04:00
$result = populate_network ( 1 , get_clean_basedomain (), sanitize_email ( $_POST [ 'email' ] ), stripslashes ( $_POST [ 'sitename' ] ), $base , $subdomain_install );
2010-03-10 20:51:24 -05:00
if ( is_wp_error ( $result ) ) {
if ( 1 == count ( $result -> get_error_codes () ) && 'no_wildcard_dns' == $result -> get_error_code () )
network_step2 ( $result );
else
network_step1 ( $result );
} else {
network_step2 ();
}
} else {
network_step2 ();
}
2010-03-09 17:42:36 -05:00
} elseif ( is_multisite () || network_domain_check () ) {
2010-03-09 13:58:05 -05:00
network_step2 ();
} else {
network_step1 ();
2010-01-31 06:55:39 -05:00
}
?>
</ div >
2010-11-18 00:24:13 -05:00
< ? php include ( ABSPATH . 'wp-admin/admin-footer.php' ); ?>