函数文档

update_site_option()

💡 云策文档标注

概述

update_site_option() 函数用于更新当前网络中已存在的选项值,是 update_network_option() 的包装函数,适用于多站点环境。

关键要点

  • 函数更新网络级别的选项值,参数 $option 和 $value 无需 SQL 转义
  • 返回布尔值:更新成功返回 true,否则返回 false
  • 从 WordPress 4.4.0 起,此函数改为 update_network_option() 的包装,数据存储在 sitemeta 表而非站点选项表
  • 仅在多站点启用时有效,否则调用 update_option()

代码示例

function update_site_option( $option, $value ) {
    return update_network_option( null, $option, $value );
}

注意事项

  • 函数名可能引起误解,实际操作网络元数据表,需注意多站点环境下的数据存储位置
  • 使用前应检查 is_multisite() 以确保功能适用性

📄 原文内容

Updates the value of an option that was already added for the current network.

Description

See also

Parameters

$optionstringrequired
Name of the option. Expected to not be SQL-escaped.
$valuemixedrequired
Option value. Expected to not be SQL-escaped.

Return

bool True if the value was updated, false otherwise.

Source

function update_site_option( $option, $value ) {
	return update_network_option( null, $option, $value );
}

Changelog

Version Description
4.4.0 Modified into wrapper for update_network_option()
2.8.0 Introduced.

User Contributed Notes