get_id_from_blogname()
get_id_from_blogname( string $slug )
检索给定其(子域或目录)slug的站点ID。
Retrieves a sites ID given its (subdomain or directory) slug.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$slug | (string) | 必需 | 网站的鼻涕虫。 |
返回(Return)
(int|null)站点ID,如果找不到给定slug的站点,则为null。
源码(Source)
/** * Given a blog's (subdomain or directory) slug, retrieve its id. * * @since MU * * @global wpdb $wpdb * * @param string $slug * @return int A blog id */ function get_id_from_blogname( $slug ) { global $wpdb; $current_site = get_current_site(); $slug = trim( $slug, '/' ); $blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' ); if ( $blog_id ) return $blog_id; if ( is_subdomain_install() ) { $domain = $slug . '.' . $current_site->domain; $path = $current_site->path; } else { $domain = $current_site->domain; $path = $current_site->path . $slug . '/'; } $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) ); wp_cache_set( 'get_id_from_blogname_' . $slug, $blog_id, 'blog-details' ); return $blog_id; }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
MU (3.0.0) | wp-includes/ms-blogs.php:86 | 2 | 3 |
笔记(Notes)
按名称获取博客的id($slug)
get_id_from_blogname() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_id_from_blogname/