get_blog_id_from_url()
get_blog_id_from_url( string $domain, string $path = ‘/…
get_blog_id_from_url( string $domain, string $path = ‘/’ )
从博客的URL获取其数字ID。
Get a blog’s numeric ID from its URL.
目录锚点:#说明#返回#源码#笔记
说明(Description)
在子目录安装中example.com/blog1网站/,$domain将是根目录’example.com网站’和$path子目录’/blog1/’。有像blog1这样的子域。example.com网站,$domain是’blog1。example.com网站’和$path是’/’。
返回(Return)
(int)如果没有找到blog,则为0,否则为匹配blog的ID
源码(Source)
/** * Get a blog's numeric ID from its URL. * * On a subdirectory installation like example.com/blog1/, * $domain will be the root 'example.com' and $path the * subdirectory '/blog1/'. With subdomains like blog1.example.com, * $domain is 'blog1.example.com' and $path is '/'. * * @since MU 2.6.5 * * @global wpdb $wpdb * * @param string $domain * @param string $path Optional. Not required for subdomain installations. * @return int 0 if no blog found, otherwise the ID of the matching blog */ function get_blog_id_from_url( $domain, $path = '/' ) { global $wpdb; $domain = strtolower( $domain ); $path = strtolower( $path ); $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); if ( $id == -1 ) // blog does not exist return 0; elseif ( $id ) return (int) $id; $id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) ); if ( ! $id ) { wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' ); return 0; } wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' ); return $id; } // Admin functions
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
MU (3.0.0) | wp-includes/ms-functions.php:349 | 0 | 3 |
笔记(Notes)
例子
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!