Make WordPress Core


Ignore:
Timestamp:
03/11/2010 01:51:24 AM (14 years ago)
Author:
nacin
Message:

First pass at error handling for populate_network() and network.php. see #11816

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/schema.php

    r13642 r13655  
    620620 *
    621621 * @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.
    622624 */
    623625function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) {
    624626    global $wpdb, $current_site, $wp_db_version, $wp_rewrite;
    625627
    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.' ) );
    632633
    633634    // 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.' ) );
    637637
    638638    $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
    641645    // set up site tables
    642646    $template = get_option( 'template' );
     
    743747    if ( $subdomain_install ) {
    744748        $vhost_ok = false;
     749        $errstr = '';
    745750        $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname!
    746751        $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'] )
    752755                $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 );
    753766        }
    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;
    765770}
    766771
Note: See TracChangeset for help on using the changeset viewer.