That’s exactly what the sanitize callback is for in the call to register_setting()
:
<?php register_setting( $option_group, $option_name, $sanitize_callback ); ?>
That third parameter, $sanitize_callback
, is a filter callback to which the user settings are passed after submitting the settings form, and before saving to the database.
The settings are passed as an array. The correct way to use the sanitize callback is to whitelist the settings: take the user input, sanitize/validate it, and return a sanitized, whitelisted array. That way, if unexpected data are passed, they are simply ignored. And if the user enters invalid or insecure data, those data are validated/sanitized.
To provide more specific direction, we’d need to know more specific information about the settings being saved.
Related Posts:
- How to pass arguments from add_settings_field() to the callback function?
- how to update serialized options programatically?
- Performance with autoload and the options table
- What’s the difference between Options & Settings?
- Add on the fly tabs to plugin options
- Settings API – changing add_settings_field() output?
- Confirmation before deleting plugin options via uninstall.php
- Set WordPress settings programmatically
- Fallback when Transient API fails
- Submenu pages delete settings from options array when saved
- get_option() from another wordpress site
- How can I get all user options?
- Settings API – save an array of options as one setting (array_push?)
- Add_settings_field() parameterizing callback?
- Set a Default Value for an Option?
- Serialized settings in rest api
- Save Theme Options (options.php) From The Frontend
- Can’t output do_settings_sections . Can’t understand why
- checkbox with get_option not working
- Settings API – how to update multiple options manually?
- Single callback with multiple setting fields
- Settings API – how to update options manually?
- How to change the file upload directory on version 3.5?
- Any way to partition wp_options?
- How do I add a value to a wp_options option that is an array?
- how can I detect that option value has changed?
- How to display some settings for super admin user only using Settings API
- Is there a limit to the number of options you can store in one settings field of wp_options?
- wp_user_roles and Advanced Manipulation
- Access general settings trough wordpress files
- get_option & update_option for multiple input fields with same name
- Settings API: Change position of custom setting field
- Can’t save options
- How to cache posts based on $_GET? Option name is too long? Options / transients
- Where is the submitted $_POST array stored after an option page submission?
- update a value in wp_options [closed]
- Insufficient permissions to save options
- Can we allow users to choose front page from theme options?
- How to display usermeta on front end of site
- save_post_{CPT} not updating the ‘sticky_posts’ option
- Settings API – Separating PHP and HTML
- Implementing action correctly
- Is there a capability for managing plugin options?
- How to create a drop down list with pages to a themes options page?
- Classes and functions involved in serialization and unserialization
- why is unregister_setting() undefined?
- options-general.php page displays different sitename, home compared to wp_options table
- Cannot save using register_setting
- How to create color scheme for my custom theme?
- Set $options reference
- problem with get_option in dashboard
- How to retrieve the options from this options page?
- Google fonts dropdown in Options Framework
- Changing max number of blog posts per page doesn’t work
- How can I increase the font sizes used by the WordPress visual and HTML post editors?
- How do I retrieve multiple values from a multidimensional array in wp_options?
- Displaying the full text instead of post title
- Updating just one option with update_option
- Upload file on pre_update_option_{option_name}
- how create an html table with all values from a serialized array in option_value
- 403 error on submit at the plugin options page
- ‘delete_option()’ only deleting the value, not the key/value pair
- WP Options Query “Rewrite Rules” Taking 10 Seconds After Testing wp_insert_post( )
- Accept code input into Options Framework
- How can you store your option at the permalink settings page?
- Problem saving wordpress settings with current version. Is it a bug?
- How can I clear memcached WordPress site options by hand?
- Uploading and inserting an image using a custom option panel like in the Twenty Ten theme?
- Autopopulate a value
- What is the XSSAttack option_name for in the options table?
- WP Optimization: Overwriting options to autoload=yes for often used options?
- Save Plugin Options as Array
- Retrieve my custom settings in the settings/ API endpoint
- Is there a standard technique or API for getting the site header image?
- Move website from root to sub
- How to save Checkbox-Options in Plugin Options Page
- Is saving data to WordPress options as array bad thing to do?
- how to compare update_option() after it saves to database?
- centralized alternative for get_option: get_site_option, get_network_option or get_site_meta?
- Some entries delete_option doesn’t work
- Options saved and called in wrong order
- Use delete_option in action link
- Editing a loaded WordPress option without updating the database
- User specific settings, limited by role
- Remove Edit Profile option but still have the profile viewable
- Hold a comment in the queue if it contains [X] or more links
- How do I create settings only used by my theme? [closed]
- Trying to change settings -> firefox downloads options.php instead
- Move one option value into another option
- Share content between two different sites in same domain
- Adding data to options table
- how can i add_option as array from a form with just a text input
- wp_allow_comments checking for blacklisted words effectively
- How to add options for Pages?
- options validator input is false?
- Best place to store company address
- $wpdb->update does not update, var_dump of data is correct
- Fatal error: Call to undefined function get_option()
- change backend header options
- If Home Page Do Nothing, If All Else Show This Content