From 018a94d5f5d8d9ffe9c2e2addf308049a219e779 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Wed, 4 Oct 2017 18:45:52 +0000 Subject: [PATCH] Multisite: Use `get_site_by()` in `get_id_from_blogname()`. Fixes #42091. Built from https://develop.svn.wordpress.org/trunk@41743 git-svn-id: http://core.svn.wordpress.org/trunk@41577 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/ms-blogs.php | 25 +++++-------------------- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index f25fa6ec6a..f5b57fd6e7 100644 --- a/wp-includes/ms-blogs.php +++ b/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; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 08221a4b38..5bd854e447 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-41742'; +$wp_version = '4.9-alpha-41743'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.