Make WordPress Core

Ticket #31240: 31240.diff

File 31240.diff, 4.1 KB (added by thomaswm, 9 years ago)
  • wp-admin/network/site-new.php

     
    4040                wp_die( __( 'Can’t create an empty site.' ) );
    4141
    4242        $blog = $_POST['blog'];
    43         $domain = '';
    44         if ( preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
    45                 $domain = strtolower( $blog['domain'] );
     43        $parsed_url = parse_url( 'http://' . trim( $blog['url'] ) );
     44       
     45        if ( empty( $parsed_url ) )
     46                wp_die( __( 'Missing or invalid site address.' ) );
     47       
     48        $newdomain = strtolower( $parsed_url['domain'] );
     49        $path = trailingslashit( $parsed_url['path'] );
    4650
    47         // If not a subdomain install, make sure the domain isn't a reserved word
    48         if ( ! is_subdomain_install() ) {
    49                 /** This filter is documented in wp-includes/ms-functions.php */
    50                 $subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed', 'wp-admin', 'wp-content', 'wp-includes' ) );
    51                 if ( in_array( $domain, $subdirectory_reserved_names ) )
     51        // Make sure the path isn't a reserved word
     52        /** This filter is documented in wp-includes/ms-functions.php */
     53        $subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed', 'wp-admin', 'wp-content', 'wp-includes' ) );
     54        foreach( $subdirectory_reserved_names as $reserved_name ) {
     55                if ( strpos( $path, '/' . $reserved_name . '/' ) !== false )
    5256                        wp_die( sprintf( __('The following words are reserved for use by WordPress functions and cannot be used as blog names: <code>%s</code>' ), implode( '</code>, <code>', $subdirectory_reserved_names ) ) );
    5357        }
    54 
     58       
    5559        $title = $blog['title'];
    5660
    5761        $meta = array(
     
    6670                }
    6771        }
    6872
    69         if ( empty( $domain ) )
    70                 wp_die( __( 'Missing or invalid site address.' ) );
    71 
    7273        if ( isset( $blog['email'] ) && '' === trim( $blog['email'] ) ) {
    7374                wp_die( __( 'Missing email address.' ) );
    7475        }
     
    7879                wp_die( __( 'Invalid email address.' ) );
    7980        }
    8081
    81         if ( is_subdomain_install() ) {
    82                 $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
    83                 $path      = $current_site->path;
    84         } else {
    85                 $newdomain = $current_site->domain;
    86                 $path      = $current_site->path . $domain . '/';
    87         }
    88 
    8982        $password = 'N/A';
    9083        $user_id = email_exists($email);
    9184        if ( !$user_id ) { // Create a new user with a random password
     85                if ( is_subdomain_install() ) {
     86                        $subdomain = explode( $newdomain, '.', 1 );
     87                        $username = $subdomain[0];
     88                } else {
     89                        $pathsegments = explode( trim( $path, '/' ), '/' );
     90                        $username = array_pop( $pathsegments );
     91                }               
    9292                $password = wp_generate_password( 12, false );
    93                 $user_id = wpmu_create_user( $domain, $password, $email );
     93                $user_id = wpmu_create_user( $username, $password, $email );
    9494                if ( false === $user_id )
    9595                        wp_die( __( 'There was an error creating the user.' ) );
    9696                else
     
    156156        <table class="form-table">
    157157                <tr class="form-field form-required">
    158158                        <th scope="row"><label for="site-address"><?php _e( 'Site Address' ) ?></label></th>
    159                         <td>
    160                         <?php if ( is_subdomain_install() ) { ?>
    161                                 <input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off"/><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', $current_site->domain ); ?></span>
    162                         <?php } else {
    163                                 echo $current_site->domain . $current_site->path ?><input name="blog[domain]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc"  autocapitalize="none" autocorrect="off" />
    164                         <?php }
    165                         echo '<p id="site-address-desc">' . __( 'Only lowercase letters (a-z) and numbers are allowed.' ) . '</p>';
    166                         ?>
     159                        <td>http://
     160                        <input name="blog[url]" type="text" class="regular-text" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off"/><span class="no-break">.<?php echo $current_site->domain . $current_site->path;  ?></span>
    167161                        </td>
    168162                </tr>
    169163                <tr class="form-field form-required">