• 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 8 years, 6 months ago by zipal.
Viewing 4 replies - 1 through 4 (of 4 total)
  • 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 8 years, 3 months ago by djpacmansd. Reason: error
    Thread Starter zipal

    (@zipal)

    @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 8 years, 3 months ago by zipal.
    Plugin Author Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    @djpacmansd That probably isn’t the issue, it’s not looking that deeply at the code.

    @zipal If you could post the answer, it might help others with the same problem.

    Thread Starter zipal

    (@zipal)

    hello guys @otto42, @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.