WordPress.org

Make WordPress Core

Ticket #31148: 31148.diff

File 31148.diff, 5.6 KB (added by earnjam, 7 years ago)

Add support for domain, path and bypassing the wp_is_large_network check

  • wp-includes/ms-functions.php

     
    23642364 * @param array $args {
    23652365 *     Array of default arguments. Optional.
    23662366 *
    2367  *     @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites
    2368  *                                 from all networks. Defaults to current network ID.
    2369  *     @type int       $public     Retrieve public or non-public sites. Default null, for any.
    2370  *     @type int       $archived   Retrieve archived or non-archived sites. Default null, for any.
    2371  *     @type int       $mature     Retrieve mature or non-mature sites. Default null, for any.
    2372  *     @type int       $spam       Retrieve spam or non-spam sites. Default null, for any.
    2373  *     @type int       $deleted    Retrieve deleted or non-deleted sites. Default null, for any.
    2374  *     @type int       $limit      Number of sites to limit the query to. Default 100.
    2375  *     @type int       $offset     Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
     2367 *     @type bool      $large_networks Allow searches for sites on large networks. Default false.
     2368 *     @type int|array $network_id     A network ID or array of network IDs. Set to null to retrieve sites
     2369 *                                     from all networks. Defaults to current network ID.
     2370 *     @type string    $domain         Retrieve sites with a specific domain. Default null, for any.
     2371 *     @type string    $path           Retrieve sites with a specific path. Default null, for any.
     2372 *     @type int       $public         Retrieve public or non-public sites. Default null, for any.
     2373 *     @type int       $archived       Retrieve archived or non-archived sites. Default null, for any.
     2374 *     @type int       $mature         Retrieve mature or non-mature sites. Default null, for any.
     2375 *     @type int       $spam           Retrieve spam or non-spam sites. Default null, for any.
     2376 *     @type int       $deleted        Retrieve deleted or non-deleted sites. Default null, for any.
     2377 *     @type int       $limit          Number of sites to limit the query to. Default 100.
     2378 *     @type int       $offset         Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
    23762379 * }
    2377  * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,
    2378  *               an associative array of site data arrays, each containing the site (network) ID, blog ID,
    2379  *               site domain and path, dates registered and modified, and the language ID. Also, boolean
    2380  *               values for whether the site is public, archived, mature, spam, and/or deleted.
     2380 * @return array An empty array if the install is considered "large" via wp_is_large_network() and the large_network
     2381 *               argument is set to false. Otherwise, an associative array of site data arrays, each containing the
     2382 *               site (network) ID, blog ID, site domain and path, dates registered and modified, and the language ID.
     2383 *               Also, boolean values for whether the site is public, archived, mature, spam, and/or deleted.
    23812384 */
    23822385function wp_get_sites( $args = array() ) {
    23832386        global $wpdb;
    23842387
    2385         if ( wp_is_large_network() )
    2386                 return array();
    2387 
    23882388        $defaults = array(
    2389                 'network_id' => $wpdb->siteid,
    2390                 'public'     => null,
    2391                 'archived'   => null,
    2392                 'mature'     => null,
    2393                 'spam'       => null,
    2394                 'deleted'    => null,
    2395                 'limit'      => 100,
    2396                 'offset'     => 0,
     2389                'large_networks' => false,
     2390                'network_id'     => $wpdb->siteid,
     2391                'domain'         => null,
     2392                'path'           => null,
     2393                'public'         => null,
     2394                'archived'       => null,
     2395                'mature'         => null,
     2396                'spam'           => null,
     2397                'deleted'        => null,
     2398                'limit'          => 100,
     2399                'offset'         => 0,
    23972400        );
    23982401
    23992402        $args = wp_parse_args( $args, $defaults );
    24002403
     2404        if ( ! $args['large_networks'] && wp_is_large_network() ) {
     2405                return array();
     2406        }
     2407
    24012408        $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 ";
    24022409
    24032410        if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) {
     
    24052412                $query .= "AND site_id IN ($network_ids) ";
    24062413        }
    24072414
    2408         if ( isset( $args['public'] ) )
     2415        if ( isset( $args['domain'] ) ) {
     2416                $query .= $wpdb->prepare( "AND domain = %s ", $args['domain'] );
     2417        }
     2418
     2419        if ( isset( $args['path'] ) ) {
     2420                $query .= $wpdb->prepare( "AND path = %s ", $args['path'] );
     2421        }
     2422
     2423        if ( isset( $args['public'] ) ) {
    24092424                $query .= $wpdb->prepare( "AND public = %d ", $args['public'] );
     2425        }
    24102426
    2411         if ( isset( $args['archived'] ) )
     2427        if ( isset( $args['archived'] ) ) {
    24122428                $query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] );
     2429        }
    24132430
    2414         if ( isset( $args['mature'] ) )
     2431        if ( isset( $args['mature'] ) ) {
    24152432                $query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] );
     2433        }
    24162434
    2417         if ( isset( $args['spam'] ) )
     2435        if ( isset( $args['spam'] ) ) {
    24182436                $query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] );
     2437        }
    24192438
    2420         if ( isset( $args['deleted'] ) )
     2439        if ( isset( $args['deleted'] ) ) {
    24212440                $query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] );
     2441        }
    24222442
    24232443        if ( isset( $args['limit'] ) && $args['limit'] ) {
    2424                 if ( isset( $args['offset'] ) && $args['offset'] )
     2444                if ( isset( $args['offset'] ) && $args['offset'] ) {
    24252445                        $query .= $wpdb->prepare( "LIMIT %d , %d ", $args['offset'], $args['limit'] );
    2426                 else
     2446                } else {
    24272447                        $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] );
     2448                }
    24282449        }
    24292450
    24302451        $site_results = $wpdb->get_results( $query, ARRAY_A );