Make WordPress Core

Changeset 37620


Ignore:
Timestamp:
06/02/2016 02:25:56 AM (8 years ago)
Author:
jeremyfelt
Message:

Multisite: Replace $wpdb->blog queries in ms-functions.php with get_sites()

get_sites() is now used in:

  • domain_exists()
  • wp_update_network_site_counts()
  • get_blog_id_from_url()

Props spacedmonkey, jeremyfelt.
See #35791.

File:
1 edited

Legend:

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

    r37618 r37620  
    297297 *
    298298 * @since MU 2.6.5
     299 * @since 4.6.0 Converted to use get_sites()
    299300 *
    300301 * @global wpdb $wpdb WordPress database abstraction object.
     
    305306 */
    306307function get_blog_id_from_url( $domain, $path = '/' ) {
    307     global $wpdb;
    308 
    309308    $domain = strtolower( $domain );
    310309    $path = strtolower( $path );
     
    316315        return (int) $id;
    317316
    318     $id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) );
     317    $args = array(
     318        'domain' => $domain,
     319        'path' => $path,
     320        'fields' => 'ids',
     321    );
     322    $result = get_sites( $args );
     323    $id = array_shift( $result );
    319324
    320325    if ( ! $id ) {
     
    12481253 *
    12491254 * @since MU
     1255 * @since 4.6.0 Converted to use get_sites()
    12501256 *
    12511257 * @global wpdb $wpdb WordPress database abstraction object.
     
    12571263 */
    12581264function domain_exists($domain, $path, $site_id = 1) {
    1259     global $wpdb;
    12601265    $path = trailingslashit( $path );
    1261     $result = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) );
     1266    $args = array(
     1267        'network_id' => $site_id,
     1268        'domain' => $domain,
     1269        'path' => $path,
     1270        'fields' => 'ids',
     1271    );
     1272    $result = get_sites( $args );
     1273    $result = array_shift( $result );
    12621274
    12631275    /**
     
    22482260 *
    22492261 * @since 3.7.0
     2262 * @since 4.6.0 Converted to use get_sites()
    22502263 *
    22512264 * @global wpdb $wpdb WordPress database abstraction object.
     
    22542267    global $wpdb;
    22552268
    2256     $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) );
     2269    $count = get_sites( array(
     2270        'network_id' => $wpdb->siteid,
     2271        'spam'       => 0,
     2272        'deleted'    => 0,
     2273        'archived'   => 0,
     2274        'count'      => true,
     2275    ) );
     2276
    22572277    update_site_option( 'blog_count', $count );
    22582278}
Note: See TracChangeset for help on using the changeset viewer.