wp_schedule_update_checks()
云策文档标注
概述
wp_schedule_update_checks() 函数用于安排 WordPress 核心、主题和插件的更新检查任务。它通过设置定时事件来定期执行这些检查,确保系统能及时获取更新信息。
关键要点
- 函数安排三个定时事件:wp_version_check(核心更新检查)、wp_update_plugins(插件更新检查)和 wp_update_themes(主题更新检查)。
- 使用 wp_schedule_event() 设置事件,频率为 'twicedaily'(每天两次)。
- 在安排事件前,会检查事件是否已安排以及 WordPress 是否处于安装模式(通过 wp_installing() 判断)。
代码示例
function wp_schedule_update_checks() {
if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_version_check' );
}
if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_update_plugins' );
}
if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_update_themes' );
}
}注意事项
- 函数在 WordPress 3.1.0 版本中引入。
- 相关函数包括 wp_installing()、wp_next_scheduled() 和 wp_schedule_event(),用于检查安装状态、获取下一个事件时间和安排事件。
原文内容
Schedules core, theme, and plugin update checks.
Source
function wp_schedule_update_checks() {
if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_version_check' );
}
if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_update_plugins' );
}
if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'twicedaily', 'wp_update_themes' );
}
}
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |