WordPress.org

Make WordPress Core

Changeset 37653


Ignore:
Timestamp:
06/08/2016 03:02:34 AM (3 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.

Location:
trunk
Files:
3 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}
  • trunk/src/wp-includes/ms-functions.php

    r37652 r37653  
    24252425}
    24262426
    2427 
    2428 /**
    2429  * Return an array of sites for a network or networks.
    2430  *
    2431  * @since 3.7.0
    2432  *
    2433  * @global wpdb $wpdb WordPress database abstraction object.
    2434  *
    2435  * @param array $args {
    2436  *     Array of default arguments. Optional.
    2437  *
    2438  *     @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites
    2439  *                                 from all networks. Defaults to current network ID.
    2440  *     @type int       $public     Retrieve public or non-public sites. Default null, for any.
    2441  *     @type int       $archived   Retrieve archived or non-archived sites. Default null, for any.
    2442  *     @type int       $mature     Retrieve mature or non-mature sites. Default null, for any.
    2443  *     @type int       $spam       Retrieve spam or non-spam sites. Default null, for any.
    2444  *     @type int       $deleted    Retrieve deleted or non-deleted sites. Default null, for any.
    2445  *     @type int       $limit      Number of sites to limit the query to. Default 100.
    2446  *     @type int       $offset     Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
    2447  * }
    2448  * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,
    2449  *               an associative array of site data arrays, each containing the site (network) ID, blog ID,
    2450  *               site domain and path, dates registered and modified, and the language ID. Also, boolean
    2451  *               values for whether the site is public, archived, mature, spam, and/or deleted.
    2452  */
    2453 function wp_get_sites( $args = array() ) {
    2454     global $wpdb;
    2455 
    2456     if ( wp_is_large_network() )
    2457         return array();
    2458 
    2459     $defaults = array(
    2460         'network_id' => $wpdb->siteid,
    2461         'public'     => null,
    2462         'archived'   => null,
    2463         'mature'     => null,
    2464         'spam'       => null,
    2465         'deleted'    => null,
    2466         'limit'      => 100,
    2467         'offset'     => 0,
    2468     );
    2469 
    2470     $args = wp_parse_args( $args, $defaults );
    2471 
    2472     // Backwards compatibility
    2473     if( is_array( $args['network_id'] ) ){
    2474         $args['network__in'] = $args['network_id'];
    2475         $args['network_id'] = null;
    2476     }
    2477 
    2478     if( is_numeric( $args['limit'] ) ){
    2479         $args['number'] = $args['limit'];
    2480         $args['limit'] = null;
    2481     }
    2482 
    2483     // Make sure count is disabled.
    2484     $args['count'] = false;
    2485 
    2486     $_sites  = get_sites( $args );
    2487 
    2488     $results = array();
    2489 
    2490     foreach ( $_sites as $_site ) {
    2491         $results[] = (array) get_site( $_site );
    2492     }
    2493 
    2494     return $results;
    2495 }
    2496 
    24972427/**
    24982428 * Retrieves a list of reserved site on a sub-directory Multisite install.
  • trunk/tests/phpunit/tests/multisite/site.php

    r36721 r37653  
    582582     *
    583583     * @ticket 14511
     584     * @expectedDeprecated wp_get_sites
    584585     */
    585586    function test_wp_get_sites_with_default_arguments() {
     
    591592    /**
    592593     * No sites should match a query that specifies an invalid network ID.
     594     *
     595     * @expectedDeprecated wp_get_sites
    593596     */
    594597    function test_wp_get_sites_with_invalid_network_id() {
     
    598601    /**
    599602     * A network ID of null should query for all public sites on all networks.
     603     *
     604     * @expectedDeprecated wp_get_sites
    600605     */
    601606    function test_wp_get_sites_with_network_id_null() {
     
    607612    /**
    608613     * Expect only sites on the specified network ID to be returned.
     614     *
     615     * @expectedDeprecated wp_get_sites
    609616     */
    610617    function test_wp_get_sites_with_specific_network_id() {
     
    616623    /**
    617624     * Expect sites from both networks if both network IDs are specified.
     625     *
     626     * @expectedDeprecated wp_get_sites
    618627     */
    619628    function test_wp_get_sites_with_multiple_network_ids() {
     
    625634    /**
    626635     * Queries for public or non public sites should work across all networks if network ID is null.
     636     *
     637     * @expectedDeprecated wp_get_sites
    627638     */
    628639    function test_wp_get_sites_with_public_meta_on_all_networks() {
     
    635646    /**
    636647     * If a network ID is specified, queries for public sites should be restricted to that network.
     648     *
     649     * @expectedDeprecated wp_get_sites
    637650     */
    638651    function test_wp_get_sites_with_public_meta_restrict_to_one_network() {
     
    645658    /**
    646659     * Test the limit and offset arguments for wp_get_sites when multiple sites are available.
     660     *
     661     * @expectedDeprecated wp_get_sites
    647662     */
    648663    function test_wp_get_sites_limit_offset() {
     
    662677    /**
    663678     * Expect 0 sites when using an offset larger than the total number of sites.
     679     *
     680     * @expectedDeprecated wp_get_sites
    664681     */
    665682    function test_wp_get_sites_offset_greater_than_available_sites() {
Note: See TracChangeset for help on using the changeset viewer.