* ability to interact with any network of sites is required.
*
* @since 4.4.0
+ *
+ * @property int $id
+ * @property int $site_id
*/
class WP_Network {
* Network ID.
*
* @since 4.4.0
- * @access public
+ * @since 4.6.0 Converted from public to private to explicitly enable more intuitive
+ * access via magic methods. As part of the access change, the type was
+ * also changed from `string` to `int`.
+ * @access private
* @var int
*/
- public $id;
+ private $id;
/**
* Domain of the network.
* Named "blog" vs. "site" for legacy reasons. A main site is mapped to
* the network when the network is created.
*
+ * A numeric string, for compatibility reasons.
+ *
* @since 4.4.0
- * @access public
- * @var int
+ * @access private
+ * @var string
*/
- public $blog_id = 0;
+ private $blog_id = '0';
/**
* Domain used to set cookies for this network.
*
* @since 4.4.0
* @access public
- * @var int
+ * @var string
*/
public $cookie_domain = '';
$this->_set_cookie_domain();
}
+ /**
+ * Getter.
+ *
+ * Allows current multisite naming conventions when getting properties.
+ *
+ * @since 4.6.0
+ * @access public
+ *
+ * @param string $key Property to get.
+ * @return mixed Value of the property. Null if not available.
+ */
+ public function __get( $key ) {
+ switch ( $key ) {
+ case 'id';
+ return (int) $this->id;
+ case 'blog_id':
+ return $this->blog_id;
+ case 'site_id':
+ return (int) $this->blog_id;
+ }
+
+ return null;
+ }
+
+ /**
+ * Isset-er.
+ *
+ * Allows current multisite naming conventions when checking for properties.
+ *
+ * @since 4.6.0
+ * @access public
+ *
+ * @param string $key Property to check if set.
+ * @return bool Whether the property is set.
+ */
+ public function __isset( $key ) {
+ switch ( $key ) {
+ case 'id':
+ case 'blog_id':
+ case 'site_id':
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Setter.
+ *
+ * Allows current multisite naming conventions while setting properties.
+ *
+ * @since 4.6.0
+ * @access public
+ *
+ * @param string $key Property to set.
+ * @param mixed $value Value to assign to the property.
+ */
+ 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;
+ break;
+ default:
+ $this->$key = $value;
+ }
+ }
+
/**
* Set the site name assigned to the network if one has not been populated.
*
$path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );
/**
- * Filter the number of path segments to consider when searching for a site.
+ * Filters the number of path segments to consider when searching for a site.
*
* @since 3.9.0
*