I would use the filter_var() function. It has some predefined filters that you can use depending on what kind of data you are expecting such as string, number, etc.
So to sanitize for a number:
$sanitizedNum = filter_var($yourVar, FILTER_SANITIZE_NUMBER_INT);
For a string you would just change “_NUM_INT” to “_STRING”.
Wrap those in a custom function then.
Related Posts:
- Is sanitize_text_field() is enough to save to DB?
- Who is responsible for data sanitization in WordPress development?
- Secure way to use name_save_pre?
- What is the most secure way to store post meta data in WP?
- Default WordPress settings API data sanitization
- How to display data from custom table in wordpress database?
- Using two different DB users on one WP install
- Is $wpdb->prepare escaping to much? How to use it properly?
- How does WordPress store data?
- How do I properly update the WordPress database password?
- What is the proper way to validate and sanitize JSON response from REST API?
- “The link you followed has expired” & “Error while saving” messages when adding new post
- data (html) migration to posts
- WordPress and user security
- Saving zero as meta value
- What can I do when an outside party hacks into my weblog and changes my display name?
- WordPress security [closed]
- Safely store code(html/js..) into database
- WordPress Database – wp_usermeta and the correct number of session_tokens rows
- Insert NULL value using prepare()
- Where is the HTML-handler part in the wpdb class?
- spambot registering without providing email or password, bypassing registration process
- Hash user emails in database?
- Custom metabox does not store data
- What is this JavaScript “require”?
- Using wpdb to connect to a separate database
- How can I make updates to a site, on a development copy, but then move updates back without overriding live site’s evolving database?
- How can I make a WordPress database portable and url independent?
- wpdb->insert multiple record at once
- How to migrate a HTTPS WordPress installation to localhost?
- How to stop WordPress using utf8mb4_unicode_520_ci collation?
- How to monitor server for error establishing a database connection
- Exporting revisions
- WP_Options ID high
- Fatal error: Call to undefined function dbDelta()
- Connect to remote database using Localhost install
- remove missing image attachments
- How to ensure data consistency in WordPress
- How to intercept update_option() before it saves data?
- wpdb query on custom table not working [closed]
- How to diagnose and keep in check encoding issues?
- Correct processing of `$_POST`, following WordPress Coding Standards
- Set Display Name to first and last name (phpmyadmin SQL Query)
- How to fix unchanged URLs in Database after running serialized search and replace script?
- wp_redirection_404 table has grown to 7GB
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- Merging two wp_posts tables while avoiding duplicates
- Strange issue saving custom field data for a WooCommerce order
- Merging two databases without borking it
- Permit Login if table row exists
- How Yoast SEO plugin works with variable %%name%%?
- What would Repair and Optimize WordPress Database do?
- Move out of sync posts from one database to another
- MS Access to manage WordPress Database
- Error message on blog posts only on my local environment [closed]
- how to read database fields
- $wpdb->query can’t insert data
- WSOD 3.9.1 – Tried Everything so far
- Contact Form Security
- Can you refresh ONLY the wordpress adminbar and not the whole page?
- Sending posts from Python to WordPress
- Problem migrating to localhost
- SQL query to set posts in bulk based on the post content
- Automate WordPress website setup with prefilled data
- How can I detect right db type?
- Add search bar to Custom Database Table in WordPress Dashboard
- Design problems when exporting remote database for local development
- How do you render posts from outside wordpress?
- A change in URL slug in database returns 404, how can I do auto-redirect?
- Second ezSQL initialization for MSSQL
- Fetch a single row from a custom table for to a given ID
- Database create or redirect
- Database structure cheatsheet
- White Screen in Home Page
- Continuous SQL query errors from outside source
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- Recovery – Restore Database after moving folder location locally
- Migrate Users From laravel to wordpress
- WordPress has been updated! Before we send you on your way, we have to update your database to the newest version
- how add more field to wp user and save it to database
- How do I cleanup my database with data that is no longer being used?
- Malware in old website – how to migrate?
- error establishing database connection (WAMP + filezilla)
- Is there a way for two deferent themes to consume two different DB on a same WP instance?
- How to display $wpdb->insert_id; value on redirected page
- Should I Use only wpdb Class to Write Custom Queries?
- Auto populate form fields based on serial input or pull listings from other websites?
- How to extract some part of WordPress full source code
- Wrong url for the images while using same database for two WordPress installations
- Error establishing a database connection for some files
- Sending WordPress database information to cross domain the safe way?
- Database Name Change
- Weird characters in title if it contain “ ”
- Where To Find bb_profile_data(); In bbPress?
- Saving data to database and exporting to excel
- One information repeated on multiple locations on one site [closed]
- Showing Error(TAble already exist)
- SQL query to rewrite all media URLs to end with .webp
- Weird WP -Cli Error Connection Refused