wp_clean_plugins_cache()
云策文档标注
概述
wp_clean_plugins_cache() 函数用于清除 get_plugins() 使用的插件缓存,默认同时清除插件更新缓存。
关键要点
- 函数参数 $clear_update_cache 为布尔值,可选,控制是否清除插件更新缓存,默认值为 true。
- 内部实现:当 $clear_update_cache 为 true 时,调用 delete_site_transient('update_plugins') 删除站点瞬态;并调用 wp_cache_delete('plugins', 'plugins') 删除缓存。
- 相关函数包括 wp_cache_delete() 和 delete_site_transient(),用于缓存和瞬态操作。
- 被 wp_clean_update_cache()、WP_Automatic_Updater::run()、Plugin_Upgrader 类中的多个方法使用。
- 自 WordPress 3.7.0 版本引入。
代码示例
function wp_clean_plugins_cache( $clear_update_cache = true ) {
if ( $clear_update_cache ) {
delete_site_transient( 'update_plugins' );
}
wp_cache_delete( 'plugins', 'plugins' );
}
原文内容
Clears the plugins cache used by get_plugins() and by default, the plugin updates cache.
Parameters
$clear_update_cachebooloptional-
Whether to clear the plugin updates cache.
Default:
true
Source
function wp_clean_plugins_cache( $clear_update_cache = true ) {
if ( $clear_update_cache ) {
delete_site_transient( 'update_plugins' );
}
wp_cache_delete( 'plugins', 'plugins' );
}
Changelog
| Version | Description |
|---|---|
| 3.7.0 | Introduced. |