diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index 0f8779e305..ce0a7532ae 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -619,25 +619,29 @@ function populate_roles_300() { * @since 3.0 * * @param int $network_id id of network to populate + * @return bool|WP_Error True on success, or WP_Error on warning (with the install otherwise successful, + * so the error code must be checked) or failure. */ function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) { global $wpdb, $current_site, $wp_db_version, $wp_rewrite; - $msg = ''; - //@todo: turn these checks into returned messages - if ( $domain == '' ) - die( 'You must provide a domain name!' ); - if ( $site_name == '' ) - die( 'You must provide a site name!' ); + $errors = new WP_Error(); + if ( '' == $domain ) + $errors->add( 'empty_domain', __( 'You must provide a domain name.' ) ); + if ( '' == $site_name ) + $errors->add( 'empty_sitename', __( 'You must provide a name for your network of sites.' ) ); // check for network collision - $existing_network = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ); - if ( $existing_network == $network_id ) - die( 'That network already exists!' ); + if ( $network_id == $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE id = %d", $network_id ) ) ) + $errors->add( 'siteid_exists', __( 'The network already exists.' ) ); $site_user = get_user_by_email( $email ); - if ( !$site_user ) - die( 'You must provide an email address!' ); + if ( ! is_email( $email ) ) + $errors->add( 'invalid_email', __( 'You must provide a valid e-mail address.' ) ); + + if ( $errors->get_error_code() ) + return $errors; + // set up site tables $template = get_option( 'template' ); $stylesheet = get_option( 'stylesheet' ); @@ -742,26 +746,27 @@ Thanks! if ( $subdomain_install ) { $vhost_ok = false; + $errstr = ''; $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname! $page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) ); - if ( is_wp_error( $page ) ) { - foreach ( $page->get_error_messages() as $err ) { - $errstr = $err; - } - } elseif( $page[ 'response' ][ 'code' ] == 200 ) { + if ( is_wp_error( $page ) ) + $errstr = $page->get_error_message(); + elseif ( 200 == $page['response']['code'] ) $vhost_ok = true; - } + if ( ! $vhost_ok ) { - // @todo Update this to reflect the merge. Also: Multisite readme file, or remove the
tags. - $msg = '

' . esc_html__( 'Warning! Wildcard DNS may not be configured correctly!' ) . '

'; - $msg .= '

' . __( '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:' ) . '
'; - $msg .= '
' . $errstr . '

'; - $msg .= '

' . __( 'From the README.txt:' ) . '

'; - $msg .= '

' . __( "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 explanation on his blog. If you still have problems, these forum messages may help." ) . '

'; - $msg .= '

' . __( '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.' ) . '

'; + $msg = '

' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '

'; + $msg .= '

' . sprintf( __( 'To use a subdomain configuration, you must have a wildcard entry in your DNS. The installer attempted to contact a random hostname (%1$s) on your domain.' ), $hostname ); + if ( ! empty ( $errstr ) ) + $msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), $errstr ); + $msg .= '

'; + $msg .= '

' . __( 'If you want to host sites in the form of http://site1.example.com then you must add a wildcard record to your DNS records. This usually means adding a * hostname record pointing at your web server in your DNS configuration tool.' ) . '

'; + $msg .= '

' . __( '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.' ) . '

'; + return new WP_Error( 'no_wildcard_dns', $msg ); } } - return $msg; + + return true; } ?> diff --git a/wp-admin/network.php b/wp-admin/network.php index 9b45a908f2..d305e2953d 100644 --- a/wp-admin/network.php +++ b/wp-admin/network.php @@ -62,7 +62,7 @@ include( './admin-header.php' );

-
+

' . __( 'ERROR: The network could not be created.' ) . '

'; + foreach ( $errors->get_error_messages() as $error ) + echo "

$error

"; + echo ''; + $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' ); ?>

' . __( 'Please make sure the Apache mod_rewrite module is installed as it will be used at the end of this install.' ) . '

'; else @@ -112,23 +127,21 @@ function network_step1() { echo '

' . __( 'If mod_rewrite is disabled ask your administrator to enable that module, or look at the Apache documentation or elsewhere for help setting it up.' ) . '

'; } - wp_nonce_field( 'install-network-1' ); - if ( 'localhost' != $hostname ) : ?>

You cannot change this later.' ); ?>

- +

Note It looks like mod_rewrite is not installed.' ); ?>

- + - +
site1.example.com and site2.example.com'); ?>
example.com/site1 and example.com/site2'); ?>
@@ -136,7 +149,7 @@ function network_step1() {

@@ -146,7 +159,6 @@ function network_step1() { %s.' ), $hostname ); ?> - @@ -171,14 +183,14 @@ function network_step1() { - ' /> +
- ' /> +
@@ -192,9 +204,14 @@ function network_step1() { * * @since 3.0.0 */ -function network_step2() { +function network_step2( $errors = false ) { global $base, $wpdb; $hostname = get_clean_basedomain(); + + // Wildcard DNS message. + if ( is_wp_error( $errors ) ) + echo '
' . $errors->get_error_message() . '
'; + if ( $_POST ) { $vhost = 'localhost' == $hostname ? false : (bool) $_POST['subdomain_install']; } else { @@ -263,14 +280,11 @@ define( 'BLOG_ID_CURRENT_SITE', 1 ); get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() ) + network_step2( $result ); + else + network_step1( $result ); + } else { + network_step2(); + } + } else { + network_step2(); + } } elseif ( is_multisite() || network_domain_check() ) { network_step2(); } else {