WordPress.org

Make WordPress Core

Changeset 37667


Ignore:
Timestamp:
06/09/2016 06:09:25 PM (3 years ago)
Author:
jeremyfelt
Message:

Multisite: Use to_array() method on WP_Site objects in wp_get_sites()

When an object with private properties is cast directly to an array, those properties are no longer available with their original keys.

Props @flixos90.
See #36717.

Location:
trunk
Files:
2 edited

Legend:

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

    r37653 r37667  
    507507
    508508    foreach ( $_sites as $_site ) {
    509         $results[] = (array) get_site( $_site );
     509        $_site = get_site( $_site );
     510        $results[] = $_site->to_array();
    510511    }
    511512
  • trunk/tests/phpunit/tests/multisite/wpGetSites.php

    r37662 r37667  
    44
    55/**
     6 * @group wp-get-site
    67 * @group ms-site
    78 * @group multisite
     
    3031
    3132        wp_update_network_site_counts();
     33    }
     34
     35    /**
     36     * @expectedDeprecated wp_get_sites
     37     */
     38    public function test_wp_get_sites_site_is_expected_array() {
     39
     40        $keys = array(
     41            'blog_id',
     42            'site_id',
     43            'domain',
     44            'path',
     45            'registered',
     46            'last_updated',
     47            'public',
     48            'archived',
     49            'mature',
     50            'spam',
     51            'deleted',
     52            'lang_id'
     53        );
     54        $sites = wp_get_sites();
     55
     56        $missing_keys = array_diff_key( array_flip( $keys ), $sites[0] );
     57
     58        $this->assertEquals( array(), $missing_keys, 'Keys are missing from site arrays.' );
    3259    }
    3360
Note: See TracChangeset for help on using the changeset viewer.