Title: Sanitize Callback fallback
Last modified: June 6, 2017

---

# Sanitize Callback fallback

 *  Resolved [limbenjamin](https://wordpress.org/support/users/limbenjamin/)
 * (@limbenjamin)
 * [9 years ago](https://wordpress.org/support/topic/sanitize-callback-fallback/)
 * I am using the WP customizer to allow users to customise the html class of a 
   certain element. As required, I have added the sanitize callback to sanitize 
   user input. I would like the user to be able to set it to either a valid html
   class or an empty string. However, if an empty string is entered, wordpress will
   fail to save the customization. How can I set the $fallback value in such a case?
 * $wp_customize->add_setting( ‘voce_social_icon_1’ , array(‘default’ => ‘fa-facebook’,‘
   sanitize_callback’ => ‘sanitize_html_class’,));
 * I am only having such problems with ‘sanitize_html_class’, ‘esc_url_raw’ happily
   accepts an empty string.
    -  This topic was modified 9 years ago by [limbenjamin](https://wordpress.org/support/users/limbenjamin/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years ago](https://wordpress.org/support/topic/sanitize-callback-fallback/#post-9207566)
 * Because of the way the setting save method is constructed, it’s impossible save
   an empty string that way. Perhaps you could save a special value when an empty
   string is desired, say “!empty!”. Make your own sanitize callback that uses sanitize_html_class()
   when a value is not empty. In the case of empty values, return “!empty!”. Then
   in whatever function utilizes this value for output, when “!empty!” is encountered,
   replace it with an empty string.
 * Another possible workaround is to again use your own sanitize callback that uses
   sanitize_html_class(). When an empty string is passed, your callback could explicitly
   save the value in the DB by some other method than the setting object’s save 
   method. Then go ahead and return the empty string, which will cause the object’s
   save method to abort, leaving what you explicitly saved intact.
 * To save such a value, you’ll need to first retrieve the entire array of values,
   alter this one thing, then save the entire array back.
 *  Thread Starter [limbenjamin](https://wordpress.org/support/users/limbenjamin/)
 * (@limbenjamin)
 * [9 years ago](https://wordpress.org/support/topic/sanitize-callback-fallback/#post-9216818)
 * Thanks. Have updated my theme with my own callback function that uses sanitize_html_class().

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Sanitize Callback fallback’ is closed to new replies.

## Tags

 * [HTML class](https://wordpress.org/support/topic-tag/html-class/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 2 participants
 * Last reply from: [limbenjamin](https://wordpress.org/support/users/limbenjamin/)
 * Last activity: [9 years ago](https://wordpress.org/support/topic/sanitize-callback-fallback/#post-9216818)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
