WordPress.org

Make WordPress Core

Changeset 37617


Ignore:
Timestamp:
06/01/2016 11:38:40 PM (3 years ago)
Author:
jeremyfelt
Message:

Multisite: Replace wp_get_sites() internals with get_sites()

get_sites() should be considered a replacement for wp_get_sites(). Backward compatibility is maintained in the meantime by using get_site() to populate the return data with associative arrays rather than WP_Site objects.

Props spacedmonkey, flixos90.
See #35791.

File:
1 edited

Legend:

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

    r37540 r37617  
    24482448    $args = wp_parse_args( $args, $defaults );
    24492449
    2450     $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 ";
    2451 
    2452     if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) {
    2453         $network_ids = implode( ',', wp_parse_id_list( $args['network_id'] ) );
    2454         $query .= "AND site_id IN ($network_ids) ";
    2455     }
    2456 
    2457     if ( isset( $args['public'] ) )
    2458         $query .= $wpdb->prepare( "AND public = %d ", $args['public'] );
    2459 
    2460     if ( isset( $args['archived'] ) )
    2461         $query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] );
    2462 
    2463     if ( isset( $args['mature'] ) )
    2464         $query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] );
    2465 
    2466     if ( isset( $args['spam'] ) )
    2467         $query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] );
    2468 
    2469     if ( isset( $args['deleted'] ) )
    2470         $query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] );
    2471 
    2472     if ( isset( $args['limit'] ) && $args['limit'] ) {
    2473         if ( isset( $args['offset'] ) && $args['offset'] )
    2474             $query .= $wpdb->prepare( "LIMIT %d , %d ", $args['offset'], $args['limit'] );
    2475         else
    2476             $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] );
    2477     }
    2478 
    2479     $site_results = $wpdb->get_results( $query, ARRAY_A );
    2480 
    2481     return $site_results;
     2450    // Backwards compatibility
     2451    if( is_array( $args['network_id'] ) ){
     2452        $args['network__in'] = $args['network_id'];
     2453        $args['network_id'] = null;
     2454    }
     2455
     2456    if( is_numeric( $args['limit'] ) ){
     2457        $args['number'] = $args['limit'];
     2458        $args['limit'] = null;
     2459    }
     2460
     2461    // Make sure count is disabled.
     2462    $args['count'] = false;
     2463
     2464    $_sites  = get_sites( $args );
     2465
     2466    $results = array();
     2467
     2468    foreach ( $_sites as $_site ) {
     2469        $results[] = get_site( $_site, ARRAY_A );
     2470    }
     2471
     2472    return $results;
    24822473}
    24832474
Note: See TracChangeset for help on using the changeset viewer.