// Source: https://github.com/WPTRT/code-examples/blob/master/customizer/sanitization-callbacks.php /** * Sanitization: number_range * Control: number, tel * * Sanitization callback for 'number' or 'tel' type text inputs. This * callback sanitizes $input as an absolute integer within a defined * min-max range. * * @uses absint() https://developer.wordpress.org/reference/functions/absint/ * @link is_int() http://php.net/manual/en/function.is-int.php */ function theme_slug_sanitize_number_range( $input ) { // Ensure input is an absolute integer $input = absint( $input ); // Get the input attributes // associated with the setting $atts = $setting->manager->get_control( $setting->id )->input_attrs; // Get min $min = ( isset( $atts['min'] ) ? $atts['min'] : $input ); // Get max $max = ( isset( $atts['max'] ) ? $atts['max'] : $input ); // Get Step $step = ( isset( $atts['step'] ) ? $atts['step'] : 1 ); // If the input is within the valid range, // return it; otherwise, return the default return ( $min <= $input && $input <= $max && is_int( $input / $step ) ? $input : $setting->default ); }