添加设置,指定sanitize_callback
:
$wp_customize->add_setting(
\'my_input\',
array(
\'default\' => \'100.00\',
\'sanitize_callback\' => \'sanitize_float\',
)
);
添加控件:
$wp_customize->add_control(
\'my_input\',
array(
\'label\' => \'Please enter a number:\',
\'section\' => \'my_section\',
\'type\' => \'number\',
\'input_attrs\' => array(
\'min\' => \'0.01\', \'step\' => \'0.01\', \'max\' => \'10000\',
),
)
);
创建执行消毒的功能-
filter_var
应返回经过消毒的浮子或
false
:
function sanitize_float( $input ) {
return filter_var($input, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
}
这是未经测试的,但应该让您开始-当然,它可以调整为清理整数。
[改编自http://themefoundation.com/wordpress-theme-customizer/]