]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-network.php
WordPress 4.7.1-scripts
[autoinstalls/wordpress.git] / wp-includes / class-wp-network.php
index 0ccafafd1cfeba3458a988e92bb79725907e8768..5ab29c2c58306ed1e5f49146ca2b8317736dad7f 100644 (file)
@@ -17,6 +17,9 @@
  * ability to interact with any network of sites is required.
  *
  * @since 4.4.0
+ *
+ * @property int $id
+ * @property int $site_id
  */
 class WP_Network {
 
@@ -24,10 +27,13 @@ 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.
@@ -53,18 +59,20 @@ class WP_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 = '';
 
@@ -133,6 +141,77 @@ class WP_Network {
                $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.
         *
@@ -226,7 +305,7 @@ class WP_Network {
                        $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
                         *