]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/class-wp-site.php
WordPress 4.5.2-scripts
[autoinstalls/wordpress.git] / wp-includes / class-wp-site.php
1 <?php
2 /**
3  * Site API: WP_Site class
4  *
5  * @package WordPress
6  * @subpackage Multisite
7  * @since 4.5.0
8  */
9
10 /**
11  * Core class used for interacting with a multisite site.
12  *
13  * This class is used during load to populate the `$current_blog` global and
14  * setup the current site.
15  *
16  * @since 4.5.0
17  */
18 final class WP_Site {
19
20         /**
21          * Site ID.
22          *
23          * A numeric string, for compatibility reasons.
24          *
25          * @since 4.5.0
26          * @access public
27          * @var string
28          */
29         public $blog_id;
30
31         /**
32          * Domain of the site.
33          *
34          * @since 4.5.0
35          * @access public
36          * @var string
37          */
38         public $domain = '';
39
40         /**
41          * Path of the site.
42          *
43          * @since 4.5.0
44          * @access public
45          * @var string
46          */
47         public $path = '';
48
49         /**
50          * The ID of the site's parent network.
51          *
52          * Named "site" vs. "network" for legacy reasons. An individual site's "site" is
53          * its network.
54          *
55          * A numeric string, for compatibility reasons.
56          *
57          * @since 4.5.0
58          * @access public
59          * @var string
60          */
61         public $site_id = '0';
62
63         /**
64          * The date on which the site was created or registered.
65          *
66          * @since 4.5.0
67          * @access public
68          * @var string Date in MySQL's datetime format.
69          */
70         public $registered = '0000-00-00 00:00:00';
71
72         /**
73          * The date and time on which site settings were last updated.
74          *
75          * @since 4.5.0
76          * @access public
77          * @var string Date in MySQL's datetime format.
78          */
79         public $last_updated = '0000-00-00 00:00:00';
80
81         /**
82          * Whether the site should be treated as public.
83          *
84          * A numeric string, for compatibility reasons.
85          *
86          * @since 4.5.0
87          * @access public
88          * @var string
89          */
90         public $public = '1';
91
92         /**
93          * Whether the site should be treated as archived.
94          *
95          * A numeric string, for compatibility reasons.
96          *
97          * @since 4.5.0
98          * @access public
99          * @var string
100          */
101         public $archived = '0';
102
103         /**
104          * Whether the site should be treated as mature.
105          *
106          * Handling for this does not exist throughout WordPress core, but custom
107          * implementations exist that require the property to be present.
108          *
109          * A numeric string, for compatibility reasons.
110          *
111          * @since 4.5.0
112          * @access public
113          * @var string
114          */
115         public $mature = '0';
116
117         /**
118          * Whether the site should be treated as spam.
119          *
120          * A numeric string, for compatibility reasons.
121          *
122          * @since 4.5.0
123          * @access public
124          * @var string
125          */
126         public $spam = '0';
127
128         /**
129          * Whether the site should be treated as deleted.
130          *
131          * A numeric string, for compatibility reasons.
132          *
133          * @since 4.5.0
134          * @access public
135          * @var string
136          */
137         public $deleted = '0';
138
139         /**
140          * The language pack associated with this site.
141          *
142          * A numeric string, for compatibility reasons.
143          *
144          * @since 4.5.0
145          * @access public
146          * @var string
147          */
148         public $lang_id = '0';
149
150         /**
151          * Retrieves a site from the database by its ID.
152          *
153          * @static
154          * @since 4.5.0
155          * @access public
156          *
157          * @global wpdb $wpdb WordPress database abstraction object.
158          *
159          * @param int $site_id The ID of the site to retrieve.
160          * @return WP_Site|false The site's object if found. False if not.
161          */
162         public static function get_instance( $site_id ) {
163                 global $wpdb;
164
165                 $site_id = (int) $site_id;
166                 if ( ! $site_id ) {
167                         return false;
168                 }
169
170                 $_site = wp_cache_get( $site_id, 'sites' );
171
172                 if ( ! $_site ) {
173                         $_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) );
174
175                         if ( empty( $_site ) || is_wp_error( $_site ) ) {
176                                 return false;
177                         }
178
179                         wp_cache_add( $site_id, $_site, 'sites' );
180                 }
181
182                 return new WP_Site( $_site );
183         }
184
185         /**
186          * Creates a new WP_Site object.
187          *
188          * Will populate object properties from the object provided and assign other
189          * default properties based on that information.
190          *
191          * @since 4.5.0
192          * @access public
193          *
194          * @param WP_Site|object $site A site object.
195          */
196         public function __construct( $site ) {
197                 foreach( get_object_vars( $site ) as $key => $value ) {
198                         $this->$key = $value;
199                 }
200         }
201 }