我尝试了您在上面共享的代码,似乎一切都正常工作。
是否确实为控件正确创建和引用了清理方法?
下面是添加到函数的完整代码。我使用的php:
function test_sanitize_text( $input ) {
$allowed_html = array(
\'br\' => array(),
);
return wp_kses( $input, $allowed_html );
}
function test_customizer( $wp_customize ) {
$wp_customize->add_setting( \'themeslug_text_setting_id\', array(
\'capability\' => \'edit_theme_options\',
\'default\' => \'Lorem Ipsum\',
\'sanitize_callback\' => \'test_sanitize_text\',
) );
$wp_customize->add_control( \'themeslug_text_setting_id\', array(
\'type\' => \'text\',
\'section\' => \'title_tagline\', // Add a default or your own section
\'label\' => __( \'Custom Text\' ),
\'description\' => __( \'This is a custom text box.\' ),
) );
}
我转到customizer to site identity部分,其中添加了输入和以下代码,并保存了customizer:
<div class="htmls"><p>testing</p><br><br><p>another</p></div>
的结果值$mod = get_theme_mod( \'themeslug_text_setting_id\' );
:
string(22) "testing<br><br>another"