WordPress.org

Make WordPress Core

Ticket #11881: 11881.10.diff

File 11881.10.diff, 25.1 KB (added by nacin, 5 years ago)

plastic surgery for multisite load files

  • wp-includes/load.php

     
    11<?php 
    2  
    32/** 
    43 * These functions are needed to load WordPress. 
    54 * 
  • wp-includes/ms-deprecated.php

     
    1414 
    1515/** 
    1616 * @since unknown 
    17  * @deprecated 3.0 
     17 * @deprecated 3.0.0 
    1818 * @deprecated Use wp_generate_password() 
    1919 * @see wp_generate_password() 
    2020 */ 
    2121function generate_random_password( $len = 8 ) { 
    2222        _deprecated_function( __FUNCTION__, '3.0', 'wp_generate_password()' ); 
    23         return wp_generate_password($len); 
     23        return wp_generate_password( $len ); 
    2424} 
    2525 
    2626/** 
     
    3232 * This function must reside in a file included only if is_multisite() due to 
    3333 * legacy function_exists() checks to determine if multisite is enabled. 
    3434 * 
    35  * @since unknown 
    36  * @deprecated 3.0 
     35 * @since MU 
     36 * @deprecated 3.0.0 
    3737 * @deprecated Use is_super_admin() 
    3838 * @see is_super_admin() 
    3939 * @see is_multisite() 
     
    5656        return is_super_admin( $user_id ); 
    5757} 
    5858 
    59 if ( !function_exists('graceful_fail') ) : 
     59if ( !function_exists( 'graceful_fail' ) ) : 
    6060/** 
    61  * @deprecated 3.0 
     61 * @since MU 
     62 * @deprecated 3.0.0 
     63 * @deprecated Use wp_die() 
     64 * @see wp_die() 
    6265 */ 
    6366function graceful_fail( $message ) { 
    6467        _deprecated_function( __FUNCTION__, '3.0', 'wp_die()' ); 
    65         $message = apply_filters('graceful_fail', $message); 
     68        $message = apply_filters( 'graceful_fail', $message ); 
    6669        $message_template = apply_filters( 'graceful_fail_template', 
    6770'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    6871<html xmlns="http://www.w3.org/1999/xhtml"><head profile="http://gmpg.org/xfn/11"> 
     
    9295endif; 
    9396 
    9497/** 
    95  * @deprecated 3.0 
     98 * @since MU 
     99 * @deprecated 3.0.0 
     100 * @deprecated Use $GLOBALS['current_user']->ID 
    96101 */ 
    97102function get_current_user_id() { 
    98         _deprecated_function( __FUNCTION__, '3.0', '' ); 
    99  
    100         global $current_user; 
    101         return $current_user->ID; 
     103        _deprecated_function( __FUNCTION__, '3.0', '$GLOBALS\'current_user\']->ID' ); 
     104        return $GLOBALS['current_user']->ID; 
    102105} 
    103106 
    104107/** 
    105  * @deprecated 3.0 
     108 * @since MU 
     109 * @deprecated 3.0.0 
     110 * @deprecated Use get_user_by() 
     111 * @see get_user_by() 
    106112 */ 
    107113function get_user_details( $username ) { 
    108114        _deprecated_function( __FUNCTION__, '3.0', 'get_user_by()' ); 
    109  
    110115        return get_user_by('login', $username); 
    111116} 
    112117 
    113118/** 
    114  * @deprecated 3.0 
     119 * @since MU 
     120 * @deprecated 3.0.0 
     121 * @deprecated Use clean_post_cache() 
     122 * @see clean_post_cache() 
    115123 */ 
    116124function clear_global_post_cache( $post_id ) { 
    117         _deprecated_function( __FUNCTION__, '3.0', 'clean_post_cache' ); 
     125        _deprecated_function( __FUNCTION__, '3.0', 'clean_post_cache()' ); 
    118126} 
    119127 
    120128/** 
    121  * @deprecated 3.0 
     129 * @since MU 
     130 * @deprecated 3.0.0 
     131 * @deprecated Use is_main_site() 
     132 * @see is_main_site() 
    122133 */ 
    123134function is_main_blog() { 
    124         _deprecated_function( __FUNCTION__, '3.0', 'is_main_site' ); 
     135        _deprecated_function( __FUNCTION__, '3.0', 'is_main_site()' ); 
    125136        return is_main_site(); 
    126137} 
    127138 
    128139/** 
    129  * @deprecated 3.0 
     140 * @since MU 
     141 * @deprecated 3.0.0 
     142 * @deprecated Use is_email() 
     143 * @see is_email() 
    130144 */ 
    131145function validate_email( $email, $check_domain = true) { 
    132146        _deprecated_function( __FUNCTION__, '3.0', 'is_email()' ); 
  • wp-includes/ms-load.php

     
    11<?php 
    22/** 
    3  * Used to setup and fix common variables and include 
    4  * the WordPress procedural and class library. 
     3 * These functions are needed to load Multisite. 
    54 * 
    6  * You should not have to change this file and allows 
    7  * for some configuration in wp-config.php. 
     5 * @since 3.0.0 
    86 * 
     7 * @package WordPress 
     8 * @subpackage Multisite 
     9 */ 
     10 
     11/** 
     12 * Whether a subdomain configuration is enabled 
     13 * 
    914 * @since 3.0 
    1015 * 
    11  * @package WordPress 
     16 * @return bool True if subdomain configuration is enabled, false otherwise. 
    1217 */ 
    13 if ( defined( 'SUNRISE' ) ) 
    14         include_once( WP_CONTENT_DIR . '/sunrise.php' ); 
     18function is_subdomain_install() { 
     19        if ( defined('VHOST') && VHOST == 'yes' ) 
     20                return true; 
    1521 
    16 require( ABSPATH . WPINC . '/ms-settings.php' ); 
    17 $wpdb->blogid = $current_blog->blog_id; 
    18 $wpdb->siteid = $current_blog->site_id; 
    19 $wpdb->set_prefix($table_prefix); // set up blog tables 
    20 $table_prefix = $wpdb->get_blog_prefix(); 
    21  
    22 // Fix empty PHP_SELF 
    23 $PHP_SELF = $_SERVER['PHP_SELF']; 
    24 if ( empty($PHP_SELF) || ( empty($PHP_SELF) && !is_subdomain_install() && $current_blog->path != '/' ) ) 
    25         $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]); 
    26  
    27 wp_cache_init(); // need to init cache again after blog_id is set 
    28 if ( function_exists('wp_cache_add_global_groups') ) { // need to add these again. Yes, it's an ugly hack 
    29         wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss')); 
    30         wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); 
     22        return false; 
    3123} 
    3224 
    33 if ( !defined( 'UPLOADBLOGSDIR' ) ) 
    34         define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' ); 
    35  
    36 if ( !defined( 'UPLOADS' ) ) 
    37         define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" ); 
    38  
    39 if ( !defined( 'BLOGUPLOADDIR' ) ) 
    40         define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" ); 
    41  
    4225function ms_network_settings() { 
    4326        global $wpdb, $current_site, $cookiehash; 
    4427 
     
    11295        return true; 
    11396} 
    11497 
    115 function ms_network_cookies() { 
    116         global $current_site; 
    117         /** 
    118          * It is possible to define this in wp-config.php 
    119          * @since 1.2.0 
    120          */ 
    121         if ( !defined( 'COOKIEPATH' ) ) 
    122                         define( 'COOKIEPATH', $current_site->path ); 
     98function get_current_site_name( $current_site ) { 
     99        global $wpdb; 
     100        $current_site->site_name = wp_cache_get( $current_site->id . ':current_site_name', "site-options" ); 
     101        if ( !$current_site->site_name ) { 
     102                $current_site->site_name = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = %d AND meta_key = 'site_name'", $current_site->id ) ); 
     103                if ( $current_site->site_name == null ) 
     104                        $current_site->site_name = ucfirst( $current_site->domain ); 
     105                wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options'); 
     106        } 
     107        return $current_site; 
     108} 
    123109 
    124         /** 
    125          * It is possible to define this in wp-config.php 
    126          * @since 1.5.0 
    127          */ 
    128         if ( !defined( 'SITECOOKIEPATH' ) ) 
    129                         define( 'SITECOOKIEPATH', $current_site->path ); 
     110function wpmu_current_site() { 
     111        global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain; 
     112        if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) { 
     113                $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1); 
     114                $current_site->domain = DOMAIN_CURRENT_SITE; 
     115                $current_site->path   = $path = PATH_CURRENT_SITE; 
     116                if ( defined( 'BLOGID_CURRENT_SITE' ) ) 
     117                        $current_site->blog_id = BLOGID_CURRENT_SITE; 
     118                if ( DOMAIN_CURRENT_SITE == $domain ) 
     119                        $current_site->cookie_domain = $cookie_domain; 
     120                elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' ) 
     121                        $current_site->cookie_domain = substr( $current_site->domain, 4 ); 
     122                else 
     123                        $current_site->cookie_domain = $current_site->domain; 
    130124 
    131         /** 
    132          * It is possible to define this in wp-config.php 
    133          * @since 2.6.0 
    134          */ 
    135         if ( !defined( 'ADMIN_COOKIE_PATH' ) ) { 
    136                         if( !is_subdomain_install() ) { 
    137                                         define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH ); 
     125                return $current_site; 
     126        } 
     127 
     128        $current_site = wp_cache_get( "current_site", "site-options" ); 
     129        if ( $current_site ) 
     130                return $current_site; 
     131 
     132        $wpdb->suppress_errors(); 
     133        $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site 
     134        if ( count( $sites ) == 1 ) { 
     135                $current_site = $sites[0]; 
     136                $path = $current_site->path; 
     137                $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" ); 
     138                $current_site = get_current_site_name( $current_site ); 
     139                if ( substr( $current_site->domain, 0, 4 ) == 'www.' ) 
     140                        $current_site->cookie_domain = substr( $current_site->domain, 4 ); 
     141                wp_cache_set( "current_site", $current_site, "site-options" ); 
     142                return $current_site; 
     143        } 
     144        $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) ); 
     145 
     146        if ( $domain == $cookie_domain ) 
     147                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) ); 
     148        else 
     149                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) ); 
     150        if ( $current_site == null ) { 
     151                if ( $domain == $cookie_domain ) 
     152                        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) ); 
     153                else 
     154                        $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) ); 
     155        } 
     156        if ( $current_site != null ) { 
     157                $path = $current_site->path; 
     158                $current_site->cookie_domain = $cookie_domain; 
     159                return $current_site; 
     160        } elseif ( is_subdomain_install() ) { 
     161                $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) ); 
     162                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) ); 
     163                if ( $current_site != null ) { 
     164                        $current_site->cookie_domain = $current_site->domain; 
     165                        return $current_site; 
     166                } 
     167                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) ); 
     168                if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) { 
     169                        if ( count( $sites ) == 1 ) { 
     170                                $current_site = $sites[0]; 
     171                                die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" ); 
    138172                        } else { 
    139                                         define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' ); 
     173                                die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." ); 
    140174                        } 
     175                } else { 
     176                        $path = '/'; 
     177                } 
     178        } elseif ( defined( "WP_INSTALLING" ) == false ) { 
     179                if ( count( $sites ) == 1 ) { 
     180                        $current_site = $sites[0]; 
     181                        die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" ); 
     182                } else { 
     183                        die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." ); 
     184                } 
     185        } else { 
     186                $path = '/'; 
    141187        } 
    142         /** 
    143          * It is possible to define this in wp-config.php 
    144          * @since 2.0.0 
    145          */ 
    146         if ( !defined('COOKIE_DOMAIN') ) 
    147                         define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain); 
     188        return $current_site; 
    148189} 
     190 
     191function is_installed() { 
     192        global $wpdb, $domain, $path; 
     193        $base = stripslashes( $base ); 
     194        if ( defined( "WP_INSTALLING" ) == false ) { 
     195                $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); 
     196                $msg = "If your blog does not display, please contact the owner of this site.<br /><br />If you are the owner of this site please check that MySQL is running properly and all tables are error free.<br /><br />"; 
     197                if ( $check == false ) { 
     198                        $msg .= "<strong>Database Tables Missing.</strong><br />Database tables are missing. This means that MySQL is either not running, WPMU was not installed properly, or someone deleted {$wpdb->site}. You really <em>should</em> look at your database now.<br />"; 
     199                } else { 
     200                        $msg .= '<strong>Could Not Find Blog!</strong><br />'; 
     201                        $msg .= "Searched for <em>" . $domain . $path . "</em> in " . DB_NAME . "::" . $wpdb->blogs . " table. Is that right?<br />"; 
     202                } 
     203                $msg .= "<br />\n<h1>What do I do now?</h1>"; 
     204                $msg .= "Read the <a target='_blank' href='http://codex.wordpress.org/Debugging_WPMU'>bug report</a> page. Some of the guidelines there may help you figure out what went wrong.<br />"; 
     205                $msg .= "If you're still stuck with this message, then check that your database contains the following tables:<ul> 
     206                        <li> $wpdb->blogs </li> 
     207                        <li> $wpdb->users </li> 
     208                        <li> $wpdb->usermeta </li> 
     209                        <li> $wpdb->site </li> 
     210                        <li> $wpdb->sitemeta </li> 
     211                        <li> $wpdb->sitecategories </li> 
     212                        </ul>"; 
     213                $msg .= "If you suspect a problem please report it to the support forums but you must include the information asked for in the <a href='http://codex.wordpress.org/Debugging_WPMU'>WPMU bug reporting guidelines</a>!<br /><br />"; 
     214                if ( is_file( 'release-info.txt' ) ) { 
     215                        $msg .= 'Your bug report must include the following text: "'; 
     216                        $info = file( 'release-info.txt' ); 
     217                        $msg .= $info[ 4 ] . '"'; 
     218                } 
     219 
     220                die( "<h1>Fatal Error</h1> " . $msg ); 
     221        } 
     222} 
     223 
    149224?> 
  • wp-includes/ms-default-constants.php

     
     1<?php 
     2/** 
     3 * Defines constants and global variables that can be overridden, generally in wp-config.php. 
     4 * 
     5 * @package WordPress 
     6 * @subpackage Multisite 
     7 */ 
     8 
     9/** 
     10 * Defines Multisite default constants. 
     11 * 
     12 * @since 3.0.0 
     13 * @param $context 
     14 */ 
     15function ms_default_constants( $context ) { 
     16        switch( $context ) { 
     17                case 'uploads' : 
     18                        global $wpdb; 
     19                        if ( !defined( 'UPLOADBLOGSDIR' ) ) 
     20                                define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' ); 
     21                 
     22                        if ( !defined( 'UPLOADS' ) ) 
     23                                define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" ); 
     24                 
     25                        if ( !defined( 'BLOGUPLOADDIR' ) ) 
     26                                define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" ); 
     27                        break; 
     28                case 'cookies' : 
     29                        global $current_site; 
     30                        /** 
     31                         * It is possible to define this in wp-config.php 
     32                         * @since 1.2.0 
     33                         */ 
     34                        if ( !defined( 'COOKIEPATH' ) ) 
     35                                        define( 'COOKIEPATH', $current_site->path ); 
     36         
     37                        /** 
     38                         * It is possible to define this in wp-config.php 
     39                         * @since 1.5.0 
     40                         */ 
     41                        if ( !defined( 'SITECOOKIEPATH' ) ) 
     42                                        define( 'SITECOOKIEPATH', $current_site->path ); 
     43         
     44                        /** 
     45                         * It is possible to define this in wp-config.php 
     46                         * @since 2.6.0 
     47                         */ 
     48                        if ( !defined( 'ADMIN_COOKIE_PATH' ) ) { 
     49                                        if( !is_subdomain_install() ) { 
     50                                                        define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH ); 
     51                                        } else { 
     52                                                        define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' ); 
     53                                        } 
     54                        } 
     55                        /** 
     56                         * It is possible to define this in wp-config.php 
     57                         * @since 2.0.0 
     58                         */ 
     59                        if ( !defined('COOKIE_DOMAIN') ) 
     60                                        define('COOKIE_DOMAIN', '.' . $current_site->cookie_domain); 
     61                        break; 
     62        } 
     63} 
     64?> 
     65 No newline at end of file 
  • wp-includes/ms-settings.php

     
    11<?php 
    2  
    32/** 
    4  * Whether a subdomain configuration is enabled 
     3 * Used to setup and fix common variables and include 
     4 * the Multisite procedural and class library. 
    55 * 
    6  * @since 3.0 
     6 * Allows for some configuration in wp-config.php (see ms-default-constants.php) 
    77 * 
    8  * @return bool True if subdomain configuration is enabled, false otherwise. 
     8 * @package WordPress 
     9 * @subpackage Multisite 
    910 */ 
    10 function is_subdomain_install() { 
    11         if ( defined('VHOST') && VHOST == 'yes' ) 
    12                 return true; 
    1311 
    14         return false; 
    15 } 
     12if ( defined( 'SUNRISE' ) ) 
     13        include_once( WP_CONTENT_DIR . '/sunrise.php' ); 
    1614 
     15/** Include Multisite initialization functions */ 
     16require( ABSPATH . WPINC . '/ms-load.php' ); 
     17require( ABSPATH . WPINC . '/ms-default-constants.php' ); 
     18 
    1719if ( isset( $current_site ) && isset( $current_blog ) ) 
    1820        return; 
    1921 
     
    4547$path = str_replace ( '/wp-admin/', '/', $path ); 
    4648$path = preg_replace( '|(/[a-z0-9-]+?/).*|', '$1', $path ); 
    4749 
    48 function get_current_site_name( $current_site ) { 
    49         global $wpdb; 
    50         $current_site->site_name = wp_cache_get( $current_site->id . ':current_site_name', "site-options" ); 
    51         if ( !$current_site->site_name ) { 
    52                 $current_site->site_name = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = %d AND meta_key = 'site_name'", $current_site->id ) ); 
    53                 if ( $current_site->site_name == null ) 
    54                         $current_site->site_name = ucfirst( $current_site->domain ); 
    55                 wp_cache_set( $current_site->id . ':current_site_name', $current_site->site_name, 'site-options'); 
    56         } 
    57         return $current_site; 
    58 } 
    59  
    60 function wpmu_current_site() { 
    61         global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain; 
    62         if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) { 
    63                 $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1); 
    64                 $current_site->domain = DOMAIN_CURRENT_SITE; 
    65                 $current_site->path   = $path = PATH_CURRENT_SITE; 
    66                 if ( defined( 'BLOGID_CURRENT_SITE' ) ) 
    67                         $current_site->blog_id = BLOGID_CURRENT_SITE; 
    68                 if ( DOMAIN_CURRENT_SITE == $domain ) 
    69                         $current_site->cookie_domain = $cookie_domain; 
    70                 elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' ) 
    71                         $current_site->cookie_domain = substr( $current_site->domain, 4 ); 
    72                 else 
    73                         $current_site->cookie_domain = $current_site->domain; 
    74  
    75                 return $current_site; 
    76         } 
    77  
    78         $current_site = wp_cache_get( "current_site", "site-options" ); 
    79         if ( $current_site ) 
    80                 return $current_site; 
    81  
    82         $wpdb->suppress_errors(); 
    83         $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site 
    84         if ( count( $sites ) == 1 ) { 
    85                 $current_site = $sites[0]; 
    86                 $path = $current_site->path; 
    87                 $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" ); 
    88                 $current_site = get_current_site_name( $current_site ); 
    89                 if ( substr( $current_site->domain, 0, 4 ) == 'www.' ) 
    90                         $current_site->cookie_domain = substr( $current_site->domain, 4 ); 
    91                 wp_cache_set( "current_site", $current_site, "site-options" ); 
    92                 return $current_site; 
    93         } 
    94         $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) ); 
    95  
    96         if ( $domain == $cookie_domain ) 
    97                 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) ); 
    98         else 
    99                 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = %s ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) ); 
    100         if ( $current_site == null ) { 
    101                 if ( $domain == $cookie_domain ) 
    102                         $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) ); 
    103                 else 
    104                         $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain IN ( %s, %s ) AND path = '/' ORDER BY CHAR_LENGTH( domain ) DESC LIMIT 1", $domain, $cookie_domain, $path ) ); 
    105         } 
    106         if ( $current_site != null ) { 
    107                 $path = $current_site->path; 
    108                 $current_site->cookie_domain = $cookie_domain; 
    109                 return $current_site; 
    110         } elseif ( is_subdomain_install() ) { 
    111                 $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) ); 
    112                 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) ); 
    113                 if ( $current_site != null ) { 
    114                         $current_site->cookie_domain = $current_site->domain; 
    115                         return $current_site; 
    116                 } 
    117                 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) ); 
    118                 if ( $current_site == null && defined( "WP_INSTALLING" ) == false ) { 
    119                         if ( count( $sites ) == 1 ) { 
    120                                 $current_site = $sites[0]; 
    121                                 die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" ); 
    122                         } else { 
    123                                 die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." ); 
    124                         } 
    125                 } else { 
    126                         $path = '/'; 
    127                 } 
    128         } elseif ( defined( "WP_INSTALLING" ) == false ) { 
    129                 if ( count( $sites ) == 1 ) { 
    130                         $current_site = $sites[0]; 
    131                         die( "That blog does not exist. Please try <a href='http://{$current_site->domain}{$current_site->path}'>http://{$current_site->domain}{$current_site->path}</a>" ); 
    132                 } else { 
    133                         die( "No WPMU site defined on this host. If you are the owner of this site, please check <a href='http://codex.wordpress.org/Debugging_WPMU'>Debugging WPMU</a> for further assistance." ); 
    134                 } 
    135         } else { 
    136                 $path = '/'; 
    137         } 
    138         return $current_site; 
    139 } 
    140  
    14150$current_site = wpmu_current_site(); 
    14251if ( !isset( $current_site->blog_id ) ) 
    14352        $current_site->blog_id = $wpdb->get_var( "SELECT blog_id FROM {$wpdb->blogs} WHERE domain='{$current_site->domain}' AND path='{$current_site->path}'" ); 
     
    17079        } 
    17180} 
    17281 
    173 if ( defined( "WP_INSTALLING" ) == false && is_subdomain_install() && !is_object( $current_blog ) ) { 
     82if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && !is_object( $current_blog ) ) { 
     83 
    17484        if ( defined( 'NOBLOGREDIRECT' ) ) { 
    17585                $destination = constant( 'NOBLOGREDIRECT' ); 
    17686                if ( $destination == '%siteurl%' ) 
     
    18494 
    18595} 
    18696 
    187 if ( defined( "WP_INSTALLING" ) == false ) { 
     97if ( ! defined( 'WP_INSTALLING' ) ) { 
    18898        if ( $current_site && $current_blog == null ) { 
    18999                if ( $current_site->domain != $_SERVER[ 'HTTP_HOST' ] ) { 
    190100                        header( "Location: http://" . $current_site->domain . $current_site->path ); 
     
    235145        // This just means the blog shouldn't show up in google, etc. Only to registered members 
    236146} 
    237147 
    238 function is_installed() { 
    239         global $wpdb, $domain, $path; 
    240         $base = stripslashes( $base ); 
    241         if ( defined( "WP_INSTALLING" ) == false ) { 
    242                 $check = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); 
    243                 $msg = "If your blog does not display, please contact the owner of this site.<br /><br />If you are the owner of this site please check that MySQL is running properly and all tables are error free.<br /><br />"; 
    244                 if ( $check == false ) { 
    245                         $msg .= "<strong>Database Tables Missing.</strong><br />Database tables are missing. This means that MySQL is either not running, WPMU was not installed properly, or someone deleted {$wpdb->site}. You really <em>should</em> look at your database now.<br />"; 
    246                 } else { 
    247                         $msg .= '<strong>Could Not Find Blog!</strong><br />'; 
    248                         $msg .= "Searched for <em>" . $domain . $path . "</em> in " . DB_NAME . "::" . $wpdb->blogs . " table. Is that right?<br />"; 
    249                 } 
    250                 $msg .= "<br />\n<h1>What do I do now?</h1>"; 
    251                 $msg .= "Read the <a target='_blank' href='http://codex.wordpress.org/Debugging_WPMU'>bug report</a> page. Some of the guidelines there may help you figure out what went wrong.<br />"; 
    252                 $msg .= "If you're still stuck with this message, then check that your database contains the following tables:<ul> 
    253                         <li> $wpdb->blogs </li> 
    254                         <li> $wpdb->users </li> 
    255                         <li> $wpdb->usermeta </li> 
    256                         <li> $wpdb->site </li> 
    257                         <li> $wpdb->sitemeta </li> 
    258                         <li> $wpdb->sitecategories </li> 
    259                         </ul>"; 
    260                 $msg .= "If you suspect a problem please report it to the support forums but you must include the information asked for in the <a href='http://codex.wordpress.org/Debugging_WPMU'>WPMU bug reporting guidelines</a>!<br /><br />"; 
    261                 if ( is_file( 'release-info.txt' ) ) { 
    262                         $msg .= 'Your bug report must include the following text: "'; 
    263                         $info = file( 'release-info.txt' ); 
    264                         $msg .= $info[ 4 ] . '"'; 
    265                 } 
     148$wpdb->blogid = $current_blog->blog_id; 
     149$wpdb->siteid = $current_blog->site_id; 
     150$wpdb->set_prefix($table_prefix); // set up blog tables 
     151$table_prefix = $wpdb->get_blog_prefix(); 
    266152 
    267                 die( "<h1>Fatal Error</h1> " . $msg ); 
    268         } 
     153// Fix empty PHP_SELF 
     154$PHP_SELF = $_SERVER['PHP_SELF']; 
     155if ( empty($PHP_SELF) || ( empty($PHP_SELF) && !is_subdomain_install() && $current_blog->path != '/' ) ) 
     156        $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]); 
     157 
     158wp_cache_init(); // need to init cache again after blog_id is set 
     159if ( function_exists('wp_cache_add_global_groups') ) { // need to add these again. Yes, it's an ugly hack 
     160        wp_cache_add_global_groups(array ('users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss')); 
     161        wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); 
    269162} 
    270163 
     164ms_default_constants( 'uploads' ); 
     165 
    271166?> 
  • wp-settings.php

     
    7575 
    7676// Initialize multisite if enabled. 
    7777if ( is_multisite() ) 
    78         require( ABSPATH . WPINC . '/ms-load.php' ); 
     78        require( ABSPATH . WPINC . '/ms-settings.php' ); 
    7979 
    8080// Load early WordPress files. 
    8181require( ABSPATH . WPINC . '/plugin.php' ); 
     
    162162                die(); 
    163163        } 
    164164        unset($file); 
    165         ms_network_cookies(); 
     165        ms_default_constants( 'cookies' ); 
    166166} 
    167167 
    168168// Define constants after multisite is loaded. Cookie-related constants may be overridden in ms_network_cookies().