Title: sanitize callback
Last modified: March 11, 2017

---

# sanitize callback

 *  [zipal](https://wordpress.org/support/users/zipal/)
 * (@zipal)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/sanitize-callback/)
 * Hello there!
    I have created my own WordPress theme from scratch. And yesterday
   When i was uploading on WordPress. It says “REQUIRED: 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.” But I already 
   have sanitize callback in each add_setting(). For example.. 1. $wp_customize-
   >add_setting(‘link_color’, array( ‘default’ => ‘#0078d7’, ‘transport’ => ‘refresh’,‘
   sanitize_callback’ => ‘phoenix_sanitize_hex_color’, ));
 * And it’s handler
    function phoenix_sanitize_hex_color($color) { if ($unhashed
   = sanitize_hex_color_no_hash($color)) return ‘#’ . $unhashed; return $color; }
   2. similarly for checkbox 3. $wp_customize->add_setting( ‘phoenix_logo’, array(‘
   default’ => ”, ‘capability’ => ‘edit_theme_options’, ‘sanitize_callback’ => ‘
   esc_url_raw’, )); I have read a thread that says. If you define a default value
   as a variable and then you have to make a variable and then use it in add_settings.
   But I don’t think so! Please help me!
    -  This topic was modified 9 years, 8 months ago by [zipal](https://wordpress.org/support/users/zipal/).

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

 *  [djpacmansd](https://wordpress.org/support/users/djpacmansd/)
 * (@djpacmansd)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/sanitize-callback/#post-8529046)
 * New myself but just looking at your code in the if statement:
 *     ```
       function phoenix_sanitize_hex_color($color) {
       if ($unhashed = sanitize_hex_color_no_hash($color)) 
       return ‘#’ . $unhashed;
       return $color;
       }
       ```
   
 * Your operator `=` is defining variable `$unhashed` to `sanitize_hex_color_no_hash(
   $color)` instead of checking a condition. If I remember correctly on php syntax
   to compare and see if two values are the same you’d have to use `==`. Lastly 
   I think you’re also missing an open curly brace in your if statement.
 * So I would try to write the code using that like this:
 *     ```
       function phoenix_sanitize_hex_color( $color ) {
       if ( $unhashed == sanitize_hex_color_no_hash( $color ) ) {
       return ‘#’ . $unhashed;
       return $color;
       }
       ```
   
 * If you really want to get specific you can compare the value and data type (string,
   integer, boolean) by using `===`
 * Let me know if that works.
    -  This reply was modified 9 years, 5 months ago by [djpacmansd](https://wordpress.org/support/users/djpacmansd/).
      Reason: error
 *  Thread Starter [zipal](https://wordpress.org/support/users/zipal/)
 * (@zipal)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/sanitize-callback/#post-8529059)
 * [@djpacmansd](https://wordpress.org/support/users/djpacmansd/) Thanks for the
   reply.
    Bye the way, I already figured out the problem, and already published
   the theme, and it’s in the queue. Cheers!
    -  This reply was modified 9 years, 5 months ago by [zipal](https://wordpress.org/support/users/zipal/).
 *  Plugin Author [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [9 years, 5 months ago](https://wordpress.org/support/topic/sanitize-callback/#post-8530468)
 * [@djpacmansd](https://wordpress.org/support/users/djpacmansd/) That probably 
   isn’t the issue, it’s not looking that deeply at the code.
 * [@zipal](https://wordpress.org/support/users/zipal/) If you could post the answer,
   it might help others with the same problem.
 *  Thread Starter [zipal](https://wordpress.org/support/users/zipal/)
 * (@zipal)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/sanitize-callback/#post-8588062)
 * hello guys [@otto42](https://wordpress.org/support/users/otto42/), [@djpacmansd](https://wordpress.org/support/users/djpacmansd/)!
   
   I’ve used another approach to solve the issue! Here it is
 *     ```
       $defaultlink_color = '0078d7';
       		$wp_customize->add_setting('link_color', array(
       		'default' 	=> $defaultlink_color,
       		'transport' => 'refresh',
       		'sanitize_callback' => 'sanitize_hex_color',
       ));
       ```
   
 * and for checkbox
 *     ```
       $wp_customize->add_setting( 'scroll_top', array(
       		'default'           => 1,
       		'transport' 		=> 'refresh',
       		'sanitize_callback' => 'sanitize_checkbox',
       ) );
       ```
   
 * And sorry for late reply!
    Thank You!

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

The topic ‘sanitize callback’ is closed to new replies.

 * ![](https://ps.w.org/theme-check/assets/icon-128x128.png?rev=972579)
 * [Theme Check](https://wordpress.org/plugins/theme-check/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/theme-check/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/theme-check/)
 * [Active Topics](https://wordpress.org/support/plugin/theme-check/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/theme-check/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/theme-check/reviews/)

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * 5 replies
 * 4 participants
 * Last reply from: [Marvin Kome](https://wordpress.org/support/users/marvinkome/)
 * Last activity: [9 years, 2 months ago](https://wordpress.org/support/topic/sanitize-callback/#post-8901928)
 * Status: not resolved