kirki icon indicating copy to clipboard operation
kirki copied to clipboard

Slider field not working for steps lower than 1

Open LuisAlejandre opened this issue 11 years ago • 2 comments

Hi, I´ve found that the sanitizing callback for the slider field doesn´t allow the use of steps smaller than 1 for the sliders (for instance: 'step' => .01).

The problem is that, in Fields.php, the fallback_callback function forces the use of the number sanitizing:

case 'slider' : $sanitize_callback = 'kirki_sanitize_number';

And, as can be seen in sanitize.php, that callback returns integers only:

function kirki_sanitize_number( $value ) { return ( is_int( $value ) || is_float( $value ) ) ? $value : intval( $value ); }

LuisAlejandre avatar Apr 17 '15 19:04 LuisAlejandre

I use slider control as opacity control, (min : 0 and max : 1) and I have the same problem. I have checked the code and I tried to debug it. but uncommon behavior is that on processing a float value (e.g. 0.83) both is_int & is_float functions return false. I have temporarily changed line 18 of sanitize.php to:

return (is_int($value) ? intval($value) : floatval($value));

and it works, but I'm not sure this is the correct approach.

DevelopOnline avatar Apr 18 '15 12:04 DevelopOnline

Since that would affect other fields instead of just the slider, what I´ve done in my case (also as a temporary fix) is modify line 551 of Fields.php, removing the sanitization for slider fields:

case 'slider' :
    // $sanitize_callback = 'kirki_sanitize_number';
    $sanitize_callback = 'kirki_sanitize_unfiltered';

LuisAlejandre avatar Apr 18 '15 12:04 LuisAlejandre