From 363533d9b3a5a0c8cef174775c0358b6652ac2dd Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Thu, 9 Jun 2016 18:09:25 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@37667 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-deprecated.php | 3 ++- tests/phpunit/tests/multisite/wpGetSites.php | 27 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/ms-deprecated.php b/src/wp-includes/ms-deprecated.php index f45896ed4f..998f04ad81 100644 --- a/src/wp-includes/ms-deprecated.php +++ b/src/wp-includes/ms-deprecated.php @@ -506,7 +506,8 @@ function wp_get_sites( $args = array() ) { $results = array(); foreach ( $_sites as $_site ) { - $results[] = (array) get_site( $_site ); + $_site = get_site( $_site ); + $results[] = $_site->to_array(); } return $results; diff --git a/tests/phpunit/tests/multisite/wpGetSites.php b/tests/phpunit/tests/multisite/wpGetSites.php index a6ec37fb94..f15c073ffd 100644 --- a/tests/phpunit/tests/multisite/wpGetSites.php +++ b/tests/phpunit/tests/multisite/wpGetSites.php @@ -3,6 +3,7 @@ if ( is_multisite() ) : /** + * @group wp-get-site * @group ms-site * @group multisite */ @@ -31,6 +32,32 @@ class Tests_Multisite_WP_Get_Sites extends WP_UnitTestCase { wp_update_network_site_counts(); } + /** + * @expectedDeprecated wp_get_sites + */ + public function test_wp_get_sites_site_is_expected_array() { + + $keys = array( + 'blog_id', + 'site_id', + 'domain', + 'path', + 'registered', + 'last_updated', + 'public', + 'archived', + 'mature', + 'spam', + 'deleted', + 'lang_id' + ); + $sites = wp_get_sites(); + + $missing_keys = array_diff_key( array_flip( $keys ), $sites[0] ); + + $this->assertEquals( array(), $missing_keys, 'Keys are missing from site arrays.' ); + } + /** * @expectedDeprecated wp_get_sites * @dataProvider data_wp_get_sites