From 421888d9f4bfb0f3589dfca9732d4805699ef6a1 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Sun, 26 Jun 2016 13:22:36 +0000 Subject: [PATCH] Multisite: Change `WP_Network` `id` property to an integer. For consistency and developer sanity. Props flixos90. Fixes #37050. git-svn-id: https://develop.svn.wordpress.org/trunk@37870 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-network.php | 16 +++++++++++----- tests/phpunit/tests/multisite/network.php | 11 +++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/class-wp-network.php b/src/wp-includes/class-wp-network.php index 683a98359a..3ba7fac6ce 100644 --- a/src/wp-includes/class-wp-network.php +++ b/src/wp-includes/class-wp-network.php @@ -18,6 +18,7 @@ * * @since 4.4.0 * + * @property int $id * @property int $site_id */ class WP_Network { @@ -25,13 +26,12 @@ class WP_Network { /** * Network ID. * - * A numeric string, for compatibility reasons. - * * @since 4.4.0 - * @access public - * @var string + * @since 4.6.0 Type changed from string to int. + * @access private + * @var int */ - public $id; + private $id; /** * Domain of the network. @@ -152,6 +152,8 @@ class WP_Network { */ public function __get( $key ) { switch ( $key ) { + case 'id'; + return (int) $this->id; case 'blog_id': return $this->blog_id; case 'site_id': @@ -174,6 +176,7 @@ class WP_Network { */ public function __isset( $key ) { switch ( $key ) { + case 'id': case 'blog_id': case 'site_id': return true; @@ -195,6 +198,9 @@ class WP_Network { */ public function __set( $key, $value ) { switch ( $key ) { + case 'id': + $this->id = (int) $value; + break; case 'blog_id': case 'site_id': $this->blog_id = (string) $value; diff --git a/tests/phpunit/tests/multisite/network.php b/tests/phpunit/tests/multisite/network.php index 1946da56cc..981ed90f1f 100644 --- a/tests/phpunit/tests/multisite/network.php +++ b/tests/phpunit/tests/multisite/network.php @@ -87,6 +87,17 @@ class Tests_Multisite_Network extends WP_UnitTestCase { return 3; } + /** + * @ticket 37050 + */ + function test_wp_network_object_id_property_is_int() { + $id = self::factory()->network->create(); + + $network = WP_Network::get_instance( $id ); + + $this->assertSame( (int) $id, $network->id ); + } + /** * @ticket 22917 */