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
This commit is contained in:
Jeremy Felt 2016-06-26 13:22:36 +00:00
parent eb2ce329f1
commit 421888d9f4
2 changed files with 22 additions and 5 deletions

View File

@ -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;

View File

@ -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
*/