default ); } /** * HTML sanitization callback example. * * - Sanitization: html * - Control: text, textarea * * Sanitization callback for 'html' type text inputs. This callback sanitizes `$html` * for HTML allowable in posts. * * NOTE: wp_filter_post_kses() can be passed directly as `$wp_customize->add_setting()` * 'sanitize_callback'. It is wrapped in a callback here merely for example purposes. * * @see wp_filter_post_kses() https://developer.wordpress.org/reference/functions/wp_filter_post_kses/ * * @param string $html HTML to sanitize. * @return string Sanitized HTML. */ function artech_sanitize_html( $html ) { return wp_kses_post( force_balance_tags( $html ) ); } /** * Image sanitization callback example. * * Checks the image's file extension and mime type against a whitelist. If they're allowed, * send back the filename, otherwise, return the setting default. * * - Sanitization: image file extension * - Control: text, WP_Customize_Image_Control * * @see wp_check_filetype() https://developer.wordpress.org/reference/functions/wp_check_filetype/ * * @param string $image Image filename. * @param WP_Customize_Setting $setting Setting instance. * @return string The image filename if the extension is allowed; otherwise, the setting default. */ function artech_sanitize_image( $image, $setting ) { /* * Array of valid image file types. * * The array includes image mime types that are included in wp_get_mime_types() */ $mimes = array( 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' => 'image/tiff', 'ico' => 'image/x-icon' ); // Return an array with file extension and mime_type. $file = wp_check_filetype( $image, $mimes ); // If $image has a valid mime_type, return it; otherwise, return the default. return ( $file['ext'] ? $image : $setting->default ); } /** * No-HTML sanitization callback example. * * - Sanitization: nohtml * - Control: text, textarea, password * * Sanitization callback for 'nohtml' type text inputs. This callback sanitizes `$nohtml` * to remove all HTML. * * NOTE: wp_filter_nohtml_kses() can be passed directly as `$wp_customize->add_setting()` * 'sanitize_callback'. It is wrapped in a callback here merely for example purposes. * * @see wp_filter_nohtml_kses() https://developer.wordpress.org/reference/functions/wp_filter_nohtml_kses/ * * @param string $nohtml The no-HTML content to sanitize. * @return string Sanitized no-HTML content. */ function artech_sanitize_nohtml( $nohtml ) { return wp_filter_nohtml_kses( $nohtml ); } /** * Number sanitization callback example. * * - Sanitization: number_absint * - Control: number * * Sanitization callback for 'number' type text inputs. This callback sanitizes `$number` * as an absolute integer (whole number, zero or greater). * * NOTE: absint() can be passed directly as `$wp_customize->add_setting()` 'sanitize_callback'. * It is wrapped in a callback here merely for example purposes. * * @see absint() https://developer.wordpress.org/reference/functions/absint/ * * @param int $number Number to sanitize. * @param WP_Customize_Setting $setting Setting instance. * @return int Sanitized number; otherwise, the setting default. */ function artech_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 ); } /** * Select sanitization callback example. * * - Sanitization: select * - Control: select, radio * * Sanitization callback for 'select' and 'radio' type controls. This callback sanitizes `$input` * as a slug, and then validates `$input` against the choices defined for the control. * * @see sanitize_key() https://developer.wordpress.org/reference/functions/sanitize_key/ * @see $wp_customize->get_control() https://developer.wordpress.org/reference/classes/wp_customize_manager/get_control/ * * @param string $input Slug to sanitize. * @param WP_Customize_Setting $setting Setting instance. * @return string Sanitized slug if it is a valid choice; otherwise, the setting default. */ function artech_sanitize_select( $input, $setting ) { // Ensure input is a slug. $input = sanitize_key( $input ); // 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 ); } /** * URL sanitization callback example. * * - Sanitization: url * - Control: text, url * * Sanitization callback for 'url' type text inputs. This callback sanitizes `$url` as a valid URL. * * NOTE: esc_url_raw() can be passed directly as `$wp_customize->add_setting()` 'sanitize_callback'. * It is wrapped in a callback here merely for example purposes. * * @see esc_url_raw() https://developer.wordpress.org/reference/functions/esc_url_raw/ * * @param string $url URL to sanitize. * @return string Sanitized URL. */ function artech_sanitize_url( $url ) { return esc_url_raw( $url ); } /* Sanitization Text*/ function artech_sanitize_text( $text ) { return wp_filter_post_kses( $text ); } /* Sanitization Integer*/ function artech_sanitize_integer( $input ) { if( is_numeric( $input ) ) { return intval( $input ); } } // Sanitize Sortable control. function artech_sanitize_sortable( $val, $setting ) { if ( is_string( $val ) || is_numeric( $val ) ) { return array( esc_attr( $val ), ); } $sanitized_value = array(); foreach ( $val as $item ) { if ( isset( $setting->manager->get_control( $setting->id )->choices[ $item ] ) ) { $sanitized_value[] = esc_attr( $item ); } } return $sanitized_value; } // Sanitize Font control. function artech_sanitize_typography_fonts( $input ) { $standard = artech_font_selector_get_standard_fonts(); $google = artech_font_selector_get_google_fonts_array(); $fonts = array_flip( array_merge( $standard, $google ) ); return ( array_key_exists( $input, $fonts ) ? $input : '' ); }