Make WordPress Core


Ignore:
Timestamp:
06/08/2016 04:13:04 AM (9 years ago)
Author:
jeremyfelt
Message:

Multisite: Allow access to network and site properties using current naming conventions

  • Add magic __get(), __set(), and __isset() methods to WP_Site and `WP_Network.
  • Provide (int) $network->site_id for (string) $network->blog_id
  • Provide (int) $site->id for (string) $site->blog_id
  • Provide (int) $site->network_id for (string) $site->site_id

Props flixos90, jeremyfelt.
Fixes #36717.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-network.php

    r37492 r37657  
    1818 *
    1919 * @since 4.4.0
     20 *
     21 * @property int $site_id
    2022 */
    2123class WP_Network {
     
    5961     *
    6062     * @since 4.4.0
    61      * @access public
    62      * @var string
    63      */
    64     public $blog_id = 0;
     63     * @access private
     64     * @var string
     65     */
     66    private $blog_id = 0;
    6567
    6668    /**
     
    136138        $this->_set_site_name();
    137139        $this->_set_cookie_domain();
     140    }
     141
     142    /**
     143     * Getter.
     144     *
     145     * Allows current multisite naming conventions when getting properties.
     146     *
     147     * @since 4.6.0
     148     * @access public
     149     *
     150     * @param string $key Property to get.
     151     * @return mixed Value of the property. Null if not available.
     152     */
     153    public function __get( $key ) {
     154        switch ( $key ) {
     155            case 'blog_id':
     156                return $this->blog_id;
     157            case 'site_id':
     158                return (int) $this->blog_id;
     159        }
     160
     161        return null;
     162    }
     163
     164    /**
     165     * Isset-er.
     166     *
     167     * Allows current multisite naming conventions when checking for properties.
     168     *
     169     * @since 4.6.0
     170     * @access public
     171     *
     172     * @param string $key Property to check if set.
     173     * @return bool Whether the property is set.
     174     */
     175    public function __isset( $key ) {
     176        switch( $key ) {
     177            case 'blog_id':
     178            case 'site_id':
     179                return true;
     180        }
     181
     182        return false;
     183    }
     184
     185    /**
     186     * Setter.
     187     *
     188     * Allows current multisite naming conventions while setting properties.
     189     *
     190     * @since 4.6.0
     191     * @access public
     192     *
     193     * @param string $key   Property to set.
     194     * @param mixed  $value Value to assign to the property.
     195     */
     196    public function __set( $key, $value ) {
     197        switch( $key ) {
     198            case 'blog_id':
     199            case 'site_id':
     200                $this->blog_id = (string) $value;
     201                break;
     202            default:
     203                $this->$key = $value;
     204        }
    138205    }
    139206
Note: See TracChangeset for help on using the changeset viewer.