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 #11796.

git-svn-id: http://svn.automattic.com/wordpress/trunk@14452 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-05-04 20:48:28 +00:00
parent 376a690988
commit 1852eae49f
5 changed files with 62 additions and 10 deletions

View File

@ -40,7 +40,7 @@ function network_domain_check() {
* Allow subdomain install
*
* @since 3.0.0
* @return bool - whether subdomain install is allowed
* @return bool Whether subdomain install is allowed
*/
function allow_subdomain_install() {
$domain = preg_replace( '|https?://[^/]|', '', get_option( 'siteurl' ) );
@ -237,14 +237,14 @@ function network_step2( $errors = false ) {
echo '<div class="error">' . $errors->get_error_message() . '</div>';
if ( $_POST ) {
$vhost = !allow_subdomain_install() ? false : (bool) $_POST['subdomain_install'];
$subdomain_install = allow_subdomain_install() ? ! empty( $_POST['subdomain_install'] ) : false;
} else {
if ( is_multisite() ) {
$vhost = is_subdomain_install();
$subdomain_install = is_subdomain_install();
?>
<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>
<?php } else {
$vhost = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
$subdomain_install = (bool) $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" );
?>
<div class="error"><p><strong><?php _e('Warning:'); ?></strong> <?php _e( 'An existing WordPress network was detected.' ); ?></p></div>
<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 ) {
<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>
<textarea class="code" readonly="readonly" cols="100" rows="7">
define( 'MULTISITE', true );
define( 'VHOST', '<?php echo $vhost ? 'yes' : 'no'; ?>' );
define( 'SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> );
$base = '<?php echo $base; ?>';
define( 'DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?>' );
define( 'PATH_CURRENT_SITE', '<?php echo $base; ?>' );
@ -309,9 +309,9 @@ RewriteBase ' . $base . '
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^' . ( $vhost ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $vhost ? 1 : 2 ) . ' [L]' . "\n";
RewriteRule ^' . ( $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $subdomain_install ? 1 : 2 ) . ' [L]' . "\n";
if ( ! $vhost )
if ( ! $subdomain_install )
$htaccess_file .= "\n# add a trailing slash to /wp-admin\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]' . "\n";
$htaccess_file .= "\n" . 'RewriteCond %{REQUEST_FILENAME} -f [OR]
@ -319,7 +319,7 @@ RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]';
// @todo custom content dir.
if ( ! $vhost )
if ( ! $subdomain_install )
$htaccess_file .= "\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]';
@ -327,7 +327,7 @@ $htaccess_file .= "\nRewriteRule . index.php [L]";
?>
<li><p><?php printf( __( 'Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other WordPress rules:' ), ABSPATH ); ?></p>
<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $vhost ? 11 : 16; ?>">
<textarea class="code" readonly="readonly" cols="100" rows="<?php echo $subdomain_install ? 11 : 16; ?>">
<?php echo wp_htmledit_pre( $htaccess_file ); ?>
</textarea></li>
</ol>

View File

@ -91,4 +91,50 @@ function ms_file_constants( ) {
if ( !defined( 'WPMU_ACCEL_REDIRECT' ) )
define( 'WPMU_ACCEL_REDIRECT', false );
}
/**
* Defines Multisite subdomain constants and handles warnings and notices.
*
* VHOST is deprecated in favor of SUBDOMAIN_INSTALL, which is a bool.
*
* On first call, the constants are checked and defined. On second call,
* we will have translations loaded and can trigger warnings easily.
*
* @since 3.0.0
*/
function ms_subdomain_constants() {
static $error = null;
static $error_warn = false;
if ( false === $error )
return;
if ( $error ) {
$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.' );
if ( $error_warn ) {
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 );
} else {
_deprecated_argument( 'define()', '3.0', $vhost_deprecated );
}
return;
}
if ( defined( 'SUBDOMAIN_INSTALL' ) && defined( 'VHOST' ) ) {
if ( SUBDOMAIN_INSTALL == ( 'yes' == VHOST ) ) {
$error = true;
} else {
$error = $error_warn = true;
}
} elseif ( defined( 'SUBDOMAIN_INSTALL' ) ) {
define( 'VHOST', SUBDOMAIN_INSTALL ? 'yes' : 'no' );
} elseif ( defined( 'VHOST' ) ) {
$error = true;
define( 'SUBDOMAIN_INSTALL', 'yes' == VHOST );
} else {
define( 'SUBDOMAIN_INSTALL', false );
define( 'VHOST', 'no' );
}
}
add_action( 'init', 'ms_subdomain_constants' );
?>

View File

@ -16,6 +16,9 @@
* @return bool True if subdomain configuration is enabled, false otherwise.
*/
function is_subdomain_install() {
if ( defined('SUBDOMAIN_INSTALL') )
return SUBDOMAIN_INSTALL;
if ( defined('VHOST') && VHOST == 'yes' )
return true;

View File

@ -21,6 +21,9 @@ require( ABSPATH . WPINC . '/ms-default-constants.php' );
if ( defined( 'SUNRISE' ) )
include_once( WP_CONTENT_DIR . '/sunrise.php' );
/** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
ms_subdomain_constants();
if ( !isset( $current_site ) || !isset( $current_blog ) ) {
$domain = addslashes( $_SERVER['HTTP_HOST'] );

View File

@ -575,7 +575,7 @@ class wpdb {
foreach ( $this->tables( 'global' ) as $table => $prefixed_table )
$this->$table = $prefixed_table;
if ( defined( 'VHOST' ) && empty( $this->blogid ) )
if ( is_multisite() && empty( $this->blogid ) )
return $old_prefix;
$this->prefix = $this->get_blog_prefix();