Ticket #42073: 42073.2.diff
File 42073.2.diff, 2.8 KB (added by , 7 years ago) |
---|
-
src/wp-includes/ms-functions.php
331 331 function get_blog_id_from_url( $domain, $path = '/' ) { 332 332 $domain = strtolower( $domain ); 333 333 $path = strtolower( $path ); 334 $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );335 334 336 if ( $id == -1 ) // blog does not exist 337 return 0; 338 elseif ( $id ) 339 return (int) $id; 340 341 $args = array( 342 'domain' => $domain, 343 'path' => $path, 344 'fields' => 'ids', 345 ); 346 $result = get_sites( $args ); 347 $id = array_shift( $result ); 335 $url = $domain . '/' . trim( $path, '/' ) . '/'; 336 $result = get_site_by( 'url', $url ); 348 337 349 if ( ! $id ) { 350 wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' ); 338 if ( ! $result ) { 351 339 return 0; 352 340 } 353 341 354 wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' ); 355 356 return $id; 342 return $result->id; 357 343 } 358 344 359 345 // Admin functions -
tests/phpunit/tests/multisite/site.php
667 667 668 668 // Test the original response and cached response for the newly created site. 669 669 $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) ); 670 $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );671 670 } 672 671 673 672 /** … … 688 687 $details = get_site( $blog_id ); 689 688 690 689 $this->assertEquals( 0, get_blog_id_from_url( $details->domain, 'foo' ) ); 691 $this->assertEquals( -1, wp_cache_get( md5( $details->domain . 'foo' ), 'blog-id-cache' ) );692 690 } 693 691 694 692 /** … … 698 696 function test_get_blog_id_from_url_with_deleted_flag() { 699 697 $blog_id = self::factory()->blog->create(); 700 698 $details = get_site( $blog_id ); 701 $key = md5( $details->domain . $details->path ); 699 702 700 wpmu_delete_blog( $blog_id ); 703 701 704 702 $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) ); 705 $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) );706 }707 708 /**709 * When deleted with the drop parameter as true, the cache will first be false, then set to710 * -1 after an attempt at `get_blog_id_from_url()` is made.711 */712 function test_get_blog_id_from_url_after_dropped() {713 $blog_id = self::factory()->blog->create();714 $details = get_site( $blog_id );715 $key = md5( $details->domain . $details->path );716 wpmu_delete_blog( $blog_id, true );717 718 $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) );719 $this->assertEquals( 0, get_blog_id_from_url( $details->domain, $details->path ) );720 $this->assertEquals( -1, wp_cache_get( $key, 'blog-id-cache' ) );721 703 } 722 704 723 705 /**