get_id_from_blogname
函数
get_id_from_blogname ( $slug )
- 参数
-
-
(string)
$slug
A site’s slug.- Required: 是
-
(string)
- 返回值
-
- (int|null) The site ID, or null if no site is found for the given slug.
- 定义位置
-
-
wp-includes/ms-blogs.php
, line 86
-
wp-includes/ms-blogs.php
- 引入
- –
- 弃用
- –
检索一个网站的ID,给定它的(子域或目录)slug。
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 );
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。


