Make WordPress Core

Ticket #38597: 38597.2.patch

File 38597.2.patch, 2.7 KB (added by johnjamesjacoby, 8 years ago)

Deprecate $blog_id, remove magic @property variables, and call __set() in __constructor() so data is cast correctly

  • src/wp-includes/class-wp-network.php

    diff --git src/wp-includes/class-wp-network.php src/wp-includes/class-wp-network.php
    old mode 100644
    new mode 100755
    index 5ab29c2..a776ed4
     
    1717 * ability to interact with any network of sites is required.
    1818 *
    1919 * @since 4.4.0
    20  *
    21  * @property int $id
    22  * @property int $site_id
    2320 */
    2421class WP_Network {
    2522
     
    3027         * @since 4.6.0 Converted from public to private to explicitly enable more intuitive
    3128         *              access via magic methods. As part of the access change, the type was
    3229         *              also changed from `string` to `int`.
    33          * @access private
     30         * @since 4.7.0 Converted back to public
     31         * @access public
    3432         * @var int
    3533         */
    36         private $id;
     34        public $id;
    3735
    3836        /**
    3937         * Domain of the network.
     
    5654        /**
    5755         * The ID of the network's main site.
    5856         *
    59          * Named "blog" vs. "site" for legacy reasons. A main site is mapped to
    60          * the network when the network is created.
     57         * Every network has a "main site" mapped to it when it is created.
    6158         *
    62          * A numeric string, for compatibility reasons.
    63          *
    64          * @since 4.4.0
    65          * @access private
    66          * @var string
     59         * @since 4.7.0
     60         * @access public
     61         * @var int
    6762         */
    68         private $blog_id = '0';
     63        public $site_id = 0;
    6964
    7065        /**
    7166         * Domain used to set cookies for this network.
     
    9893         * @param int $network_id The ID of the network to retrieve.
    9994         * @return WP_Network|bool The network's object if found. False if not.
    10095         */
    101         public static function get_instance( $network_id ) {
     96        public static function get_instance( $network_id = 0 ) {
    10297                global $wpdb;
    10398
    10499                $network_id = (int) $network_id;
     
    134129         */
    135130        public function __construct( $network ) {
    136131                foreach( get_object_vars( $network ) as $key => $value ) {
    137                         $this->$key = $value;
     132                        $this->__set( $key, $value );
    138133                }
    139134
    140135                $this->_set_site_name();
     
    156151                switch ( $key ) {
    157152                        case 'id';
    158153                                return (int) $this->id;
    159                         case 'blog_id':
    160                                 return $this->blog_id;
    161154                        case 'site_id':
    162                                 return (int) $this->blog_id;
     155                                return (int) $this->site_id;
     156
     157                        // Support blog_id for legacy reasons
     158                        case 'blog_id':
     159                                return (string) $this->site_id;
    163160                }
    164161
    165162                return null;
     
    179176        public function __isset( $key ) {
    180177                switch ( $key ) {
    181178                        case 'id':
    182                         case 'blog_id':
    183179                        case 'site_id':
     180
     181                        // Support blog_id for legacy reasons
     182                        case 'blog_id':
    184183                                return true;
    185184                }
    186185
     
    203202                        case 'id':
    204203                                $this->id = (int) $value;
    205204                                break;
     205
     206                        // Support blog_id for legacy reasons
    206207                        case 'blog_id':
    207208                        case 'site_id':
    208                                 $this->blog_id = (string) $value;
     209                                $this->site_id = (int) $value;
    209210                                break;
    210211                        default:
    211212                                $this->$key = $value;