Found a Customizer that didn't have a sanitation callback function. wordpress theme validator plugin

i added add_setting ()'sanitize_callback'

to each function but it still shows error. Please check my code snippet and give me a suggestion

function bookish_customize_register( $wp_customize ) {

$wp_customize->get_setting( 'blogname' )->transport        = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';

$wp_customize->remove_control( 'header_textcolor' );
$wp_customize->remove_control( 'background_color' );
$wp_customize->remove_section( 'background_image' );
$wp_customize->remove_section( 'header_image' );

/*-----------------------------------------------------------*
 * Assent Color  section
 *-----------------------------------------------------------*/ 

$wp_customize->add_setting(
    'tcx_link_color',
    array(
        'default'     => '#000000',
        'sanitize_callback' => 'bookish_sanitize_text',
        'transport'   => 'postMessage',

    )
);

$wp_customize->add_control(
    new WP_Customize_Color_Control(
        $wp_customize,
        'link_color',
        array(
            'label'      => __( 'Link Color', 'tcx' ),
            'section'    => 'colors',
            'settings'   => 'tcx_link_color'
        )
    )
);
/*-----------------------------------------------------------*
 * Defining General Setting  section
 *-----------------------------------------------------------*/

$wp_customize->add_section(
    'bookish_general_setting',
    array(
        'title'     => 'General Settings',
        'priority'  => 1

    )
);



$wp_customize->add_setting(
            'bookish-logo',
            array(
                'default' => '',
                'sanitize_callback' => 'esc_url_raw',
                'transport'   => 'postMessage',

            )
        );

$wp_customize->add_control(
    new WP_Customize_Image_Control(
        $wp_customize,
        'bookish-logo',
        array(
            'label'    => __( ' Logo', 'bookish' ),
            'section'  => 'bookish_general_setting',
            'settings' => 'bookish-logo',
            'priority' => 1

        )
    )
);

$wp_customize->add_setting(
        'bookish-retina-logo',
        array(
            'default' => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport'   => 'postMessage',
        )
    );

$wp_customize->add_control(
    new WP_Customize_Image_Control(
        $wp_customize,
        'bookish-retina-logo',
        array(
            'label'    => __( 'Retina Logo', 'bookish' ),
            'section'  => 'bookish_general_setting',
            'settings' => 'bookish-retina-logo',
            'priority' => 2

        )
    )
);

$wp_customize->add_setting(
    'bookish-favicon',
    array(
        'default'  => '',
        'sanitize_callback' => 'esc_url_raw',
        'transport'   => 'postMessage',

    )
);

$wp_customize->add_control(
    new WP_Customize_Image_Control(
        $wp_customize,
        'bookish-favicon',
        array(
            'label'    => __( ' Favicon', 'bookish' ),
            'section'  => 'bookish_general_setting',
            'settings' => 'bookish-favicon',
            'priority' => 3

        )
    )
);

$wp_customize->add_setting(
    'bookish-avatar',
    array(
        'default'          => '',
        'sanitize_callback' => 'esc_url_raw',
        'transport'   => 'postMessage',

    )
);

$wp_customize->add_control(
    new WP_Customize_Image_Control(
        $wp_customize,
        'bookish-avatar',
        array(
            'label'    => __( 'Avatar', 'bookish' ),
            'section'  => 'bookish_general_setting',
            'settings' => 'bookish-avatar',
            'priority' => 4
        )
    )
);

$wp_customize->add_setting(
    'bookish-retina-avatar',
    array(
        'default'          => '',
        'sanitize_callback' => 'esc_url_raw',
        'transport'   => 'postMessage',

    )
);

$wp_customize->add_control(
    new WP_Customize_Image_Control(
        $wp_customize,
        'bookish-retina-avatar',
        array(
            'label'    => __( 'Retina Avatar', 'bookish' ),
            'section'  => 'bookish_general_setting',
            'settings' => 'bookish-retina-avatar',
            'priority' => 5
        )
    )
);

$wp_customize->add_setting(
    'bookish_profile_name',
    array(
        'default'    =>  'Vincent Doe',
        'sanitize_callback' => 'bookish_sanitize_text',
        'transport'  =>  'postMessage',
    )
);

$wp_customize->add_control(
    'bookish_profile_name',
    array(
        'section'   => 'bookish_general_setting',
        'label'     => 'Profile Name',
        'type'      => 'text'
    )
);

$wp_customize->add_setting(
    'bookish_profile_desc',
    array(
        'default'    =>  'I lie close to the earth, a thousand unknown plants are noticed by me: when I hear the buzz of the little world among the stalks.',
        'sanitize_callback' => 'bookish_sanitize_textarea',
        'transport'  =>  'postMessage',

    )
);

$wp_customize->add_control(
    'bookish_profile_desc',
    array(
        'section'   => 'bookish_general_setting',
        'label'     => 'Profile Description',
        'type'      => 'textarea'
    )
);

$wp_customize->add_section(
    'contact_setting',
    array(
        'title'     => 'Contact Info',
        'priority'  => 2
    )
);

$wp_customize->add_setting(
    'contact_heading',
    array(
        'default'    =>  'Get in touch',
        'sanitize_callback' => 'bookish_sanitize_text',
        'transport'  =>  'postMessage',
    )
);

$wp_customize->add_control(
    'contact_heading',
    array(
        'section'   => 'contact_setting',
        'label'     => 'Contact Heading',
        'type'      => 'text'
    )
);

$wp_customize->add_setting(
    'contact_email',
    array(
        'default'    =>  '',
        'sanitize_callback' => 'bookish_sanitize_email',
        'transport'  =>  'postMessage',
    )
);

$wp_customize->add_control(
    'contact_email',
    array(
        'section'   => 'contact_setting',
        'label'     => 'Email',
        'type'      =>  'email'

    )
);

$wp_customize->add_setting(
    'contact_phone',
    array(
        'default'    =>  '',
        'sanitize_callback' => 'bookish_sanitize_number',
        'transport'  =>  'postMessage',
    )
);

$wp_customize->add_control(
    'contact_phone',
    array(
        'section'   => 'contact_setting',
        'label'     => 'Phone Number',
        'type'      => 'text'
    )
);

}

