pre_option
云策文档标注
概述
pre_option 是一个 WordPress 过滤器,用于在获取任何现有选项值之前拦截并修改其值。通过返回非 false 的值,可以短路选项检索过程,直接返回该值。
关键要点
- 过滤器名称:pre_option
- 作用:在 get_option() 函数检索选项值之前过滤该值,允许开发者自定义返回结果
- 参数:$pre(要返回的值,默认为 false)、$option(选项名称)、$default_value(选项不存在时的回退值)
- 注意事项:返回非 false 值会短路选项检索,直接返回该值;这与 $default_value 不同,后者仅在选项不存在时使用
代码示例
$pre = apply_filters( 'pre_option', $pre, $option, $default_value );
原文内容
Filters the value of any existing option before it is retrieved.
Description
Returning a value other than false from the filter will short-circuit retrieval and return that value instead.
Parameters
$pre_optionmixed-
The value to return instead of the option value. This differs from
$default_value, which is used as the fallback value in the event the option doesn’t exist elsewhere in get_option() .
Default false (to skip past the short-circuit). $optionstring-
Name of the option.
$default_valuemixed-
The fallback value to return if the option does not exist.
Default false.
Source
$pre = apply_filters( 'pre_option', $pre, $option, $default_value );
Changelog
| Version | Description |
|---|---|
| 6.1.0 | Introduced. |