{"id":4505,"date":"2018-02-10T17:11:19","date_gmt":"2018-02-10T16:11:19","guid":{"rendered":"https:\/\/florianbrinkmann.com\/en\/?p=4505"},"modified":"2020-02-09T11:29:12","modified_gmt":"2020-02-09T10:29:12","slug":"validating-customize-settings-with-displaying-error-messages","status":"publish","type":"post","link":"https:\/\/florianbrinkmann.com\/en\/validating-customize-settings-with-displaying-error-messages-4505\/","title":{"rendered":"Validating customize settings with displaying error messages"},"content":{"rendered":"
Since WordPress 4.6 it is relatively simple to add validation to customize settings, to give helpful error messages to the user. Here I show you how that works.<\/p>\n\n\n\n\n\n\n\n
There are three ways to add validation:<\/p>\n\n\n\n
validate_callback<\/code> when registering a setting.<\/li>- By using the
sanitize_callback<\/code> of a setting.<\/li>- By creating a custom
validate<\/code> method of the WP_Customize_Setting<\/code> class.<\/li><\/ol>\n\n\n\n