0

I have added a new setting to customizer.php

$wp_customize->add_setting( 'understrap_footer_text', array(
        'default'           => 'Copyright © 2017' ,
        'type'              => 'theme_mod',
        'sanitize_callback' => 'sanitize_textarea_field',
        'capability'        => 'edit_theme_options',
    ) );
        $wp_customize->add_control(
        new WP_Customize_Control(
            $wp_customize,
            'understrap_footer_text', array(
                'label'       => __( 'Footer Text', 'understrap' ),
                'description' => __( "No HTML", 'understrap'),
                'section'     => 'understrap_theme_post_options',
                'settings'    =>  'understrap_footer_text',
                'type'        => 'textarea',
                'priority'    => '10',
            )
        ) );

Theme Check Plugin error: REQUIRED: Found a Customizer setting that did not have a sanitization callback function. Every call to the add_setting() method needs to have a sanitization callback function passed.

When I remove © from default text of add_setting(), it shows no error.

Decimal code © won't work too.

I need to show the © symbol, is there any way I can make this work?

2
  • 3
    This seems to be an issue with the Theme Check plugin and you should take it up with the author. If you're worried about your theme not passing review because of this I'm sure that pointing out that it's an issue with the plugin would be sufficient. – Jacob Peattie Mar 28 '18 at 4:48
  • @JacobPeattie I'm not sure I would consider the Theme Check plugin entirely third-party, as it's pretty much recommended in order to submit a theme to the wordpress.org repository. The particular error is also pointing out a specific issue with the way the WordPress funciton add_setting() was used. – Tim Malone Apr 4 '18 at 4:29
1

You need to make sure that you have the call back function to handle your sanitization.

$wp_customize->add_setting( 'understrap_footer_text', array(
        'default'           => 'Copyright © 2017' ,
        'type'              => 'theme_mod',
        'sanitize_callback' => 'sanitize_textarea_field',
        'capability'        => 'edit_theme_options',
    ) );

So you need a function like this

/**
 * [sanitize_html description]
 * @param  [string] $input [input from textarea]
 * @return [string]        [sanitize all input no tags]
 */
function sanitize_textarea_field( $input ) {
    return wp_strip_all_tags( $input );
}
3
  • ; will not break an array when inside a string in regular PHP. If the Theme Check plugin is not actually running the PHP and just parsing the test of the PHP files then this might trip it up if it doesn't account for the possibility. This is still an issue with the Theme Check plugin. – Jacob Peattie Mar 28 '18 at 9:29
  • I fixed this by assigning the default value to another variable and then doing 'default' => $variable. – Rohan Sharma Mar 28 '18 at 13:35
  • You can also set it up for translation by using __( 'Copyright © 2017', theme-slug ), or __( $your_variable, theme-slug), – DevTurtle Mar 29 '18 at 5:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.