Add is_subdomain_install() to ms code - Fixes #11796

git-svn-id: http://svn.automattic.com/wordpress/trunk@12674 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
wpmuguru 2010-01-08 21:25:01 +00:00
parent 166435891c
commit 4b8c87da92
8 changed files with 112 additions and 97 deletions

View File

@ -732,7 +732,7 @@ function site_admin_notice() {
add_action( 'admin_notices', 'site_admin_notice' ); add_action( 'admin_notices', 'site_admin_notice' );
function avoid_blog_page_permalink_collision( $data, $postarr ) { function avoid_blog_page_permalink_collision( $data, $postarr ) {
if( constant( 'VHOST' ) == 'yes' ) if( is_subdomain_install() )
return $data; return $data;
if( $data[ 'post_type' ] != 'page' ) if( $data[ 'post_type' ] != 'page' )
return $data; return $data;

View File

@ -70,7 +70,7 @@ switch( $_GET['action'] ) {
if ( false === $blog_details ) { if ( false === $blog_details ) {
if ( is_numeric( $dashboard_blog ) ) if ( is_numeric( $dashboard_blog ) )
wp_die( __( 'Dashboard blog_id must be a blog that already exists' ) ); wp_die( __( 'Dashboard blog_id must be a blog that already exists' ) );
if ( constant( 'VHOST' ) == 'yes' ) { if ( is_subdomain_install() ) {
$domain = $dashboard_blog . '.' . $current_site->domain; $domain = $dashboard_blog . '.' . $current_site->domain;
$path = $current_site->path; $path = $current_site->path;
} else { } else {
@ -145,7 +145,7 @@ switch( $_GET['action'] ) {
if( !is_email( $email ) ) if( !is_email( $email ) )
wp_die( __('Invalid email address') ); wp_die( __('Invalid email address') );
if( constant( 'VHOST' ) == 'yes' ) { if( is_subdomain_install() ) {
$newdomain = $domain.".".$current_site->domain; $newdomain = $domain.".".$current_site->domain;
$path = $base; $path = $base;
} else { } else {

View File

@ -55,7 +55,7 @@ if (isset($_GET['updated'])) {
<label><input name="registration" type="radio" id="registration3" value='user' <?php echo get_site_option('registration') == 'user' ? 'checked="checked"' : ''; ?> /> <?php _e('Only user account can be created.'); ?></label><br /> <label><input name="registration" type="radio" id="registration3" value='user' <?php echo get_site_option('registration') == 'user' ? 'checked="checked"' : ''; ?> /> <?php _e('Only user account can be created.'); ?></label><br />
<label><input name="registration" type="radio" id="registration4" value='blog' <?php echo get_site_option('registration') == 'blog' ? 'checked="checked"' : ''; ?> /> <?php _e('Only logged in users can create new blogs.'); ?></label><br /> <label><input name="registration" type="radio" id="registration4" value='blog' <?php echo get_site_option('registration') == 'blog' ? 'checked="checked"' : ''; ?> /> <?php _e('Only logged in users can create new blogs.'); ?></label><br />
<p><?php _e('Disable or enable registration and who or what can be registered. (Default=all)'); ?></p> <p><?php _e('Disable or enable registration and who or what can be registered. (Default=all)'); ?></p>
<?php if( constant( 'VHOST' ) == 'yes' ) { <?php if( is_subdomain_install() ) {
echo "<p>" . __('If registration is disabled, please set "NOBLOGREDIRECT" in wp-config.php to a url you will redirect visitors to if they visit a non existant blog.') . "</p>"; echo "<p>" . __('If registration is disabled, please set "NOBLOGREDIRECT" in wp-config.php to a url you will redirect visitors to if they visit a non existant blog.') . "</p>";
} ?> } ?>
</td> </td>

View File

@ -401,7 +401,7 @@ switch( $_GET['action'] ) {
<?php <?php
// define the columns to display, the syntax is 'internal name' => 'display name' // define the columns to display, the syntax is 'internal name' => 'display name'
$blogname_columns = ( constant( "VHOST" ) == 'yes' ) ? __('Domain') : __('Path'); $blogname_columns = ( is_subdomain_install() ) ? __('Domain') : __('Path');
$posts_columns = array( $posts_columns = array(
'id' => __('ID'), 'id' => __('ID'),
'blogname' => $blogname_columns, 'blogname' => $blogname_columns,
@ -457,7 +457,7 @@ switch( $_GET['action'] ) {
} }
echo "<tr $bgcolour class='$class'>"; echo "<tr $bgcolour class='$class'>";
$blogname = ( constant( "VHOST" ) == 'yes' ) ? str_replace('.'.$current_site->domain, '', $blog['domain']) : $blog['path']; $blogname = ( is_subdomain_install() ) ? str_replace('.'.$current_site->domain, '', $blog['domain']) : $blog['path'];
foreach( $posts_columns as $column_name=>$column_display_name ) { foreach( $posts_columns as $column_name=>$column_display_name ) {
switch($column_name) { switch($column_name) {
case 'id': ?> case 'id': ?>
@ -586,7 +586,7 @@ switch( $_GET['action'] ) {
<tr class="form-field form-required"> <tr class="form-field form-required">
<th style="text-align:center;" scope='row'><?php _e('Blog Address') ?></th> <th style="text-align:center;" scope='row'><?php _e('Blog Address') ?></th>
<td> <td>
<?php if ( constant( "VHOST" ) == 'yes' ) { ?> <?php if ( is_subdomain_install() ) { ?>
<input name="blog[domain]" type="text" title="<?php _e('Domain') ?>"/>.<?php echo $current_site->domain;?> <input name="blog[domain]" type="text" title="<?php _e('Domain') ?>"/>.<?php echo $current_site->domain;?>
<?php } else { <?php } else {
echo $current_site->domain . $current_site->path ?><input name="blog[domain]" type="text" title="<?php _e('Domain') ?>"/> echo $current_site->domain . $current_site->path ?><input name="blog[domain]" type="text" title="<?php _e('Domain') ?>"/>

View File

@ -1,76 +1,76 @@
<?php <?php
/** /**
* The base configurations of the WordPress. * The base configurations of the WordPress.
* *
* This file has the following configurations: MySQL settings, Table Prefix, * This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information by * Secret Keys, WordPress Language, and ABSPATH. You can find more information by
* visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing * visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host. * wp-config.php} Codex page. You can get the MySQL settings from your web host.
* *
* This file is used by the wp-config.php creation script during the * This file is used by the wp-config.php creation script during the
* installation. You don't have to use the web site, you can just copy this file * installation. You don't have to use the web site, you can just copy this file
* to "wp-config.php" and fill in the values. * to "wp-config.php" and fill in the values.
* *
* @package WordPress * @package WordPress
*/ */
// ** MySQL settings - You can get this info from your web host ** // // ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */ /** The name of the database for WordPress */
define('DB_NAME', 'putyourdbnamehere'); define('DB_NAME', 'putyourdbnamehere');
/** MySQL database username */ /** MySQL database username */
define('DB_USER', 'usernamehere'); define('DB_USER', 'usernamehere');
/** MySQL database password */ /** MySQL database password */
define('DB_PASSWORD', 'yourpasswordhere'); define('DB_PASSWORD', 'yourpasswordhere');
/** MySQL hostname */ /** MySQL hostname */
define('DB_HOST', 'localhost'); define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */ /** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8'); define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */ /** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', ''); define('DB_COLLATE', '');
/**#@+ /**#@+
* Authentication Unique Keys. * Authentication Unique Keys.
* *
* Change these to different unique phrases! * Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/ WordPress.org secret-key service} * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
* *
* @since 2.6.0 * @since 2.6.0
*/ */
define('AUTH_KEY', 'put your unique phrase here'); define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here'); define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here'); define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here'); define('NONCE_KEY', 'put your unique phrase here');
/**#@-*/ /**#@-*/
/** /**
* WordPress Database Table prefix. * WordPress Database Table prefix.
* *
* You can have multiple installations in one database if you give each a unique * You can have multiple installations in one database if you give each a unique
* prefix. Only numbers, letters, and underscores please! * prefix. Only numbers, letters, and underscores please!
*/ */
$table_prefix = 'wp_'; $table_prefix = 'wp_';
/** /**
* WordPress Localized Language, defaults to English. * WordPress Localized Language, defaults to English.
* *
* Change this to localize WordPress. A corresponding MO file for the chosen * Change this to localize WordPress. A corresponding MO file for the chosen
* language must be installed to wp-content/languages. For example, install * language must be installed to wp-content/languages. For example, install
* de.mo to wp-content/languages and set WPLANG to 'de' to enable German * de.mo to wp-content/languages and set WPLANG to 'de' to enable German
* language support. * language support.
*/ */
define ('WPLANG', ''); define ('WPLANG', '');
/* That's all, stop editing! Happy blogging. */ /* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */ /** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') ) if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/'); define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */ /** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php'); require_once(ABSPATH . 'wp-settings.php');

View File

@ -31,7 +31,7 @@ function get_blogaddress_by_id( $blog_id ) {
function get_blogaddress_by_name( $blogname ) { function get_blogaddress_by_name( $blogname ) {
global $current_site; global $current_site;
if( defined( "VHOST" ) && constant( "VHOST" ) == 'yes' ) { if( is_subdomain_install() ) {
if( $blogname == 'main' ) if( $blogname == 'main' )
$blogname = 'www'; $blogname = 'www';
return clean_url( "http://" . $blogname . "." . $current_site->domain . $current_site->path ); return clean_url( "http://" . $blogname . "." . $current_site->domain . $current_site->path );
@ -41,7 +41,7 @@ function get_blogaddress_by_name( $blogname ) {
} }
function get_blogaddress_by_domain( $domain, $path ){ function get_blogaddress_by_domain( $domain, $path ){
if( defined( "VHOST" ) && constant( "VHOST" ) == 'yes' ) { if( is_subdomain_install() ) {
$url = "http://".$domain.$path; $url = "http://".$domain.$path;
} else { } else {
if( $domain != $_SERVER['HTTP_HOST'] ) { if( $domain != $_SERVER['HTTP_HOST'] ) {
@ -108,7 +108,7 @@ function get_id_from_blogname( $name ) {
if ( $blog_id ) if ( $blog_id )
return $blog_id; return $blog_id;
if ( defined('VHOST') && constant( 'VHOST' ) == 'yes' ) { if ( is_subdomain_install() ) {
$domain = $name . '.' . $current_site->domain; $domain = $name . '.' . $current_site->domain;
$path = $current_site->path; $path = $current_site->path;
} else { } else {
@ -1033,7 +1033,7 @@ function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') {
$errors->add('blogname', __("Sorry, blog names may not contain the character '_'!")); $errors->add('blogname', __("Sorry, blog names may not contain the character '_'!"));
// do not allow users to create a blog that conflicts with a page on the main blog. // do not allow users to create a blog that conflicts with a page on the main blog.
if ( constant( "VHOST" ) == 'no' && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) { if ( !is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( "SELECT post_name FROM " . $wpdb->get_blog_prefix( $current_site->blog_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) {
$errors->add( 'blogname', __( "Sorry, you may not use that blog name" ) ); $errors->add( 'blogname', __( "Sorry, you may not use that blog name" ) );
} }
@ -1051,7 +1051,7 @@ function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') {
$errors->add('blog_title', __("Please enter a blog title")); $errors->add('blog_title', __("Please enter a blog title"));
// Check if the domain/path has been used already. // Check if the domain/path has been used already.
if( constant( "VHOST" ) == 'yes' ) { if( is_subdomain_install() ) {
$mydomain = "$blogname.$domain"; $mydomain = "$blogname.$domain";
$path = $base; $path = $base;
} else { } else {
@ -1138,7 +1138,7 @@ function wpmu_signup_blog_notification($domain, $path, $title, $user, $user_emai
return false; return false;
// Send email with activation link. // Send email with activation link.
if( constant( "VHOST" ) == 'no' || $current_site->id != 1 ) { if( !is_subdomain_install() || $current_site->id != 1 ) {
$activate_url = "http://" . $current_site->domain . $current_site->path . "wp-activate.php?key=$key"; $activate_url = "http://" . $current_site->domain . $current_site->path . "wp-activate.php?key=$key";
} else { } else {
$activate_url = "http://{$domain}{$path}wp-activate.php?key=$key"; $activate_url = "http://{$domain}{$path}wp-activate.php?key=$key";
@ -1267,7 +1267,7 @@ function wpmu_create_user( $user_name, $password, $email) {
function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) { function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) {
$domain = preg_replace( "/\s+/", '', sanitize_user( $domain, true ) ); $domain = preg_replace( "/\s+/", '', sanitize_user( $domain, true ) );
if( constant( 'VHOST' ) == 'yes' ) if( is_subdomain_install() )
$domain = str_replace( '@', '', $domain ); $domain = str_replace( '@', '', $domain );
$title = strip_tags( $title ); $title = strip_tags( $title );
$user_id = (int) $user_id; $user_id = (int) $user_id;

View File

@ -1,4 +1,19 @@
<?php <?php
/**
* Whether a subdomain configuration is enabled
*
* @since 3.0
*
* @return bool True if subdomain configuration is enabled, false otherwise.
*/
function is_subdomain_install() {
if ( defined('VHOST') && VHOST == 'yes' )
return true;
return false;
}
if( isset( $current_site ) && isset( $current_blog ) ) if( isset( $current_site ) && isset( $current_blog ) )
return; return;
@ -65,7 +80,7 @@ function wpmu_current_site() {
return $current_site; return $current_site;
} }
$path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) ); $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
if( constant( 'VHOST' ) == 'yes' ) { if( is_subdomain_install() ) {
$current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) ); $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
if( $current_site != null ) if( $current_site != null )
return $current_site; return $current_site;
@ -113,7 +128,7 @@ $current_site = wpmu_current_site();
if( !isset( $current_site->blog_id ) ) if( !isset( $current_site->blog_id ) )
$current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" ); $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" );
if( constant( 'VHOST' ) == 'yes' ) { if( is_subdomain_install() ) {
$current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' ); $current_blog = wp_cache_get( 'current_blog_' . $domain, 'site-options' );
if( !$current_blog ) { if( !$current_blog ) {
$current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain) ); $current_blog = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s", $domain) );
@ -143,7 +158,7 @@ if( constant( 'VHOST' ) == 'yes' ) {
} }
} }
if( defined( "WP_INSTALLING" ) == false && constant( 'VHOST' ) == 'yes' && !is_object( $current_blog ) ) { if( defined( "WP_INSTALLING" ) == false && is_subdomain_install() && !is_object( $current_blog ) ) {
if( defined( 'NOBLOGREDIRECT' ) ) { if( defined( 'NOBLOGREDIRECT' ) ) {
$destination = constant( 'NOBLOGREDIRECT' ); $destination = constant( 'NOBLOGREDIRECT' );
if ( $destination == '%siteurl%' ) if ( $destination == '%siteurl%' )

View File

@ -56,7 +56,7 @@ get_header();
function show_blog_form($blogname = '', $blog_title = '', $errors = '') { function show_blog_form($blogname = '', $blog_title = '', $errors = '') {
global $current_site; global $current_site;
// Blog name // Blog name
if( constant( "VHOST" ) == 'no' ) if( !is_subdomain_install() )
echo '<label for="blogname">' . __('Blog Name:') . '</label>'; echo '<label for="blogname">' . __('Blog Name:') . '</label>';
else else
echo '<label for="blogname">' . __('Blog Domain:') . '</label>'; echo '<label for="blogname">' . __('Blog Domain:') . '</label>';
@ -65,14 +65,14 @@ function show_blog_form($blogname = '', $blog_title = '', $errors = '') {
<p class="error"><?php echo $errmsg ?></p> <p class="error"><?php echo $errmsg ?></p>
<?php } <?php }
if( constant( "VHOST" ) == 'no' ) { if( !is_subdomain_install() ) {
echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blogname" type="text" id="blogname" value="'. esc_attr($blogname) .'" maxlength="50" /><br />'; echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span><input name="blogname" type="text" id="blogname" value="'. esc_attr($blogname) .'" maxlength="50" /><br />';
} else { } else {
echo '<input name="blogname" type="text" id="blogname" value="'.esc_attr($blogname).'" maxlength="50" /><span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />'; echo '<input name="blogname" type="text" id="blogname" value="'.esc_attr($blogname).'" maxlength="50" /><span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
} }
if ( !is_user_logged_in() ) { if ( !is_user_logged_in() ) {
print '(<strong>' . __( 'Your address will be ' ); print '(<strong>' . __( 'Your address will be ' );
if( constant( "VHOST" ) == 'no' ) { if( !is_subdomain_install() ) {
print $current_site->domain . $current_site->path . __( 'blogname' ); print $current_site->domain . $current_site->path . __( 'blogname' );
} else { } else {
print __( 'domain.' ) . $current_site->domain . $current_site->path; print __( 'domain.' ) . $current_site->domain . $current_site->path;
@ -420,7 +420,7 @@ if( $active_signup == "none" ) {
_e( "You're logged in already. No need to register again!" ); _e( "You're logged in already. No need to register again!" );
} }
if ($newblogname) { if ($newblogname) {
if( constant( "VHOST" ) == 'no' ) if( !is_subdomain_install() )
$newblog = 'http://' . $current_site->domain . $current_site->path . $newblogname . '/'; $newblog = 'http://' . $current_site->domain . $current_site->path . $newblogname . '/';
else else
$newblog = 'http://' . $newblogname . '.' . $current_site->domain . $current_site->path; $newblog = 'http://' . $newblogname . '.' . $current_site->domain . $current_site->path;