Make WordPress Core


Ignore:
Timestamp:
03/11/2010 01:51:24 AM (15 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/network.php

    r13644 r13655  
    6363<h2><?php echo esc_html( $title ); ?></h2>
    6464
    65 <form method="post" action="network.php">
     65<form method="post">
    6666<?php
    6767/**
     
    7373 * @since 3.0.0
    7474 */
    75 function network_step1() {
     75function network_step1( $errors = false ) {
    7676
    7777    $active_plugins = get_option( 'active_plugins' );
     
    9696    }
    9797
     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' );
    98111    ?>
    99112    <p><?php _e( 'Welcome to the Network installation process!' ); ?></p>
     
    102115
    103116    // @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;
    106121    } else {
    107         $rewrite_enabled = false;
     122        $subdomain_install = false;
    108123        if ( got_mod_rewrite() ) // dangerous assumptions
    109124            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>';
     
    113128    }
    114129
    115     wp_nonce_field( 'install-network-1' );
    116 
    117130    if ( 'localhost' != $hostname ) : ?>
    118131        <h3><?php esc_html_e( 'Addresses of Sites in your Network' ); ?></h3>
     
    120133        <p><?php _e( "You will need a wildcard DNS record if you're going to use the virtual host (sub-domain) functionality." ); ?></p>
    121134        <?php /* @todo: Link to an MS readme? */ ?>
    122         <?php if ( ! $rewrite_enabled ) { ?>
     135        <?php if ( ! $subdomain_install ) { ?>
    123136        <p><?php _e( '<strong>Note</strong> It looks like <code>mod_rewrite</code> is not installed.' ); ?></p>
    124137        <?php } ?>
    125138        <table class="form-table">
    126139            <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>
    128141                <td><?php _e('like <code>site1.example.com</code> and <code>site2.example.com</code>'); ?></td>
    129142            </tr>
    130143            <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>
    132145                <td><?php _e('like <code>example.com/site1</code> and <code>example.com/site2</code>'); ?></td>
    133146            </tr>
     
    137150    endif;
    138151
    139         $is_www = ( substr( $hostname, 0, 4 ) == 'www.' );
     152        $is_www = ( 0 === strpos( $hostname, 'www.' ) );
    140153        if ( $is_www ) :
    141154        ?>
     
    147160                <td>
    148161                    <?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 ); ?>' />
    150162                </td>
    151163            </tr>
     
    172184                <th scope='row'><?php esc_html_e( 'Network Title' ); ?></th>
    173185                <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 ); ?>' />
    175187                    <br /><?php _e( 'What would you like to call your network?' ); ?>
    176188                </td>
     
    179191                <th scope='row'><?php esc_html_e( 'Admin E-mail Address' ); ?></th>
    180192                <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 ); ?>' />
    182194                    <br /><?php _e( 'Your email address.' ); ?>
    183195                </td>
     
    193205 * @since 3.0.0
    194206 */
    195 function network_step2() {
     207function network_step2( $errors = false ) {
    196208    global $base, $wpdb;
    197209    $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
    198215    if ( $_POST ) {
    199216        $vhost = 'localhost' == $hostname ? false : (bool) $_POST['subdomain_install'];
     
    264281<?php
    265282
    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
     285RewriteBase ' . $base . '
     286
     287# uploaded files
    274288RewriteRule ^(.*/)?files/$ index.php [L]
    275289RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
     
    308322    $hostname = get_clean_basedomain();
    309323    $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    }
    314337} elseif ( is_multisite() || network_domain_check() ) {
    315338    network_step2();
Note: See TracChangeset for help on using the changeset viewer.