通过更改sanitize_callback
返回整数值的自定义函数的值:
$wp_customize->add_section( \'range\', array (
\'title\' => __( \'Range\', \'textdomain\' ),
\'priority\' => 45,
) );
$wp_customize->add_setting( \'range_field_id1\', array(
\'default\' => \'\',
\'type\' => \'theme_mod\',
\'capability\' => \'edit_theme_options\',
\'transport\' => \'\',
\'sanitize_callback\' => \'wpse_intval\',
) );
$wp_customize->add_control( \'range_field_id1\', array(
\'type\' => \'range\',
\'priority\' => 10,
\'section\' => \'range\',
\'label\' => __( \'Range Field\', \'textdomain\' ),
\'description\' => \'\',
\'input_attrs\' => array(
\'min\' => 1,
\'max\' => 100,
\'step\' => 1,
\'class\' => \'example-class\',
\'style\' => \'color: #ff0022\',
),
));
我定义了简单
wpse_intval()
自定义程序类之外的函数:
function wpse_intval( $value ) {
return (int) $value;
}
我使用了原始问题中发布的相同代码来显示保存的值:
$content_mod = get_theme_mod(\'range_field_id1\');
var_dump( $content_mod );
在这一点上,我不确定为什么会发生这种情况,因为
intval()
看起来应该有用。
迷你注意事项:Customizer Dev Tools 插件是一个方便的故障排除工具。