Ticket #40228: 40228.improved-caching.diff
File 40228.improved-caching.diff, 1.3 KB (added by , 7 years ago) |
---|
-
src/wp-includes/ms-blogs.php
462 462 } 463 463 } 464 464 465 switch ( $field ) { 466 case 'id': 467 if ( ! is_numeric( $value ) ) { 465 if ( 'id' === $field ) { 466 if ( ! is_numeric( $value ) ) { 467 return null; 468 } 469 $site = get_site( $value ); 470 if ( $network_id && $site ) { 471 if ( $network_id != $site->network_id ) { 468 472 return null; 469 473 } 470 $args['site__in'][] = intval( $value ); 471 break; 474 } 475 476 return $site; 477 } 478 479 switch ( $field ) { 472 480 case 'slug': 473 481 $network = get_network( $network_id ); 474 482 if ( ! $network ) { … … 538 546 539 547 $args['number'] = 1; 540 548 541 $sites = get_sites( $args ); 549 if ( $field == 'url' || $field == 'domain' ) { 550 551 $value = str_replace( '', array( 'https://', 'http://' ), $value); 552 $cache_key = md5( $value ); 553 $blog = wp_cache_get( $cache_key, 'blog-lookup' ); 554 555 if ( false === $blog ) { 556 return $blog; 557 } 558 } 542 559 560 $sites = get_sites( $args ); 543 561 if ( empty( $sites ) ) { 544 return null; 562 $site = null; 563 } else { 564 $site = array_shift( $sites ); 565 } 566 if ( $field == 'url' || $field == 'domain' ) { 567 wp_cache_add( $cache_key, $site, 'blog-lookup' ); 545 568 } 546 569 547 return array_shift( $sites );570 return $site; 548 571 } 549 572 550 573 /**