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.
71 * @return bool|string Returns true on success, or drop-in file to include.
73 function ms_site_check() {
74 $blog = get_blog_details();
77 * Filter checking the status of the current blog.
81 * @param bool null Whether to skip the blog status check. Default null.
83 $check = apply_filters( 'ms_site_check', null );
84 if ( null !== $check )
87 // Allow super admins to see blocked sites
88 if ( is_super_admin() )
91 if ( '1' == $blog->deleted ) {
92 if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) )
93 return WP_CONTENT_DIR . '/blog-deleted.php';
95 wp_die( __( 'This user has elected to delete their account and the content is no longer available.' ), '', array( 'response' => 410 ) );
98 if ( '2' == $blog->deleted ) {
99 if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) )
100 return WP_CONTENT_DIR . '/blog-inactive.php';
102 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@' . get_current_site()->domain ) ) ) );
105 if ( $blog->archived == '1' || $blog->spam == '1' ) {
106 if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) )
107 return WP_CONTENT_DIR . '/blog-suspended.php';
109 wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) );
116 * Sets current site name.
120 * @return object $current_site object with site_name
122 function get_current_site_name( $current_site ) {
125 $current_site->site_name = wp_cache_get( $current_site->id . ':site_name', 'site-options' );
126 if ( ! $current_site->site_name ) {
127 $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 ) );
128 if ( ! $current_site->site_name )
129 $current_site->site_name = ucfirst( $current_site->domain );
130 wp_cache_set( $current_site->id . ':site_name', $current_site->site_name, 'site-options' );
133 return $current_site;
137 * Sets current_site object.
141 * @return object $current_site object
143 function wpmu_current_site() {
144 global $wpdb, $current_site, $domain, $path, $sites, $cookie_domain;
146 if ( empty( $current_site ) )
147 $current_site = new stdClass;
149 if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) {
150 $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1;
151 $current_site->domain = DOMAIN_CURRENT_SITE;
152 $current_site->path = $path = PATH_CURRENT_SITE;
153 if ( defined( 'BLOG_ID_CURRENT_SITE' ) )
154 $current_site->blog_id = BLOG_ID_CURRENT_SITE;
155 elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) // deprecated.
156 $current_site->blog_id = BLOGID_CURRENT_SITE;
157 if ( DOMAIN_CURRENT_SITE == $domain )
158 $current_site->cookie_domain = $cookie_domain;
159 elseif ( substr( $current_site->domain, 0, 4 ) == 'www.' )
160 $current_site->cookie_domain = substr( $current_site->domain, 4 );
162 $current_site->cookie_domain = $current_site->domain;
164 wp_load_core_site_options( $current_site->id );
166 return $current_site;
169 $current_site = wp_cache_get( 'current_site', 'site-options' );
171 return $current_site;
173 $sites = $wpdb->get_results( "SELECT * FROM $wpdb->site" ); // usually only one site
174 if ( 1 == count( $sites ) ) {
175 $current_site = $sites[0];
176 wp_load_core_site_options( $current_site->id );
177 $path = $current_site->path;
178 $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 ) );
179 $current_site = get_current_site_name( $current_site );
180 if ( substr( $current_site->domain, 0, 4 ) == 'www.' )
181 $current_site->cookie_domain = substr( $current_site->domain, 4 );
182 wp_cache_set( 'current_site', $current_site, 'site-options' );
183 return $current_site;
185 $path = substr( $_SERVER[ 'REQUEST_URI' ], 0, 1 + strpos( $_SERVER[ 'REQUEST_URI' ], '/', 1 ) );
187 if ( $domain == $cookie_domain )
188 $current_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) );
190 $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 ) );
192 if ( ! $current_site ) {
193 if ( $domain == $cookie_domain )
194 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $domain ) );
196 $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 ) );
199 if ( $current_site ) {
200 $path = $current_site->path;
201 $current_site->cookie_domain = $cookie_domain;
202 return $current_site;
205 if ( is_subdomain_install() ) {
206 $sitedomain = substr( $domain, 1 + strpos( $domain, '.' ) );
207 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path) );
208 if ( $current_site ) {
209 $current_site->cookie_domain = $current_site->domain;
210 return $current_site;
213 $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) );
216 if ( $current_site || defined( 'WP_INSTALLING' ) ) {
218 return $current_site;
222 wp_load_translations_early();
224 if ( 1 == count( $sites ) )
225 wp_die( sprintf( __( 'That site does not exist. Please try <a href="%s">%s</a>.' ), 'http://' . $sites[0]->domain . $sites[0]->path ) );
227 wp_die( __( '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.' ) );
231 * Displays a failure message.
233 * Used when a blog's tables do not exist. Checks for a missing $wpdb->site table as well.
238 function ms_not_installed() {
239 global $wpdb, $domain, $path;
241 wp_load_translations_early();
243 $title = __( 'Error establishing a database connection' );
244 $msg = '<h1>' . $title . '</h1>';
247 $msg .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . '';
248 $msg .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>';
249 if ( ! $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) )
250 $msg .= '<p>' . sprintf( __( '<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.' ), $wpdb->site ) . '</p>';
252 $msg .= '<p>' . sprintf( __( '<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?' ), rtrim( $domain . $path, '/' ), $wpdb->blogs, DB_NAME ) . '</p>';
253 $msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> ';
254 $msg .= __( '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.' );
255 $msg .= ' ' . __( 'If you’re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>';
256 foreach ( $wpdb->tables('global') as $t => $table ) {
257 if ( 'sitecategories' == $t )
259 $msg .= '<li>' . $table . '</li>';
263 wp_die( $msg, $title );