WordPress.org

Make WordPress Core

Ticket #19796: 19796-hack-day.4.diff

File 19796-hack-day.4.diff, 8.5 KB (added by markjaquith, 8 years ago)
  • wp-includes/link-template.php

     
    21292129        if ( 'relative' == $scheme )
    21302130                $url = $current_site->path;
    21312131        else
    2132                 $url = $scheme . '://' . $current_site->domain . $current_site->path;
     2132                $url = $scheme . '://' . trailingslashit( $current_site->domain ) . trailingslashit( $current_site->wp_siteurl_subdir );
    21332133
    21342134        if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
    21352135                $url .= ltrim($path, '/');
  • wp-includes/ms-load.php

     
    142142                $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
    143143                $current_site->domain = DOMAIN_CURRENT_SITE;
    144144                $current_site->path   = $path = PATH_CURRENT_SITE;
     145                if( defined( 'WP_SITEURL_SUBDIR' ) )
     146                        $current_site->wp_siteurl_subdir = WP_SITEURL_SUBDIR;
     147                else
     148                        $current_site->wp_siteurl_subdir = $current_site->path;
    145149                if ( defined( 'BLOG_ID_CURRENT_SITE' ) )
    146150                        $current_site->blog_id = BLOG_ID_CURRENT_SITE;
    147151                elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated.
  • wp-includes/ms-functions.php

     
    11501150        populate_roles();
    11511151        $wp_roles->_init();
    11521152
    1153         $url = untrailingslashit( $url );
     1153        $url = $siteurl = untrailingslashit( $url );
    11541154        // fix url.
    1155         update_option('siteurl', $url);
     1155        if ( defined( 'WP_SITEURL_SUBDIR' ) && WP_SITEURL_SUBDIR ) {
     1156                $siteurl = trailingslashit( $siteurl ) . WP_SITEURL_SUBDIR;
     1157        }
     1158               
     1159        update_option('siteurl', $siteurl);
    11561160        update_option('home', $url);
    11571161        update_option('fileupload_url', $url . "/files" );
    11581162        update_option('upload_path', UPLOADBLOGSDIR . "/$blog_id/files");
  • wp-includes/ms-default-constants.php

     
    4747         * @since 1.5.0
    4848         */
    4949        if ( !defined( 'SITECOOKIEPATH' ) )
    50                 define( 'SITECOOKIEPATH', $current_site->path );
     50                define( 'SITECOOKIEPATH', $current_site->wp_siteurl_subdir );
    5151
    5252        /**
    5353         * @since 2.6.0
  • wp-admin/network.php

     
    5151 * @return bool Whether subdomain install is allowed
    5252 */
    5353function allow_subdomain_install() {
    54         $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'siteurl' ) );
    55         if( false !== strpos( $domain, '/' ) || 'localhost' == $domain || preg_match( '|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|', $domain ) )
     54        $domain = preg_replace( '|https?://([^/]+)|', '$1', get_option( 'home' ) );
     55        if( parse_url( get_option( 'home' ), PHP_URL_PATH ) || 'localhost' == $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) )
    5656                return false;
    5757
    5858        return true;
     
    144144function network_step1( $errors = false ) {
    145145        global $is_apache;
    146146
    147         if ( get_option( 'siteurl' ) != get_option( 'home' ) ) {
    148                 echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . sprintf( __( 'Your <strong>WordPress address</strong> must match your <strong>Site address</strong> before creating a Network. See <a href="%s">General Settings</a>.' ), esc_url( admin_url( 'options-general.php' ) ) ) . '</p></div>';
    149                 echo '</div>';
    150                 include ( ABSPATH . 'wp-admin/admin-footer.php' );
    151                 die();
    152         }
    153 
    154147        if ( defined('DO_NOT_UPGRADE_GLOBAL_TABLES') ) {
    155148                echo '<div class="error"><p><strong>' . __('ERROR:') . '</strong> ' . __( 'The constant DO_NOT_UPGRADE_GLOBAL_TABLES cannot be defined when creating a network.' ) . '</p></div>';
    156149                echo '</div>';
     
    316309function network_step2( $errors = false ) {
    317310        global $base, $wpdb;
    318311        $hostname = get_clean_basedomain();
     312        $wp_siteurl_subdir = str_replace( trailingslashit( get_option( 'home' ) ), '', get_option( 'siteurl' ) );
     313        $rewrite_base =  empty( $wp_siteurl_subdir ) ? '' : trailingslashit( $wp_siteurl_subdir );
    319314
    320315        if ( ! isset( $base ) )
    321                 $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
     316                $base = parse_url( trailingslashit( get_option( 'home' ) ), PHP_URL_PATH );
    322317
    323318        // Wildcard DNS message.
    324319        if ( is_wp_error( $errors ) )
     
    366361                                        echo ' <strong>' . __('Warning:') . ' ' . __( 'Networks may not be fully compatible with custom wp-content directories.' ) . '</strong>';
    367362                        ?></p></li>
    368363                        <li><p><?php printf( __( 'Add the following to your <code>wp-config.php</code> file in <code>%s</code> <strong>above</strong> the line reading <code>/* That&#8217;s all, stop editing! Happy blogging. */</code>:' ), ABSPATH ); ?></p>
    369                                 <textarea class="code" readonly="readonly" cols="100" rows="7">
     364                                <textarea class="code" readonly="readonly" cols="100" rows="8">
    370365define('MULTISITE', true);
    371366define('SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?>);
    372367$base = '<?php echo $base; ?>';
    373368define('DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>');
    374369define('PATH_CURRENT_SITE', '<?php echo $base; ?>');
    375370define('SITE_ID_CURRENT_SITE', 1);
    376 define('BLOG_ID_CURRENT_SITE', 1);</textarea>
     371define('BLOG_ID_CURRENT_SITE', 1);
     372define('WP_SITEURL_SUBDIR', '<?php echo $wp_siteurl_subdir; ?>');</textarea>
    377373<?php
    378374        $keys_salts = array( 'AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => '' );
    379375        foreach ( $keys_salts as $c => $v ) {
     
    465461                </rule>
    466462                <rule name="WordPress Rule 5" stopProcessing="true">
    467463                    <match url="^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*)" ignoreCase="false" />
    468                     <action type="Rewrite" url="{R:1}" />
     464                    <action type="Rewrite" url="' . $rewrite_base . '{R:1}" />
    469465                </rule>
    470466                <rule name="WordPress Rule 6" stopProcessing="true">
    471467                    <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
    472                     <action type="Rewrite" url="{R:2}" />
     468                    <action type="Rewrite" url="' . $rewrite_base . '{R:2}" />
    473469                </rule>
    474470                <rule name="WordPress Rule 7" stopProcessing="true">
    475471                    <match url="." ignoreCase="false" />
     
    504500RewriteRule ^ - [L]';
    505501
    506502                // @todo custom content dir.
    507                 if ( ! $subdomain_install )
    508                         $htaccess_file .= "\nRewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]\nRewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]";
     503                if ( ! $subdomain_install ) {
     504                        $htaccess_file .= "\nRewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $rewrite_base$1 [L]\nRewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $rewrite_base$1 [L]";
     505                }
    509506
    510507                $htaccess_file .= "\nRewriteRule . index.php [L]";
    511508
    512509                ?>
    513                 <li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p>
     510                <li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), trailingslashit( str_replace( trailingslashit( $wp_siteurl_subdir ), '', ABSPATH ) ) ); ?></p>
    514511                <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $subdomain_install ? 11 : 16; ?>">
    515512<?php echo esc_textarea( $htaccess_file ); ?></textarea></li>
    516513                </ol>
     
    525522
    526523if ( $_POST ) {
    527524
    528         $base = trailingslashit( stripslashes( dirname( dirname( $_SERVER['SCRIPT_NAME'] ) ) ) );
    529 
    530525        check_admin_referer( 'install-network-1' );
    531526
    532527        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     
    535530        $hostname = get_clean_basedomain();
    536531        $subdomain_install = allow_subdomain_install() ? !empty( $_POST['subdomain_install'] ) : false;
    537532        if ( ! network_domain_check() ) {
    538                 $result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), stripslashes( $_POST['sitename'] ), $base, $subdomain_install );
     533                $result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), stripslashes( $_POST['sitename'] ), $rewrite_base, $subdomain_install );
    539534                if ( is_wp_error( $result ) ) {
    540535                        if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' == $result->get_error_code() )
    541536                                network_step2( $result );