函数原型
get_id_from_blogname( string $slug ): int|null
函数描述
Retrieves a site’s ID given its (subdomain or directory) slug.
是否弃用
未弃用
函数参数
-
$slug
string
Required - A site’s slug.
函数返回值
int|null The site ID, or null if no site is found for the given slug.
函数位置
File: wp-includes/ms-blogs.php.
函数源码
function get_id_from_blogname( $slug ) {
$current_network = get_network();
$slug = trim( $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,
'update_site_meta_cache' => false,
)
);
if ( empty( $site_ids ) ) {
return null;
}
return array_shift( $site_ids );
}
源码链接
变更日志
| Version | Description |
|---|---|
| MU (3.0.0) | MU (3.0.0) |
| 4.7.0 | Introduced. |

