Networks and Sites: In `get_site_by_path()`, use single `domain` and `path` parameters if there's only one item to look for.

This should increase the chances of `WP_Site_Query::get_sites()` hitting an existing cache.

Props spacedmonkey.
Fixes #42299.

git-svn-id: https://develop.svn.wordpress.org/trunk@42698 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2018-02-11 17:08:58 +00:00
parent 4bc7afd701
commit 2e2fd97287
1 changed files with 7 additions and 3 deletions

View File

@ -234,17 +234,21 @@ function get_site_by_path( $domain, $path, $segments = null ) {
}
$args = array(
'domain__in' => $domains,
'path__in' => $paths,
'number' => 1,
'number' => 1,
);
if ( count( $domains ) > 1 ) {
$args['domain__in'] = $domains;
$args['orderby']['domain_length'] = 'DESC';
} else {
$args['domain'] = array_shift( $domains );
}
if ( count( $paths ) > 1 ) {
$args['path__in'] = $paths;
$args['orderby']['path_length'] = 'DESC';
} else {
$args['path'] = array_shift( $paths );
}
$result = get_sites( $args );