_maybe_update_core()
云策文档标注
概述
_maybe_update_core() 函数用于判断 WordPress 核心是否需要更新,通过检查缓存和版本信息来避免频繁的版本检查。
关键要点
- 函数检查 update_core 站点瞬态,基于 last_checked 时间戳和 version_checked 版本号决定是否执行 wp_version_check()。
- 如果上次检查在 12 小时内且版本未变,则跳过更新检查,否则调用 wp_version_check() 进行版本验证。
- 函数依赖于 get_site_transient()、wp_get_wp_version() 和 wp_version_check() 等核心函数。
代码示例
function _maybe_update_core() {
$current = get_site_transient( 'update_core' );
if ( isset( $current->last_checked, $current->version_checked )
&& 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
&& wp_get_wp_version() === $current->version_checked
) {
return;
}
wp_version_check();
}注意事项
- 函数在 WordPress 2.8.0 版本中引入,用于优化核心更新检查的性能。
- 开发者应避免直接调用此函数,除非需要自定义更新逻辑,因为它已集成到 WordPress 核心更新流程中。
原文内容
Determines whether core should be updated.
Source
function _maybe_update_core() {
$current = get_site_transient( 'update_core' );
if ( isset( $current->last_checked, $current->version_checked )
&& 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked )
&& wp_get_wp_version() === $current->version_checked
) {
return;
}
wp_version_check();
}
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |