From caf0e9a151cc113f4d365edab8989e67edf3b6a0 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Wed, 1 Jun 2016 23:38:40 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@37617 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-functions.php | 45 +++++++++++++------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index 2e17efe5f3..84a4063488 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -2447,38 +2447,29 @@ function wp_get_sites( $args = array() ) { $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 = implode( ',', wp_parse_id_list( $args['network_id'] ) ); - $query .= "AND site_id IN ($network_ids) "; + // Backwards compatibility + if( is_array( $args['network_id'] ) ){ + $args['network__in'] = $args['network_id']; + $args['network_id'] = null; } - 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'] ) && $args['limit'] ) { - if ( isset( $args['offset'] ) && $args['offset'] ) - $query .= $wpdb->prepare( "LIMIT %d , %d ", $args['offset'], $args['limit'] ); - else - $query .= $wpdb->prepare( "LIMIT %d ", $args['limit'] ); + if( is_numeric( $args['limit'] ) ){ + $args['number'] = $args['limit']; + $args['limit'] = null; } - $site_results = $wpdb->get_results( $query, ARRAY_A ); + // Make sure count is disabled. + $args['count'] = false; - return $site_results; + $_sites = get_sites( $args ); + + $results = array(); + + foreach ( $_sites as $_site ) { + $results[] = get_site( $_site, ARRAY_A ); + } + + return $results; } /**