3 * Site API: WP_Site class
6 * @subpackage Multisite
11 * Core class used for interacting with a multisite site.
13 * This class is used during load to populate the `$current_blog` global and
14 * setup the current site.
23 * A numeric string, for compatibility reasons.
50 * The ID of the site's parent network.
52 * Named "site" vs. "network" for legacy reasons. An individual site's "site" is
55 * A numeric string, for compatibility reasons.
61 public $site_id = '0';
64 * The date on which the site was created or registered.
68 * @var string Date in MySQL's datetime format.
70 public $registered = '0000-00-00 00:00:00';
73 * The date and time on which site settings were last updated.
77 * @var string Date in MySQL's datetime format.
79 public $last_updated = '0000-00-00 00:00:00';
82 * Whether the site should be treated as public.
84 * A numeric string, for compatibility reasons.
93 * Whether the site should be treated as archived.
95 * A numeric string, for compatibility reasons.
101 public $archived = '0';
104 * Whether the site should be treated as mature.
106 * Handling for this does not exist throughout WordPress core, but custom
107 * implementations exist that require the property to be present.
109 * A numeric string, for compatibility reasons.
115 public $mature = '0';
118 * Whether the site should be treated as spam.
120 * A numeric string, for compatibility reasons.
129 * Whether the site should be treated as deleted.
131 * A numeric string, for compatibility reasons.
137 public $deleted = '0';
140 * The language pack associated with this site.
142 * A numeric string, for compatibility reasons.
148 public $lang_id = '0';
151 * Retrieves a site from the database by its ID.
157 * @global wpdb $wpdb WordPress database abstraction object.
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.
162 public static function get_instance( $site_id ) {
165 $site_id = (int) $site_id;
170 $_site = wp_cache_get( $site_id, 'sites' );
173 $_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) );
175 if ( empty( $_site ) || is_wp_error( $_site ) ) {
179 wp_cache_add( $site_id, $_site, 'sites' );
182 return new WP_Site( $_site );
186 * Creates a new WP_Site object.
188 * Will populate object properties from the object provided and assign other
189 * default properties based on that information.
194 * @param WP_Site|object $site A site object.
196 public function __construct( $site ) {
197 foreach( get_object_vars( $site ) as $key => $value ) {
198 $this->$key = $value;