Current Path : /home/theafprt/khurram.com/wp-content/themes/classic-portfolio/inc/ |
Current File : /home/theafprt/khurram.com/wp-content/themes/classic-portfolio/inc/sanitization-callbacks.php |
<?php /** * Customizer: Sanitization Callbacks * * This file demonstrates how to define sanitization callback functions for various data types. * * @package Classic Portfolio * @copyright Copyright (c) 2015, WordPress Theme Review Team * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, v2 (or newer) */ /** * Checkbox sanitization callback example. * * Sanitization callback for 'checkbox' type controls. This callback sanitizes `$checked` * as a boolean value, either TRUE or FALSE. * * @param bool $checked Whether the checkbox is checked. * @return bool Whether the checkbox is checked. */ function classic_portfolio_sanitize_checkbox( $checked ) { // Boolean check. return ( ( isset( $checked ) && true == $checked ) ? true : false ); } /** * HEX Color sanitization callback example. * * - Sanitization: hex_color * - Control: text, WP_Customize_Color_Control * * Note: sanitize_hex_color_no_hash() can also be used here, depending on whether * or not the hash prefix should be stored/retrieved with the hex color value. * * @see sanitize_hex_color() https://developer.wordpress.org/reference/functions/sanitize_hex_color/ * @link sanitize_hex_color_no_hash() https://developer.wordpress.org/reference/functions/sanitize_hex_color_no_hash/ * * @param string $hex_color HEX color to sanitize. * @param WP_Customize_Setting $setting Setting instance. * @return string The sanitized hex color if not null; otherwise, the setting default. */ function classic_portfolio_sanitize_hex_color( $hex_color, $setting ) { // Sanitize $input as a hex value without the hash prefix. $hex_color = sanitize_hex_color( $hex_color ); // If $input is a valid hex value, return it; otherwise, return the default. return ( ! is_null( $hex_color ) ? $hex_color : $setting->default ); } /*radio button sanitization*/ function classic_portfolio_sanitize_choices( $input, $setting ) { global $wp_customize; $control = $wp_customize->get_control( $setting->id ); if ( array_key_exists( $input, $control->choices ) ) { return $input; } else { return $setting->default; } } if ( ! function_exists( 'classic_portfolio_sanitize_integer' ) ) { function classic_portfolio_sanitize_integer( $input ) { return (int) $input; } } //sanitize number field function classic_portfolio_sanitize_number_absint( $number, $setting ) { // Ensure $number is an absolute integer (whole number, zero or greater). $number = absint( $number ); // If the input is an absolute integer, return it; otherwise, return the default return ( $number ? $number : $setting->default ); } function classic_portfolio_sanitize_select( $input, $setting ){ //input must be a slug: lowercase alphanumeric characters, dashes and underscores are allowed only $input = sanitize_key($input); //get the list of possible select options $choices = $setting->manager->get_control( $setting->id )->choices; //return input if valid or return default option return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); }