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 return ( defined( 'VHOST' ) && VHOST == 'yes' );
26 * Returns array of network plugin files to be included in global scope.
28 * The default directory is wp-content/plugins. To change the default directory
29 * manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` in `wp-config.php`.
34 * @return array Files to include.
36 function wp_get_active_network_plugins() {
37 $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
38 if ( empty( $active_plugins ) )
42 $active_plugins = array_keys( $active_plugins );
43 sort( $active_plugins );
45 foreach ( $active_plugins as $plugin ) {
46 if ( ! validate_file( $plugin ) // $plugin must validate as file
47 && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
48 && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
50 $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
56 * Checks status of current blog.
58 * Checks if the blog is deleted, inactive, archived, or spammed.
60 * Dies with a default message if the blog does not pass the check.
62 * To change the default message when a blog does not pass the check,
63 * use the wp-content/blog-deleted.php, blog-inactive.php and
64 * blog-suspended.php drop-ins.
68 * @return true|string Returns true on success, or drop-in file to include.
70 function ms_site_check() {
71 $blog = get_blog_details();
74 * Filter checking the status of the current blog.
78 * @param bool null Whether to skip the blog status check. Default null.
80 $check = apply_filters( 'ms_site_check', null );
81 if ( null !== $check )
84 // Allow super admins to see blocked sites
85 if ( is_super_admin() )
88 if ( '1' == $blog->deleted ) {
89 if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) )
90 return WP_CONTENT_DIR . '/blog-deleted.php';
92 wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) );
95 if ( '2' == $blog->deleted ) {
96 if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) {
97 return WP_CONTENT_DIR . '/blog-inactive.php';
99 $admin_email = str_replace( '@', ' AT ', get_site_option( 'admin_email', 'support@' . get_current_site()->domain ) );
101 /* translators: %s: admin email link */
102 sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact %s.' ),
103 sprintf( '<a href="mailto:%s">%s</a>', $admin_email )
109 if ( $blog->archived == '1' || $blog->spam == '1' ) {
110 if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) )
111 return WP_CONTENT_DIR . '/blog-suspended.php';
113 wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) );
120 * Retrieve the closest matching network for a domain and path.
123 * @since 4.4.0 Converted to a wrapper for WP_Network::get_by_path()
125 * @param string $domain Domain to check.
126 * @param string $path Path to check.
127 * @param int|null $segments Path segments to use. Defaults to null, or the full path.
128 * @return WP_Network|false Network object if successful. False when no network is found.
130 function get_network_by_path( $domain, $path, $segments = null ) {
131 return WP_Network::get_by_path( $domain, $path, $segments );
135 * Retrieve an object containing information about the requested network.
138 * @since 4.4.0 Converted to leverage WP_Network
140 * @param object|int $network The network's database row or ID.
141 * @return WP_Network|false Object containing network information if found, false if not.
143 function wp_get_network( $network ) {
144 if ( ! is_object( $network ) ) {
145 $network = WP_Network::get_instance( $network );
147 $network = new WP_Network( $network );
154 * Retrieve a site object by its domain and path.
158 * @global wpdb $wpdb WordPress database abstraction object.
160 * @param string $domain Domain to check.
161 * @param string $path Path to check.
162 * @param int|null $segments Path segments to use. Defaults to null, or the full path.
163 * @return object|false Site object if successful. False when no site is found.
165 function get_site_by_path( $domain, $path, $segments = null ) {
168 $path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );
171 * Filter the number of path segments to consider when searching for a site.
175 * @param int|null $segments The number of path segments to consider. WordPress by default looks at
176 * one path segment following the network path. The function default of
177 * null only makes sense when you know the requested path should match a site.
178 * @param string $domain The requested domain.
179 * @param string $path The requested path, in full.
181 $segments = apply_filters( 'site_by_path_segments_count', $segments, $domain, $path );
183 if ( null !== $segments && count( $path_segments ) > $segments ) {
184 $path_segments = array_slice( $path_segments, 0, $segments );
189 while ( count( $path_segments ) ) {
190 $paths[] = '/' . implode( '/', $path_segments ) . '/';
191 array_pop( $path_segments );
197 * Determine a site by its domain and path.
199 * This allows one to short-circuit the default logic, perhaps by
200 * replacing it with a routine that is more optimal for your setup.
202 * Return null to avoid the short-circuit. Return false if no site
203 * can be found at the requested domain and path. Otherwise, return
208 * @param null|bool|object $site Site value to return by path.
209 * @param string $domain The requested domain.
210 * @param string $path The requested path, in full.
211 * @param int|null $segments The suggested number of paths to consult.
212 * Default null, meaning the entire path was to be consulted.
213 * @param array $paths The paths to search for, based on $path and $segments.
215 $pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths );
216 if ( null !== $pre ) {
222 * get_blog_details(), caching, etc. Consider alternative optimization routes,
223 * perhaps as an opt-in for plugins, rather than using the pre_* filter.
224 * For example: The segments filter can expand or ignore paths.
225 * If persistent caching is enabled, we could query the DB for a path <> '/'
226 * then cache whether we can just always ignore paths.
229 // Either www or non-www is supported, not both. If a www domain is requested,
230 // query for both to provide the proper redirect.
231 $domains = array( $domain );
232 if ( 'www.' === substr( $domain, 0, 4 ) ) {
233 $domains[] = substr( $domain, 4 );
234 $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'";
237 if ( count( $paths ) > 1 ) {
238 $search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'";
241 if ( count( $domains ) > 1 && count( $paths ) > 1 ) {
242 $site = $wpdb->get_row( "SELECT * FROM $wpdb->blogs WHERE domain IN ($search_domains) AND path IN ($search_paths) ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC LIMIT 1" );
243 } elseif ( count( $domains ) > 1 ) {
244 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE path = %s", $paths[0] );
245 $sql .= " AND domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1";
246 $site = $wpdb->get_row( $sql );
247 } elseif ( count( $paths ) > 1 ) {
248 $sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domains[0] );
249 $sql .= " AND path IN ($search_paths) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1";
250 $site = $wpdb->get_row( $sql );
252 $site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domains[0], $paths[0] ) );
256 // @todo get_blog_details()
264 * Displays a failure message.
266 * Used when a blog's tables do not exist. Checks for a missing $wpdb->site table as well.
270 * @since 4.4.0 The `$domain` and `$path` parameters were added.
272 * @global wpdb $wpdb WordPress database abstraction object.
274 * @param string $domain The requested domain for the error to reference.
275 * @param string $path The requested path for the error to reference.
277 function ms_not_installed( $domain, $path ) {
280 if ( ! is_admin() ) {
284 wp_load_translations_early();
286 $title = __( 'Error establishing a database connection' );
288 $msg = '<h1>' . $title . '</h1>';
289 $msg .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . '';
290 $msg .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>';
291 $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->site ) );
292 if ( ! $wpdb->get_var( $query ) ) {
293 $msg .= '<p>' . sprintf(
294 /* translators: %s: table name */
295 __( '<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted %s. You really should look at your database now.' ),
296 '<code>' . $wpdb->site . '</code>'
299 $msg .= '<p>' . sprintf(
300 /* translators: 1: site url, 2: table name, 3: database name */
301 __( '<strong>Could not find site %1$s.</strong> Searched for table %2$s in database %3$s. Is that right?' ),
302 '<code>' . rtrim( $domain . $path, '/' ) . '</code>',
303 '<code>' . $wpdb->blogs . '</code>',
304 '<code>' . DB_NAME . '</code>'
307 $msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> ';
308 /* translators: %s: Codex URL */
309 $msg .= sprintf( __( 'Read the <a href="%s" target="_blank">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.' ),
310 __( 'https://codex.wordpress.org/Debugging_a_WordPress_Network' )
312 $msg .= ' ' . __( 'If you’re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>';
313 foreach ( $wpdb->tables('global') as $t => $table ) {
314 if ( 'sitecategories' == $t )
316 $msg .= '<li>' . $table . '</li>';
320 wp_die( $msg, $title, array( 'response' => 500 ) );
324 * This deprecated function formerly set the site_name property of the $current_site object.
326 * This function simply returns the object, as before.
327 * The bootstrap takes care of setting site_name.
331 * @deprecated 3.9.0 Use get_current_site() instead.
333 * @param object $current_site
336 function get_current_site_name( $current_site ) {
337 _deprecated_function( __FUNCTION__, '3.9', 'get_current_site()' );
338 return $current_site;
342 * This deprecated function managed much of the site and network loading in multisite.
344 * The current bootstrap code is now responsible for parsing the site and network load as
345 * well as setting the global $current_site object.
351 * @global object $current_site
355 function wpmu_current_site() {
356 global $current_site;
357 _deprecated_function( __FUNCTION__, '3.9' );
358 return $current_site;