register_setting()

注册设置及其数据。

register_setting( string $option_group , string $option_name , array $args = array() )

参数(Parameters)

参数类型必填说明
$option_group(string)必需设置组名。应与白名单选项键名称相对应。默认白名单选项键名称包括“常规”、“讨论”、“媒体”、“读取”、“写入”、“杂项”、“选项”和“隐私”。
$option_name(string)必需要清理和保存的选项的名称。
$args(array)可选用于描述注册时设置的数据type’(string)与此设置关联的数据类型。有效值为“string”、“boolean”、“integer”、“number”、“array”和“object”。
“description”(string) 附加到此设置的数据的说明。“sanitize_callback”(callable)一个回调函数,用于清理选项的值。可选调用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.0wp-includes/option.php:211627
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索