PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/network.php

https://bitbucket.org/aqge/deptandashboard
PHP | 558 lines | 452 code | 52 blank | 54 comment | 78 complexity | 729b689479beba3404abb6ce341a43fe MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Network installation administration panel.
  4. *
  5. * A multi-step process allowing the user to enable a network of WordPress sites.
  6. *
  7. * @since 3.0.0
  8. *
  9. * @package WordPress
  10. * @subpackage Administration
  11. */
  12. define( 'WP_INSTALLING_NETWORK', true );
  13. /** WordPress Administration Bootstrap */
  14. require_once( './admin.php' );
  15. if ( ! is_super_admin() )
  16. wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
  17. if ( is_multisite() ) {
  18. if ( ! is_network_admin() ) {
  19. wp_redirect( network_admin_url( 'setup.php' ) );
  20. exit;
  21. }
  22. if ( ! defined( 'MULTISITE' ) )
  23. wp_die( __( 'The Network creation panel is not for WordPress MU networks.' ) );
  24. }
  25. // We need to create references to ms global tables to enable Network.
  26. foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table )
  27. $wpdb->$table = $prefixed_table;
  28. /**
  29. * Check for an existing network.
  30. *
  31. * @since 3.0.0
  32. * @return Whether a network exists.
  33. */
  34. function network_domain_check() {
  35. global $wpdb;
  36. if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
  37. return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" );
  38. return false;
  39. }
  40. /**
  41. * Allow subdomain install
  42. *
  43. * @since 3.0.0
  44. * @return bool Whether subdomain install is allowed
  45. */
  46. function allow_subdomain_install() {
  47. $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'siteurl' ) );
  48. if( false !== strpos( $domain, '/' ) || 'localhost' == $domain || preg_match( '|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|', $domain ) )
  49. return false;
  50. return true;
  51. }
  52. /**
  53. * Allow subdirectory install
  54. *
  55. * @since 3.0.0
  56. * @return bool Whether subdirectory install is allowed
  57. */
  58. function allow_subdirectory_install() {
  59. global $wpdb;
  60. if ( apply_filters( 'allow_subdirectory_install', false ) )
  61. return true;
  62. if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL )
  63. return true;
  64. $post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish'" );
  65. if ( empty( $post ) )
  66. return true;
  67. return false;
  68. }
  69. /**
  70. * Get base domain of network.
  71. *
  72. * @since 3.0.0
  73. * @return string Base domain.
  74. */
  75. function get_clean_basedomain() {
  76. if ( $existing_domain = network_domain_check() )
  77. return $existing_domain;
  78. $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
  79. if ( $slash = strpos( $domain, '/' ) )
  80. $domain = substr( $domain, 0, $slash );
  81. return $domain;
  82. }
  83. if ( ! network_domain_check() && ( ! defined( 'WP_ALLOW_MULTISITE' ) || ! WP_ALLOW_MULTISITE ) )
  84. 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.' ) );
  85. if ( is_network_admin() ) {
  86. $title = __( 'Network Setup' );
  87. $parent_file = 'settings.php';
  88. } else {
  89. $title = __( 'Create a Network of WordPress Sites' );
  90. $parent_file = 'tools.php';
  91. }
  92. $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>' .
  93. '<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>' .
  94. '<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>' .
  95. '<p>' . __('Add a <code>blogs.dir</code> directory under <code>/wp-content</code> and 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>' .
  96. '<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>' .
  97. '<p>' . __('The choice of subdirectory sites is disabled if this setup is more than a month old because of permalink problems with &#8220;/blog/&#8221; from the main site. This disabling will be addressed in a future version.') . '</p>' .
  98. '<p><strong>' . __('For more information:') . '</strong></p>' .
  99. '<p>' . __('<a href="http://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>') . '</p>' .
  100. '<p>' . __('<a href="http://codex.wordpress.org/Tools_Network_Screen" target="_blank">Documentation on the Network Screen</a>') . '</p>';
  101. get_current_screen()->add_help_tab( array(
  102. 'id' => 'network',
  103. 'title' => __('Network'),
  104. 'content' => $network_help,
  105. ) );
  106. get_current_screen()->set_help_sidebar(
  107. '<p><strong>' . __('For more information:') . '</strong></p>' .
  108. '<p>' . __('<a href="http://codex.wordpress.org/Create_A_Network" target="_blank">Documentation on Creating a Network</a>') . '</p>' .
  109. '<p>' . __('<a href="http://codex.wordpress.org/Tools_Network_Screen" target="_blank">Documentation on the Network Screen</a>') . '</p>' .
  110. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  111. );
  112. include( ABSPATH . 'wp-admin/admin-header.php' );
  113. ?>
  114. <div class="wrap">
  115. <?php screen_icon('tools'); ?>
  116. <h2><?php echo esc_html( $title ); ?></h2>
  117. <?php
  118. /**
  119. * Prints step 1 for Network installation process.
  120. *
  121. * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. Navigating to Tools > Network
  122. * should not be a sudden "Welcome to a new install process! Fill this out and click here." See also contextual help todo.
  123. *
  124. * @since 3.0.0
  125. */
  126. function network_step1( $errors = false ) {
  127. global $is_apache;
  128. if ( get_option( 'siteurl' ) != get_option( 'home' ) ) {
  129. echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . sprintf( __( 'Your <strong>WordPress address</strong> must match your <strong>Site address</strong> before creating a Network. See <a href="%s">General Settings</a>.' ), esc_url( admin_url( 'options-general.php' ) ) ) . '</p></div>';
  130. echo '</div>';
  131. include ( ABSPATH . 'wp-admin/admin-footer.php' );
  132. die();
  133. }
  134. if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
  135. echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '</p></div>';
  136. echo '</div>';
  137. include ( ABSPATH . 'wp-admin/admin-footer.php' );
  138. die();
  139. }
  140. $active_plugins = get_option( 'active_plugins' );
  141. if ( ! empty( $active_plugins ) ) {
  142. 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>';
  143. echo '</div>';
  144. include( ABSPATH . 'wp-admin/admin-footer.php' );
  145. die();
  146. }
  147. $hostname = get_clean_basedomain();
  148. $has_ports = strstr( $hostname, ':' );
  149. if ( ( false !== $has_ports && ! in_array( $has_ports, array( ':80', ':443' ) ) ) ) {
  150. echo '<div class="error"><p><strong>' . __( 'ERROR:') . '</strong> ' . __( 'You cannot install a network of sites with your server address.' ) . '</p></div>';
  151. echo '<p>' . sprintf( __( 'You cannot use port numbers such as <code>%s</code>.' ), $has_ports ) . '</p>';
  152. echo '<a href="' . esc_url( admin_url() ) . '">' . __( 'Return to Dashboard' ) . '</a>';
  153. echo '</div>';
  154. include( ABSPATH . 'wp-admin/admin-footer.php' );
  155. die();
  156. }
  157. echo '<form method="post" action="">';
  158. wp_nonce_field( 'install-network-1' );
  159. $error_codes = array();
  160. if ( is_wp_error( $errors ) ) {
  161. echo '<div class="error"><p><strong>' . __( 'ERROR: The network could not be created.' ) . '</strong></p>';
  162. foreach ( $errors->get_error_messages() as $error )
  163. echo "<p>$error</p>";
  164. echo '</div>';
  165. $error_codes = $errors->get_error_codes();
  166. }
  167. if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' )
  168. echo '<div class="error"><p><strong>' . __('Warning!') . '</strong> ' . __( 'Networks may not be fully compatible with custom wp-content directories.' ) . '</p></div>';
  169. $site_name = ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) ? $_POST['sitename'] : sprintf( _x('%s Sites', 'Default network name' ), get_option( 'blogname' ) );
  170. $admin_email = ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) ? $_POST['email'] : get_option( 'admin_email' );
  171. ?>
  172. <p><?php _e( 'Welcome to the Network installation process!' ); ?></p>
  173. <p><?php _e( 'Fill in the information below and you&#8217;ll be on your way to creating a network of WordPress sites. We will create configuration files in the next step.' ); ?></p>
  174. <?php
  175. if ( isset( $_POST['subdomain_install'] ) ) {
  176. $subdomain_install = (bool) $_POST['subdomain_install'];
  177. } elseif ( apache_mod_loaded('mod_rewrite') ) { // assume nothing
  178. $subdomain_install = true;
  179. } elseif ( !allow_subdirectory_install() ) {
  180. $subdomain_install = true;
  181. } else {
  182. $subdomain_install = false;
  183. if ( $got_mod_rewrite = got_mod_rewrite() ) // dangerous assumptions
  184. 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>';
  185. elseif ( $is_apache )
  186. echo '<div class="error inline"><p><strong>' . __( 'Warning!' ) . '</strong> ' . __( 'It looks like the Apache <code>mod_rewrite</code> module is not installed.' ) . '</p>';
  187. if ( $got_mod_rewrite || $is_apache ) // Protect against mod_rewrite mimicry (but ! Apache)
  188. 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>';
  189. }
  190. if ( allow_subdomain_install() && allow_subdirectory_install() ) : ?>
  191. <h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
  192. <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>
  193. <p><?php _e( 'You will need a wildcard DNS record if you are going to use the virtual host (sub-domain) functionality.' ); ?></p>
  194. <?php // @todo: Link to an MS readme? ?>
  195. <table class="form-table">
  196. <tr>
  197. <th><label><input type='radio' name='subdomain_install' value='1'<?php checked( $subdomain_install ); ?> /> <?php _e( 'Sub-domains' ); ?></label></th>
  198. <td><?php printf( _x( 'like <code>site1.%1$s</code> and <code>site2.%1$s</code>', 'subdomain examples' ), $hostname ); ?></td>
  199. </tr>
  200. <tr>
  201. <th><label><input type='radio' name='subdomain_install' value='0'<?php checked( ! $subdomain_install ); ?> /> <?php _e( 'Sub-directories' ); ?></label></th>
  202. <td><?php printf( _x( 'like <code>%1$s/site1</code> and <code>%1$s/site2</code>', 'subdirectory examples' ), $hostname ); ?></td>
  203. </tr>
  204. </table>
  205. <?php
  206. endif;
  207. $is_www = ( 0 === strpos( $hostname, 'www.' ) );
  208. if ( $is_www ) :
  209. ?>
  210. <h3><?php esc_html_e( 'Server Address' ); ?></h3>
  211. <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>
  212. <table class="form-table">
  213. <tr>
  214. <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
  215. <td>
  216. <?php printf( __( 'The internet address of your network will be <code>%s</code>.' ), $hostname ); ?>
  217. </td>
  218. </tr>
  219. </table>
  220. <?php endif; ?>
  221. <h3><?php esc_html_e( 'Network Details' ); ?></h3>
  222. <table class="form-table">
  223. <?php if ( 'localhost' == $hostname ) : ?>
  224. <tr>
  225. <th scope="row"><?php esc_html_e( 'Sub-directory Install' ); ?></th>
  226. <td><?php
  227. _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.' );
  228. // Uh oh:
  229. if ( !allow_subdirectory_install() )
  230. echo ' <strong>' . __( 'Warning!' ) . ' ' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
  231. ?></td>
  232. </tr>
  233. <?php elseif ( !allow_subdomain_install() ) : ?>
  234. <tr>
  235. <th scope="row"><?php esc_html_e( 'Sub-directory Install' ); ?></th>
  236. <td><?php
  237. _e( 'Because your install is in a directory, the sites in your WordPress network must use sub-directories.' );
  238. // Uh oh:
  239. if ( !allow_subdirectory_install() )
  240. echo ' <strong>' . __( 'Warning!' ) . ' ' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
  241. ?></td>
  242. </tr>
  243. <?php elseif ( !allow_subdirectory_install() ) : ?>
  244. <tr>
  245. <th scope="row"><?php esc_html_e( 'Sub-domain Install' ); ?></th>
  246. <td><?php _e( 'Because your install is not new, the sites in your WordPress network must use sub-domains.' );
  247. echo ' <strong>' . __( 'The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.' ) . '</strong>';
  248. ?></td>
  249. </tr>
  250. <?php endif; ?>
  251. <?php if ( ! $is_www ) : ?>
  252. <tr>
  253. <th scope='row'><?php esc_html_e( 'Server Address' ); ?></th>
  254. <td>
  255. <?php printf( __( 'The internet address of your network will be <code>%s</code>.' ), $hostname ); ?>
  256. </td>
  257. </tr>
  258. <?php endif; ?>
  259. <tr>
  260. <th scope='row'><?php esc_html_e( 'Network Title' ); ?></th>
  261. <td>
  262. <input name='sitename' type='text' size='45' value='<?php echo esc_attr( $site_name ); ?>' />
  263. <br /><?php _e( 'What would you like to call your network?' ); ?>
  264. </td>
  265. </tr>
  266. <tr>
  267. <th scope='row'><?php esc_html_e( 'Admin E-mail Address' ); ?></th>
  268. <td>
  269. <input name='email' type='text' size='45' value='<?php echo esc_attr( $admin_email ); ?>' />
  270. <br /><?php _e( 'Your email address.' ); ?>
  271. </td>
  272. </tr>
  273. </table>
  274. <?php submit_button( __( 'Install' ), 'primary', 'submit' ); ?>
  275. </form>
  276. <?php
  277. }
  278. /**
  279. * Prints step 2 for Network installation process.
  280. *
  281. * @since 3.0.0
  282. */
  283. function network_step2( $errors = false ) {
  284. global $base, $wpdb;
  285. $hostname = get_clean_basedomain();
  286. if ( ! isset( $base ) )
  287. $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
  288. // Wildcard DNS message.
  289. if ( is_wp_error( $errors ) )
  290. echo '<div class="error">' . $errors->get_error_message() . '</div>';
  291. if ( $_POST ) {
  292. if ( allow_subdomain_install() )
  293. $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true;
  294. else
  295. $subdomain_install = false;
  296. } else {
  297. if ( is_multisite() ) {
  298. $subdomain_install = is_subdomain_install();
  299. ?>
  300. <p><?php _e( 'The original configuration steps are shown here for reference.' ); ?></p>
  301. <?php
  302. } else {
  303. $subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
  304. ?>
  305. <div class="error"><p><strong><?php _e('Warning:'); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div>
  306. <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>
  307. <?php
  308. }
  309. }
  310. if ( $_POST || ! is_multisite() ) {
  311. ?>
  312. <h3><?php esc_html_e( 'Enabling the Network' ); ?></h3>
  313. <p><?php _e( 'Complete the following steps to enable the features for creating a network of sites.' ); ?></p>
  314. <div class="updated inline"><p><?php
  315. if ( file_exists( ABSPATH . '.htaccess' ) )
  316. printf( __( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.' ), '.htaccess' );
  317. elseif ( file_exists( ABSPATH . 'web.config' ) )
  318. printf( __( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> and <code>%s</code> files.' ), 'web.config' );
  319. else
  320. _e( '<strong>Caution:</strong> We recommend you back up your existing <code>wp-config.php</code> file.' );
  321. ?></p></div>
  322. <?php
  323. }
  324. ?>
  325. <ol>
  326. <li><p><?php
  327. printf( __( 'Create a <code>blogs.dir</code> directory at <code>%s/blogs.dir</code>. This directory is used to store uploaded media for your additional sites and must be writeable by the web server.' ), WP_CONTENT_DIR );
  328. if ( WP_CONTENT_DIR != ABSPATH . 'wp-content' )
  329. echo ' <strong>' . __('Warning:') . ' ' . __( 'Networks may not be fully compatible with custom wp-content directories.' ) . '</strong>';
  330. ?></p></li>
  331. <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&#8217;s all, stop editing! Happy blogging. */</code>:' ), ABSPATH ); ?></p>
  332. <textarea class="code" readonly="readonly" cols="100" rows="7">
  333. define( 'MULTISITE', true );
  334. define( 'SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> );
  335. $base = '<?php echo $base; ?>';
  336. define( 'DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>' );
  337. define( 'PATH_CURRENT_SITE', '<?php echo $base; ?>' );
  338. define( 'SITE_ID_CURRENT_SITE', 1 );
  339. define( 'BLOG_ID_CURRENT_SITE', 1 );</textarea>
  340. <?php
  341. $keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' );
  342. foreach ( $keys_salts as $c => $v ) {
  343. if ( defined( $c ) )
  344. unset( $keys_salts[ $c ] );
  345. }
  346. if ( ! empty( $keys_salts ) ) {
  347. $keys_salts_str = '';
  348. $from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
  349. if ( is_wp_error( $from_api ) ) {
  350. foreach ( $keys_salts as $c => $v ) {
  351. $keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";
  352. }
  353. } else {
  354. $from_api = explode( "\n", wp_remote_retrieve_body( $from_api ) );
  355. foreach ( $keys_salts as $c => $v ) {
  356. $keys_salts_str .= "\ndefine( '$c', '" . substr( array_shift( $from_api ), 28, 64 ) . "' );";
  357. }
  358. }
  359. $num_keys_salts = count( $keys_salts );
  360. ?>
  361. <p><?php
  362. 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>
  363. <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?>"><?php echo esc_textarea( $keys_salts_str ); ?></textarea>
  364. <?php
  365. }
  366. ?>
  367. </li>
  368. <?php
  369. if ( iis7_supports_permalinks() ) :
  370. if ( $subdomain_install ) {
  371. $web_config_file =
  372. '<?xml version="1.0" encoding="UTF-8"?>
  373. <configuration>
  374. <system.webServer>
  375. <rewrite>
  376. <rules>
  377. <rule name="WordPress Rule 1" stopProcessing="true">
  378. <match url="^index\.php$" ignoreCase="false" />
  379. <action type="None" />
  380. </rule>
  381. <rule name="WordPress Rule 2" stopProcessing="true">
  382. <match url="^files/(.+)" ignoreCase="false" />
  383. <action type="Rewrite" url="wp-includes/ms-files.php?file={R:1}" appendQueryString="false" />
  384. </rule>
  385. <rule name="WordPress Rule 3" stopProcessing="true">
  386. <match url="^" ignoreCase="false" />
  387. <conditions logicalGrouping="MatchAny">
  388. <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
  389. <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
  390. </conditions>
  391. <action type="None" />
  392. </rule>
  393. <rule name="WordPress Rule 4" stopProcessing="true">
  394. <match url="." ignoreCase="false" />
  395. <action type="Rewrite" url="index.php" />
  396. </rule>
  397. </rules>
  398. </rewrite>
  399. </system.webServer>
  400. </configuration>';
  401. } else {
  402. $web_config_file =
  403. '<?xml version="1.0" encoding="UTF-8"?>
  404. <configuration>
  405. <system.webServer>
  406. <rewrite>
  407. <rules>
  408. <rule name="WordPress Rule 1" stopProcessing="true">
  409. <match url="^index\.php$" ignoreCase="false" />
  410. <action type="None" />
  411. </rule>
  412. <rule name="WordPress Rule 2" stopProcessing="true">
  413. <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" />
  414. <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" />
  415. </rule>
  416. <rule name="WordPress Rule 3" stopProcessing="true">
  417. <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
  418. <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
  419. </rule>
  420. <rule name="WordPress Rule 4" stopProcessing="true">
  421. <match url="^" ignoreCase="false" />
  422. <conditions logicalGrouping="MatchAny">
  423. <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
  424. <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
  425. </conditions>
  426. <action type="None" />
  427. </rule>
  428. <rule name="WordPress Rule 5" stopProcessing="true">
  429. <match url="^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*)" ignoreCase="false" />
  430. <action type="Rewrite" url="{R:1}" />
  431. </rule>
  432. <rule name="WordPress Rule 6" stopProcessing="true">
  433. <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
  434. <action type="Rewrite" url="{R:2}" />
  435. </rule>
  436. <rule name="WordPress Rule 7" stopProcessing="true">
  437. <match url="." ignoreCase="false" />
  438. <action type="Rewrite" url="index.php" />
  439. </rule>
  440. </rules>
  441. </rewrite>
  442. </system.webServer>
  443. </configuration>';
  444. }
  445. ?>
  446. <li><p><?php printf( __( 'Add the following to your <code>web.config</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p>
  447. <textarea class="code" readonly="readonly" cols="100" rows="20">
  448. <?php echo esc_textarea( $web_config_file ); ?>
  449. </textarea></li>
  450. </ol>
  451. <?php else : // end iis7_supports_permalinks(). construct an htaccess file instead:
  452. $htaccess_file = 'RewriteEngine On
  453. RewriteBase ' . $base . '
  454. RewriteRule ^index\.php$ - [L]
  455. # uploaded files
  456. RewriteRule ^' . ( $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $subdomain_install ? 1 : 2 ) . ' [L]' . "\n";
  457. if ( ! $subdomain_install )
  458. $htaccess_file .= "\n# add a trailing slash to /wp-admin\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]' . "\n";
  459. $htaccess_file .= "\n" . 'RewriteCond %{REQUEST_FILENAME} -f [OR]
  460. RewriteCond %{REQUEST_FILENAME} -d
  461. RewriteRule ^ - [L]';
  462. // @todo custom content dir.
  463. if ( ! $subdomain_install )
  464. $htaccess_file .= "\nRewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]\nRewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]";
  465. $htaccess_file .= "\nRewriteRule . index.php [L]";
  466. ?>
  467. <li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p>
  468. <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $subdomain_install ? 11 : 16; ?>">
  469. <?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
  470. </ol>
  471. <?php endif; // end IIS/Apache code branches.
  472. if ( !is_multisite() ) { ?>
  473. <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>
  474. <?php
  475. }
  476. }
  477. if ( $_POST ) {
  478. $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
  479. check_admin_referer( 'install-network-1' );
  480. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  481. // create network tables
  482. install_network();
  483. $hostname = get_clean_basedomain();
  484. $subdomain_install = allow_subdomain_install() ? !empty( $_POST['subdomain_install'] ) : false;
  485. if ( ! network_domain_check() ) {
  486. $result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), stripslashes( $_POST['sitename'] ), $base, $subdomain_install );
  487. if ( is_wp_error( $result ) ) {
  488. if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() )
  489. network_step2( $result );
  490. else
  491. network_step1( $result );
  492. } else {
  493. network_step2();
  494. }
  495. } else {
  496. network_step2();
  497. }
  498. } elseif ( is_multisite() || network_domain_check() ) {
  499. network_step2();
  500. } else {
  501. network_step1();
  502. }
  503. ?>
  504. </div>
  505. <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>