get_preferred_from_update_core()
云策文档标注
概述
get_preferred_from_update_core() 函数用于从核心更新选项中选取第一个可用的更新版本。它通过调用 get_core_updates() 获取更新列表,并返回第一个更新对象或表示最新版本的响应。
关键要点
- 函数返回类型为 object|array|false,成功时返回 API 响应对象或数组,失败时返回 false。
- 如果 get_core_updates() 返回非数组,函数返回 false。
- 如果更新列表为空,函数返回一个对象,其 response 属性为 'latest',表示当前已是最新版本。
- 函数在 WordPress 2.7.0 版本中引入。
代码示例
function get_preferred_from_update_core() {
$updates = get_core_updates();
if ( ! is_array( $updates ) ) {
return false;
}
if ( empty( $updates ) ) {
return (object) array( 'response' => 'latest' );
}
return $updates[0];
}注意事项
- 此函数主要用于内部更新流程,如自动更新器发送邮件、显示更新通知等。
- 相关函数包括 get_core_updates()、WP_Automatic_Updater::send_email()、core_update_footer()、update_nag() 和 update_right_now_message()。
原文内容
Selects the first update version from the update_core option.
Source
function get_preferred_from_update_core() {
$updates = get_core_updates();
if ( ! is_array( $updates ) ) {
return false;
}
if ( empty( $updates ) ) {
return (object) array( 'response' => 'latest' );
}
return $updates[0];
}
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |