register_setting()
register_setting( string $option_group, string $option_name, array $args = array() )
注册设置及其数据。
Registers a setting and its data.
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$option_group | (string) | 必需 | 设置组名。应与白名单选项键名称相对应。默认白名单选项键名称包括“常规”、“讨论”、“媒体”、“读取”、“写入”、“杂项”、“选项”和“隐私”。 |
$option_name | (string) | 必需 | 要清理和保存的选项的名称。 |
$args | (array) | 可选 | 用于描述注册时设置的数据type’(string)与此设置关联的数据类型。有效值为“string”、“boolean”、“integer”、“number”、“array”和“object”。 |
‘description'(string) A description of the data attached to this setting. | ‘sanitize_callback’(callable) A callback function that sanitizes the option’s value. | 可选 | 调用get_option()时的“默认”(混合)默认值。 |
返回(Return)
无返回值
源码(Source)
/** * Register a setting and its sanitization callback * * @since 2.7.0 * * @global array $new_whitelist_options * * @param string $option_group A settings group name. Should correspond to a whitelisted option key name. * Default whitelisted option key names include "general," "discussion," and "reading," among others. * @param string $option_name The name of an option to sanitize and save. * @param callable $sanitize_callback A callback function that sanitizes the option's value. */ function register_setting( $option_group, $option_name, $sanitize_callback = '' ) { global $new_whitelist_options; if ( 'misc' == $option_group ) { _deprecated_argument( __FUNCTION__, '3.0', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'misc' ) ); $option_group = 'general'; } if ( 'privacy' == $option_group ) { _deprecated_argument( __FUNCTION__, '3.5', sprintf( __( 'The "%s" options group has been removed. Use another settings group.' ), 'privacy' ) ); $option_group = 'reading'; } $new_whitelist_options[ $option_group ][] = $option_name; if ( $sanitize_callback != '' ) add_filter( "sanitize_option_{$option_name}", $sanitize_callback ); }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
4.7.0 | wp-includes/option.php:2116 | 2 | 7 |
register_setting() 为WP2原创文章,链接:https://www.wp2.cn/functions/register_setting/