WordPress REST API Development Skill
Overview
Systematic REST API review for WordPress plugins, themes, and custom code. Core principle: Every route needs a clear contract, explicit authorization, validated input, and predictable output. Review covers route registration, controller patterns, request parsing, schema and argument validation, response formatting, caching implications, and compatibility concerns. Report findings with line numbers, severity labels, and BAD/GOOD code pairs where helpful.
When to Use
Use when:
- Reviewing
register_rest_route() usage
- Auditing custom API endpoints or controller classes
- Checking
permission_callback logic
- Validating
WP_REST_Request input handling
- Reviewing response shape, status codes, and schema
- Designing versioned endpoints for headless or block-driven apps
Don't use for:
- General plugin architecture without REST focus (use wp-plugin-development)
- Security-only review across the whole plugin (use wp-security-review)
- Full WooCommerce endpoint review (use wp-woocommerce-dev when WC-specific)
- GraphQL-specific guidance
Code Review Workflow
Identify REST context
- Route callbacks in plugin bootstrap
- Controller classes extending
WP_REST_Controller
- Headless frontend integration
- Internal admin-only API usage
Check route registration first
- Namespace and version format
- HTTP methods match operation intent
permission_callback present and specific
args definitions for request validation
Review request handling
- Use
$request->get_param() or typed getters instead of raw globals
- Validate and sanitize all user input
- Reject malformed input with meaningful
WP_Error
Review response design
- Consistent response shape
- Proper status codes
rest_ensure_response() where helpful
- Avoid leaking internal details
Check for CRITICAL/WARNING/INFO patterns
- CRITICAL: Missing
permission_callback, write routes with __return_true, raw globals, unsanitized DB queries
- WARNING: Inconsistent schema, weak validation, mixed response shapes, missing pagination info
- INFO: Could use controller class, schema reuse, versioning cleanup
Report with cross-references
- If auth or nonce issues dominate, suggest
/wp-sec-review
- If route logic is plugin-architecture-heavy, suggest
/wp-plugin-review
File-Type Specific Checks
Route Registration (register_rest_route)
- CRITICAL: Missing
permission_callback
- CRITICAL:
'permission_callback' => '__return_true' on write endpoints
- WARNING: Namespace without version segment
- WARNING: Route registered outside
rest_api_init
- INFO: Repeated inline callbacks that should use controller methods
Permission Callbacks
- CRITICAL: Capability checks missing on private data
- WARNING: Callback always returns true for admin-like actions
- WARNING: No ownership check for user-specific resources
- INFO: Could centralize repeated permission logic
Request Args and Validation
- CRITICAL: Raw
$_GET/$_POST used inside endpoint callback
- WARNING: Missing
sanitize_callback or validate_callback
- WARNING: Missing enum/format constraints for known values
- INFO: Could define reusable item schema
Response Handling
- WARNING: Mixed success response shape across routes
- WARNING:
wp_send_json() inside REST callbacks instead of returning response data
- INFO: Could use
WP_REST_Response for headers/status control
Search Patterns for Quick Detection (API-21)
Use these rg commands for quick REST API scanning. Organized by severity.
CRITICAL Patterns
# register_rest_route candidates
rg -n "register_rest_route\s*\(" . -g '*.php'
# permission_callback returning true
rg -n "permission_callback.*__return_true" . -g '*.php'
# Raw superglobals inside REST callbacks
rg -n "\$_GET|\$_POST|\$_REQUEST" . -g '*.php'
WARNING Patterns
# WP_REST_Request usage without obvious validation helpers
rg -n "WP_REST_Request|get_param\s*\(" . -g '*.php'
# REST callbacks using wp_send_json
rg -n "wp_send_json|wp_send_json_success|wp_send_json_error" . -g '*.php'
# Route namespaces to inspect for versioning
rg -n "register_rest_route\s*\(\s*['\"][^'\"]+" . -g '*.php'
INFO Patterns
# WP_REST_Controller classes
rg -n "extends\s+WP_REST_Controller" . -g '*.php'
# rest_ensure_response usage
rg -n "rest_ensure_response|new\s+WP_REST_Response" . -g '*.php'
Reference Files
references/route-patterns.md - Route registration, controller structure, and namespace design
references/schema-and-auth-guide.md - Args schema, permission callbacks, input validation, and response design
Output Format (API-23)
For each finding include:
- Severity:
CRITICAL, WARNING, or INFO
- File and line number
- Issue summary
- Why it matters for WordPress REST API behavior
- Recommended fix
If no issues are found, say so clearly and mention any residual gaps such as missing tests, inconsistent schema documentation, or limited versioning strategy.
1---2name: wp-rest-api-development-23description: WordPress REST API review and development guidance. Use when reviewing custom REST routes, permission_callback logic, schema design, WP_REST_Request handling, response structure, versioning, controller classes, nonce or auth usage, or when user mentions "REST API review", "register_rest_route", "permission_callback", "WP_REST_Request", "REST endpoint", "custom API", "API schema", "REST controller", "headless WordPress", or "API auth". Detects route registration issues, authorization mistakes, schema drift, input validation gaps, and response design problems in WordPress REST API code.4---56# WordPress REST API Development Skill78## Overview910Systematic REST API review for WordPress plugins, themes, and custom code. **Core principle:** Every route needs a clear contract, explicit authorization, validated input, and predictable output. Review covers route registration, controller patterns, request parsing, schema and argument validation, response formatting, caching implications, and compatibility concerns. Report findings with line numbers, severity labels, and BAD/GOOD code pairs where helpful.1112## When to Use1314**Use when:**15- Reviewing `register_rest_route()` usage16- Auditing custom API endpoints or controller classes17- Checking `permission_callback` logic18- Validating `WP_REST_Request` input handling19- Reviewing response shape, status codes, and schema20- Designing versioned endpoints for headless or block-driven apps2122**Don't use for:**23- General plugin architecture without REST focus (use wp-plugin-development)24- Security-only review across the whole plugin (use wp-security-review)25- Full WooCommerce endpoint review (use wp-woocommerce-dev when WC-specific)26- GraphQL-specific guidance2728## Code Review Workflow29301. **Identify REST context**31 - Route callbacks in plugin bootstrap32 - Controller classes extending `WP_REST_Controller`33 - Headless frontend integration34 - Internal admin-only API usage35362. **Check route registration first**37 - Namespace and version format38 - HTTP methods match operation intent39 - `permission_callback` present and specific40 - `args` definitions for request validation41423. **Review request handling**43 - Use `$request->get_param()` or typed getters instead of raw globals44 - Validate and sanitize all user input45 - Reject malformed input with meaningful `WP_Error`46474. **Review response design**48 - Consistent response shape49 - Proper status codes50 - `rest_ensure_response()` where helpful51 - Avoid leaking internal details52535. **Check for CRITICAL/WARNING/INFO patterns**54 - **CRITICAL:** Missing `permission_callback`, write routes with `__return_true`, raw globals, unsanitized DB queries55 - **WARNING:** Inconsistent schema, weak validation, mixed response shapes, missing pagination info56 - **INFO:** Could use controller class, schema reuse, versioning cleanup57586. **Report with cross-references**59 - If auth or nonce issues dominate, suggest `/wp-sec-review`60 - If route logic is plugin-architecture-heavy, suggest `/wp-plugin-review`6162## File-Type Specific Checks6364### Route Registration (`register_rest_route`)6566- CRITICAL: Missing `permission_callback`67- CRITICAL: `'permission_callback' => '__return_true'` on write endpoints68- WARNING: Namespace without version segment69- WARNING: Route registered outside `rest_api_init`70- INFO: Repeated inline callbacks that should use controller methods7172### Permission Callbacks7374- CRITICAL: Capability checks missing on private data75- WARNING: Callback always returns true for admin-like actions76- WARNING: No ownership check for user-specific resources77- INFO: Could centralize repeated permission logic7879### Request Args and Validation8081- CRITICAL: Raw `$_GET`/`$_POST` used inside endpoint callback82- WARNING: Missing `sanitize_callback` or `validate_callback`83- WARNING: Missing enum/format constraints for known values84- INFO: Could define reusable item schema8586### Response Handling8788- WARNING: Mixed success response shape across routes89- WARNING: `wp_send_json()` inside REST callbacks instead of returning response data90- INFO: Could use `WP_REST_Response` for headers/status control9192## Search Patterns for Quick Detection (API-21)9394Use these `rg` commands for quick REST API scanning. Organized by severity.9596### CRITICAL Patterns9798```bash99# register_rest_route candidates100rg -n "register_rest_route\s*\(" . -g '*.php'101102# permission_callback returning true103rg -n "permission_callback.*__return_true" . -g '*.php'104105# Raw superglobals inside REST callbacks106rg -n "\$_GET|\$_POST|\$_REQUEST" . -g '*.php'107```108109### WARNING Patterns110111```bash112# WP_REST_Request usage without obvious validation helpers113rg -n "WP_REST_Request|get_param\s*\(" . -g '*.php'114115# REST callbacks using wp_send_json116rg -n "wp_send_json|wp_send_json_success|wp_send_json_error" . -g '*.php'117118# Route namespaces to inspect for versioning119rg -n "register_rest_route\s*\(\s*['\"][^'\"]+" . -g '*.php'120```121122### INFO Patterns123124```bash125# WP_REST_Controller classes126rg -n "extends\s+WP_REST_Controller" . -g '*.php'127128# rest_ensure_response usage129rg -n "rest_ensure_response|new\s+WP_REST_Response" . -g '*.php'130```131132## Reference Files133134- `references/route-patterns.md` - Route registration, controller structure, and namespace design135- `references/schema-and-auth-guide.md` - Args schema, permission callbacks, input validation, and response design136137## Output Format (API-23)138139For each finding include:1401411. Severity: `CRITICAL`, `WARNING`, or `INFO`1422. File and line number1433. Issue summary1444. Why it matters for WordPress REST API behavior1455. Recommended fix146147If no issues are found, say so clearly and mention any residual gaps such as missing tests, inconsistent schema documentation, or limited versioning strategy.148