Skip to content

Commit 42e9ce3

Browse files
committed
Deprecate VHOST in favor of a boolean, SUBDOMAIN_INSTALL. Core will keep VHOST defined for plugins' sake, but you should only define SUBDOMAIN_INSTALL. Throws a notice if VHOST is defined, and a warning if they somehow conflict. Sunrise can still handle them. fixes WordPress#11796.
git-svn-id: https://develop.svn.wordpress.org/trunk@14452 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 0a20229 commit 42e9ce3

5 files changed

Lines changed: 62 additions & 10 deletions

File tree

wp-admin/network.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function network_domain_check() {
4040
* Allow subdomain install
4141
*
4242
* @since 3.0.0
43-
* @return bool - whether subdomain install is allowed
43+
* @return bool Whether subdomain install is allowed
4444
*/
4545
function allow_subdomain_install() {
4646
$domain = preg_replace( '|https?://[^/]|', '', get_option( 'siteurl' ) );
@@ -237,14 +237,14 @@ function network_step2( $errors = false ) {
237237
echo '<div class="error">' . $errors->get_error_message() . '</div>';
238238

239239
if ( $_POST ) {
240-
$vhost = !allow_subdomain_install() ? false : (bool) $_POST['subdomain_install'];
240+
$subdomain_install = allow_subdomain_install() ? ! empty( $_POST['subdomain_install'] ) : false;
241241
} else {
242242
if ( is_multisite() ) {
243-
$vhost = is_subdomain_install();
243+
$subdomain_install = is_subdomain_install();
244244
?>
245245
<div class="updated"><p><strong><?php _e( 'Notice: The Network feature is already enabled.' ); ?></strong> <?php _e( 'The original configuration steps are shown here for reference.' ); ?></p></div>
246246
<?php } else {
247-
$vhost = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
247+
$subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
248248
?>
249249
<div class="error"><p><strong><?php _e('Warning:'); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div>
250250
<p><?php _e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?></p>
@@ -265,7 +265,7 @@ function network_step2( $errors = false ) {
265265
<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>
266266
<textarea class="code" readonly="readonly" cols="100" rows="7">
267267
define( 'MULTISITE', true );
268-
define( 'VHOST', '<?php echo $vhost ? 'yes' : 'no'; ?>' );
268+
define( 'SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> );
269269
$base = '<?php echo $base; ?>';
270270
define( 'DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>' );
271271
define( 'PATH_CURRENT_SITE', '<?php echo $base; ?>' );
@@ -309,25 +309,25 @@ function network_step2( $errors = false ) {
309309
RewriteRule ^index\.php$ - [L]
310310
311311
# uploaded files
312-
RewriteRule ^' . ( $vhost ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $vhost ? 1 : 2 ) . ' [L]' . "\n";
312+
RewriteRule ^' . ( $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $subdomain_install ? 1 : 2 ) . ' [L]' . "\n";
313313

314-
if ( ! $vhost )
314+
if ( ! $subdomain_install )
315315
$htaccess_file .= "\n# add a trailing slash to /wp-admin\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]' . "\n";
316316

317317
$htaccess_file .= "\n" . 'RewriteCond %{REQUEST_FILENAME} -f [OR]
318318
RewriteCond %{REQUEST_FILENAME} -d
319319
RewriteRule ^ - [L]';
320320

321321
// @todo custom content dir.
322-
if ( ! $vhost )
322+
if ( ! $subdomain_install )
323323
$htaccess_file .= "\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
324324
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]';
325325

326326
$htaccess_file .= "\nRewriteRule . index.php [L]";
327327

328328
?>
329329
<li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p>
330-
<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $vhost ? 11 : 16; ?>">
330+
<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $subdomain_install ? 11 : 16; ?>">
331331
<?php echo wp_htmledit_pre( $htaccess_file ); ?>
332332
</textarea></li>
333333
</ol>

wp-includes/ms-default-constants.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,50 @@ function ms_file_constants( ) {
9191
if ( !defined( 'WPMU_ACCEL_REDIRECT' ) )
9292
define( 'WPMU_ACCEL_REDIRECT', false );
9393
}
94+
95+
/**
96+
* Defines Multisite subdomain constants and handles warnings and notices.
97+
*
98+
* VHOST is deprecated in favor of SUBDOMAIN_INSTALL, which is a bool.
99+
*
100+
* On first call, the constants are checked and defined. On second call,
101+
* we will have translations loaded and can trigger warnings easily.
102+
*
103+
* @since 3.0.0
104+
*/
105+
function ms_subdomain_constants() {
106+
static $error = null;
107+
static $error_warn = false;
108+
109+
if ( false === $error )
110+
return;
111+
112+
if ( $error ) {
113+
$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.' );
114+
if ( $error_warn ) {
115+
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 );
116+
} else {
117+
_deprecated_argument( 'define()', '3.0', $vhost_deprecated );
118+
}
119+
return;
120+
}
121+
122+
if ( defined( 'SUBDOMAIN_INSTALL' ) && defined( 'VHOST' ) ) {
123+
if ( SUBDOMAIN_INSTALL == ( 'yes' == VHOST ) ) {
124+
$error = true;
125+
} else {
126+
$error = $error_warn = true;
127+
}
128+
} elseif ( defined( 'SUBDOMAIN_INSTALL' ) ) {
129+
define( 'VHOST', SUBDOMAIN_INSTALL ? 'yes' : 'no' );
130+
} elseif ( defined( 'VHOST' ) ) {
131+
$error = true;
132+
define( 'SUBDOMAIN_INSTALL', 'yes' == VHOST );
133+
} else {
134+
define( 'SUBDOMAIN_INSTALL', false );
135+
define( 'VHOST', 'no' );
136+
}
137+
}
138+
add_action( 'init', 'ms_subdomain_constants' );
139+
94140
?>

wp-includes/ms-load.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
* @return bool True if subdomain configuration is enabled, false otherwise.
1717
*/
1818
function is_subdomain_install() {
19+
if ( defined('SUBDOMAIN_INSTALL') )
20+
return SUBDOMAIN_INSTALL;
21+
1922
if ( defined('VHOST') && VHOST == 'yes' )
2023
return true;
2124

wp-includes/ms-settings.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
if ( defined( 'SUNRISE' ) )
2222
include_once( WP_CONTENT_DIR . '/sunrise.php' );
2323

24+
/** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
25+
ms_subdomain_constants();
26+
2427
if ( !isset( $current_site ) || !isset( $current_blog ) ) {
2528

2629
$domain = addslashes( $_SERVER['HTTP_HOST'] );

wp-includes/wp-db.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ function set_prefix( $prefix, $set_table_names = true ) {
575575
foreach ( $this->tables( 'global' ) as $table => $prefixed_table )
576576
$this->$table = $prefixed_table;
577577

578-
if ( defined( 'VHOST' ) && empty( $this->blogid ) )
578+
if ( is_multisite() && empty( $this->blogid ) )
579579
return $old_prefix;
580580

581581
$this->prefix = $this->get_blog_prefix();

0 commit comments

Comments
 (0)