3 * These functions are needed to load Multisite.
8 * @subpackage Multisite
12 * Whether a subdomain configuration is enabled.
16 * @return bool True if subdomain configuration is enabled, false otherwise.
18 function is_subdomain_install() {
19 if ( defined('SUBDOMAIN_INSTALL') )
20 return SUBDOMAIN_INSTALL;
22 if ( defined('VHOST') && VHOST == 'yes' )
29 * Returns array of network plugin files to be included in global scope.
31 * The default directory is wp-content/plugins. To change the default directory
32 * manually, define <code>WP_PLUGIN_DIR</code> and <code>WP_PLUGIN_URL</code>
37 * @return array Files to include
39 function wp_get_active_network_plugins() {
40 $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
41 if ( empty( $active_plugins ) )
45 $active_plugins = array_keys( $active_plugins );
46 sort( $active_plugins );
48 foreach ( $active_plugins as $plugin ) {
49 if ( ! validate_file( $plugin ) // $plugin must validate as file
50 && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
51 && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
53 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
59 * Checks status of current blog.
61 * Checks if the blog is deleted, inactive, archived, or spammed.
63 * Dies with a default message if the blog does not pass the check.
65 * To change the default message when a blog does not pass the check,
66 * use the wp-content/blog-deleted.php, blog-inactive.php and
67 * blog-suspended.php drop-ins.
69 * @return bool|string Returns true on success, or drop-in file to include.
71 function ms_site_check() {
72 global $wpdb, $current_blog;
74 // Allow short-circuiting
75 $check = apply_filters('ms_site_check', null);
76 if ( null !== $check )
79 // Allow super admins to see blocked sites
80 if ( is_super_admin() )
83 if ( '1' == $current_blog->deleted ) {
84 if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) )
85 return WP_CONTENT_DIR . '/blog-deleted.php';
87 wp_die( __( 'This user has elected to delete their account and the content is no longer available.' ), '', array( 'response' => 410 ) );
90 if ( '2' == $current_blog->deleted ) {
91 if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) )
92 return WP_CONTENT_DIR . '/blog-inactive.php';
94 wp_die( sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact <a href="mailto:%1$s">%1$s</a>.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', "support@{$current_site->domain}" ) ) ) );
97 if ( $current_blog->archived == '1' || $current_blog->spam == '1' ) {
98 if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) )
99 return WP_CONTENT_DIR . '/blog-suspended.php';
101 wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) );
108 * Sets current site name.
112 * @return object $current_site object with site_name
114 function get_current_site_name( $current_site ) {
117 $current_site->site_name = wp_cache_get( $current_site->id . ':site_name', 'site-options' );
118 if ( ! $current_site->site_name ) {
119 $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 ) );
120 if ( ! $current_site->site_name )
121 $current_site->site_name = ucfirst( $current_site->domain );
122 wp_cache_set( $current_site->id . ':site_name', $current_site->site_name, 'site-options' );
125 return $current_site;
129 * Sets current_site object.
133 * @return object $current_site object
135 function wpmu_current_site() {
136 global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;
138 if ( empty( $current_site ) )
139 $current_site = new stdClass;
141 if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
142 $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
143 $current_site->domain = DOMAIN_CURRENT_SITE;
144 $current_site->path = $path = PATH_CURRENT_SITE;
145 if ( defined( 'BLOG_ID_CURRENT_SITE' ) )
146 $current_site->blog_id = BLOG_ID_CURRENT_SITE;
147 elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated.
148 $current_site->blog_id = BLOGID_CURRENT_SITE;
149 if ( DOMAIN_CURRENT_SITE == $domain )
150 $current_site->cookie_domain = $cookie_domain;
151 elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' )
152 $current_site->cookie_domain = substr( $current_site->domain, 4 );
154 $current_site->cookie_domain = $current_site->domain;
156 wp_load_core_site_options( $current_site->id );
158 return $current_site;
161 $current_site = wp_cache_get( 'current_site', 'site-options' );
163 return $current_site;
165 $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site
166 if ( 1 == count( $sites ) ) {
167 $current_site = $sites[0];
168 wp_load_core_site_options( $current_site->id );
169 $path = $current_site->path;
170 $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->domain, $current_site->path ) );
171 $current_site = get_current_site_name( $current_site );
172 if ( substr( $current_site->domain, 0, 4 ) == 'www.' )
173 $current_site->cookie_domain = substr( $current_site->domain, 4 );
174 wp_cache_set( 'current_site', $current_site, 'site-options' );
175 return $current_site;
177 $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
179 if ( $domain == $cookie_domain )
180 $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );
182 $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 ) );
184 if ( ! $current_site ) {
185 if ( $domain == $cookie_domain )
186 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) );
188 $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 ) );
191 if ( $current_site ) {
192 $path = $current_site->path;
193 $current_site->cookie_domain = $cookie_domain;
194 return $current_site;
197 if ( is_subdomain_install() ) {
198 $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
199 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
200 if ( $current_site ) {
201 $current_site->cookie_domain = $current_site->domain;
202 return $current_site;
205 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
208 if ( $current_site || defined( 'WP_INSTALLING' ) ) {
210 return $current_site;
214 if ( 1 == count( $sites ) )
215 wp_die( sprintf( /*WP_I18N_BLOG_DOESNT_EXIST*/'That site does not exist. Please try <a href="%s">%s</a>.'/*/WP_I18N_BLOG_DOESNT_EXIST*/, $sites[0]->domain . $sites[0]->path ) );
217 wp_die( /*WP_I18N_NO_SITE_DEFINED*/'No site defined on this host. If you are the owner of this site, please check <a href="http://codex.wordpress.org/Debugging_a_WordPress_Network">Debugging a WordPress Network</a> for help.'/*/WP_I18N_NO_SITE_DEFINED*/ );
221 * Displays a failure message.
223 * Used when a blog's tables do not exist. Checks for a missing $wpdb->site table as well.
228 function ms_not_installed() {
229 global $wpdb, $domain, $path;
231 $title = /*WP_I18N_FATAL_ERROR*/'Error establishing database connection'/*/WP_I18N_FATAL_ERROR*/;
232 $msg = '<h1>' . $title . '</h1>';
235 $msg .= '<p>' . /*WP_I18N_CONTACT_OWNER*/'If your site does not display, please contact the owner of this network.'/*/WP_I18N_CONTACT_OWNER*/ . '';
236 $msg .= ' ' . /*WP_I18N_CHECK_MYSQL*/'If you are the owner of this network please check that MySQL is running properly and all tables are error free.'/*/WP_I18N_CHECK_MYSQL*/ . '</p>';
237 if ( false && !$wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
238 $msg .= '<p>' . sprintf( /*WP_I18N_TABLES_MISSING_LONG*/'<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted <code>%s</code>. You really should look at your database now.'/*/WP_I18N_TABLES_MISSING_LONG*/, $wpdb->site ) . '</p>';
240 $msg .= '<p>' . sprintf( /*WP_I18N_NO_SITE_FOUND*/'<strong>Could not find site <code>%1$s</code>.</strong> Searched for table <code>%2$s</code> in database <code>%3$s</code>. Is that right?'/*/WP_I18N_NO_SITE_FOUND*/, rtrim( $domain . $path, '/' ), $wpdb->blogs, DB_NAME ) . '</p>';
241 $msg .= '<p><strong>' . /*WP_I18N_WHAT_DO_I_DO*/'What do I do now?'/*/WP_I18N_WHAT_DO_I_DO*/ . '</strong> ';
242 $msg .= /*WP_I18N_RTFM*/'Read the <a target="_blank" href="http://codex.wordpress.org/Debugging_a_WordPress_Network">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.'/*/WP_I18N_RTFM*/;
243 $msg .= ' ' . /*WP_I18N_STUCK*/'If you’re still stuck with this message, then check that your database contains the following tables:'/*/WP_I18N_STUCK*/ . '</p><ul>';
244 foreach ( $wpdb->tables('global') as $t => $table ) {
245 if ( 'sitecategories' == $t )
247 $msg .= '<li>' . $table . '</li>';
251 wp_die( $msg, $title );