pre_wp_load_alloptions
云策文档标注
概述
pre_wp_load_alloptions 是一个 WordPress 过滤器,用于在 wp_load_alloptions() 函数填充所有选项数组之前进行干预。开发者可以通过此 Hook 修改或替换默认的 alloptions 数组,从而优化性能或自定义选项加载行为。
关键要点
- pre_wp_load_alloptions 过滤器在 wp_load_alloptions() 执行前触发,允许开发者拦截并返回自定义的 alloptions 数组。
- 如果过滤器返回一个数组,将直接跳过 wp_load_alloptions() 的正常执行流程,使用该数组作为结果。
- 过滤器接受两个参数:$alloptions(默认为 null)和 $force_cache(默认为 false),用于控制缓存行为。
- 此 Hook 从 WordPress 6.2.0 版本开始引入,适用于需要精细控制选项加载的场景。
代码示例
$alloptions = apply_filters( 'pre_wp_load_alloptions', null, $force_cache );注意事项
- 使用此过滤器时需谨慎,因为返回自定义数组可能影响其他插件或主题的正常运行。
- 确保返回的数组格式与 WordPress 预期的 alloptions 结构一致,以避免潜在错误。
原文内容
Filters the array of alloptions before it is populated.
Description
Returning an array from the filter will effectively short circuit wp_load_alloptions() , returning that value instead.
Parameters
$alloptionsarray|null-
An array of alloptions. Default null.
$force_cachebool-
Whether to force an update of the local cache from the persistent cache. Default false.
Source
$alloptions = apply_filters( 'pre_wp_load_alloptions', null, $force_cache );
Changelog
| Version | Description |
|---|---|
| 6.2.0 | Introduced. |