Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions skills/wp-plugin-development/references/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,27 @@ Practical rules:
- use `wp_unslash()` before sanitizing when needed
- use prepared statements for SQL; avoid interpolating user input into queries

Common review guidance:
## Output escaping contexts

Escape at output, using the function that matches the context:

* HTML text: `esc_html()`
* HTML attribute: `esc_attr()`
* URL: `esc_url()`
* textarea: `esc_textarea()`
* JavaScript strings: `esc_js()`

For JSON data, prefer `wp_json_encode()` and pass data through WordPress script APIs such as `wp_add_inline_script()` or `wp_localize_script()`.

- https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/
For user-provided HTML, restrict allowed markup with `wp_kses_post()` or `wp_kses()` before output.

## AJAX handlers

* For `wp_ajax_*`, verify nonce and check capabilities.
* For `wp_ajax_nopriv_*`, assume unauthenticated attacker-controlled traffic.
* Return JSON with `wp_send_json_success()` or `wp_send_json_error()`.
* Do not expose private data from AJAX responses.

Common review guidance:

- https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/
Loading