Changeset 13655
- Timestamp:
- 03/11/2010 01:51:24 AM (15 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/schema.php
r13642 r13655 620 620 * 621 621 * @param int $network_id id of network to populate 622 * @return bool|WP_Error True on success, or WP_Error on warning (with the install otherwise successful, 623 * so the error code must be checked) or failure. 622 624 */ 623 625 function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) { 624 626 global $wpdb, $current_site, $wp_db_version, $wp_rewrite; 625 627 626 $msg = ''; 627 //@todo: turn these checks into returned messages 628 if ( $domain == '' ) 629 die( 'You must provide a domain name!' ); 630 if ( $site_name == '' ) 631 die( 'You must provide a site name!' ); 628 $errors = new WP_Error(); 629 if ( '' == $domain ) 630 $errors->add( 'empty_domain', __( 'You must provide a domain name.' ) ); 631 if ( '' == $site_name ) 632 $errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) ); 632 633 633 634 // check for network collision 634 $existing_network = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ); 635 if ( $existing_network == $network_id ) 636 die( 'That network already exists!' ); 635 if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) ) 636 $errors->add( 'siteid_exists', __( 'The network already exists.' ) ); 637 637 638 638 $site_user = get_user_by_email( $email ); 639 if ( !$site_user ) 640 die( 'You must provide an email address!' ); 639 if ( ! is_email( $email ) ) 640 $errors->add( 'invalid_email', __( 'You must provide a valid e-mail address.' ) ); 641 642 if ( $errors->get_error_code() ) 643 return $errors; 644 641 645 // set up site tables 642 646 $template = get_option( 'template' ); … … 743 747 if ( $subdomain_install ) { 744 748 $vhost_ok = false; 749 $errstr = ''; 745 750 $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname! 746 751 $page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) ); 747 if ( is_wp_error( $page ) ) { 748 foreach ( $page->get_error_messages() as $err ) { 749 $errstr = $err; 750 } 751 } elseif( $page[ 'response' ][ 'code' ] == 200 ) { 752 if ( is_wp_error( $page ) ) 753 $errstr = $page->get_error_message(); 754 elseif ( 200 == $page['response']['code'] ) 752 755 $vhost_ok = true; 756 757 if ( ! $vhost_ok ) { 758 $msg = '<p><strong>' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</strong></p>'; 759 $msg .= '<p>' . sprintf( __( 'To use a subdomain configuration, you must have a wildcard entry in your DNS. The installer attempted to contact a random hostname (<code>%1$s</code>) on your domain.' ), $hostname ); 760 if ( ! empty ( $errstr ) ) 761 $msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), $errstr ); 762 $msg .= '</p>'; 763 $msg .= '<p>' . __( 'If you want to host sites in the form of <code>http://site1.example.com</code> then you must add a wildcard record to your DNS records. This usually means adding a <code>*</code> hostname record pointing at your web server in your DNS configuration tool.' ) . '</p>'; 764 $msg .= '<p>' . __( 'You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.' ) . '</p>'; 765 return new WP_Error( 'no_wildcard_dns', $msg ); 753 766 } 754 if ( ! $vhost_ok ) { 755 // @todo Update this to reflect the merge. Also: Multisite readme file, or remove the <blockquote> tags. 756 $msg = '<h2>' . esc_html__( 'Warning! Wildcard DNS may not be configured correctly!' ) . '</h2>'; 757 $msg .= '<p>' . __( 'To use the subdomain feature of WordPress MU you must have a wildcard entry in your dns. The installer attempted to contact a random hostname ($hostname) on your domain but failed. It returned this error message:' ) . '<br />'; 758 $msg .= '<br/><strong>' . $errstr . '</strong></p>'; 759 $msg .= '<p>' . __( 'From the README.txt:' ) . '</p>'; 760 $msg .= '<blockquote><p>' . __( "If you want to host blogs of the form http://blog.domain.tld/ where domain.tld is the domain name of your machine then you must add a wildcard record to your DNS records. This usually means adding a '*' hostname record pointing at your webserver in your DNS configuration tool. Matt has a more detailed <a href='http://ma.tt/2003/10/10/wildcard-dns-and-sub-domains/'>explanation</a> on his blog. If you still have problems, these <a href='http://mu.wordpress.org/forums/tags/wildcard'>forum messages</a> may help." ) . '</p></blockquote>'; 761 $msg .= '<p>' . __( 'You can still use your site but any subdomain you create may not be accessible. This check is not foolproof so ignore if you know your dns is correct.' ) . '</p>'; 762 } 763 } 764 return $msg; 767 } 768 769 return true; 765 770 } 766 771 -
trunk/wp-admin/network.php
r13644 r13655 63 63 <h2><?php echo esc_html( $title ); ?></h2> 64 64 65 <form method="post" action="network.php">65 <form method="post"> 66 66 <?php 67 67 /** … … 73 73 * @since 3.0.0 74 74 */ 75 function network_step1( ) {75 function network_step1( $errors = false ) { 76 76 77 77 $active_plugins = get_option( 'active_plugins' ); … … 96 96 } 97 97 98 wp_nonce_field( 'install-network-1' ); 99 100 $error_codes = array(); 101 if ( is_wp_error( $errors ) ) { 102 echo '<div class="error"><p><strong>' . __( 'ERROR: The network could not be created.' ) . '</strong></p>'; 103 foreach ( $errors->get_error_messages() as $error ) 104 echo "<p>$error</p>"; 105 echo '</div>'; 106 $error_codes = $errors->get_error_codes(); 107 } 108 109 $site_name = ( ! empty( $_POST['sitename'] ) && ! in_array( 'empty_sitename', $error_codes ) ) ? $_POST['sitename'] : sprintf( _x('%s Sites', 'Default network name' ), get_option( 'blogname' ) ); 110 $admin_email = ( ! empty( $_POST['email'] ) && ! in_array( 'invalid_email', $error_codes ) ) ? $_POST['email'] : get_option( 'admin_email' ); 98 111 ?> 99 112 <p><?php _e( 'Welcome to the Network installation process!' ); ?></p> … … 102 115 103 116 // @todo IIS... 104 if ( apache_mod_loaded('mod_rewrite') ) { // assume nothing 105 $rewrite_enabled = true; 117 if ( ! empty( $_POST['subdomain_install'] ) ) { 118 $subdomain_install = (bool) $_POST['subdomain_install']; 119 } elseif ( apache_mod_loaded('mod_rewrite') ) { // assume nothing 120 $subdomain_install = true; 106 121 } else { 107 $ rewrite_enabled= false;122 $subdomain_install = false; 108 123 if ( got_mod_rewrite() ) // dangerous assumptions 109 124 echo '<p>' . __( 'Please make sure the Apache <code>mod_rewrite</code> module is installed as it will be used at the end of this install.' ) . '</p>'; … … 113 128 } 114 129 115 wp_nonce_field( 'install-network-1' );116 117 130 if ( 'localhost' != $hostname ) : ?> 118 131 <h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3> … … 120 133 <p><?php _e( "You will need a wildcard DNS record if you're going to use the virtual host (sub-domain) functionality." ); ?></p> 121 134 <?php /* @todo: Link to an MS readme? */ ?> 122 <?php if ( ! $ rewrite_enabled) { ?>135 <?php if ( ! $subdomain_install ) { ?> 123 136 <p><?php _e( '<strong>Note</strong> It looks like <code>mod_rewrite</code> is not installed.' ); ?></p> 124 137 <?php } ?> 125 138 <table class="form-table"> 126 139 <tr> 127 <th><label><input type='radio' name='subdomain_install' value='1'<?php checked( $ rewrite_enabled); ?> /> Sub-domains</label></th>140 <th><label><input type='radio' name='subdomain_install' value='1'<?php checked( $subdomain_install ); ?> /> Sub-domains</label></th> 128 141 <td><?php _e('like <code>site1.example.com</code> and <code>site2.example.com</code>'); ?></td> 129 142 </tr> 130 143 <tr> 131 <th><label><input type='radio' name='subdomain_install' value='0'<?php checked( ! $ rewrite_enabled); ?> /> Sub-directories</label></th>144 <th><label><input type='radio' name='subdomain_install' value='0'<?php checked( ! $subdomain_install ); ?> /> Sub-directories</label></th> 132 145 <td><?php _e('like <code>example.com/site1</code> and <code>example.com/site2</code>'); ?></td> 133 146 </tr> … … 137 150 endif; 138 151 139 $is_www = ( substr( $hostname, 0, 4 ) == 'www.');152 $is_www = ( 0 === strpos( $hostname, 'www.' ) ); 140 153 if ( $is_www ) : 141 154 ?> … … 147 160 <td> 148 161 <?php printf( __( 'The Internet address of your network will be <code>%s</code>.' ), $hostname ); ?> 149 <input type='hidden' name='basedomain' value='<?php echo esc_attr( $hostname ); ?>' />150 162 </td> 151 163 </tr> … … 172 184 <th scope='row'><?php esc_html_e( 'Network Title' ); ?></th> 173 185 <td> 174 <input name=' weblog_title' type='text' size='45' value='<?php echo esc_attr( sprintf( __('%s Sites'), get_option( 'blogname' ) )); ?>' />186 <input name='sitename' type='text' size='45' value='<?php echo esc_attr( $site_name ); ?>' /> 175 187 <br /><?php _e( 'What would you like to call your network?' ); ?> 176 188 </td> … … 179 191 <th scope='row'><?php esc_html_e( 'Admin E-mail Address' ); ?></th> 180 192 <td> 181 <input name='email' type='text' size='45' value='<?php echo esc_attr( get_option( 'admin_email' )); ?>' />193 <input name='email' type='text' size='45' value='<?php echo esc_attr( $admin_email ); ?>' /> 182 194 <br /><?php _e( 'Your email address.' ); ?> 183 195 </td> … … 193 205 * @since 3.0.0 194 206 */ 195 function network_step2( ) {207 function network_step2( $errors = false ) { 196 208 global $base, $wpdb; 197 209 $hostname = get_clean_basedomain(); 210 211 // Wildcard DNS message. 212 if ( is_wp_error( $errors ) ) 213 echo '<div class="error">' . $errors->get_error_message() . '</div>'; 214 198 215 if ( $_POST ) { 199 216 $vhost = 'localhost' == $hostname ? false : (bool) $_POST['subdomain_install']; … … 264 281 <?php 265 282 266 // remove ending slash from $base and $url 267 $htaccess = ''; 268 $base = rtrim( $base, '/' ); 269 270 $htaccess_file = 'RewriteEngine On 271 RewriteBase ' . $base . '/ 272 273 #uploaded files 283 // @todo custom content dir 284 $htaccess_file = 'RewriteEngine On 285 RewriteBase ' . $base . ' 286 287 # uploaded files 274 288 RewriteRule ^(.*/)?files/$ index.php [L] 275 289 RewriteCond %{REQUEST_URI} !.*wp-content/plugins.* … … 308 322 $hostname = get_clean_basedomain(); 309 323 $subdomain_install = 'localhost' == $hostname ? false : (bool) $_POST['subdomain_install']; 310 if ( ! network_domain_check() ) 311 populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), $_POST['weblog_title'], $base, $subdomain_install ); 312 // create wp-config.php / htaccess 313 network_step2(); 324 if ( ! network_domain_check() ) { 325 $result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), $_POST['sitename'], $base, $subdomain_install ); 326 if ( is_wp_error( $result ) ) { 327 if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() ) 328 network_step2( $result ); 329 else 330 network_step1( $result ); 331 } else { 332 network_step2(); 333 } 334 } else { 335 network_step2(); 336 } 314 337 } elseif ( is_multisite() || network_domain_check() ) { 315 338 network_step2();
Note: See TracChangeset
for help on using the changeset viewer.