The rules that prevent most WordPress vulnerabilities: validate and sanitize input, escape output for its context, use nonces and capability checks, and pass every value through $wpdb->prepare().
Home » Posts tagged 'Sanitizing & escaping' (Page 2)
User registration hooks: validate extra fields, save them, send a welcome email The registration form on wp-login.php?action=register asks only for a username and an email. Three hooks let you extend it: register_form prints extra fields, the registration_errors filter validates them and can stop the registration, and user_register runs after the account was created. With profile_update…
add_query_arg() and remove_query_arg(): build URLs safely Admin redirects with ?status=saved, filter links that keep the other filters, URLs without tracking parameters: building query strings by hand with ?, & and parse_url() breaks as soon as the URL already has a query string or a value needs encoding. WordPress has two helpers for it, and one…
wp_kses(): allow exactly the HTML you need strip_tags() removes all HTML, including the bold text and links your users wanted to keep. wp_kses() works the other way round: it keeps only the tags and attributes on your list and removes everything else, including event attributes like onclick and dangerous URL protocols like javascript:. Core uses…
Sanitize or escape? Which WordPress function to use where WordPress has two families of functions for user data, and they are often mixed up. Sanitizing cleans data on the way in, before it is saved. Escaping makes data safe on the way out, for the exact place in the HTML where it is printed. They…
wp_redirect() and wp_safe_redirect() in WordPress Redirects are an everyday task: after a form is sent, after login, when a page has moved, when a guest opens a page for members. In WordPress you do not call header( 'Location: ...' ) yourself; there are two functions for it, and the difference between them matters for security.