| 137 | * Retrieve an object containing information about the requested network. |
| 138 | * |
| 139 | * @since 3.9.0 |
| 140 | * |
| 141 | * @param string $domain The network's domain. |
| 142 | * @param string $path The primary path of the network. |
| 143 | * @param string $cookie_domain The domain to be used for cookies on the network. |
| 144 | * |
| 145 | * @return mixed Object containing network information if found, false if not. |
| 146 | */ |
| 147 | function wp_get_network( $domain, $path, $cookie_domain = '' ) { |
| 148 | global $wpdb; |
| 149 | |
| 150 | if ( empty( $cookie_domain ) ) { |
| 151 | if ( 'www.' === substr( $domain, 0, 4 ) ) { |
| 152 | $cookie_domain = substr( $domain, 4 ); |
| 153 | } else { |
| 154 | $cookie_domain = $domain; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | if ( $domain === $cookie_domain ) { |
| 159 | $network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE domain = %s AND path = %s", $domain, $path ) ); |
| 160 | } else { |
| 161 | $network = $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 ) ); |
| 162 | } |
| 163 | |
| 164 | if ( $network ) { |
| 165 | wp_load_core_site_options( $network->id ); |
| 166 | $network = get_current_site_name( $network ); |
| 167 | $network->cookie_domain = $cookie_domain; |
| 168 | return $network; |
| 169 | } |
| 170 | |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | /** |
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; |
184 | | } |
| 213 | // Find the first complete path after the domain. |
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 ) ); |
189 | | else |
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 ) ); |
| 216 | // If we expect this to be a subdomain install, strip the first part of the domain for the network lookup. |
| 217 | if ( is_subdomain_install() ) { |
| 218 | $domain = substr( $domain, 1 + strpos( $domain, '.' ) ); |
| 219 | } |
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; |
211 | | } |
212 | | |
213 | | $current_site = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->site WHERE domain = %s AND path='/'", $sitedomain) ); |
214 | | } |
215 | | |
216 | | if ( $current_site || defined( 'WP_INSTALLING' ) ) { |
217 | | $path = '/'; |