Changeset 38659
- Timestamp:
- 09/27/2016 06:17:23 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ms-blogs.php
r38658 r38659 73 73 74 74 /** 75 * Given a blog's (subdomain or directory) slug, retrieve its id. 76 * 77 * @since MU 78 * 79 * @global wpdb $wpdb WordPress database abstraction object. 80 * 81 * @param string $slug 82 * @return int A blog id 75 * Retrieves a sites ID given its (subdomain or directory) slug. 76 * 77 * @since MU 78 * @since 4.7.0 Converted to use get_sites(). 79 * 80 * @param string $slug A site's slug. 81 * @return int|null The site ID, or null if no site is found for the given slug. 83 82 */ 84 83 function get_id_from_blogname( $slug ) { 85 global $wpdb;86 87 84 $current_site = get_current_site(); 88 85 $slug = trim( $slug, '/' ); 89 90 $blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' );91 if ( $blog_id )92 return $blog_id;93 86 94 87 if ( is_subdomain_install() ) { … … 100 93 } 101 94 102 $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) ); 103 wp_cache_set( 'get_id_from_blogname_' . $slug, $blog_id, 'blog-details' ); 104 return $blog_id; 95 $site_ids = get_sites( array( 96 'number' => 1, 97 'fields' => 'ids', 98 'domain' => $domain, 99 'path' => $path, 100 ) ); 101 102 if ( empty( $site_ids ) ) { 103 return null; 104 } 105 106 return array_shift( $site_ids ); 105 107 } 106 108 … … 454 456 wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' ); 455 457 wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' ); 456 wp_cache_delete( 'get_id_from_blogname_' . trim( $blog->path, '/' ), 'blog-details' );457 458 wp_cache_delete( $domain_path_key, 'blog-id-cache' ); 458 459 -
trunk/tests/phpunit/tests/multisite/site.php
r38655 r38659 88 88 $this->assertEquals( $details, wp_cache_get( $blog_id . 'short', 'blog-details' ) ); 89 89 90 // get_id_from_blogname(), see #2095091 $this->assertEquals( $blog_id, get_id_from_blogname( $details->path ) );92 $this->assertEquals( $blog_id, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) );93 94 90 // get_blogaddress_by_name() 95 91 $this->assertEquals( 'http://' . $details->domain . $details->path, get_blogaddress_by_name( trim( $details->path, '/' ) ) ); … … 139 135 wpmu_delete_blog( $blog_id, false ); 140 136 141 $this->assertEquals( false, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) );142 137 $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) ); 143 138 $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) ); … … 178 173 wpmu_delete_blog( $blog_id, true ); 179 174 180 $this->assertEquals( false, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) );181 175 $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) ); 182 176 $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) ); … … 217 211 wpmu_delete_blog( $blog_id, true ); 218 212 219 $this->assertEquals( false, wp_cache_get( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' ) );220 213 $this->assertEquals( false, wp_cache_get( $blog_id, 'blog-details' ) ); 221 214 $this->assertEquals( false, wp_cache_get( $blog_id . 'short', 'blog-details' ) );
Note: See TracChangeset
for help on using the changeset viewer.