WordPress supports MultiSites

WordPress now supports MultiSites with its 3.0 version. It’s the current SVN development version. This means you can have one wordpress install for multiple sites. You can see how it works by looking into “ms-settings.php”.

This is quite a good news for anyone willing to manage a community of bloggers.

Here is a part of the wp-includes/wp-settings.php file :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function wpmu_current_site() {
        global $wpdb, $current_site, $domain, $path, $sites;
        if( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
                $current_site->id = (defined( 'SITE_ID_CURRENT_SITE' ) ? constant('SITE_ID_CURRENT_SITE') : 1);
                $current_site->domain = DOMAIN_CURRENT_SITE;
                $current_site->path   = $path = PATH_CURRENT_SITE;
                if( defined( 'BLOGID_CURRENT_SITE' ) )
                        $current_site->blog_id = BLOGID_CURRENT_SITE;
                return $current_site;
        }
 
        $current_site = wp_cache_get( "current_site", "site-options" );
        if( $current_site )
                return $current_site;
 
        $wpdb->suppress_errors();
        $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site
        if( count( $sites ) == 1 ) {
                $current_site = $sites[0];
                $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}'" );
                $current_site = get_current_site_name( $current_site );
                wp_cache_set( "current_site", $current_site, "site-options" );
                return $current_site;
        }
        $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
        if( is_subdomain_install() ) {
                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
                if( $current_site != null )
                        return $current_site;
                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) );
                if( $current_site != null ) {
                        $path = '/';
                        return $current_site;
                }
 
                $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
                if( $current_site != null )
                        return $current_site;
                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
                if( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
                        if( count( $sites ) == 1 ) {
                                $current_site = $sites[0];
                                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>" );
                        } else {
                                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 f
urther assistance." );
                        }
                } else {
                        $path = '/';
                }
        } else {
                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path) );
                if( $current_site != null )
                        return $current_site;
                $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain) );
                if( $current_site == null && defined( "WP_INSTALLING" ) == false ) {
                        if( count( $sites ) == 1 ) {
                                $current_site = $sites[0];
                                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>" );
                        } else {
                                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 f
urther assistance." );
                        }
                } else {
                        $path = '/';
                }
        }
        return $current_site;
}

Leave a Reply

Your email address will not be published. Required fields are marked *