Edit File by line
/home/barbar84/www/wp-inclu...
File: class-wp-site.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Site API: WP_Site class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Multisite
[5] Fix | Delete
* @since 4.5.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class used for interacting with a multisite site.
[10] Fix | Delete
*
[11] Fix | Delete
* This class is used during load to populate the `$current_blog` global and
[12] Fix | Delete
* setup the current site.
[13] Fix | Delete
*
[14] Fix | Delete
* @since 4.5.0
[15] Fix | Delete
*
[16] Fix | Delete
* @property int $id
[17] Fix | Delete
* @property int $network_id
[18] Fix | Delete
* @property string $blogname
[19] Fix | Delete
* @property string $siteurl
[20] Fix | Delete
* @property int $post_count
[21] Fix | Delete
* @property string $home
[22] Fix | Delete
*/
[23] Fix | Delete
final class WP_Site {
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Site ID.
[27] Fix | Delete
*
[28] Fix | Delete
* Named "blog" vs. "site" for legacy reasons.
[29] Fix | Delete
*
[30] Fix | Delete
* A numeric string, for compatibility reasons.
[31] Fix | Delete
*
[32] Fix | Delete
* @since 4.5.0
[33] Fix | Delete
* @var string
[34] Fix | Delete
*/
[35] Fix | Delete
public $blog_id;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Domain of the site.
[39] Fix | Delete
*
[40] Fix | Delete
* @since 4.5.0
[41] Fix | Delete
* @var string
[42] Fix | Delete
*/
[43] Fix | Delete
public $domain = '';
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Path of the site.
[47] Fix | Delete
*
[48] Fix | Delete
* @since 4.5.0
[49] Fix | Delete
* @var string
[50] Fix | Delete
*/
[51] Fix | Delete
public $path = '';
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* The ID of the site's parent network.
[55] Fix | Delete
*
[56] Fix | Delete
* Named "site" vs. "network" for legacy reasons. An individual site's "site" is
[57] Fix | Delete
* its network.
[58] Fix | Delete
*
[59] Fix | Delete
* A numeric string, for compatibility reasons.
[60] Fix | Delete
*
[61] Fix | Delete
* @since 4.5.0
[62] Fix | Delete
* @var string
[63] Fix | Delete
*/
[64] Fix | Delete
public $site_id = '0';
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* The date and time on which the site was created or registered.
[68] Fix | Delete
*
[69] Fix | Delete
* @since 4.5.0
[70] Fix | Delete
* @var string Date in MySQL's datetime format.
[71] Fix | Delete
*/
[72] Fix | Delete
public $registered = '0000-00-00 00:00:00';
[73] Fix | Delete
[74] Fix | Delete
/**
[75] Fix | Delete
* The date and time on which site settings were last updated.
[76] Fix | Delete
*
[77] Fix | Delete
* @since 4.5.0
[78] Fix | Delete
* @var string Date in MySQL's datetime format.
[79] Fix | Delete
*/
[80] Fix | Delete
public $last_updated = '0000-00-00 00:00:00';
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Whether the site should be treated as public.
[84] Fix | Delete
*
[85] Fix | Delete
* A numeric string, for compatibility reasons.
[86] Fix | Delete
*
[87] Fix | Delete
* @since 4.5.0
[88] Fix | Delete
* @var string
[89] Fix | Delete
*/
[90] Fix | Delete
public $public = '1';
[91] Fix | Delete
[92] Fix | Delete
/**
[93] Fix | Delete
* Whether the site should be treated as archived.
[94] Fix | Delete
*
[95] Fix | Delete
* A numeric string, for compatibility reasons.
[96] Fix | Delete
*
[97] Fix | Delete
* @since 4.5.0
[98] Fix | Delete
* @var string
[99] Fix | Delete
*/
[100] Fix | Delete
public $archived = '0';
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Whether the site should be treated as mature.
[104] Fix | Delete
*
[105] Fix | Delete
* Handling for this does not exist throughout WordPress core, but custom
[106] Fix | Delete
* implementations exist that require the property to be present.
[107] Fix | Delete
*
[108] Fix | Delete
* A numeric string, for compatibility reasons.
[109] Fix | Delete
*
[110] Fix | Delete
* @since 4.5.0
[111] Fix | Delete
* @var string
[112] Fix | Delete
*/
[113] Fix | Delete
public $mature = '0';
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Whether the site should be treated as spam.
[117] Fix | Delete
*
[118] Fix | Delete
* A numeric string, for compatibility reasons.
[119] Fix | Delete
*
[120] Fix | Delete
* @since 4.5.0
[121] Fix | Delete
* @var string
[122] Fix | Delete
*/
[123] Fix | Delete
public $spam = '0';
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Whether the site should be treated as deleted.
[127] Fix | Delete
*
[128] Fix | Delete
* A numeric string, for compatibility reasons.
[129] Fix | Delete
*
[130] Fix | Delete
* @since 4.5.0
[131] Fix | Delete
* @var string
[132] Fix | Delete
*/
[133] Fix | Delete
public $deleted = '0';
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* The language pack associated with this site.
[137] Fix | Delete
*
[138] Fix | Delete
* A numeric string, for compatibility reasons.
[139] Fix | Delete
*
[140] Fix | Delete
* @since 4.5.0
[141] Fix | Delete
* @var string
[142] Fix | Delete
*/
[143] Fix | Delete
public $lang_id = '0';
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Retrieves a site from the database by its ID.
[147] Fix | Delete
*
[148] Fix | Delete
* @since 4.5.0
[149] Fix | Delete
*
[150] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[151] Fix | Delete
*
[152] Fix | Delete
* @param int $site_id The ID of the site to retrieve.
[153] Fix | Delete
* @return WP_Site|false The site's object if found. False if not.
[154] Fix | Delete
*/
[155] Fix | Delete
public static function get_instance( $site_id ) {
[156] Fix | Delete
global $wpdb;
[157] Fix | Delete
[158] Fix | Delete
$site_id = (int) $site_id;
[159] Fix | Delete
if ( ! $site_id ) {
[160] Fix | Delete
return false;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
$_site = wp_cache_get( $site_id, 'sites' );
[164] Fix | Delete
[165] Fix | Delete
if ( false === $_site ) {
[166] Fix | Delete
$_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) );
[167] Fix | Delete
[168] Fix | Delete
if ( empty( $_site ) || is_wp_error( $_site ) ) {
[169] Fix | Delete
$_site = -1;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
wp_cache_add( $site_id, $_site, 'sites' );
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
if ( is_numeric( $_site ) ) {
[176] Fix | Delete
return false;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
return new WP_Site( $_site );
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Creates a new WP_Site object.
[184] Fix | Delete
*
[185] Fix | Delete
* Will populate object properties from the object provided and assign other
[186] Fix | Delete
* default properties based on that information.
[187] Fix | Delete
*
[188] Fix | Delete
* @since 4.5.0
[189] Fix | Delete
*
[190] Fix | Delete
* @param WP_Site|object $site A site object.
[191] Fix | Delete
*/
[192] Fix | Delete
public function __construct( $site ) {
[193] Fix | Delete
foreach ( get_object_vars( $site ) as $key => $value ) {
[194] Fix | Delete
$this->$key = $value;
[195] Fix | Delete
}
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Converts an object to array.
[200] Fix | Delete
*
[201] Fix | Delete
* @since 4.6.0
[202] Fix | Delete
*
[203] Fix | Delete
* @return array Object as array.
[204] Fix | Delete
*/
[205] Fix | Delete
public function to_array() {
[206] Fix | Delete
return get_object_vars( $this );
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Getter.
[211] Fix | Delete
*
[212] Fix | Delete
* Allows current multisite naming conventions when getting properties.
[213] Fix | Delete
* Allows access to extended site properties.
[214] Fix | Delete
*
[215] Fix | Delete
* @since 4.6.0
[216] Fix | Delete
*
[217] Fix | Delete
* @param string $key Property to get.
[218] Fix | Delete
* @return mixed Value of the property. Null if not available.
[219] Fix | Delete
*/
[220] Fix | Delete
public function __get( $key ) {
[221] Fix | Delete
switch ( $key ) {
[222] Fix | Delete
case 'id':
[223] Fix | Delete
return (int) $this->blog_id;
[224] Fix | Delete
case 'network_id':
[225] Fix | Delete
return (int) $this->site_id;
[226] Fix | Delete
case 'blogname':
[227] Fix | Delete
case 'siteurl':
[228] Fix | Delete
case 'post_count':
[229] Fix | Delete
case 'home':
[230] Fix | Delete
default: // Custom properties added by 'site_details' filter.
[231] Fix | Delete
if ( ! did_action( 'ms_loaded' ) ) {
[232] Fix | Delete
return null;
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
$details = $this->get_details();
[236] Fix | Delete
if ( isset( $details->$key ) ) {
[237] Fix | Delete
return $details->$key;
[238] Fix | Delete
}
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
return null;
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
/**
[245] Fix | Delete
* Isset-er.
[246] Fix | Delete
*
[247] Fix | Delete
* Allows current multisite naming conventions when checking for properties.
[248] Fix | Delete
* Checks for extended site properties.
[249] Fix | Delete
*
[250] Fix | Delete
* @since 4.6.0
[251] Fix | Delete
*
[252] Fix | Delete
* @param string $key Property to check if set.
[253] Fix | Delete
* @return bool Whether the property is set.
[254] Fix | Delete
*/
[255] Fix | Delete
public function __isset( $key ) {
[256] Fix | Delete
switch ( $key ) {
[257] Fix | Delete
case 'id':
[258] Fix | Delete
case 'network_id':
[259] Fix | Delete
return true;
[260] Fix | Delete
case 'blogname':
[261] Fix | Delete
case 'siteurl':
[262] Fix | Delete
case 'post_count':
[263] Fix | Delete
case 'home':
[264] Fix | Delete
if ( ! did_action( 'ms_loaded' ) ) {
[265] Fix | Delete
return false;
[266] Fix | Delete
}
[267] Fix | Delete
return true;
[268] Fix | Delete
default: // Custom properties added by 'site_details' filter.
[269] Fix | Delete
if ( ! did_action( 'ms_loaded' ) ) {
[270] Fix | Delete
return false;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
$details = $this->get_details();
[274] Fix | Delete
if ( isset( $details->$key ) ) {
[275] Fix | Delete
return true;
[276] Fix | Delete
}
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
return false;
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* Setter.
[284] Fix | Delete
*
[285] Fix | Delete
* Allows current multisite naming conventions while setting properties.
[286] Fix | Delete
*
[287] Fix | Delete
* @since 4.6.0
[288] Fix | Delete
*
[289] Fix | Delete
* @param string $key Property to set.
[290] Fix | Delete
* @param mixed $value Value to assign to the property.
[291] Fix | Delete
*/
[292] Fix | Delete
public function __set( $key, $value ) {
[293] Fix | Delete
switch ( $key ) {
[294] Fix | Delete
case 'id':
[295] Fix | Delete
$this->blog_id = (string) $value;
[296] Fix | Delete
break;
[297] Fix | Delete
case 'network_id':
[298] Fix | Delete
$this->site_id = (string) $value;
[299] Fix | Delete
break;
[300] Fix | Delete
default:
[301] Fix | Delete
$this->$key = $value;
[302] Fix | Delete
}
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
/**
[306] Fix | Delete
* Retrieves the details for this site.
[307] Fix | Delete
*
[308] Fix | Delete
* This method is used internally to lazy-load the extended properties of a site.
[309] Fix | Delete
*
[310] Fix | Delete
* @since 4.6.0
[311] Fix | Delete
*
[312] Fix | Delete
* @see WP_Site::__get()
[313] Fix | Delete
*
[314] Fix | Delete
* @return stdClass A raw site object with all details included.
[315] Fix | Delete
*/
[316] Fix | Delete
private function get_details() {
[317] Fix | Delete
$details = wp_cache_get( $this->blog_id, 'site-details' );
[318] Fix | Delete
[319] Fix | Delete
if ( false === $details ) {
[320] Fix | Delete
[321] Fix | Delete
switch_to_blog( $this->blog_id );
[322] Fix | Delete
// Create a raw copy of the object for backward compatibility with the filter below.
[323] Fix | Delete
$details = new stdClass();
[324] Fix | Delete
foreach ( get_object_vars( $this ) as $key => $value ) {
[325] Fix | Delete
$details->$key = $value;
[326] Fix | Delete
}
[327] Fix | Delete
$details->blogname = get_option( 'blogname' );
[328] Fix | Delete
$details->siteurl = get_option( 'siteurl' );
[329] Fix | Delete
$details->post_count = get_option( 'post_count' );
[330] Fix | Delete
$details->home = get_option( 'home' );
[331] Fix | Delete
restore_current_blog();
[332] Fix | Delete
[333] Fix | Delete
wp_cache_set( $this->blog_id, $details, 'site-details' );
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
/** This filter is documented in wp-includes/ms-blogs.php */
[337] Fix | Delete
$details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' );
[338] Fix | Delete
[339] Fix | Delete
/**
[340] Fix | Delete
* Filters a site's extended properties.
[341] Fix | Delete
*
[342] Fix | Delete
* @since 4.6.0
[343] Fix | Delete
*
[344] Fix | Delete
* @param stdClass $details The site details.
[345] Fix | Delete
*/
[346] Fix | Delete
$details = apply_filters( 'site_details', $details );
[347] Fix | Delete
[348] Fix | Delete
return $details;
[349] Fix | Delete
}
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function