- if ( ! defined( 'WP_INSTALLING' ) && is_subdomain_install() && ! is_object( $current_blog ) ) {
- if ( defined( 'NOBLOGREDIRECT' ) ) {
- $destination = NOBLOGREDIRECT;
- if ( '%siteurl%' == $destination )
- $destination = "http://" . $current_site->domain . $current_site->path;
- } else {
- $destination = 'http://' . $current_site->domain . $current_site->path . 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
+ // The network declared by the site trumps any constants.
+ if ( $current_blog && $current_blog->site_id != $current_site->id ) {
+ $current_site = wp_get_network( $current_blog->site_id );
+ }
+
+ // No network has been found, bail.
+ if ( empty( $current_site ) ) {
+ ms_not_installed();
+ }
+
+ // @todo Investigate when exactly this can occur.
+ if ( empty( $current_blog ) && defined( 'WP_INSTALLING' ) ) {
+ $current_blog = new stdClass;
+ $current_blog->blog_id = $blog_id = 1;
+ }
+
+ // No site has been found, bail.
+ if ( empty( $current_blog ) ) {
+ // We're going to redirect to the network URL, with some possible modifications.
+ $scheme = is_ssl() ? 'https' : 'http';
+ $destination = "$scheme://{$current_site->domain}{$current_site->path}";
+
+ /**
+ * Fires when a network can be determined but a site cannot.
+ *
+ * At the time of this action, the only recourse is to redirect somewhere
+ * and exit. If you want to declare a particular site, do so earlier.
+ *
+ * @since 3.9.0
+ *
+ * @param object $current_site The network that had been determined.
+ * @param string $domain The domain used to search for a site.
+ * @param string $path The path used to search for a site.
+ */
+ do_action( 'ms_site_not_found', $current_site, $domain, $path );
+
+ if ( is_subdomain_install() && ! defined( 'NOBLOGREDIRECT' ) ) {
+ // For a "subdomain" install, redirect to the signup form specifically.
+ $destination .= 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain );
+ } elseif ( is_subdomain_install() ) {
+ // For a "subdomain" install, the NOBLOGREDIRECT constant
+ // can be used to avoid a redirect to the signup form.
+ // Using the ms_site_not_found action is preferred to the constant.
+ if ( '%siteurl%' !== NOBLOGREDIRECT ) {
+ $destination = NOBLOGREDIRECT;
+ }
+ } elseif ( 0 === strcasecmp( $current_site->domain, $domain ) ) {
+ /*
+ * If the domain we were searching for matches the network's domain,
+ * it's no use redirecting back to ourselves -- it'll cause a loop.
+ * As we couldn't find a site, we're simply not installed.
+ */
+ ms_not_installed();