WordPress.org

Make WordPress Core

Changeset 37628


Ignore:
Timestamp:
06/02/2016 09:45:20 PM (3 years ago)
Author:
jeremyfelt
Message:

Multisite: Replace $wpdb->blog queries in get_site_by_path() with get_sites()

Props spacedmonkey, DrewAPicture.
See #35791.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-load.php

    r37518 r37628  
    155155 *
    156156 * @since 3.9.0
     157 * @since 4.6.0 Converted to use get_sites()
    157158 *
    158159 * @global wpdb $wpdb WordPress database abstraction object.
     
    164165 */
    165166function get_site_by_path( $domain, $path, $segments = null ) {
    166     global $wpdb;
    167 
    168167    $path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );
    169168
     
    232231    if ( 'www.' === substr( $domain, 0, 4 ) ) {
    233232        $domains[] = substr( $domain, 4 );
    234         $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'";
    235     }
    236 
    237     if ( count( $paths ) > 1 ) {
    238         $search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'";
    239     }
     233    }
     234
     235    $args = array(
     236        'domain__in' => $domains,
     237        'path__in' => $paths,
     238        'number' => 1,
     239    );
    240240
    241241    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" );
     242        $args['orderby'] = 'domain_length path_length';
     243        $args['order'] = 'DESC DESC';
    243244    } 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 );
     245        $args['orderby'] = 'domain_length';
     246        $args['order'] = 'DESC';
    247247    } 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 );
    251     } else {
    252         $site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domains[0], $paths[0] ) );
    253     }
     248        $args['orderby'] = 'path_length';
     249        $args['order'] = 'DESC';
     250    }
     251
     252    $result = get_sites( $args );
     253    $site = array_shift( $result );
    254254
    255255    if ( $site ) {
Note: See TracChangeset for help on using the changeset viewer.