Trouvé un paramètre de personnalisation qui n’avait pas de fonction de rappel de désinfection. plugin de vérification de thème wordpress

Publié par Jean-Michel le

J’ai ajouté 'sanitize_callback'à chaque fonction add_setting() mais cela affiche toujours l’erreur. S’il vous plaît n’importe qui Vérifiez mon extrait de code et donnez-moi une 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' );

Merci d’avance

Solution n°1 trouvée

installez le plugin de vérification de thème puis modifiez le fichier plugins/theme-check/checks/customizer.php

ajouterecho "$file_path: $match ";

Après cette section de 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' );`

Cela devrait indiquer le fichier et le fragment de code à l’origine de l’erreur.

Solution n°2 trouvée

J’ai une nouvelle solution si le problème ci-dessus

'sanitize_callback' => 'esc_attr',

Ensuite, après avoir vérifié le thème sur le vérificateur de thème, je ne peux pas obtenir d’erreur là-bas, j’espère aider quelqu’un.

Solution n°3 trouvée

Je sais que c’est peut-être très ancien pour commenter, mais je pense que la réponse sera:

'sanitize_callback' => 'sanitize_hex_color',

J’espère que cela aidera quelqu’un d’autre. bon codage 🙂

Catégories : Wordpress

Jean-Michel

Jean-Michel est en charge de la partie blog du site. Il met en place la stratégie de contenu et répond aux questions fréquentes sur Wordpress.

0 commentaire

Laisser un commentaire

Avatar placeholder

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *