pre_transient_{$transient}
云策文档标注
概述
pre_transient_{$transient} 是一个 WordPress 过滤器钩子,用于在获取现有瞬态值之前过滤其值。通过此钩子,开发者可以拦截瞬态的检索过程,并返回自定义值以替代原始值。
关键要点
- 这是一个动态钩子,钩子名称中的 $transient 部分对应瞬态名称。
- 从过滤器返回非 false 的值将短路瞬态的检索,直接返回该值。
- 参数包括 $pre_transient(默认值,若瞬态不存在则返回)和 $transient(瞬态名称)。
- 常用于 get_transient() 函数中,位于 wp-includes/option.php 文件。
- 自 WordPress 2.8.0 版本引入,4.4.0 版本添加了 $transient 参数。
代码示例
$pre = apply_filters( "pre_transient_{$transient}", false, $transient );
原文内容
Filters the value of an existing transient before it is retrieved.
Description
The dynamic portion of the hook name, $transient, refers to the transient name.
Returning a value other than false from the filter will short-circuit retrieval and return that value instead.
Parameters
$pre_transientmixed-
The default value to return if the 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_transient_{$transient}", false, $transient );