Edit File by line
/home/barbar84/www/wp-inclu...
File: ms-blogs.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Site/blog functions that work with the blogs table and related data.
[3] Fix | Delete
*
[4] Fix | Delete
* @package WordPress
[5] Fix | Delete
* @subpackage Multisite
[6] Fix | Delete
* @since MU (3.0.0)
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
require_once ABSPATH . WPINC . '/ms-site.php';
[10] Fix | Delete
require_once ABSPATH . WPINC . '/ms-network.php';
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Update the last_updated field for the current site.
[14] Fix | Delete
*
[15] Fix | Delete
* @since MU (3.0.0)
[16] Fix | Delete
*/
[17] Fix | Delete
function wpmu_update_blogs_date() {
[18] Fix | Delete
$site_id = get_current_blog_id();
[19] Fix | Delete
[20] Fix | Delete
update_blog_details( $site_id, array( 'last_updated' => current_time( 'mysql', true ) ) );
[21] Fix | Delete
/**
[22] Fix | Delete
* Fires after the blog details are updated.
[23] Fix | Delete
*
[24] Fix | Delete
* @since MU (3.0.0)
[25] Fix | Delete
*
[26] Fix | Delete
* @param int $blog_id Site ID.
[27] Fix | Delete
*/
[28] Fix | Delete
do_action( 'wpmu_blog_updated', $site_id );
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Get a full blog URL, given a blog ID.
[33] Fix | Delete
*
[34] Fix | Delete
* @since MU (3.0.0)
[35] Fix | Delete
*
[36] Fix | Delete
* @param int $blog_id Blog ID.
[37] Fix | Delete
* @return string Full URL of the blog if found. Empty string if not.
[38] Fix | Delete
*/
[39] Fix | Delete
function get_blogaddress_by_id( $blog_id ) {
[40] Fix | Delete
$bloginfo = get_site( (int) $blog_id );
[41] Fix | Delete
[42] Fix | Delete
if ( empty( $bloginfo ) ) {
[43] Fix | Delete
return '';
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
$scheme = parse_url( $bloginfo->home, PHP_URL_SCHEME );
[47] Fix | Delete
$scheme = empty( $scheme ) ? 'http' : $scheme;
[48] Fix | Delete
[49] Fix | Delete
return esc_url( $scheme . '://' . $bloginfo->domain . $bloginfo->path );
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Get a full blog URL, given a blog name.
[54] Fix | Delete
*
[55] Fix | Delete
* @since MU (3.0.0)
[56] Fix | Delete
*
[57] Fix | Delete
* @param string $blogname The (subdomain or directory) name
[58] Fix | Delete
* @return string
[59] Fix | Delete
*/
[60] Fix | Delete
function get_blogaddress_by_name( $blogname ) {
[61] Fix | Delete
if ( is_subdomain_install() ) {
[62] Fix | Delete
if ( 'main' === $blogname ) {
[63] Fix | Delete
$blogname = 'www';
[64] Fix | Delete
}
[65] Fix | Delete
$url = rtrim( network_home_url(), '/' );
[66] Fix | Delete
if ( ! empty( $blogname ) ) {
[67] Fix | Delete
$url = preg_replace( '|^([^\.]+://)|', '${1}' . $blogname . '.', $url );
[68] Fix | Delete
}
[69] Fix | Delete
} else {
[70] Fix | Delete
$url = network_home_url( $blogname );
[71] Fix | Delete
}
[72] Fix | Delete
return esc_url( $url . '/' );
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Retrieves a sites ID given its (subdomain or directory) slug.
[77] Fix | Delete
*
[78] Fix | Delete
* @since MU (3.0.0)
[79] Fix | Delete
* @since 4.7.0 Converted to use `get_sites()`.
[80] Fix | Delete
*
[81] Fix | Delete
* @param string $slug A site's slug.
[82] Fix | Delete
* @return int|null The site ID, or null if no site is found for the given slug.
[83] Fix | Delete
*/
[84] Fix | Delete
function get_id_from_blogname( $slug ) {
[85] Fix | Delete
$current_network = get_network();
[86] Fix | Delete
$slug = trim( $slug, '/' );
[87] Fix | Delete
[88] Fix | Delete
if ( is_subdomain_install() ) {
[89] Fix | Delete
$domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_network->domain );
[90] Fix | Delete
$path = $current_network->path;
[91] Fix | Delete
} else {
[92] Fix | Delete
$domain = $current_network->domain;
[93] Fix | Delete
$path = $current_network->path . $slug . '/';
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
$site_ids = get_sites(
[97] Fix | Delete
array(
[98] Fix | Delete
'number' => 1,
[99] Fix | Delete
'fields' => 'ids',
[100] Fix | Delete
'domain' => $domain,
[101] Fix | Delete
'path' => $path,
[102] Fix | Delete
'update_site_meta_cache' => false,
[103] Fix | Delete
)
[104] Fix | Delete
);
[105] Fix | Delete
[106] Fix | Delete
if ( empty( $site_ids ) ) {
[107] Fix | Delete
return null;
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
return array_shift( $site_ids );
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Retrieve the details for a blog from the blogs table and blog options.
[115] Fix | Delete
*
[116] Fix | Delete
* @since MU (3.0.0)
[117] Fix | Delete
*
[118] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[119] Fix | Delete
*
[120] Fix | Delete
* @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against.
[121] Fix | Delete
* If not specified the current blog ID is used.
[122] Fix | Delete
* @param bool $get_all Whether to retrieve all details or only the details in the blogs table.
[123] Fix | Delete
* Default is true.
[124] Fix | Delete
* @return WP_Site|false Blog details on success. False on failure.
[125] Fix | Delete
*/
[126] Fix | Delete
function get_blog_details( $fields = null, $get_all = true ) {
[127] Fix | Delete
global $wpdb;
[128] Fix | Delete
[129] Fix | Delete
if ( is_array( $fields ) ) {
[130] Fix | Delete
if ( isset( $fields['blog_id'] ) ) {
[131] Fix | Delete
$blog_id = $fields['blog_id'];
[132] Fix | Delete
} elseif ( isset( $fields['domain'] ) && isset( $fields['path'] ) ) {
[133] Fix | Delete
$key = md5( $fields['domain'] . $fields['path'] );
[134] Fix | Delete
$blog = wp_cache_get( $key, 'blog-lookup' );
[135] Fix | Delete
if ( false !== $blog ) {
[136] Fix | Delete
return $blog;
[137] Fix | Delete
}
[138] Fix | Delete
if ( 'www.' === substr( $fields['domain'], 0, 4 ) ) {
[139] Fix | Delete
$nowww = substr( $fields['domain'], 4 );
[140] Fix | Delete
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
[141] Fix | Delete
} else {
[142] Fix | Delete
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );
[143] Fix | Delete
}
[144] Fix | Delete
if ( $blog ) {
[145] Fix | Delete
wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details' );
[146] Fix | Delete
$blog_id = $blog->blog_id;
[147] Fix | Delete
} else {
[148] Fix | Delete
return false;
[149] Fix | Delete
}
[150] Fix | Delete
} elseif ( isset( $fields['domain'] ) && is_subdomain_install() ) {
[151] Fix | Delete
$key = md5( $fields['domain'] );
[152] Fix | Delete
$blog = wp_cache_get( $key, 'blog-lookup' );
[153] Fix | Delete
if ( false !== $blog ) {
[154] Fix | Delete
return $blog;
[155] Fix | Delete
}
[156] Fix | Delete
if ( 'www.' === substr( $fields['domain'], 0, 4 ) ) {
[157] Fix | Delete
$nowww = substr( $fields['domain'], 4 );
[158] Fix | Delete
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
[159] Fix | Delete
} else {
[160] Fix | Delete
$blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) );
[161] Fix | Delete
}
[162] Fix | Delete
if ( $blog ) {
[163] Fix | Delete
wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details' );
[164] Fix | Delete
$blog_id = $blog->blog_id;
[165] Fix | Delete
} else {
[166] Fix | Delete
return false;
[167] Fix | Delete
}
[168] Fix | Delete
} else {
[169] Fix | Delete
return false;
[170] Fix | Delete
}
[171] Fix | Delete
} else {
[172] Fix | Delete
if ( ! $fields ) {
[173] Fix | Delete
$blog_id = get_current_blog_id();
[174] Fix | Delete
} elseif ( ! is_numeric( $fields ) ) {
[175] Fix | Delete
$blog_id = get_id_from_blogname( $fields );
[176] Fix | Delete
} else {
[177] Fix | Delete
$blog_id = $fields;
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
$blog_id = (int) $blog_id;
[182] Fix | Delete
[183] Fix | Delete
$all = $get_all ? '' : 'short';
[184] Fix | Delete
$details = wp_cache_get( $blog_id . $all, 'blog-details' );
[185] Fix | Delete
[186] Fix | Delete
if ( $details ) {
[187] Fix | Delete
if ( ! is_object( $details ) ) {
[188] Fix | Delete
if ( -1 == $details ) {
[189] Fix | Delete
return false;
[190] Fix | Delete
} else {
[191] Fix | Delete
// Clear old pre-serialized objects. Cache clients do better with that.
[192] Fix | Delete
wp_cache_delete( $blog_id . $all, 'blog-details' );
[193] Fix | Delete
unset( $details );
[194] Fix | Delete
}
[195] Fix | Delete
} else {
[196] Fix | Delete
return $details;
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
// Try the other cache.
[201] Fix | Delete
if ( $get_all ) {
[202] Fix | Delete
$details = wp_cache_get( $blog_id . 'short', 'blog-details' );
[203] Fix | Delete
} else {
[204] Fix | Delete
$details = wp_cache_get( $blog_id, 'blog-details' );
[205] Fix | Delete
// If short was requested and full cache is set, we can return.
[206] Fix | Delete
if ( $details ) {
[207] Fix | Delete
if ( ! is_object( $details ) ) {
[208] Fix | Delete
if ( -1 == $details ) {
[209] Fix | Delete
return false;
[210] Fix | Delete
} else {
[211] Fix | Delete
// Clear old pre-serialized objects. Cache clients do better with that.
[212] Fix | Delete
wp_cache_delete( $blog_id, 'blog-details' );
[213] Fix | Delete
unset( $details );
[214] Fix | Delete
}
[215] Fix | Delete
} else {
[216] Fix | Delete
return $details;
[217] Fix | Delete
}
[218] Fix | Delete
}
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
if ( empty( $details ) ) {
[222] Fix | Delete
$details = WP_Site::get_instance( $blog_id );
[223] Fix | Delete
if ( ! $details ) {
[224] Fix | Delete
// Set the full cache.
[225] Fix | Delete
wp_cache_set( $blog_id, -1, 'blog-details' );
[226] Fix | Delete
return false;
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
if ( ! $details instanceof WP_Site ) {
[231] Fix | Delete
$details = new WP_Site( $details );
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
if ( ! $get_all ) {
[235] Fix | Delete
wp_cache_set( $blog_id . $all, $details, 'blog-details' );
[236] Fix | Delete
return $details;
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
$switched_blog = false;
[240] Fix | Delete
[241] Fix | Delete
if ( get_current_blog_id() !== $blog_id ) {
[242] Fix | Delete
switch_to_blog( $blog_id );
[243] Fix | Delete
$switched_blog = true;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
$details->blogname = get_option( 'blogname' );
[247] Fix | Delete
$details->siteurl = get_option( 'siteurl' );
[248] Fix | Delete
$details->post_count = get_option( 'post_count' );
[249] Fix | Delete
$details->home = get_option( 'home' );
[250] Fix | Delete
[251] Fix | Delete
if ( $switched_blog ) {
[252] Fix | Delete
restore_current_blog();
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
/**
[256] Fix | Delete
* Filters a blog's details.
[257] Fix | Delete
*
[258] Fix | Delete
* @since MU (3.0.0)
[259] Fix | Delete
* @deprecated 4.7.0 Use {@see 'site_details'} instead.
[260] Fix | Delete
*
[261] Fix | Delete
* @param WP_Site $details The blog details.
[262] Fix | Delete
*/
[263] Fix | Delete
$details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' );
[264] Fix | Delete
[265] Fix | Delete
wp_cache_set( $blog_id . $all, $details, 'blog-details' );
[266] Fix | Delete
[267] Fix | Delete
$key = md5( $details->domain . $details->path );
[268] Fix | Delete
wp_cache_set( $key, $details, 'blog-lookup' );
[269] Fix | Delete
[270] Fix | Delete
return $details;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
/**
[274] Fix | Delete
* Clear the blog details cache.
[275] Fix | Delete
*
[276] Fix | Delete
* @since MU (3.0.0)
[277] Fix | Delete
*
[278] Fix | Delete
* @param int $blog_id Optional. Blog ID. Defaults to current blog.
[279] Fix | Delete
*/
[280] Fix | Delete
function refresh_blog_details( $blog_id = 0 ) {
[281] Fix | Delete
$blog_id = (int) $blog_id;
[282] Fix | Delete
if ( ! $blog_id ) {
[283] Fix | Delete
$blog_id = get_current_blog_id();
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
clean_blog_cache( $blog_id );
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* Update the details for a blog. Updates the blogs table for a given blog ID.
[291] Fix | Delete
*
[292] Fix | Delete
* @since MU (3.0.0)
[293] Fix | Delete
*
[294] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[295] Fix | Delete
*
[296] Fix | Delete
* @param int $blog_id Blog ID.
[297] Fix | Delete
* @param array $details Array of details keyed by blogs table field names.
[298] Fix | Delete
* @return bool True if update succeeds, false otherwise.
[299] Fix | Delete
*/
[300] Fix | Delete
function update_blog_details( $blog_id, $details = array() ) {
[301] Fix | Delete
global $wpdb;
[302] Fix | Delete
[303] Fix | Delete
if ( empty( $details ) ) {
[304] Fix | Delete
return false;
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
if ( is_object( $details ) ) {
[308] Fix | Delete
$details = get_object_vars( $details );
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
$site = wp_update_site( $blog_id, $details );
[312] Fix | Delete
[313] Fix | Delete
if ( is_wp_error( $site ) ) {
[314] Fix | Delete
return false;
[315] Fix | Delete
}
[316] Fix | Delete
[317] Fix | Delete
return true;
[318] Fix | Delete
}
[319] Fix | Delete
[320] Fix | Delete
/**
[321] Fix | Delete
* Cleans the site details cache for a site.
[322] Fix | Delete
*
[323] Fix | Delete
* @since 4.7.4
[324] Fix | Delete
*
[325] Fix | Delete
* @param int $site_id Optional. Site ID. Default is the current site ID.
[326] Fix | Delete
*/
[327] Fix | Delete
function clean_site_details_cache( $site_id = 0 ) {
[328] Fix | Delete
$site_id = (int) $site_id;
[329] Fix | Delete
if ( ! $site_id ) {
[330] Fix | Delete
$site_id = get_current_blog_id();
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
wp_cache_delete( $site_id, 'site-details' );
[334] Fix | Delete
wp_cache_delete( $site_id, 'blog-details' );
[335] Fix | Delete
}
[336] Fix | Delete
[337] Fix | Delete
/**
[338] Fix | Delete
* Retrieve option value for a given blog id based on name of option.
[339] Fix | Delete
*
[340] Fix | Delete
* If the option does not exist or does not have a value, then the return value
[341] Fix | Delete
* will be false. This is useful to check whether you need to install an option
[342] Fix | Delete
* and is commonly used during installation of plugin options and to test
[343] Fix | Delete
* whether upgrading is required.
[344] Fix | Delete
*
[345] Fix | Delete
* If the option was serialized then it will be unserialized when it is returned.
[346] Fix | Delete
*
[347] Fix | Delete
* @since MU (3.0.0)
[348] Fix | Delete
*
[349] Fix | Delete
* @param int $id A blog ID. Can be null to refer to the current blog.
[350] Fix | Delete
* @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
[351] Fix | Delete
* @param mixed $default Optional. Default value to return if the option does not exist.
[352] Fix | Delete
* @return mixed Value set for the option.
[353] Fix | Delete
*/
[354] Fix | Delete
function get_blog_option( $id, $option, $default = false ) {
[355] Fix | Delete
$id = (int) $id;
[356] Fix | Delete
[357] Fix | Delete
if ( empty( $id ) ) {
[358] Fix | Delete
$id = get_current_blog_id();
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
if ( get_current_blog_id() == $id ) {
[362] Fix | Delete
return get_option( $option, $default );
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
switch_to_blog( $id );
[366] Fix | Delete
$value = get_option( $option, $default );
[367] Fix | Delete
restore_current_blog();
[368] Fix | Delete
[369] Fix | Delete
/**
[370] Fix | Delete
* Filters a blog option value.
[371] Fix | Delete
*
[372] Fix | Delete
* The dynamic portion of the hook name, `$option`, refers to the blog option name.
[373] Fix | Delete
*
[374] Fix | Delete
* @since 3.5.0
[375] Fix | Delete
*
[376] Fix | Delete
* @param string $value The option value.
[377] Fix | Delete
* @param int $id Blog ID.
[378] Fix | Delete
*/
[379] Fix | Delete
return apply_filters( "blog_option_{$option}", $value, $id );
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
/**
[383] Fix | Delete
* Add a new option for a given blog ID.
[384] Fix | Delete
*
[385] Fix | Delete
* You do not need to serialize values. If the value needs to be serialized, then
[386] Fix | Delete
* it will be serialized before it is inserted into the database. Remember,
[387] Fix | Delete
* resources can not be serialized or added as an option.
[388] Fix | Delete
*
[389] Fix | Delete
* You can create options without values and then update the values later.
[390] Fix | Delete
* Existing options will not be updated and checks are performed to ensure that you
[391] Fix | Delete
* aren't adding a protected WordPress option. Care should be taken to not name
[392] Fix | Delete
* options the same as the ones which are protected.
[393] Fix | Delete
*
[394] Fix | Delete
* @since MU (3.0.0)
[395] Fix | Delete
*
[396] Fix | Delete
* @param int $id A blog ID. Can be null to refer to the current blog.
[397] Fix | Delete
* @param string $option Name of option to add. Expected to not be SQL-escaped.
[398] Fix | Delete
* @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
[399] Fix | Delete
* @return bool True if the option was added, false otherwise.
[400] Fix | Delete
*/
[401] Fix | Delete
function add_blog_option( $id, $option, $value ) {
[402] Fix | Delete
$id = (int) $id;
[403] Fix | Delete
[404] Fix | Delete
if ( empty( $id ) ) {
[405] Fix | Delete
$id = get_current_blog_id();
[406] Fix | Delete
}
[407] Fix | Delete
[408] Fix | Delete
if ( get_current_blog_id() == $id ) {
[409] Fix | Delete
return add_option( $option, $value );
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
switch_to_blog( $id );
[413] Fix | Delete
$return = add_option( $option, $value );
[414] Fix | Delete
restore_current_blog();
[415] Fix | Delete
[416] Fix | Delete
return $return;
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
/**
[420] Fix | Delete
* Removes option by name for a given blog ID. Prevents removal of protected WordPress options.
[421] Fix | Delete
*
[422] Fix | Delete
* @since MU (3.0.0)
[423] Fix | Delete
*
[424] Fix | Delete
* @param int $id A blog ID. Can be null to refer to the current blog.
[425] Fix | Delete
* @param string $option Name of option to remove. Expected to not be SQL-escaped.
[426] Fix | Delete
* @return bool True if the option was deleted, false otherwise.
[427] Fix | Delete
*/
[428] Fix | Delete
function delete_blog_option( $id, $option ) {
[429] Fix | Delete
$id = (int) $id;
[430] Fix | Delete
[431] Fix | Delete
if ( empty( $id ) ) {
[432] Fix | Delete
$id = get_current_blog_id();
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
if ( get_current_blog_id() == $id ) {
[436] Fix | Delete
return delete_option( $option );
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
switch_to_blog( $id );
[440] Fix | Delete
$return = delete_option( $option );
[441] Fix | Delete
restore_current_blog();
[442] Fix | Delete
[443] Fix | Delete
return $return;
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
/**
[447] Fix | Delete
* Update an option for a particular blog.
[448] Fix | Delete
*
[449] Fix | Delete
* @since MU (3.0.0)
[450] Fix | Delete
*
[451] Fix | Delete
* @param int $id The blog ID.
[452] Fix | Delete
* @param string $option The option key.
[453] Fix | Delete
* @param mixed $value The option value.
[454] Fix | Delete
* @param mixed $deprecated Not used.
[455] Fix | Delete
* @return bool True if the value was updated, false otherwise.
[456] Fix | Delete
*/
[457] Fix | Delete
function update_blog_option( $id, $option, $value, $deprecated = null ) {
[458] Fix | Delete
$id = (int) $id;
[459] Fix | Delete
[460] Fix | Delete
if ( null !== $deprecated ) {
[461] Fix | Delete
_deprecated_argument( __FUNCTION__, '3.1.0' );
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
if ( get_current_blog_id() == $id ) {
[465] Fix | Delete
return update_option( $option, $value );
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
switch_to_blog( $id );
[469] Fix | Delete
$return = update_option( $option, $value );
[470] Fix | Delete
restore_current_blog();
[471] Fix | Delete
[472] Fix | Delete
return $return;
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
/**
[476] Fix | Delete
* Switch the current blog.
[477] Fix | Delete
*
[478] Fix | Delete
* This function is useful if you need to pull posts, or other information,
[479] Fix | Delete
* from other blogs. You can switch back afterwards using restore_current_blog().
[480] Fix | Delete
*
[481] Fix | Delete
* Things that aren't switched:
[482] Fix | Delete
* - plugins. See #14941
[483] Fix | Delete
*
[484] Fix | Delete
* @see restore_current_blog()
[485] Fix | Delete
* @since MU (3.0.0)
[486] Fix | Delete
*
[487] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[488] Fix | Delete
* @global int $blog_id
[489] Fix | Delete
* @global array $_wp_switched_stack
[490] Fix | Delete
* @global bool $switched
[491] Fix | Delete
* @global string $table_prefix
[492] Fix | Delete
* @global WP_Object_Cache $wp_object_cache
[493] Fix | Delete
*
[494] Fix | Delete
* @param int $new_blog_id The ID of the blog to switch to. Default: current blog.
[495] Fix | Delete
* @param bool $deprecated Not used.
[496] Fix | Delete
* @return true Always returns true.
[497] Fix | Delete
*/
[498] Fix | Delete
function switch_to_blog( $new_blog_id, $deprecated = null ) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function