You can use sanitize_text_field
exactly as you are. From the function’s documentation:
- Checks for invalid UTF-8,
- Converts single < characters to entities
- Strips all tags
- Removes line breaks, tabs, and extra whitespace
- Strips percent-encoded characters
sanitize_text_field()
is already defined as a function in WordPress, so you don’t need to change anything. The sanitize_callback
parameter takes a function name; only if you want to do custom sanitization would you need to define a new function.
Related Posts:
- In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
- How to properly validate data from $_GET or $_REQUEST using WordPress functions?
- What is the difference between esc_html and wp_filter_nohtml_kses?
- What is the difference between strip_tags and wp_filter_nohtml_kses?
- array_map() for sanitizing $_POST
- Coding a plugin on WordPress; when should I sanitize? [duplicate]
- How to sanitize user input?
- WP_Editor – Saving Value into Plugin Option – Stripping HTML
- Prevent invalid or empty values from being saved to the database and retain the form field values upon error
- wordpress is adding a second backslash when I use addslashes
- Sanitize WordPress Array Input?
- do I need to sanitize a shortcode’s function input?
- Array/List Edit in Backend
- oneOf two possible objects in WP REST API?
- Sanitize and Save metabox values
- esc_url, esc_url_raw or sanitize_url?
- How can a plugin create a page/form in the front end?
- Looking for WordPress System Diagrams
- How to output message during plugin activation
- How to provide translations for a WordPress TinyMCE plugin?
- Where do I start from
- How do you create a custom edit.php / edit pages page
- Check the Version of an Enqueue’d External Library
- Edit the output of wp_widget_rss_output()
- Change of query var in pre_get_posts not maintained
- Menu Error in Admin Console with Custom Plugin: You do not have sufficient permissions to access this page
- How to Parse an Array of Elements in Gutenberg Block
- Custom rewrite rule serves content, but returns 404 error code
- Will changing the ‘Plugin Name’ header in the next update of a plugin break anything?
- Performance of several get_option() calls
- How to edit mySQL wp_posts table from plugin php?
- Creating a Wordpess Plugin that writes data to a csv file. The data doesn’t show in the csv file?
- Using the Settings API, how should I add multiple values to an option?
- WP custom menus error > menu name already exists?
- Problem with is_active_sidebar?
- Prevent Plugin from loading on ‘wp-admin / wp-login’
- Remove Internal Style Sheet if no Value Provided?
- Widget update function not saving values
- override pluggable.php functions
- get_the_excerpt() is not returning an empty string when the_excerpt is blank?
- “Plugin could not be activated because it triggered a fatal error.”
- Storing product price data in the database
- Does the order of sections in readme.txt matter?
- Add column in WP user but it goes wrong
- modify wordpress default search
- How to remove the current post from the query?
- Is file_get_contents() the only way for plugins reading local files OR does WP_Filesystem_Direct::get_contents() even work?
- how to get up row in wordpress with wpdb
- Hook into Jetpacks Publicize without using a post type
- How to limit number of number of categories displayed by categories widget
- How to remove default style of header in wordpress metabox
- Is it necessary to do validation again when retrieving data from database?
- Using WordPress PHP code, how to bulk delete only 100 subscribers at a time from thousands of users?
- Checking a WordPress for OWASP top 10 vulnerabilities [closed]
- term_exists() returning NULL on term that exists
- hook filter after the_content on a specific page
- The Correct Way to Use Nonce Field without Settings API
- Run command “composer install” when activating wordpress plugin
- Enqueue a file that’s not js or css
- Import user data using CSV
- Disable Auto-Expanding Menu in WordPress Admin Menus
- How to submit/upload data to database and in specific folder?
- OOP plugin not working
- Undefined is_user_logged_in() error with Plugin Query code
- Plugin Options not saving options and doesn’t work
- WordPress dynamic widget by location?
- JQuery Slider – Similar to www.internetmarketinginc.com [closed]
- Development plugin to view and manage scheduled wordpress cron jobs?
- Add user managable titles to custom menus?
- WordPress video js error this.mediaElement.play is not a function
- Custom Icon for Plugin
- WP_Query order posts by category
- How to override supports of innerBlocks?
- How to store sensitive user data (passwords)
- How can we upload file to root directory of wordpress
- Implications of creating a plugin that adds functionality to other developer’s plugin?
- Adding External Gmap JS to WordPress
- First page download plugin
- why is update_user_meta creating arrays when trying to change the same value?
- How to avoid conflict if a plugin already have included open library?
- WordPress OOP get current user question?
- Override WooCommerce files from plugin
- Add WordPress Meta Box saved form input to WordPress RSS feed [duplicate]
- WordPress Dropdown image select
- Unable to link CSS file
- What should I use instead of get_blog_option?
- post_results filter confused by pagination in sidebar and main section
- Best place to keep files that are called by cron jobs?
- Children Shortcodes?
- How do I call the dashboard’s sortable javascript in a plugin page?
- Settings API with arrays example
- Ajax functions – no access to wp-admin.php only online
- How can I get a plugin to hook ‘dbdelta_queries’ — a filter used during version update?
- Send retrieve password notification email with custom HTML email template
- Personalized URL for non-logged in WordPress
- WordPress Breadcrumb Taxonomy Display
- Adding custom avatar field to comments
- i want to auto create pages with shortcode when plugin is activated and delete when deactivated
- wordpress wp_editor() does not support tag
- Insert meta-description into Yoast-SEO input-field via JavaScript