WordPress.org

Make WordPress Core

Changeset 41743


Ignore:
Timestamp:
10/04/2017 06:44:36 PM (23 months ago)
Author:
jeremyfelt
Message:

Multisite: Use get_site_by() in get_id_from_blogname().

Fixes #42091.

File:
1 edited

Legend:

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

    r41719 r41743  
    7171
    7272/**
    73  * Retrieves a sites ID given its (subdomain or directory) slug.
     73 * Retrieves a site's ID given its (subdomain or directory) slug.
    7474 *
    7575 * @since MU (3.0.0)
    7676 * @since 4.7.0 Converted to use get_sites().
     77 * @since 4.9.0 Converted to use get_site_by().
    7778 *
    7879 * @param string $slug A site's slug.
     
    8081 */
    8182function get_id_from_blogname( $slug ) {
    82     $current_network = get_network();
    83     $slug = trim( $slug, '/' );
    84 
    85     if ( is_subdomain_install() ) {
    86         $domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_network->domain );
    87         $path = $current_network->path;
    88     } else {
    89         $domain = $current_network->domain;
    90         $path = $current_network->path . $slug . '/';
    91     }
    92 
    93     $site_ids = get_sites( array(
    94         'number' => 1,
    95         'fields' => 'ids',
    96         'domain' => $domain,
    97         'path' => $path,
    98     ) );
    99 
    100     if ( empty( $site_ids ) ) {
     83    $result = get_site_by( 'slug', $slug );
     84
     85    if ( ! $result ) {
    10186        return null;
    10287    }
    10388
    104     return array_shift( $site_ids );
     89    return $result->id;
    10590}
    10691
Note: See TracChangeset for help on using the changeset viewer.