Add a third parameter, which is an $args array, and add your sanitization callback in there:
register_setting(
'sports_api_key',
'sports_api_key',
array(
'sanitization_callback' => 'sanitize_text_field'
)
);
This is enough for your use case, the sanitize_text_field
function already exists, so you don’t need to create it.
More information here for how to add a sanitization callback and here to sanitize text fields.
Related Posts:
- Settings API – sanitizing urls, email addresses and text
- Storing HTML in wp_options
- WordPress Settings API – Sanitize Integer
- Preserve old values on error in setting API
- Seeking clarity on data sanitization fields for settings textarea
- How to handle complex data with Settings API
- settings api and the data passed in the parameter
- Settings api sanatize callback not being triggered
- Settings API vs Theme Customizer
- Run function AFTER theme options are saved?
- Add your own settings page for plugin
- Adding an html editor to plugin settings page
- add static page to reading settings for custom post type
- How to display an admin notice after updating plugin settings?
- Add settings fields on options discussion admin page
- Validate an option array
- Default WordPress settings API data sanitization
- Dynamic settings fields with Settings API
- Settings API repeater fields
- do_settings_sections() doesn’t escape quotes
- Import / Export Settings API fields values?
- Saving multiple checkboxes with WordPress settings api
- Letting user dynamically create fields using Settings API
- wordpress settings api add fields
- Adding labels to Setting titles with API
- register_setting sanitize callback $input is null
- Can I dynamically create duplicate fields with the Settings API?
- What exactly is the purpose of settings_fields()?
- Persist fields with Setting API
- wordpress settings API and option array structure
- Echo all API Settings sections?
- Settings Page won’t save
- How do I save custom options on the options page ‘Reading’?
- Submit options page input values with decimals
- Using multiple settings_fields() on 1 settings page
- Output ‘do_settings_sections()’ as tabs, not one under the other
- Saving plugin’s settings in 1 field in json format
- PHP Notice: Undefined offset: 0 in /wordpress/wp-includes/plugin.php and Register Settings API change
- Hide output of add_settings_field()
- How to make new plugin setting checkbox default as checked
- How to wrap html around Settings API add_settings_section()
- Settings API – sanitize_callback is not called and it leads to an incorrect behavior
- What is the best way to save and retrieve Multiple rows of data with the Settings API?
- Multiple fields with add_settings_field callback
- Settings API: Two update notices after saving settings?
- Settings API in Section
- Storage of array in settings
- Settings API and dynamically generated submenu pages
- Error: options page not found when I try to save the changes made in my settings page
- Display Each Setting Section In Each Specific Tab within Same Page || Settings API
- WordPress API Setting : the title of the section rendered not showing
- add_settings_section() order
- Splitting do_settings_sections within HTML?
- Why are these settings unregistered?
- Settings field is not showing up in the general options page
- How to use/retrieve an options array, with defaults, using get_option()
- How to prevent options.php deleting valid existing data from the database
- Displaying errors with settings api
- Displaying validation message in options-general.php
- How I can Make two input field at add_settings_section
- Settings Page – Option won’t save in database
- Customize format of settings
- Prevent invalid or empty values from being saved to the database and retain the form field values upon error
- Getting error to display radio button value in General Settings page
- How to create a WordPress options page
- When should I use register_setting() and add_settings_field()
- Why aren’t these WordPress options being saved to the database correctly?
- Is it possible to get a list of options for a specific options group?
- update_option_$option action not working as expected
- Saving array of data to database using wordpress settings API
- settings api sub menu and data not populating
- how to get wp_editor to save data in plugin admin page
- Getting all the settings for a plugin
- Use the Settings API to whitelist a setting, but don’t output it
- Can’t save settings to database using Setting API
- How to use checked() function with multiple check box group? How to properly sanitize that checkbox group?
- Verify Submitted Form Values and Show Warning Messages with Setting API
- WordPress settings API VS Table In Database?
- Writing Mysql and Php code in wordpress Posts
- Should I escape the html for the settings field created with add_settings_field?
- How to Save value from two inputs as array?
- How to save Checkbox-Options in Plugin Options Page
- Assign value to custom checkbox using get_option()
- Multiple plugins linked to same settings page
- Settings page – can’t change checkbox to unchecked
- Add Logo Upload per Setting API
- Add two input fields in add_settings_field
- Custom setting field value not working inside add_action init hook
- settings api callback functions won’t display?
- Restrict access to options-*.php pages
- How to move setting field up a row on general page?
- Option doesn’t save
- Save button in theme customization page stays disabled
- Settings API Multiple Checkbox in General Settings
- Can I use add_option for a plugin categories and how?
- Adding Form Fields with Settings API
- illegal offset in option add
- WordPress’s automatic ‘Settings saved.’ text fails to display after tapping on the ‘Save Changes’ button on my custom settings page
- Tab Nav and WordPress Settings API
- Do I need to validate the nonce when using the settings api?