update_blog_details()
云策文档标注
概述
update_blog_details() 函数用于更新指定博客的详细信息及其在 blogs 表中的数据。它接受博客 ID 和详情数组作为参数,返回更新成功与否的布尔值。
关键要点
- 函数接受两个参数:$blog_id(必需,整数类型)和 $details(可选,数组类型,默认为空数组)。
- 如果 $details 为空或为对象,函数会进行相应处理并可能返回 false。
- 内部调用 wp_update_site() 来执行更新操作,并检查是否返回 WP_Error。
- 返回值为布尔类型:true 表示更新成功,false 表示失败。
代码示例
function update_blog_details( $blog_id, $details = array() ) {
if ( empty( $details ) ) {
return false;
}
if ( is_object( $details ) ) {
$details = get_object_vars( $details );
}
$site = wp_update_site( $blog_id, $details );
if ( is_wp_error( $site ) ) {
return false;
}
return true;
}注意事项
- 该函数自 WordPress MU 3.0.0 版本引入,适用于多站点环境。
- 相关函数包括 wp_update_site() 和 is_wp_error(),用于数据库更新和错误检查。
- 被 wpmu_update_blogs_date() 使用,用于更新当前站点的 last_updated 字段。
原文内容
Updates the details for a blog and the blogs table for a given blog ID.
Parameters
$blog_idintrequired-
Blog ID.
$detailsarrayoptional-
Array of details keyed by blogs table field names.
Default:
array()
Source
function update_blog_details( $blog_id, $details = array() ) {
if ( empty( $details ) ) {
return false;
}
if ( is_object( $details ) ) {
$details = get_object_vars( $details );
}
$site = wp_update_site( $blog_id, $details );
if ( is_wp_error( $site ) ) {
return false;
}
return true;
}
Changelog
| Version | Description |
|---|---|
| MU (3.0.0) | Introduced. |