WordPress.org

Make WordPress Core

Ticket #14511: 14511.2.diff

File 14511.2.diff, 1.8 KB (added by jeremyfelt, 7 years ago)
  • src/wp-includes/ms-functions.php

     
    19831983        $count = get_blog_count();
    19841984        return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );
    19851985}
     1986
     1987/**
     1988 * Return an array of sites on the specified network. If no network is specified,
     1989 * return all sites, regardless of network.
     1990 *
     1991 * @since 3.7.0
     1992 *
     1993 * @param array|string $args Optional. Specify the status of the sites to return.
     1994 * @return array An array of site data
     1995 */
     1996function wp_get_sites( $args = array() ) {
     1997        global $wpdb;
     1998
     1999        if ( wp_is_large_network() )
     2000                return;
     2001
     2002        $defaults = array( 'network_id' => null );
     2003
     2004        $args = wp_parse_args( $args, $defaults );
     2005
     2006        $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 ";
     2007
     2008        if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) {
     2009                $network_ids = array_map('intval', (array) $args['network_id'] );
     2010                $network_ids = implode( ',', $network_ids );
     2011                $query .= "AND site_id IN ($network_ids) ";
     2012        }
     2013
     2014        if ( isset( $args['public'] ) )
     2015                $query .= $wpdb->prepare( "AND public = %s ", $args['public'] );
     2016
     2017        if ( isset( $args['archived'] ) )
     2018                $query .= $wpdb->prepare( "AND archived = %s ", $args['archived'] );
     2019
     2020        if ( isset( $args['mature'] ) )
     2021                $query .= $wpdb->prepare( "AND mature = %s ", $args['mature'] );
     2022
     2023        if ( isset( $args['spam'] ) )
     2024                $query .= $wpdb->prepare( "AND spam = %s ", $args['spam'] );
     2025
     2026        if ( isset( $args['deleted'] ) )
     2027                $query .= $wpdb->prepare( "AND deleted = %s ", $args['deleted'] );
     2028
     2029        $site_results = $wpdb->get_results( $query );
     2030
     2031        $sites = Array();
     2032
     2033        foreach ( $site_results as $site ) {
     2034                $sites[ $site->blog_id ] = $site;
     2035        }
     2036
     2037        return $sites;
     2038}