WordPress Security

Secure WordPress development by sanitizing input, validating data, and escaping output.

6|2|Updated Dec 1, 2025
One-click install
npx skills add https://github.com/courtneyr-dev/wp-dev-prompts --skill wordpress-security-courtneyr-dev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: WordPress Security
Source: https://github.com/courtneyr-dev/wp-dev-prompts/tree/main/skills/wordpress-security
Command: npx skills add https://github.com/courtneyr-dev/wp-dev-prompts --skill wordpress-security-courtneyr-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers write secure WordPress code by providing clear guidelines and examples for preventing common vulnerabilities like XSS, CSRF, and SQL injection.

Core Features & Use Cases

  • Input Sanitization: Learn how to properly clean data entering your WordPress application.
  • Output Escaping: Understand how to safely display data in various HTML, JavaScript, and URL contexts.
  • Nonces and Capabilities: Implement checks to prevent Cross-Site Request Forgery and unauthorized access.
  • Secure Database Queries: Write safe SQL queries using $wpdb->prepare().
  • Use Case: When developing a new plugin, use this Skill to ensure all user-submitted data is sanitized and all output is properly escaped, preventing common security flaws.

Quick Start

Review the provided examples for sanitizing text input using sanitize_text_field.

Frequently Asked Questions about WordPress Security

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent SQL injection in WordPress database queries?

To prevent SQL injection in WordPress, use the `$wpdb->prepare()` method for all database queries. This function securely escapes user-supplied data, ensuring malicious SQL commands cannot be executed by your plugin or theme code.

What is the best way to sanitize input and escape output in WordPress?

The best way to secure WordPress is implementing the Security Trinity: sanitize input, validate data, and escape output. Use functions like `sanitize_text_field` for incoming data and context-specific escaping functions for safe HTML, JavaScript, or URL display.

How do nonces and capabilities prevent CSRF and privilege escalation in WordPress?

Nonces and capabilities prevent CSRF and privilege escalation by verifying user intent and authorization. Nonces validate that requests are intentionally submitted by the authenticated user, while capability checks ensure users only perform actions their specific role permits.

How do I protect my WordPress plugin from XSS vulnerabilities?

Protect your WordPress plugin from XSS vulnerabilities by properly escaping all output before rendering it in HTML, JavaScript, or URL contexts. This ensures any malicious scripts submitted through user input are safely neutralized during display.

When should I use $wpdb->prepare() instead of direct database queries in WordPress?

You should use `$wpdb->prepare()` whenever your WordPress database query includes any variables or user-submitted data. Direct queries are unsafe because they do not automatically escape input, leaving your application vulnerable to SQL injection attacks.