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
This commit is contained in:
parent
0f0ab0e8ef
commit
018a94d5f5
|
@ -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 MU (3.0.0)
|
||||||
* @since 4.7.0 Converted to use get_sites().
|
* @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.
|
* @param string $slug A site's slug.
|
||||||
* @return int|null The site ID, or null if no site is found for the given slug.
|
* @return int|null The site ID, or null if no site is found for the given slug.
|
||||||
*/
|
*/
|
||||||
function get_id_from_blogname( $slug ) {
|
function get_id_from_blogname( $slug ) {
|
||||||
$current_network = get_network();
|
$result = get_site_by( 'slug', $slug );
|
||||||
$slug = trim( $slug, '/' );
|
|
||||||
|
|
||||||
if ( is_subdomain_install() ) {
|
if ( ! $result ) {
|
||||||
$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 ) ) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_shift( $site_ids );
|
return $result->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue