I have a theme on review, and I do add section 'type'=> 'select' on few occasions like this.

$wp_customize->add_setting( 'personal_lite_post_link', array(
        'default' => 'enable',
        'sanitize_callback' => 'personal_lite_select_callback'
    ) );
    $wp_customize->add_control('postlink-options', array(
        'label' => esc_html__('Post navigation', 'personal-lite'),
        'section' => 'personal_lite_post', 
        'settings' => 'personal_lite_post_link',
        'type' => 'select', 
        'choices' => array('enable' => esc_html__('Enable', 'personal-lite'), 'disable' => esc_html__('Disable', 'personal-lite'))
    ) );

and sanitizing like this

function personal_lite_select_callback($input) {
    $valid = array(
        'lightslategrey' => esc_html__('Grey', 'personal-lite'),
        'seagreen' => esc_html__('Green', 'personal-lite'),
        'enable' => esc_html__('Enable', 'personal-lite'),
        'disable' => esc_html__('Disable', 'personal-lite'),
    if (array_key_exists($input, $valid)) {
        return $input;
    } else {
        return '';

Now reviewer asks to break the sanitize into two functions? how to do that?

Here is the exact word from reviewer.

I'm a fan of whitelisting for sanitization. However, this function should be broken into two separate functions:

Only some settings can have some of those keys. Make sure the setting is valid by using the appropriate whitelist function for that setting.

How can solve this? please help me.


Honestly for the select field it's not so important what the choices are for sanitizing the field and in fact what you are doing I don't believe is a good idea if a user wants to filter your settings to add new options to the select field. More importantly you are looking to sanitize the output which is a string value. So using wp_strip_all_tags or even esc_html for the sanitize callback I believe would be best. Your input will still be sanitized for malicious code but also allow for easier tweaking via a child theme.

But in terms of what your reviewer is telling you is most likely you are using the personal_lite_select_callback function for multiple select options in the customizer some which have different values so they want you to make a new function for each.

  • That's awsome Clarke! You are right, I'm using that function on various places. Now it makes sense, going to edit as you said. – Ponvendhan Mar 5 '17 at 4:46
  • Great! Good luck with your theme ;) Don't forget to upvote if I was helpful 8-) ~ AJ – WPExplorer Mar 6 '17 at 0:06
  • Oh, you know who I am - wow, I feel famous, lol. – WPExplorer Mar 6 '17 at 0:07
  • 1
    Of course you are famous. I learned a lot from you, Your contribution to the WordPress community is awesome. – Ponvendhan Mar 10 '17 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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