钩子文档

wp_cache_themes_persistently

💡 云策文档标注

概述

wp_cache_themes_persistently 是一个 WordPress 过滤器,用于控制是否获取已注册主题目录的缓存。它主要用于优化主题搜索和加载过程。

关键要点

  • 这是一个过滤器,允许开发者修改是否获取主题目录缓存的行为。
  • 接受两个参数:$cache_expiration(布尔值,默认 false)和 $context(字符串,调用过滤器的类或函数名)。
  • 在 WordPress 3.4.0 版本中引入。

代码示例

$cache_expiration = apply_filters( 'wp_cache_themes_persistently', false, 'search_theme_directories' );

注意事项

  • 默认情况下,此过滤器返回 false,表示不获取缓存;开发者可以通过钩子修改此值以启用缓存。
  • 相关函数包括 search_theme_directories() 和 WP_Theme::__construct(),用于主题搜索和初始化。

📄 原文内容

Filters whether to get the cache of the registered theme directories.

Parameters

$cache_expirationbool
Whether to get the cache of the theme directories. Default false.
$contextstring
The class or function name calling the filter.

Source

$cache_expiration = apply_filters( 'wp_cache_themes_persistently', false, 'search_theme_directories' );

Changelog

Version Description
3.4.0 Introduced.