TUTORIALS, RESOURCES & NEWS As you may already know, with WordPress Customizer API theme developers are able to create settings for their themes which allow site owners to fine tune things like color scheme, background image and other custom options and see a preview of these changes in real time. Since we should never trust user input, the Customizer API requires to define a callback function for each setting to validate and sanitize input. Unfortunately I often run into the problem that I don't know or don't remember the proper WordPress sanitization function for a particular setting. That's why I created this tutorial. The following code examples below will demonstrate how to define sanitization callback functions for various data types. For order's sake, the codes also include the method to add a section and a setting in Theme Customizer. Jump to the code with a click: How to sanitize radio box How to sanitize checkbox How to sanitize select options How to sanitize text input and how to sanitize textarea If we want to allow simple text only, it's enough to call wp_filter_nohtml_kses() native function for sanitize_callback directly. How to sanitize email address How to sanitize
Share This