Make WordPress Core


Ignore:
Timestamp:
09/24/2012 07:31:37 PM (12 years ago)
Author:
ryan
Message:
  • 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/ms-blogs.php

    r21595 r21979  
    8585
    8686/**
    87  * Given a blog's (subdomain or directory) name, retrieve it's id.
    88  *
    89  * @since MU
    90  *
    91  * @param string $name
     87 * Given a blog's (subdomain or directory) slug, retrieve it's id.
     88 *
     89 * @since MU
     90 *
     91 * @param string $slug
    9292 * @return int A blog id
    9393 */
    94 function get_id_from_blogname( $name ) {
     94function get_id_from_blogname( $slug ) {
    9595    global $wpdb, $current_site;
    96     $blog_id = wp_cache_get( 'get_id_from_blogname_' . $name, 'blog-details' );
     96
     97    $slug = trim( $slug, '/' );
     98
     99    $blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' );
    97100    if ( $blog_id )
    98101        return $blog_id;
    99102
    100103    if ( is_subdomain_install() ) {
    101         $domain = $name . '.' . $current_site->domain;
     104        $domain = $slug . '.' . $current_site->domain;
    102105        $path = $current_site->path;
    103106    } else {
    104107        $domain = $current_site->domain;
    105         $path = $current_site->path . $name . '/';
    106     }
     108        $path = $current_site->path . $slug . '/';
     109    }
     110
    107111    $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) );
    108     wp_cache_set( 'get_id_from_blogname_' . $name, $blog_id, 'blog-details' );
     112    wp_cache_set( 'get_id_from_blogname_' . $slug, $blog_id, 'blog-details' );
    109113    return $blog_id;
    110114}
     
    115119 * @since MU
    116120 *
    117  * @param int|string|array $fields A blog ID, a blog name, or an array of fields to query against.
     121 * @param int|string|array $fields A blog ID, a blog slug, or an array of fields to query against.
    118122 * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
    119123 * @return object Blog details.
     
    255259    wp_cache_delete( 'current_blog_' . $details->domain, 'site-options' );
    256260    wp_cache_delete( 'current_blog_' . $details->domain . $details->path, 'site-options' );
     261    wp_cache_delete( 'get_id_from_blogname_' . trim( $details->path, '/' ), 'blog-details' );
    257262
    258263    do_action( 'refresh_blog_details', $blog_id );
Note: See TracChangeset for help on using the changeset viewer.