pre_site_transient_{$transient}
云策文档标注
概述
pre_site_transient_{$transient} 是一个 WordPress 过滤器钩子,用于在获取站点瞬态值之前修改其值。通过返回非 false 值,可以短路检索过程并直接返回该值。
关键要点
- 这是一个动态钩子,钩子名称中的 $transient 部分对应瞬态名称。
- 返回任何非 false 的值将短路瞬态的检索,并直接返回该值。
- 参数包括 $pre_site_transient(默认值,若瞬态不存在时返回)和 $transient(瞬态名称)。
- 从 WordPress 4.4.0 版本开始添加了 $transient 参数,最初在 2.9.0 版本引入。
代码示例
$pre = apply_filters( "pre_site_transient_{$transient}", false, $transient );注意事项
- 此钩子主要用于 get_site_transient() 函数中,用于控制站点瞬态的检索行为。
- 使用时需确保钩子名称中的 $transient 部分正确匹配目标瞬态。
原文内容
Filters the value of an existing site transient before it is retrieved.
Description
The dynamic portion of the hook name, $transient, refers to the transient name.
Returning a value other than boolean false will short-circuit retrieval and return that value instead.
Parameters
$pre_site_transientmixed-
The default value to return if the site transient does not exist.
Any value other than false will short-circuit the retrieval of the transient, and return that value. $transientstring-
Transient name.
Source
$pre = apply_filters( "pre_site_transient_{$transient}", false, $transient );