From 1852eae49f6451f5954359c29db1c0888ad4330d Mon Sep 17 00:00:00 2001 From: nacin Date: Tue, 4 May 2010 20:48:28 +0000 Subject: [PATCH] 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 --- wp-admin/network.php | 18 +++++------ wp-includes/ms-default-constants.php | 46 ++++++++++++++++++++++++++++ wp-includes/ms-load.php | 3 ++ wp-includes/ms-settings.php | 3 ++ wp-includes/wp-db.php | 2 +- 5 files changed, 62 insertions(+), 10 deletions(-) diff --git a/wp-admin/network.php b/wp-admin/network.php index 4caf4cdeac..351f7432f2 100644 --- a/wp-admin/network.php +++ b/wp-admin/network.php @@ -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 '
' . $errors->get_error_message() . '
'; 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(); ?>

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'" ); ?>

@@ -265,7 +265,7 @@ function network_step2( $errors = false ) {
  • wp-config.php file in %s above the line reading /* That’s all, stop editing! Happy blogging. */:' ), ABSPATH ); ?>

  • diff --git a/wp-includes/ms-default-constants.php b/wp-includes/ms-default-constants.php index 23e04f3c41..38dce50fb8 100644 --- a/wp-includes/ms-default-constants.php +++ b/wp-includes/ms-default-constants.php @@ -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 VHOST is deprecated. Use the boolean constant SUBDOMAIN_INSTALL 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( __( 'Conflicting values for the constants VHOST and SUBDOMAIN_INSTALL. 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' ); + ?> diff --git a/wp-includes/ms-load.php b/wp-includes/ms-load.php index ecb83d77a7..bcb075cdab 100644 --- a/wp-includes/ms-load.php +++ b/wp-includes/ms-load.php @@ -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; diff --git a/wp-includes/ms-settings.php b/wp-includes/ms-settings.php index cc0691cad7..14862f9e16 100644 --- a/wp-includes/ms-settings.php +++ b/wp-includes/ms-settings.php @@ -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'] ); diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 64e812be1f..de63b71884 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -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();