Sanitization and Validation — a practical guide to WordPress sanitize validate with clear examples you can reuse in real projects.
WordPress Plugin Development Series (25/95). Prefer one article? Read the complete WordPress plugin development tutorial.
Short description
Sanitize cleans data. Validate checks business rules. Do both on input; escape on output.
Sanitize helpers
$email = sanitize_email(wp_unslash($_POST['email'] ?? ''));
$url = esc_url_raw(wp_unslash($_POST['url'] ?? ''));
$html = wp_kses_post(wp_unslash($_POST['content'] ?? ''));
if (! is_email($email)) {
// invalid
}