* Invalidate the get_id_from_blogname_* cache in refresh_blog_details()

* Change $name to $slug in get_id_from_blogname() for some semblance of clarity.
* Strip leading and trailing slashes from the slug in get_id_from_blogname() so get_blog_details()->path can be passed directly.

Props wonderboymusic
see #20950


git-svn-id: http://core.svn.wordpress.org/trunk@21979 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan Boren 2012-09-24 19:31:37 +00:00
parent 0ced797e20
commit c57b0f836f
1 changed files with 13 additions and 8 deletions

View File

@ -84,28 +84,32 @@ function get_blogaddress_by_domain( $domain, $path ) {
}
/**
* Given a blog's (subdomain or directory) name, retrieve it's id.
* Given a blog's (subdomain or directory) slug, retrieve it's id.
*
* @since MU
*
* @param string $name
* @param string $slug
* @return int A blog id
*/
function get_id_from_blogname( $name ) {
function get_id_from_blogname( $slug ) {
global $wpdb, $current_site;
$blog_id = wp_cache_get( 'get_id_from_blogname_' . $name, 'blog-details' );
$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 = $name . '.' . $current_site->domain;
$domain = $slug . '.' . $current_site->domain;
$path = $current_site->path;
} else {
$domain = $current_site->domain;
$path = $current_site->path . $name . '/';
$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_' . $name, $blog_id, 'blog-details' );
wp_cache_set( 'get_id_from_blogname_' . $slug, $blog_id, 'blog-details' );
return $blog_id;
}
@ -114,7 +118,7 @@ function get_id_from_blogname( $name ) {
*
* @since MU
*
* @param int|string|array $fields A blog ID, a blog name, or an array of fields to query against.
* @param int|string|array $fields A blog ID, a blog slug, or an array of fields to query against.
* @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
* @return object Blog details.
*/
@ -254,6 +258,7 @@ function refresh_blog_details( $blog_id ) {
wp_cache_delete( md5( $details->domain . $details->path ) , 'blog-lookup' );
wp_cache_delete( 'current_blog_' . $details->domain, 'site-options' );
wp_cache_delete( 'current_blog_' . $details->domain . $details->path, 'site-options' );
wp_cache_delete( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' );
do_action( 'refresh_blog_details', $blog_id );
}