WordPress.org

Make WordPress Core

Ticket #11796: 11796.2.diff

File 11796.2.diff, 8.2 KB (added by nacin, 6 years ago)

Would introduce SUBDOMAIN_INSTALL and deprecate VHOST

  • wp-admin/includes/schema.php

     
    619619 * 
    620620 * @param int $network_id id of network to populate 
    621621 */ 
    622 function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $vhost = 'no' ) { 
     622function populate_network( $network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false ) { 
    623623        global $wpdb, $current_site, $wp_version, $wp_db_version, $wp_rewrite; 
    624624 
    625625        $msg = ''; 
     
    701701                update_usermeta( $site_user->ID, 'primary_blog', 1 ); 
    702702        } 
    703703 
    704         if ( $vhost == 'yes' ) 
     704        if ( $subdomain_install && $subdomain_install != 'no' ) // back compat vhost value 
    705705                update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/'); 
    706706        else 
    707707                update_option( 'permalink_structure', '/blog/%year%/%monthnum%/%day%/%postname%/'); 
    708708 
    709709        $wp_rewrite->flush_rules(); 
    710710 
    711         if ( $vhost == 'yes' ) { 
     711        if ( $subdomain_install && $subdomain_install != 'no' ) // back compat vhost value 
    712712                $vhost_ok = false; 
    713713                $hostname = substr( md5( time() ), 0, 6 ) . '.' . $domain; // Very random hostname! 
    714714                $page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) ); 
  • wp-admin/includes/wp-config.ms

     
    3434 
    3535/** Network settings - added by the network settings installer */ 
    3636define('MULTISITE', true); 
    37 define('VHOST', 'VHOSTSETTING');  
     37define('SUBDOMAIN_INSTALL', 'false');  
    3838$base = 'BASE'; 
    3939define('DOMAIN_CURRENT_SITE', 'current_site_domain' ); 
    4040define('PATH_CURRENT_SITE', 'current_site_path' ); 
     
    9393// remember to change WP_CONTENT too. 
    9494// define( "UPLOADBLOGSDIR", "fileserver" ); 
    9595 
    96 // If VHOST is 'yes' uncomment and set this to a URL to redirect if a blog does not exist or is a 404 on the main blog. (Useful if signup is disabled) 
     96// If SUBDOMAIN_INSTALL is true uncomment and set this to a URL to redirect if a blog does not exist or is a 404 on the main blog. (Useful if signup is disabled) 
    9797// For example, the browser will redirect to http://examples.com/ for the following: define( 'NOBLOGREDIRECT', 'http://example.com/' ); 
    9898// Set this value to %siteurl% to redirect to the root of the site 
    9999// define( 'NOBLOGREDIRECT', '' ); 
  • wp-admin/network.php

     
    142142                <p><?php _e( '<strong>Note</strong> It looks like <code>mod_rewrite</code> is not installed.'); ?></p> 
    143143                <?php } ?> 
    144144                <p class="blog-address"> 
    145                         <label><input type='radio' name='vhost' value='yes'<?php if( $rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-domains (like <code>blog1.example.com</code>)' ); ?></label><br /> 
    146                         <label><input type='radio' name='vhost' value='no'<?php if( !$rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-directories (like <code>example.com/blog1</code>) '); ?></label> 
     145                        <label><input type='radio' name='vhost' value='1'<?php if( $rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-domains (like <code>blog1.example.com</code>)' ); ?></label><br /> 
     146                        <label><input type='radio' name='vhost' value='0'<?php if( !$rewrite_enabled ) echo ' checked="checked"'; ?> /> <?php _e( 'Sub-directories (like <code>example.com/blog1</code>) '); ?></label> 
    147147                </p> 
    148148 
    149149                <h2><?php esc_html_e( 'Server Address' ); ?></h2> 
     
    195195} 
    196196 
    197197function step2_config() { 
    198         global $base, $wpdb, $vhost; 
     198        global $base, $wpdb; 
    199199 
    200         $vhost   = stripslashes($_POST['vhost' ]); 
    201         $prefix  = $wpdb->base_prefix; 
     200        $subdomain_install = (bool) $_POST['vhost']; 
     201        $prefix            = $wpdb->base_prefix; 
    202202 
    203203        $config_sample = ABSPATH . 'wp-admin/includes/wp-config.ms'; 
    204204        if ( !file_exists( $config_sample ) ) 
     
    223223                        case "define('DB_HOST'": 
    224224                                $output = str_replace("localhost", DB_HOST, $line); 
    225225                                break; 
    226                         case "define('VHOST',": 
    227                                 $output = str_replace("VHOSTSETTING", $vhost, $line); 
     226                        case "define('SUBDOMAI": 
     227                                if ( ! $subdomain_install ) { 
     228                                        $output = $line; 
     229                                        break; 
     230                                } 
     231                                $output = str_replace('false', 'true', $line); 
    228232                                break; 
    229233                        case '$table_prefix  =': 
    230234                                $output = str_replace('wp_', $prefix, $line); 
     
    285289                // create network tables 
    286290                $domain = get_clean_basedomain(); 
    287291                install_network(); 
    288                 populate_network( 1, $domain, sanitize_email( $_POST[ 'email' ] ), $_POST[ 'weblog_title' ], $base, $_POST[ 'vhost' ] ); 
     292                populate_network( 1, $domain, sanitize_email( $_POST[ 'email' ] ), $_POST[ 'weblog_title' ], $base, (bool) $_POST[ 'vhost' ] ); 
    289293                // create wp-config.php / htaccess 
    290294                step2(); 
    291295        break; 
  • wp-includes/default-constants.php

     
    277277                        define('STYLESHEETPATH', get_stylesheet_directory()); 
    278278                        break; 
    279279 
     280                case 'subdomain_install': 
     281 
     282                        if ( defined( 'VHOST' ) ) 
     283                                $vhost_deprecated = __( 'The constant <code>VHOST</code> <strong>is deprecated</strong>. Use the boolean constant <code>SUBDOMAIN_INSTALL</code> in wp-config.php to enable a subdomain configuration. Use is_subdomain_install() to check whether a subdomain configuration is enabled.' ); 
     284 
     285                        if ( defined( 'SUBDOMAIN_INSTALL' ) && defined( 'VHOST' ) ) { 
     286                                if ( SUBDOMAIN_INSTALL == ( 'yes' == VHOST ) ) { 
     287                                        _deprecated_argument( 'define()', '3.0', $vhost_deprecated ); 
     288                                } else { 
     289                                        trigger_error( __( '<strong>Conflicting values for the constants VHOST and SUBDOMAIN_INSTALL.</strong> The value of SUBDOMAIN_INSTALL will be assumed to be your subdomain configuration setting.' ) . ' ' . $vhost_deprecated, E_USER_WARNING ); 
     290                                } 
     291                        } elseif ( defined( 'SUBDOMAIN_INSTALL' ) ) { 
     292                                define( 'VHOST', SUBDOMAIN_INSTALL ? 'yes' : 'no' ); 
     293                        } elseif ( defined( 'VHOST' ) ) { 
     294                                _deprecated_argument( 'define()', '3.0', $vhost_deprecated ); 
     295                                define( 'SUBDOMAIN_INSTALL', 'yes' == VHOST ); 
     296                        } else {         
     297                                define( 'SUBDOMAIN_INSTALL', false ); 
     298                                define( 'VHOST', 'no' ); 
     299                        } 
     300 
     301                        break; 
     302 
    280303        } 
    281304 
    282305} 
  • wp-includes/ms-load.php

     
    2121 
    2222// Fix empty PHP_SELF 
    2323$PHP_SELF = $_SERVER['PHP_SELF']; 
    24 if ( empty($PHP_SELF) || ( empty($PHP_SELF) && constant( 'VHOST' ) == 'no' && $current_blog->path != '/' ) ) 
     24if ( empty($PHP_SELF) || ( empty($PHP_SELF) && !is_subdomain_install() && $current_blog->path != '/' ) ) 
    2525        $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]); 
    2626 
    2727wp_cache_init(); // need to init cache again after blog_id is set 
  • wp-includes/ms-settings.php

     
    11<?php 
    22 
     3wp_default_constants( 'subdomain_install' ); 
    34/** 
    4  * Whether a subdomain configuration is enabled 
     5 * Whether a subdomain configuration is enabled. 
    56 * 
    67 * @since 3.0 
    78 * 
    89 * @return bool True if subdomain configuration is enabled, false otherwise. 
    910 */ 
    1011function is_subdomain_install() { 
    11         if ( defined('VHOST') && VHOST == 'yes' ) 
    12                 return true; 
    13  
    14         return false; 
     12        return SUBDOMAIN_INSTALL; 
    1513} 
    1614 
    1715if ( isset( $current_site ) && isset( $current_blog ) ) 
  • wp-includes/wp-db.php

     
    456456                foreach ( $this->global_tables as $table ) 
    457457                        $this->$table = $prefix . $table; 
    458458 
    459                 if ( defined('VHOST') && empty($this->blogid) ) 
     459                if ( is_multisite() && empty($this->blogid) ) 
    460460                        return $old_prefix; 
    461461 
    462462                $this->prefix = $this->get_blog_prefix( $this->blogid );