<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[14452] trunk: Deprecate VHOST in favor of a boolean, SUBDOMAIN_INSTALL.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/14452">14452</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-05-04 20:48:28 +0000 (Tue, 04 May 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>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 <a href="http://trac.wordpress.org/ticket/11796">#11796</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminnetworkphp">trunk/wp-admin/network.php</a></li>
<li><a href="#trunkwpincludesmsdefaultconstantsphp">trunk/wp-includes/ms-default-constants.php</a></li>
<li><a href="#trunkwpincludesmsloadphp">trunk/wp-includes/ms-load.php</a></li>
<li><a href="#trunkwpincludesmssettingsphp">trunk/wp-includes/ms-settings.php</a></li>
<li><a href="#trunkwpincludeswpdbphp">trunk/wp-includes/wp-db.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminnetworkphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/network.php (14451 => 14452)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/network.php        2010-05-04 19:54:42 UTC (rev 14451)
+++ trunk/wp-admin/network.php        2010-05-04 20:48:28 UTC (rev 14452)
</span><span class="lines">@@ -40,7 +40,7 @@
</span><span class="cx">  * Allow subdomain install
</span><span class="cx">  *
</span><span class="cx">  * @since 3.0.0
</span><del>- * @return bool - whether subdomain install is allowed
</del><ins>+ * @return bool Whether subdomain install is allowed
</ins><span class="cx">  */
</span><span class="cx"> function allow_subdomain_install() {
</span><span class="cx">         $domain = preg_replace( '|https?://[^/]|', '', get_option( 'siteurl' ) );
</span><span class="lines">@@ -237,14 +237,14 @@
</span><span class="cx">                 echo '&lt;div class=&quot;error&quot;&gt;' . $errors-&gt;get_error_message() . '&lt;/div&gt;';
</span><span class="cx"> 
</span><span class="cx">         if ( $_POST ) {
</span><del>-                $vhost = !allow_subdomain_install() ? false : (bool) $_POST['subdomain_install'];
</del><ins>+                $subdomain_install = allow_subdomain_install() ? ! empty( $_POST['subdomain_install'] ) : false;
</ins><span class="cx">         } else {
</span><span class="cx">                 if ( is_multisite() ) {
</span><del>-                        $vhost = is_subdomain_install();
</del><ins>+                        $subdomain_install = is_subdomain_install();
</ins><span class="cx"> ?&gt;
</span><span class="cx">         &lt;div class=&quot;updated&quot;&gt;&lt;p&gt;&lt;strong&gt;&lt;?php _e( 'Notice: The Network feature is already enabled.' ); ?&gt;&lt;/strong&gt; &lt;?php _e( 'The original configuration steps are shown here for reference.' ); ?&gt;&lt;/p&gt;&lt;/div&gt;
</span><span class="cx"> &lt;?php        } else {
</span><del>-                        $vhost = (bool) $wpdb-&gt;get_var( &quot;SELECT meta_value FROM $wpdb-&gt;sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'&quot; );
</del><ins>+                        $subdomain_install = (bool) $wpdb-&gt;get_var( &quot;SELECT meta_value FROM $wpdb-&gt;sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'&quot; );
</ins><span class="cx"> ?&gt;
</span><span class="cx">         &lt;div class=&quot;error&quot;&gt;&lt;p&gt;&lt;strong&gt;&lt;?php _e('Warning:'); ?&gt;&lt;/strong&gt; &lt;?php _e( 'An existing WordPress network was detected.' ); ?&gt;&lt;/p&gt;&lt;/div&gt;
</span><span class="cx">         &lt;p&gt;&lt;?php _e( 'Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.' ); ?&gt;&lt;/p&gt;
</span><span class="lines">@@ -265,7 +265,7 @@
</span><span class="cx">                         &lt;li&gt;&lt;p&gt;&lt;?php printf( __( 'Add the following to your &lt;code&gt;wp-config.php&lt;/code&gt; file in &lt;code&gt;%s&lt;/code&gt; &lt;strong&gt;above&lt;/strong&gt; the line reading &lt;code&gt;/* That&amp;#8217;s all, stop editing! Happy blogging. */&lt;/code&gt;:' ), ABSPATH ); ?&gt;&lt;/p&gt;
</span><span class="cx">                                 &lt;textarea class=&quot;code&quot; readonly=&quot;readonly&quot; cols=&quot;100&quot; rows=&quot;7&quot;&gt;
</span><span class="cx"> define( 'MULTISITE', true );
</span><del>-define( 'VHOST', '&lt;?php echo $vhost ? 'yes' : 'no'; ?&gt;' );
</del><ins>+define( 'SUBDOMAIN_INSTALL', &lt;?php echo $subdomain_install ? 'true' : 'false'; ?&gt; );
</ins><span class="cx"> $base = '&lt;?php echo $base; ?&gt;';
</span><span class="cx"> define( 'DOMAIN_CURRENT_SITE', '&lt;?php echo $hostname; ?&gt;' );
</span><span class="cx"> define( 'PATH_CURRENT_SITE', '&lt;?php echo $base; ?&gt;' );
</span><span class="lines">@@ -309,9 +309,9 @@
</span><span class="cx"> RewriteRule ^index\.php$ - [L]
</span><span class="cx"> 
</span><span class="cx"> # uploaded files
</span><del>-RewriteRule ^' . ( $vhost ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $vhost ? 1 : 2 ) . ' [L]' . &quot;\n&quot;;
</del><ins>+RewriteRule ^' . ( $subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?' ) . 'files/(.+) wp-includes/ms-files.php?file=$' . ( $subdomain_install ? 1 : 2 ) . ' [L]' . &quot;\n&quot;;
</ins><span class="cx"> 
</span><del>-if ( ! $vhost )
</del><ins>+if ( ! $subdomain_install )
</ins><span class="cx">         $htaccess_file .= &quot;\n# add a trailing slash to /wp-admin\n&quot; . 'RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]' . &quot;\n&quot;;
</span><span class="cx"> 
</span><span class="cx"> $htaccess_file .= &quot;\n&quot; . 'RewriteCond %{REQUEST_FILENAME} -f [OR]
</span><span class="lines">@@ -319,7 +319,7 @@
</span><span class="cx"> RewriteRule ^ - [L]';
</span><span class="cx"> 
</span><span class="cx"> // @todo custom content dir.
</span><del>-if ( ! $vhost )
</del><ins>+if ( ! $subdomain_install )
</ins><span class="cx">         $htaccess_file .= &quot;\n&quot; . 'RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
</span><span class="cx"> RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]';
</span><span class="cx"> 
</span><span class="lines">@@ -327,7 +327,7 @@
</span><span class="cx"> 
</span><span class="cx"> ?&gt;
</span><span class="cx">                         &lt;li&gt;&lt;p&gt;&lt;?php printf( __( 'Add the following to your &lt;code&gt;.htaccess&lt;/code&gt; file in &lt;code&gt;%s&lt;/code&gt;, replacing other WordPress rules:' ), ABSPATH ); ?&gt;&lt;/p&gt;
</span><del>-                                &lt;textarea class=&quot;code&quot; readonly=&quot;readonly&quot; cols=&quot;100&quot; rows=&quot;&lt;?php echo $vhost ? 11 : 16; ?&gt;&quot;&gt;
</del><ins>+                                &lt;textarea class=&quot;code&quot; readonly=&quot;readonly&quot; cols=&quot;100&quot; rows=&quot;&lt;?php echo $subdomain_install ? 11 : 16; ?&gt;&quot;&gt;
</ins><span class="cx"> &lt;?php echo wp_htmledit_pre( $htaccess_file ); ?&gt;
</span><span class="cx"> &lt;/textarea&gt;&lt;/li&gt;
</span><span class="cx">                 &lt;/ol&gt;
</span></span></pre></div>
<a id="trunkwpincludesmsdefaultconstantsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/ms-default-constants.php (14451 => 14452)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/ms-default-constants.php        2010-05-04 19:54:42 UTC (rev 14451)
+++ trunk/wp-includes/ms-default-constants.php        2010-05-04 20:48:28 UTC (rev 14452)
</span><span class="lines">@@ -91,4 +91,50 @@
</span><span class="cx">         if ( !defined( 'WPMU_ACCEL_REDIRECT' ) )
</span><span class="cx">                 define( 'WPMU_ACCEL_REDIRECT', false );
</span><span class="cx"> }
</span><ins>+
+/**
+ * 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 &lt;code&gt;VHOST&lt;/code&gt; &lt;strong&gt;is deprecated&lt;/strong&gt;. Use the boolean constant &lt;code&gt;SUBDOMAIN_INSTALL&lt;/code&gt; 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( __( '&lt;strong&gt;Conflicting values for the constants VHOST and SUBDOMAIN_INSTALL.&lt;/strong&gt; 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' ) &amp;&amp; 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' );
+
</ins><span class="cx"> ?&gt;
</span></span></pre></div>
<a id="trunkwpincludesmsloadphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/ms-load.php (14451 => 14452)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/ms-load.php        2010-05-04 19:54:42 UTC (rev 14451)
+++ trunk/wp-includes/ms-load.php        2010-05-04 20:48:28 UTC (rev 14452)
</span><span class="lines">@@ -16,6 +16,9 @@
</span><span class="cx">  * @return bool True if subdomain configuration is enabled, false otherwise.
</span><span class="cx">  */
</span><span class="cx"> function is_subdomain_install() {
</span><ins>+        if ( defined('SUBDOMAIN_INSTALL') )
+                return SUBDOMAIN_INSTALL;
+
</ins><span class="cx">         if ( defined('VHOST') &amp;&amp; VHOST == 'yes' )
</span><span class="cx">                 return true;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesmssettingsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/ms-settings.php (14451 => 14452)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/ms-settings.php        2010-05-04 19:54:42 UTC (rev 14451)
+++ trunk/wp-includes/ms-settings.php        2010-05-04 20:48:28 UTC (rev 14452)
</span><span class="lines">@@ -21,6 +21,9 @@
</span><span class="cx"> if ( defined( 'SUNRISE' ) )
</span><span class="cx">         include_once( WP_CONTENT_DIR . '/sunrise.php' );
</span><span class="cx"> 
</span><ins>+/** Check for and define SUBDOMAIN_INSTALL and the deprecated VHOST constant. */
+ms_subdomain_constants();
+
</ins><span class="cx"> if ( !isset( $current_site ) || !isset( $current_blog ) ) {
</span><span class="cx"> 
</span><span class="cx">         $domain = addslashes( $_SERVER['HTTP_HOST'] );
</span></span></pre></div>
<a id="trunkwpincludeswpdbphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/wp-db.php (14451 => 14452)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/wp-db.php        2010-05-04 19:54:42 UTC (rev 14451)
+++ trunk/wp-includes/wp-db.php        2010-05-04 20:48:28 UTC (rev 14452)
</span><span class="lines">@@ -575,7 +575,7 @@
</span><span class="cx">                         foreach ( $this-&gt;tables( 'global' ) as $table =&gt; $prefixed_table )
</span><span class="cx">                                 $this-&gt;$table = $prefixed_table;
</span><span class="cx"> 
</span><del>-                        if ( defined( 'VHOST' ) &amp;&amp; empty( $this-&gt;blogid ) )
</del><ins>+                        if ( is_multisite() &amp;&amp; empty( $this-&gt;blogid ) )
</ins><span class="cx">                                 return $old_prefix;
</span><span class="cx"> 
</span><span class="cx">                         $this-&gt;prefix = $this-&gt;get_blog_prefix();
</span></span></pre>
</div>
</div>

</body>
</html>