Class: WP_Site

Core class used for interacting with a multisite site.

This class is used during load to populate the $current_blog global and setup the current site.


Properties

Name Type(s) Default Value Summary
blog_id string Site ID.

A numeric string, for compatibility reasons.

domain string Domain of the site.
path string Path of the site.
site_id string The ID of the site's parent network.

Named "site" vs. "network" for legacy reasons. An individual site's "site" is its network.

A numeric string, for compatibility reasons.

registered string The date on which the site was created or registered.
last_updated string The date and time on which site settings were last updated.
public string Whether the site should be treated as public.

A numeric string, for compatibility reasons.

archived string Whether the site should be treated as archived.

A numeric string, for compatibility reasons.

mature string Whether the site should be treated as mature.

Handling for this does not exist throughout WordPress core, but custom implementations exist that require the property to be present.

A numeric string, for compatibility reasons.

spam string Whether the site should be treated as spam.

A numeric string, for compatibility reasons.

deleted string Whether the site should be treated as deleted.

A numeric string, for compatibility reasons.

lang_id string The language pack associated with this site.

A numeric string, for compatibility reasons.

id integer
network_id integer
blogname string
siteurl string
post_count integer
home string

Methods

WP_Site:: __construct( WP_Site | object $site )

Creates a new WP_Site object. Since 4.5.0.

Will populate object properties from the object provided and assign other default properties based on that information.

Arguments

Name Type(s) Default Value Description
$site WP_Site | object

A site object.


WP_Site:: __get( string $key )

Getter. Since 4.6.0.

Allows current multisite naming conventions when getting properties. Allows access to extended site properties.

Arguments

Name Type(s) Default Value Description
$key string

Property to get.

Returns

mixed

Value of the property. Null if not available.


WP_Site:: __isset( string $key )

Isset-er. Since 4.6.0.

Allows current multisite naming conventions when checking for properties. Checks for extended site properties.

Arguments

Name Type(s) Default Value Description
$key string

Property to check if set.

Returns

boolean

Whether the property is set.


WP_Site:: __set( string $key, mixed $value )

Setter. Since 4.6.0.

Allows current multisite naming conventions while setting properties.

Arguments

Name Type(s) Default Value Description
$key string

Property to set.

$value mixed

Value to assign to the property.


WP_Site:: get_details( )

Retrieves the details for this site. Since 4.6.0.

This method is used internally to lazy-load the extended properties of a site.

Returns

\stdClass

A raw site object with all details included.


WP_Site:: get_instance( integer $site_id )

Retrieves a site from the database by its ID. Since 4.5.0.

Arguments

Name Type(s) Default Value Description
$site_id integer

The ID of the site to retrieve.

Returns

WP_Site | false

The site's object if found. False if not.


WP_Site:: to_array( )

Converts an object to array. Since 4.6.0.

Returns

array

Object as array.


WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.