manager->get_control( $setting->id )->choices; // If the input is a valid key, return it; otherwise, return the default. return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); } } if ( ! function_exists( 'bansta_sanitize_number_range') ) { function bansta_sanitize_number_range( $input, $setting ) { // 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; } } /* Sanitize Google Fonts */ if ( ! function_exists( 'bansta_sanitize_google_fonts') ) { function bansta_sanitize_google_fonts( $input, $setting ) { // Get list of choices from the control associated with the setting. $choices = $setting->manager->get_control( $setting->id )->choices; // If the input is a valid key, return it; otherwise, return the default. return array_key_exists( $input, $choices ) ? $input : $setting->default; } } //Sanitize float value if ( ! function_exists( 'bansta_sanitize_float') ) { function bansta_sanitize_float( $input ) { return filter_var($input, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); } } if ( ! function_exists( 'bansta_sanitize_file') ) { function bansta_sanitize_file( $file, $setting ) { //Allowd file types $mimes = [ 'jpg|jpeg|jpe' => 'image/jpeg', 'png' => 'image/png' ]; //Check file type from file name $file_ext = wp_check_filetype( $file, $mimes ); //If file has a valid mime return return ( $file_ext['ext'] ? $file : $setting->default ); } } /** * Sanitize colors. * * @since 1.0.0 * @param string $value The color. * @return string */ if ( ! function_exists( 'bansta_sanitize_color') ) { function bansta_sanitize_color( $value ) { // This pattern will check and match 3/6/8-character hex, rgb, rgba, hsl, & hsla colors. $pattern = '/^(\#[\da-f]{3}|\#[\da-f]{6}|\#[\da-f]{8}|rgba\(((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*,\s*){2}((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*)(,\s*(0\.\d+|1))\)|hsla\(\s*((\d{1,2}|[1-2]\d{2}|3([0-5]\d|60)))\s*,\s*((\d{1,2}|100)\s*%)\s*,\s*((\d{1,2}|100)\s*%)(,\s*(0\.\d+|1))\)|rgb\(((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*,\s*){2}((\d{1,2}|1\d\d|2([0-4]\d|5[0-5]))\s*)|hsl\(\s*((\d{1,2}|[1-2]\d{2}|3([0-5]\d|60)))\s*,\s*((\d{1,2}|100)\s*%)\s*,\s*((\d{1,2}|100)\s*%)\))$/'; \preg_match( $pattern, $value, $matches ); // Return the 1st match found. if ( isset( $matches[0] ) ) { if ( is_string( $matches[0] ) ) { return $matches[0]; } if ( is_array( $matches[0] ) && isset( $matches[0][0] ) ) { return $matches[0][0]; } } // If no match was found, return an empty string. return ''; } } //script input sanitization function if ( ! function_exists( 'bansta_sanitize_js_code') ) { function bansta_sanitize_js_code($input){ return $input; } } //output escape function if ( ! function_exists( 'bansta_escape_js_output' ) ) { function bansta_escape_js_output($input){ return esc_textarea( $input ); } }