WordPress.org

Make WordPress Core

Ticket #14511: 14511.4.diff

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

     
    19861986        $count = get_blog_count();
    19871987        return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );
    19881988}
     1989
     1990/**
     1991 * Return an array of sites on the specified network. If no network is specified,
     1992 * return all sites, regardless of network.
     1993 *
     1994 * @since 3.7.0
     1995 *
     1996 * @param array $args (optional) An array of arguments to modify the query {
     1997 *     @type int|array 'network_id' A network ID or array of network IDs
     1998 *     @type int       'limit'      Number of sites to limit the query to
     1999 * }
     2000 *
     2001 * @return array An array of site data
     2002 */
     2003function wp_get_sites( $args = array() ) {
     2004        global $wpdb;
     2005
     2006        if ( wp_is_large_network() )
     2007                return;
     2008
     2009        $defaults = array(
     2010                'network_id' => null,
     2011                'limit'      => 100,
     2012        );
     2013
     2014        $args = wp_parse_args( $args, $defaults );
     2015
     2016        $query = "SELECT * FROM $wpdb->blogs WHERE 1=1 ";
     2017
     2018        if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) {
     2019                $network_ids = array_map('intval', (array) $args['network_id'] );
     2020                $network_ids = implode( ',', $network_ids );
     2021                $query .= "AND site_id IN ($network_ids) ";
     2022        }
     2023
     2024        if ( isset( $args['public'] ) )
     2025                $query .= $wpdb->prepare( "AND public = %d ", $args['public'] );
     2026
     2027        if ( isset( $args['archived'] ) )
     2028                $query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] );
     2029
     2030        if ( isset( $args['mature'] ) )
     2031                $query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] );
     2032
     2033        if ( isset( $args['spam'] ) )
     2034                $query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] );
     2035
     2036        if ( isset( $args['deleted'] ) )
     2037                $query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] );
     2038
     2039        if ( isset( $args['limit'] ) )
     2040                $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] );
     2041
     2042        $site_results = (array) $wpdb->get_results( $query );
     2043
     2044        return $site_results;
     2045}