钩子文档

pre_site_option

💡 云策文档标注

概述

pre_site_option 是一个 WordPress 过滤器钩子,用于在获取网络选项值之前修改其值。通过返回非 false 的值,可以短路检索过程并直接返回该值。

关键要点

  • pre_site_option 过滤器允许在 get_network_option() 函数中拦截和修改网络选项的检索值。
  • 返回非 false 的值将短路选项检索,直接返回该值,否则继续正常流程。
  • 参数包括 $pre(要返回的值,默认为 false)、$option(选项名)、$network_id(网络ID)和 $default_value(默认回退值)。
  • 该钩子从 WordPress 6.9.0 版本开始引入。

代码示例

$pre = apply_filters( 'pre_site_option', $pre, $option, $network_id, $default_value );

注意事项

  • $pre 参数与 $default_value 不同:$pre 用于短路返回,而 $default_value 仅在选项不存在时作为回退值使用。
  • 确保在开发中正确处理返回值,以避免意外覆盖选项值。

📄 原文内容

Filters the value of any existing network 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 network 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_network_option() .
Default false (to skip past the short-circuit).
$optionstring
Name of the option.
$network_idint
ID of the network.
$default_valuemixed
The fallback value to return if the option does not exist.
Default false.

Source

$pre = apply_filters( 'pre_site_option', $pre, $option, $network_id, $default_value );

Changelog

Version Description
6.9.0 Introduced.