Make WordPress Core

Ticket #37217: 37217.2.diff

File 37217.2.diff, 2.6 KB (added by flixos90, 7 years ago)
  • src/wp-includes/class-wp-network.php

     
    267267         * @return WP_Network|bool Network object if successful. False when no network is found.
    268268         */
    269269        public static function get_by_path( $domain = '', $path = '', $segments = null ) {
    270                 global $wpdb;
    271 
    272270                $domains = array( $domain );
    273271                $pieces  = explode( '.', $domain );
    274272
     
    295293                if ( wp_using_ext_object_cache() ) {
    296294                        $using_paths = wp_cache_get( 'networks_have_paths', 'site-options' );
    297295                        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                                ) );
    299301                                wp_cache_add( 'networks_have_paths', $using_paths, 'site-options'  );
    300302                        }
    301303                }
     
    356358                // @todo Consider additional optimization routes, perhaps as an opt-in for plugins.
    357359                // We already have paths covered. What about how far domains should be drilled down (including www)?
    358360
    359                 $search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'";
    360 
    361361                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                        ) );
    368369
    369                         if ( ! empty( $network ) && ! is_wp_error( $network ) ) {
    370                                 return new WP_Network( $network );
     370                        if ( ! empty( $networks ) ) {
     371                                return array_shift( $networks );
    371372                        }
    372373
    373374                        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) DESC
    382                         " );
    383375                }
    384376
     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
    385386                /*
    386387                 * Domains are sorted by length of domain, then by length of path.
    387388                 * The domain must match for the path to be considered. Otherwise,
     
    402403                }
    403404
    404405                if ( true === $found ) {
    405                         return new WP_Network( $network );
     406                        return $network;
    406407                }
    407408
    408409                return false;