From c57b0f836face113b12a312b590336d2da35b44a Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Mon, 24 Sep 2012 19:31:37 +0000 Subject: [PATCH] * 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 --- wp-includes/ms-blogs.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index d3ba0514f0..1ca85f0a2c 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -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 ); }