add_option_update_handler()
云策文档标注
概述
add_option_update_handler() 是一个已弃用的 WordPress 函数,用于注册设置及其清理回调。自 3.0.0 版本起,建议使用 register_setting() 替代。
关键要点
- 函数已弃用:自 WordPress 3.0.0 起,add_option_update_handler() 被标记为弃用,应改用 register_setting()。
- 功能作用:注册一个设置组和选项名称,并可指定一个清理回调函数来验证和清理选项值。
- 参数说明:接受三个参数:$option_group(设置组名称,如 'general')、$option_name(选项名称)和可选的 $sanitize_callback(清理回调函数)。
- 替代函数:内部调用 register_setting() 实现相同功能,确保向后兼容。
注意事项
在开发新代码时,应避免使用此函数,转而使用 register_setting() 以符合最新 WordPress 标准。
原文内容
Register a setting and its sanitization callback
Description
See also
Parameters
$option_groupstringrequired-
A settings group name. Should correspond to an allowed option key name.
Default allowed option key names include'general','discussion','media','reading','writing', and'options'. $option_namestringrequired-
The name of an option to sanitize and save.
$sanitize_callbackcallableoptional-
A callback function that sanitizes the option’s value.
Source
function add_option_update_handler( $option_group, $option_name, $sanitize_callback = '' ) {
_deprecated_function( __FUNCTION__, '3.0.0', 'register_setting()' );
register_setting( $option_group, $option_name, $sanitize_callback );
}
Changelog
| Version | Description |
|---|---|
| 3.0.0 | Deprecated. Use register_setting() |
| 2.7.0 | Introduced. |