Wp Rest API
WordPressOfficialPublished by WordPress
- Skill
- Tool integration
- Software development
- GPL-2.0-or-later
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured approach to working with the WordPress REST API. It covers the lifecycle of API development, from registering custom routes and controllers to implementing schema validation, authentication, and response shaping. It emphasizes security best practices, such as proper permission callbacks, and provides guidance on exposing custom post types and taxonomies to the API.
What it does
- Registers custom REST routes and endpoints using WP_REST_Controller or procedural code.
- Configures schema and argument validation for request parameters.
- Implements authentication strategies including cookie-based nonces and application passwords.
- Exposes custom post types and taxonomies via the REST API.
- Adds custom fields and meta data to existing REST responses.
- Troubleshoots common API errors like 401, 403, and 404 status codes.
When to use it
- When creating new custom endpoints for a WordPress plugin or theme.
- When debugging permission issues or missing data in REST responses.
- When you need to expose custom content types to external applications.
- When implementing complex argument validation or response formatting.
Advantages
- Promotes consistent use of WordPress core patterns and controller classes.
- Ensures secure API development through mandatory permission callbacks.
- Provides clear debugging steps for common REST API failure modes.
- Supports standard WordPress discovery and pagination features.
Usage examples
- “How do I register a new custom REST API endpoint for my plugin?”
- The agent will guide you to use register_rest_route within a rest_api_init hook, recommending a controller class for non-trivial logic and defining required permission_callback.
- “My custom post type isn't showing up in the REST API, how do I fix it?”
- The agent will instruct you to verify that show_in_rest is set to true in your register_post_type call and check if a rest_base is required.
- “How do I debug a 403 error on my custom REST route?”
- The agent will help you inspect your permission_callback logic and verify that the correct authentication (nonce or application password) is being provided.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/wordpress/wp-rest-api/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip wp-rest-api.zip -d .agents/skills
Documentation by WordPress
WP REST API
When to use
Use this skill when you need to:
create or update REST routes/endpoints
debug 401/403/404 errors or permission/nonce issues
add custom fields/meta to REST responses
expose custom post types or taxonomies via REST
implement schema + argument validation
adjust response links/embedding/pagination
Inputs required
Repo root + target plugin/theme/mu-plugin (path to entrypoint).
Desired namespace + version (e.g.
my-plugin/v1) and routes.Authentication mode (cookie + nonce vs application passwords vs auth plugin).
Target WordPress version constraints (if below 7.0, call out).
Procedure
0) Triage and locate REST usage
Run triage:
node skills/wp-project-triage/scripts/detect_wp_project.mjs
Search for existing REST usage:
register_rest_routeWP_REST_Controllerrest_api_initshow_in_rest,rest_base,rest_controller_class
If this is a full site repo, pick the specific plugin/theme before changing code.
1) Choose the right approach
Expose CPT/taxonomy in
wp/v2:Use
show_in_rest => true+rest_baseif needed.Optionally provide
rest_controller_class.Read
references/custom-content-types.md.
Custom endpoints:
Use
register_rest_route()onrest_api_init.Prefer a controller class (
WP_REST_Controllersubclass) for anything non-trivial.Read
references/routes-and-endpoints.mdandreferences/schema.md.
2) Register routes safely (namespaces, methods, permissions)
Use a unique namespace
vendor/v1; avoidwp/*unless core.Always provide
permission_callback(use__return_truefor public endpoints).Use
WP_REST_Server::READABLE/CREATABLE/EDITABLE/DELETABLEconstants.Return data via
rest_ensure_response()orWP_REST_Response.Return errors via
WP_Errorwith an explicitstatus.
Read references/routes-and-endpoints.md.
3) Validate/sanitize request args
Define
argswithtype,default,required,validate_callback,sanitize_callback.Prefer JSON Schema validation with
rest_validate_value_from_schemathenrest_sanitize_value_from_schema.Never read
$_GET/$_POSTdirectly inside endpoints; useWP_REST_Request.
Read references/schema.md.
4) Responses, fields, and links
Do not remove core fields from default endpoints; add fields instead.
Use
register_rest_fieldfor computed fields;register_metawithshow_in_restfor meta.For
object/arraymeta, define schema inshow_in_rest.schema.If you need unfiltered post content (e.g., ToC plugins injecting HTML), request
?context=editto accesscontent.raw(auth required). Pair with_fields=content.rawto keep responses small.Add related resource links via
WP_REST_Response::add_link().
Read references/responses-and-fields.md.
5) Authentication and authorization
For wp-admin/JS: cookie auth +
X-WP-Nonce(actionwp_rest).For external clients: application passwords (basic auth) or an auth plugin.
Use capability checks in
permission_callback(authorization), not just “logged in”.
Read references/authentication.md.
6) Client-facing behavior (discovery, pagination, embeds)
Ensure discovery works (
Linkheader or<link rel="https://api.w.org/">).Support
_fields,_embed,_method,_envelope, pagination headers.Remember
per_pageis capped at 100.
Read references/discovery-and-params.md.
Verification
/wp-json/index includes your namespace.OPTIONSon your route returns schema (when provided).Endpoint returns expected data; permission failures return 401/403 as appropriate.
CPT/taxonomy routes appear under
wp/v2whenshow_in_restis true.Run repo lint/tests and any PHP/JS build steps.
Failure modes / debugging
404:
rest_api_initnot firing, route typo, or permalinks off (use?rest_route=).401/403: missing nonce/auth, or
permission_callbacktoo strict._doing_it_wrongfor missingpermission_callback: add it (use__return_trueif public).Invalid params: missing/incorrect
argsschema or validation callbacks.Fields missing:
show_in_restfalse, meta not registered, or CPT lackscustom-fieldssupport.
Escalation
If version support or behavior is unclear, consult the REST API Handbook and core docs before inventing patterns.
Files
- ATTRIBUTION.mdAdded by AutoGineer886 B
- LICENSELicence file added by AutoGineer750 B
- SKILL.md4.8 KiB
- references/authentication.md627 B
- references/custom-content-types.md760 B
- references/discovery-and-params.md730 B
- references/responses-and-fields.md1.1 KiB
- references/routes-and-endpoints.md1.3 KiB
- references/schema.md964 B
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Node.js
The author says: Targets WordPress 7.0+ (PHP 7.4.0+). Filesystem-based agent with bash + node. Some workflows require WP-CLI.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- WordPress
- Publisher
- WordPress (Official)
- Source
- WordPress/agent-skills · skills/wp-rest-api · commit 7374e6f
- Licence
- GNU General Public License v2.0 or later (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by WordPress or WordPress.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download wp-rest-api.zip