add_action( 'customize_register', 'bookish_customize_register', 11 );

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function bookish_customize_preview_js() {
    wp_enqueue_script( 'bookish_customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), '20130508', true );
}
add_action( 'customize_preview_init', 'bookish_customize_preview_js' );

function bookish_sanitize_text( $str ) {
    return sanitize_text_field( $str );
} 

function bookish_sanitize_textarea( $text ) {
    return esc_textarea( $text );
} 

function bookish_sanitize_number( $int ) {
    return absint( $int );
} 

function bookish_sanitize_email( $email ) {
    if(is_email( $email )){
        return $email;
    }else{
        return '';
    }
} 

function bookish_sanitize_file_url( $url ) {
    $output = '';
    $filetype = wp_check_filetype( $url );
    if ( $filetype["ext"] ) {
        $output = esc_url( $url );
    }
    return $output;
}

function tcx_customizer_css() {
?>
     <style type="text/css">

        .TopBanner { background-color: <?php echo get_theme_mod( 'tcx_link_color' ); ?>!important; }

     </style>
<?php
}
add_action( 'wp_head', 'tcx_customizer_css' );

      

Thanks in Advance

+3


source to share


3 answers


install the theme check plugin and then modify the plugins / theme-check / checks / customizer.php file

add echo "$file_path: $match ";

After this section of code:



`if ( false === strpos( $match, 'sanitize_callback' ) && false === strpos( $match, 'sanitize_js_callback' ) ) {
$this->error[] = '<span class="tc-lead tc-required">' .       __('REQUIRED','theme-check') . '</span>: ' . __( 'Found a Customizer setting that did not have a sanitization callback function. Every call to the <strong>add_setting()</strong> method needs to have a sanitization callback function passed.', 'theme-check' );`

      

This should point to the section of the file and code causing the error.

+2


source


I have a new solution if above problem

'sanitize_callback' => 'esc_attr',

      



Then after checking the topic on topic checker, I can't get any errors there I hope to help someone.

+3


source


You can add a callback to the __return_false function like

'sanitize_callback' => '__return_false'

      

and add a function to filter

 function __return_false_value($value) {
    return $value;
}

add_filter('__return_false', '__return_false_value');

      

-1


source







All Articles