WordPress Version: 4.4
/**
* Update the details for a blog. Updates the blogs table for a given blog id.
*
* @since MU
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $blog_id Blog ID
* @param array $details Array of details keyed by blogs table field names.
* @return bool True if update succeeds, false otherwise.
*/
function update_blog_details($blog_id, $details = array())
{
global $wpdb;
if (empty($details)) {
return false;
}
if (is_object($details)) {
$details = get_object_vars($details);
}
$current_details = get_blog_details($blog_id, false);
if (empty($current_details)) {
return false;
}
$current_details = get_object_vars($current_details);
$details = array_merge($current_details, $details);
$details['last_updated'] = current_time('mysql', true);
$update_details = array();
$fields = array('site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
foreach (array_intersect(array_keys($details), $fields) as $field) {
if ('path' === $field) {
$details[$field] = trailingslashit('/' . trim($details[$field], '/'));
}
$update_details[$field] = $details[$field];
}
$result = $wpdb->update($wpdb->blogs, $update_details, array('blog_id' => $blog_id));
if (false === $result) {
return false;
}
// If spam status changed, issue actions.
if ($details['spam'] != $current_details['spam']) {
if ($details['spam'] == 1) {
/**
* Fires when the blog status is changed to 'spam'.
*
* @since MU
*
* @param int $blog_id Blog ID.
*/
do_action('make_spam_blog', $blog_id);
} else {
/**
* Fires when the blog status is changed to 'ham'.
*
* @since MU
*
* @param int $blog_id Blog ID.
*/
do_action('make_ham_blog', $blog_id);
}
}
// If mature status changed, issue actions.
if ($details['mature'] != $current_details['mature']) {
if ($details['mature'] == 1) {
/**
* Fires when the blog status is changed to 'mature'.
*
* @since 3.1.0
*
* @param int $blog_id Blog ID.
*/
do_action('mature_blog', $blog_id);
} else {
/**
* Fires when the blog status is changed to 'unmature'.
*
* @since 3.1.0
*
* @param int $blog_id Blog ID.
*/
do_action('unmature_blog', $blog_id);
}
}
// If archived status changed, issue actions.
if ($details['archived'] != $current_details['archived']) {
if ($details['archived'] == 1) {
/**
* Fires when the blog status is changed to 'archived'.
*
* @since MU
*
* @param int $blog_id Blog ID.
*/
do_action('archive_blog', $blog_id);
} else {
/**
* Fires when the blog status is changed to 'unarchived'.
*
* @since MU
*
* @param int $blog_id Blog ID.
*/
do_action('unarchive_blog', $blog_id);
}
}
// If deleted status changed, issue actions.
if ($details['deleted'] != $current_details['deleted']) {
if ($details['deleted'] == 1) {
/**
* Fires when the blog status is changed to 'deleted'.
*
* @since 3.5.0
*
* @param int $blog_id Blog ID.
*/
do_action('make_delete_blog', $blog_id);
} else {
/**
* Fires when the blog status is changed to 'undeleted'.
*
* @since 3.5.0
*
* @param int $blog_id Blog ID.
*/
do_action('make_undelete_blog', $blog_id);
}
}
if (isset($details['public'])) {
switch_to_blog($blog_id);
update_option('blog_public', $details['public']);
restore_current_blog();
}
refresh_blog_details($blog_id);
return true;
}