In a perfect world, you don’t need sanitize your querys because the WordPress ORM avoids sql injections going to the database, but is extremely recommended to clean your input data, particularly if is input data provided by a visitor.
For example, you can use something like this:
$name = sanitize_text_field( $_POST['name'] );
// WP_Query arguments
$args = array (
'name' => $name,
);
// The Query
$query = new WP_Query( $args );
There are a lot of filter functions that can sanitize:
- sanitize_email()
- sanitize_file_name()
- sanitize_html_class()
- sanitize_key()
- sanitize_meta()
- sanitize_mime_type()
- sanitize_option()
- sanitize_sql_orderby()
- sanitize_text_field()
- sanitize_title()
- sanitize_title_for_query()
- sanitize_title_with_dashes()
- sanitize_user()
For more information read:
https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data
Related Posts:
- WordPress SQL Injections through User Agent
- When you use ‘badidea’ or ‘thisisunsafe’ to bypass a Chrome certificate/HSTS error, does it only apply for the current site? [closed]
- When you use ‘badidea’ or ‘thisisunsafe’ to bypass a Chrome certificate/HSTS error, does it only apply for the current site? [closed]
- Why does the URL http://a/%%30%30 crash Google Chrome?
- When you use ‘badidea’ or ‘thisisunsafe’ to bypass a Chrome certificate/HSTS error, does it only apply for the current site?
- Can an attacker use inspect element harmfully?
- Where does Internet Explorer store saved passwords?
- Infected Files – what to do [closed]
- WordPress 4.7.1 REST API still exposing users
- Should I escape wordpress functions like the_title, the_excerpt, the_content
- When to use esc_html and when to use sanitize_text_field?
- Why does WordPress have more than one salt?
- What is the ideal setup to address security concerns?
- Will there be security updates for 3.1 once 3.2 is released?
- Can someone explain the use cases of esc_html?
- Close a wordpress blog – keep site as it is but prevent hacks
- Moving wp-config.php: Can this be done after site launch?
- Prevent setup-config.php page from appearing when host blocks database
- How to get WordPress to save upload file beyond web root [closed]
- WordPress and Security
- Is security a problem in WordPress?
- Is /wp-login.php?redirect_to[] exploitable?
- Logout via Subdomain, non-wordpress page on a different server?
- brute force attack even though it is limited by IP
- What should I do about hacked server?
- How can I tell who changed the password?
- WordPress website Security [closed]
- How do I authenticate WP users from a chrome extension?
- Can’t reset WordPress password
- Website is being flooded [closed]
- Is the “lost password” feature truly a vulnerability?
- Is it possible to reduce the minimum character length for passwords?
- Handling email piping attachments and detecting unsupported file types
- Why was my blog post inserted lot’s of ad links by others?
- Should I Worry About SQL Injection When Using wp_insert_post?
- Auth cookie value security risk?
- Is there a way for a user to have an alias?
- Security – Shortcode injection attack
- Registration Plugin – Recaptcha integration
- Security threat with `home_url`?
- How to combat flooding admin-ajax.php?
- When is wp_set_password() called or how to capture a password
- Moving away from MD5: Where to declare the custom global $wp_hasher?
- Would it be dangerous to send all the wp_options to javascript file?
- Frequently getting attacks on admin-ajax.php, wp-cron.php, xmlrpc.php and wp-login.php
- Should I disable directory listing for wp-includes?
- How to get WordPress to send Password Reset Link Email instead of New Password?
- Safety side of storing emoji into database
- Verifying that I have fully removed a WordPress hack?
- Large Session Tokens
- How can I safely hide the fact that my website runs on WordPress? [closed]
- How to change permissions of WordPress and/or apache on macOS securely?
- How can I display nickname instead username in links
- My WordPress Websites are always under attack
- Is there value in using a wp_nonce for POST requests?
- Using an Encryption class in a WordPress Plugin
- How to hide easy access to my website temporarily?
- Can I Remove xmlrpc.php completely?
- Config file with no Keys..?
- How much should I worry about these messages?
- Security concerns with external links
- Uploading .webm format on WordPress results in security guidline breach and fail
- Any any insecure http:// URLs left in wordpress?
- White screen of death on admin pages after moving wp-config up two levels for security
- .htaccess password protection bypassed
- Session Cookie security questions
- Storing FTP details in wp-config.php
- Can a WordPress administrator see other users’ passwords?
- Why my plugins are updating automatically?
- Spam injected in w3 total cache page cache [closed]
- Privilege escalation bugs in 2.9?
- Content-Security-Policy blocks WordPress check boxes from being activated
- How to distinguish between a hack and an encoding error?
- WordPress SQL search, how to handle SQL Injection?
- How to change location of wp-config.php to folder or 2 folders up?
- wordpress admin security
- Remove hacked code – out of ideas! [closed]
- Why do people use “admin” username by default? [closed]
- WordPress Database Re-installed (Hacked)
- WordPress Security tools
- Robots.txt file not updating
- Security: Critical backend outside of wordpress
- How can I stop other plugins from using my class’ sensitive methods?
- What are WordPress Current Security Issues in 2017?
- wp-config.php moved above root results in no plugin updates
- Password-protect feed and make it usable in major aggregators
- Should I change the default file and folder permissions?
- How to rewrite rules for WP-security in Nginx?
- how to find the way they hacked my WP site
- Is it a bad idea to CHMOD 777 all the files on your site?
- How to stop repeated hack on header.php of custom theme? [closed]
- is this code properly secured
- nginx + wordpress: Best practices for configuring it to be secure, reliable, and fast? [closed]
- How to get real password (before encrypt) when register a user?
- checking the form submit in right order
- Our security auditor is an idiot. How do I give him the information he wants?
- I am under DDoS. What can I do?
- SSH keypair generation: RSA or DSA?
- How do I protect my company from my IT guy? [closed]
- Does changing default port number actually increase security? [closed]