Introduce wp_get_sites(), a long-awaited replacement for get_blog_list().

props jeremyfelt.
see #14511.

Built from https://develop.svn.wordpress.org/trunk@25445


git-svn-id: http://core.svn.wordpress.org/trunk@25366 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2013-09-14 21:13:10 +00:00
parent 031576d79e
commit efdaf1e915
2 changed files with 73 additions and 1 deletions

View File

@ -161,7 +161,7 @@ function validate_email( $email, $check_domain = true) {
* @deprecated No alternative available. For performance reasons this function is not recommended.
*/
function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) {
_deprecated_function( __FUNCTION__, '3.0' );
_deprecated_function( __FUNCTION__, '3.0', 'wp_get_sites()' );
global $wpdb;
$blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A );

View File

@ -1987,3 +1987,75 @@ function wp_is_large_network( $using = 'sites' ) {
$count = get_blog_count();
return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );
}
/**
* Return an array of sites for a network.
*
* @see wp_is_large_network() Returns an empty array if the install is considered large.
*
* @since 3.7.0
*
* @param array $args {
* Array of arguments. Optional.
*
* @type int|array 'network_id' A network ID or array of network IDs. Set to null to retrieve sites
* from all networks. Defaults to current network ID.
* @type int 'public' Retrieve public or non-public sites. Default null, for any.
* @type int 'archived' Retrieve archived or non-archived sites. Default null, for any.
* @type int 'mature' Retrieve mature or non-mature sites. Default null, for any.
* @type int 'spam' Retrieve spam or non-spam sites. Default null, for any.
* @type int 'deleted' Retrieve deleted or non-deleted sites. Default null, for any.
* @type int 'limit' Number of sites to limit the query to. Default 100.
* }
*
* @return array An array of site data
*/
function wp_get_sites( $args = array() ) {
global $wpdb;
if ( wp_is_large_network() )
return array();
$defaults = array(
'network_id' => $wpdb->siteid,
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => 100,
);
$args = wp_parse_args( $args, $defaults );
$query = "SELECT * FROM $wpdb->blogs WHERE 1=1 ";
if ( isset( $args['network_id'] ) && ( is_array( $args['network_id'] ) || is_numeric( $args['network_id'] ) ) ) {
$network_ids = array_map('intval', (array) $args['network_id'] );
$network_ids = implode( ',', $network_ids );
$query .= "AND site_id IN ($network_ids) ";
}
if ( isset( $args['public'] ) )
$query .= $wpdb->prepare( "AND public = %d ", $args['public'] );
if ( isset( $args['archived'] ) )
$query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] );
if ( isset( $args['mature'] ) )
$query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] );
if ( isset( $args['spam'] ) )
$query .= $wpdb->prepare( "AND spam = %d ", $args['spam'] );
if ( isset( $args['deleted'] ) )
$query .= $wpdb->prepare( "AND deleted = %d ", $args['deleted'] );
if ( isset( $args['limit'] ) )
$query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] );
$site_results = $wpdb->get_results( $query, ARRAY_A );
return $site_results;
}