I added a section to the customizer of my WP theme that allows a user to change which categories display on the first page of the theme. However, when checking with the Theme Check plugin, it returned the following error:
REQUIRED: Found a Customizer setting that did not have a sanitization callback function. Every call to the add_setting() method needs to have a sanitization callback function passed. I have no idea how to add this function to my code. If you can help, here’s the code:
Thanks in advance!
By default, the Customizer does not handle validation and sanitization of the user input values. It is therefore essential to sanitize these values before saving them to the database.
The add_setting() method of the WP_Customizer object accepts an 'sanitize_callback' argument, that can be used to specify a sanitization callback. So, in every add_setting() call, add the sanitization callback function.
The Sanitize callback function: