Make WordPress Core


Ignore:
Timestamp:
06/08/2016 03:02:34 AM (9 years ago)
Author:
jeremyfelt
Message:

Multisite: Deprecate wp_get_sites()

Defer to the new get_sites() replacement, offering fresh (...or cached) WP_Site objects via the new WP_Site_Query.

Props flixos90.
Fixes #36994.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-deprecated.php

    r36725 r37653  
    439439    return false;
    440440}
     441
     442/**
     443 * Return an array of sites for a network or networks.
     444 *
     445 * @since 3.7.0
     446 * @deprecated 4.6.0
     447 * @see get_sites()
     448 *
     449 * @global wpdb $wpdb WordPress database abstraction object.
     450 *
     451 * @param array $args {
     452 *     Array of default arguments. Optional.
     453 *
     454 *     @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites
     455 *                                 from all networks. Defaults to current network ID.
     456 *     @type int       $public     Retrieve public or non-public sites. Default null, for any.
     457 *     @type int       $archived   Retrieve archived or non-archived sites. Default null, for any.
     458 *     @type int       $mature     Retrieve mature or non-mature sites. Default null, for any.
     459 *     @type int       $spam       Retrieve spam or non-spam sites. Default null, for any.
     460 *     @type int       $deleted    Retrieve deleted or non-deleted sites. Default null, for any.
     461 *     @type int       $limit      Number of sites to limit the query to. Default 100.
     462 *     @type int       $offset     Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
     463 * }
     464 * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,
     465 *               an associative array of site data arrays, each containing the site (network) ID, blog ID,
     466 *               site domain and path, dates registered and modified, and the language ID. Also, boolean
     467 *               values for whether the site is public, archived, mature, spam, and/or deleted.
     468 */
     469function wp_get_sites( $args = array() ) {
     470    global $wpdb;
     471
     472    _deprecated_function( __FUNCTION__, '4.6', 'get_sites()' );
     473
     474    if ( wp_is_large_network() )
     475        return array();
     476
     477    $defaults = array(
     478        'network_id' => $wpdb->siteid,
     479        'public'     => null,
     480        'archived'   => null,
     481        'mature'     => null,
     482        'spam'       => null,
     483        'deleted'    => null,
     484        'limit'      => 100,
     485        'offset'     => 0,
     486    );
     487
     488    $args = wp_parse_args( $args, $defaults );
     489
     490    // Backwards compatibility
     491    if( is_array( $args['network_id'] ) ){
     492        $args['network__in'] = $args['network_id'];
     493        $args['network_id'] = null;
     494    }
     495
     496    if( is_numeric( $args['limit'] ) ){
     497        $args['number'] = $args['limit'];
     498        $args['limit'] = null;
     499    }
     500
     501    // Make sure count is disabled.
     502    $args['count'] = false;
     503
     504    $_sites  = get_sites( $args );
     505
     506    $results = array();
     507
     508    foreach ( $_sites as $_site ) {
     509        $results[] = (array) get_site( $_site );
     510    }
     511
     512    return $results;
     513}
Note: See TracChangeset for help on using the changeset viewer.