Ticket #38175: 38175.diff
File 38175.diff, 4.0 KB (added by , 9 years ago) |
---|
-
src/wp-includes/ms-blogs.php
72 72 } 73 73 74 74 /** 75 * Given a blog's (subdomain or directory) slug, retrieve its id.75 * Retrieves a sites ID given its (subdomain or directory) slug. 76 76 * 77 77 * @since MU 78 * @since 4.7.0 Converted to use get_sites(). 78 79 * 79 * @global wpdb $wpdb WordPress database abstraction object. 80 * 81 * @param string $slug 82 * @return int A blog id 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 86 90 $blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' );91 if ( $blog_id )92 return $blog_id;93 94 87 if ( is_subdomain_install() ) { 95 88 $domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_site->domain ); 96 89 $path = $current_site->path; … … 99 92 $path = $current_site->path . $slug . '/'; 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 107 109 /** … … 453 455 wp_cache_delete( $domain_path_key, 'blog-lookup' ); 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 459 460 /** -
tests/phpunit/tests/multisite/site.php
87 87 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, '/' ) ) ); 96 92 … … 138 134 // Delete the site without forcing a table drop. 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' ) ); 144 139 $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) ); … … 177 172 // Delete the site and force a table drop. 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' ) ); 183 177 $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) ); … … 216 210 // Delete the site and force a table drop. 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' ) ); 222 215 $this->assertEquals( false, wp_cache_get( $key, 'blog-lookup' ) );