wp_update_core()
云策文档标注
概述
wp_update_core() 是一个已弃用的 WordPress 函数,用于启动核心更新器。自 3.7.0 版本起,建议直接实例化 Core_Upgrader 类并调用其 'upgrade' 方法。
关键要点
- wp_update_core() 函数已弃用,替代方案是使用 Core_Upgrader 类。
- 该函数在 3.7.0 版本被标记为弃用,最初在 2.7.0 版本引入。
- 函数内部调用 _deprecated_function() 来通知开发者弃用状态。
- 如果提供 $feedback 参数,会通过 add_filter() 添加回调到 'update_feedback' 钩子。
- 函数加载 class-wp-upgrader.php 文件,创建 Core_Upgrader 实例并执行升级。
代码示例
function wp_update_core($current, $feedback = '') {
_deprecated_function( __FUNCTION__, '3.7.0', 'new Core_Upgrader();' );
if ( !empty($feedback) )
add_filter('update_feedback', $feedback);
require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new Core_Upgrader();
return $upgrader->upgrade($current);
}注意事项
- 开发者应避免使用此函数,转而使用 Core_Upgrader 类以实现核心更新。
- 弃用信息会通过 _deprecated_function() 在调试模式下显示,帮助迁移代码。
原文内容
This was once used to kick-off the Core Updater.
Description
Deprecated in favor of instantiating a Core_Upgrader instance directly, and calling the ‘upgrade’ method.
See also
Source
function wp_update_core($current, $feedback = '') {
_deprecated_function( __FUNCTION__, '3.7.0', 'new Core_Upgrader();' );
if ( !empty($feedback) )
add_filter('update_feedback', $feedback);
require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new Core_Upgrader();
return $upgrader->upgrade($current);
}
Changelog
| Version | Description |
|---|---|
| 3.7.0 | Deprecated. Use Core_Upgrader |
| 2.7.0 | Introduced. |