From ce6dd8e53041af15835e18359a90a4f2cc0745b3 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Wed, 4 Oct 2017 18:44:36 +0000 Subject: [PATCH] Multisite: Use `get_site_by()` in `get_id_from_blogname()`. Fixes #42091. git-svn-id: https://develop.svn.wordpress.org/trunk@41743 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-blogs.php | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index f25fa6ec6a..f5b57fd6e7 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -70,38 +70,23 @@ function get_blogaddress_by_name( $blogname ) { } /** - * Retrieves a sites ID given its (subdomain or directory) slug. + * Retrieves a site's ID given its (subdomain or directory) slug. * * @since MU (3.0.0) * @since 4.7.0 Converted to use get_sites(). + * @since 4.9.0 Converted to use get_site_by(). * * @param string $slug A site's slug. * @return int|null The site ID, or null if no site is found for the given slug. */ function get_id_from_blogname( $slug ) { - $current_network = get_network(); - $slug = trim( $slug, '/' ); + $result = get_site_by( 'slug', $slug ); - if ( is_subdomain_install() ) { - $domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_network->domain ); - $path = $current_network->path; - } else { - $domain = $current_network->domain; - $path = $current_network->path . $slug . '/'; - } - - $site_ids = get_sites( array( - 'number' => 1, - 'fields' => 'ids', - 'domain' => $domain, - 'path' => $path, - ) ); - - if ( empty( $site_ids ) ) { + if ( ! $result ) { return null; } - return array_shift( $site_ids ); + return $result->id; } /**