Getting Add Setting Error message while adding the control in customizer.
-
Hi,
Recently I tried creating a theme using a wordpress customizer feature. Everything has worked all fine. Yesterday i thought of checking the theme via ‘theme check’ plugin and found out i had following error message.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.Rather than using the straight forward process of adding the controls and settings, I added them using array and loops (Following code might clarify what I am talking about.) Has this process got something to do with the error message I am receiving. I have added the sanitization function and it’s functioning too. Although I don’t get why the sanitization error is being displayed. I would appreciate any kind of help you can provide on this matter.
<?php /** * Mytheme Theme Customizer * * @package Mytheme */ /** * Add postMessage support for site title and description for the Theme Customizer. * * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ function mytheme_customize_register( $wp_customize ) { $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; $controls = array( 'top_section_bg_color' => array( 'id' => 'top_section_bg_color', 'args' => array( 'label' => __('Top Section Color', 'mytheme'), 'section' => 'general_section', 'type' => 'text', 'priority' => 1 ) ) ); $settings = array( 'top_section_bg_color' => array( 'id'=> 'top_section_bg_color', 'args' => array( 'default' => '#FFFFFF', 'sanitize_callback' => 'mytheme_sanitize_text' ) ) ); $sections = array( 'general_section' => array( 'id' => 'general_section', 'args' => array( 'title' => __('General Settings', 'mytheme'), 'description' => __('General Setting Configurations', 'mytheme'), 'priority' => 1, 'capability' => 'edit_theme_options', 'theme_supports' => '', ) ) ); foreach($settings as $setting) : $wp_customize->add_setting($setting['id'],$setting['args']); endforeach; foreach($sections as $section) : $wp_customize->add_section($section['id'], $section['args']); endforeach; foreach($controls as $control) : $wp_customize->add_control($control['id'], $control['args']); endforeach; function mytheme_sanitize_text($input) { return esc_attr($input); } } add_action( 'customize_register', 'mytheme_customize_register' ); /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function mytheme_customize_preview_js() { wp_enqueue_script( 'mytheme_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true ); } add_action( 'customize_preview_init', 'mytheme_customize_preview_js' );Thanks,
The topic ‘Getting Add Setting Error message while adding the control in customizer.’ is closed to new replies.