Ticket #37217: 37217.2.diff
File 37217.2.diff, 2.6 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-network.php
267 267 * @return WP_Network|bool Network object if successful. False when no network is found. 268 268 */ 269 269 public static function get_by_path( $domain = '', $path = '', $segments = null ) { 270 global $wpdb;271 272 270 $domains = array( $domain ); 273 271 $pieces = explode( '.', $domain ); 274 272 … … 295 293 if ( wp_using_ext_object_cache() ) { 296 294 $using_paths = wp_cache_get( 'networks_have_paths', 'site-options' ); 297 295 if ( false === $using_paths ) { 298 $using_paths = (int) $wpdb->get_var( "SELECT id FROM {$wpdb->site} WHERE path <> '/' LIMIT 1" ); 296 $using_paths = get_networks( array( 297 'number' => 1, 298 'count' => true, 299 'path__not_in' => '/', 300 ) ); 299 301 wp_cache_add( 'networks_have_paths', $using_paths, 'site-options' ); 300 302 } 301 303 } … … 356 358 // @todo Consider additional optimization routes, perhaps as an opt-in for plugins. 357 359 // We already have paths covered. What about how far domains should be drilled down (including www)? 358 360 359 $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'";360 361 361 if ( ! $using_paths ) { 362 $network = $wpdb->get_row( " 363 SELECT * FROM {$wpdb->site} 364 WHERE domain IN ({$search_domains}) 365 ORDER BY CHAR_LENGTH(domain) 366 DESC LIMIT 1 367 " ); 362 $networks = get_networks( array( 363 'number' => 1, 364 'orderby' => array( 365 'domain_length' => 'ASC', 366 ), 367 'domain__in' => $domains, 368 ) ); 368 369 369 if ( ! empty( $network ) && ! is_wp_error( $network) ) {370 return new WP_Network( $network);370 if ( ! empty( $networks ) ) { 371 return array_shift( $networks ); 371 372 } 372 373 373 374 return false; 374 375 } else {376 $search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'";377 $networks = $wpdb->get_results( "378 SELECT * FROM {$wpdb->site}379 WHERE domain IN ({$search_domains})380 AND path IN ({$search_paths})381 ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC382 " );383 375 } 384 376 377 $networks = get_networks( array( 378 'orderby' => array( 379 'domain_length' => 'DESC', 380 'path_length' => 'DESC', 381 ), 382 'domain__in' => $domains, 383 'path__in' => $paths, 384 ) ); 385 385 386 /* 386 387 * Domains are sorted by length of domain, then by length of path. 387 388 * The domain must match for the path to be considered. Otherwise, … … 402 403 } 403 404 404 405 if ( true === $found ) { 405 return new WP_Network( $network );406 return $network; 406 407 } 407 408 408 409 return false;