
Wp Rest Api
- 3.5k installs
- 1.9k repo stars
- Updated July 27, 2026
- wordpress/agent-skills
wp-rest-api is a skill that creates, extends, and debugs WordPress REST routes, schema, and permissions so headless apps receive reliable JSON from WordPress.
About
wp-rest-api guides agents building and debugging WordPress REST API endpoints for WordPress 6.9+ on PHP 7.2.24+ using bash and node, with some workflows requiring WP-CLI. Triage starts with wp-project-triage detect_wp_project.mjs and searches for register_rest_route, WP_REST_Controller, rest_api_init, and show_in_rest usage. Custom endpoints use unique vendor/v1 namespaces, mandatory permission_callback, WP_REST_Server method constants, rest_ensure_response returns, and WP_Error statuses. Argument validation defines args with type, default, required, validate_callback, and sanitize_callback using rest_validate_value_from_schema. Response work covers register_rest_field computed fields, register_meta with show_in_rest schema for objects and arrays, context=edit for raw content, and WP_REST_Response add_link for related resources. Authentication guidance contrasts cookie plus X-WP-Nonce for wp-admin JS, application passwords for external clients, and capability checks in permission_callback. Discovery, pagination, _fields, _embed, and per_page caps are documented. Verification checks namespace index, OPTIONS schema, permission failures, and CPT routes under wp/v2.
- Triages repos with wp-project-triage before editing REST routes or controllers.
- Covers register_rest_route, WP_REST_Controller, schema validation, and permission_callback.
- Documents cookie nonce, application passwords, and capability-based authorization patterns.
- Guides register_rest_field, register_meta, and show_in_rest for CPTs and taxonomies.
- Debugging playbook for 404 route misses, 401/403 auth failures, and missing fields.
Wp Rest Api by the numbers
- 3,478 all-time installs (skills.sh)
- +183 installs in the week ending Jul 28, 2026 (Skillselion tracking)
- Ranked #173 of 4,386 Backend & APIs skills by installs in the Skillselion catalog
- Security screen: MEDIUM risk (skills.sh audit)
- Data as of Jul 28, 2026 (Skillselion catalog sync)
wp-rest-api capabilities & compatibility
- Capabilities
- route and controller registration · schema and argument validation · authentication and permission patterns · custom fields and meta exposure · rest debugging and verification
- Use cases
- api development
npx skills add https://github.com/wordpress/agent-skills --skill wp-rest-apiAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 3.5k |
|---|---|
| repo stars | ★ 1.9k |
| Security audit | 3 / 3 scanners passed |
| Last updated | July 27, 2026 |
| Repository | wordpress/agent-skills ↗ |
How do I register custom WordPress REST endpoints with correct schema, permission_callback, and authentication for headless clients?
Add or fix custom WordPress REST routes, permissions, and schema when headless apps or integrations need reliable JSON from your site.
Who is it for?
WordPress plugin and theme developers exposing CPTs, meta, or custom endpoints to headless frontends and integrations.
Skip if: Skip for non-WordPress stacks or front-end theme styling without REST route or permission work.
When should I use this skill?
User debugs 401/403/404 REST errors, register_rest_route, WP_REST_Controller, register_rest_field, or show_in_rest for CPTs.
What you get
Working REST routes with validated args, proper authorization, custom fields in responses, and verified discovery under /wp-json/.
- custom REST routes
- WP_REST_Controller classes
- REST schema definitions
By the numbers
- Targets WordPress 6.9+ with PHP 7.2.24+ minimum
- Covers debugging for 401, 403, and 404 REST API errors
Files
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 6.9, call out).
Procedure
0) Triage and locate REST usage
1. Run triage:
node skills/wp-project-triage/scripts/detect_wp_project.mjs
2. 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.
Authentication (summary)
Cookie authentication (in-dashboard / same-site)
- Standard for wp-admin and theme/plugin JS.
- Requires a REST nonce (
wp_rest) sent asX-WP-Nonceheader or_wpnonceparam. - If the nonce is missing, the request is treated as unauthenticated even if cookies exist.
Application Passwords (external clients)
- Available in WordPress 5.6+.
- Use HTTPS + Basic Auth with the application password.
- Recommended over the legacy Basic Auth plugin.
Auth plugins
- OAuth 1.0a or JWT plugins are common for external apps.
- Use only if required; follow plugin docs and security guidance.
Custom Content Types (summary)
Custom post types
- Set
show_in_rest => trueinregister_post_type()to expose inwp/v2. - Use
rest_baseto change the route slug. - Optionally set
rest_controller_class(must extendWP_REST_Controller).
Custom taxonomies
- Set
show_in_rest => trueinregister_taxonomy(). - Use
rest_baseand optionalrest_controller_class(defaultWP_REST_Terms_Controller).
Adding REST support to existing types
- Use
register_post_type_argsorregister_taxonomy_argsfilters to enableshow_in_restfor types you do not control.
Discovery links for custom controllers
- If you use a custom controller class, use
rest_route_for_postorrest_route_for_termfilters to map objects to routes.
Discovery and Global Parameters (summary)
API discovery
- REST API root is discovered via the
Linkheader:rel="https://api.w.org/". - HTML pages also include a
<link rel="https://api.w.org/" href="...">element. - For non-pretty permalinks, use
?rest_route=/.
Global parameters
_fieldslimits response fields (supports nested meta keys)._embedincludes linked resources in_embedded._methodorX-HTTP-Method-Overrideallows POST to simulate PUT/DELETE._envelopeputs headers/status in the response body._jsonpenables JSONP for legacy clients.
Pagination
- Collections accept
page,per_page(1-100), andoffset. - Pagination headers:
X-WP-TotalandX-WP-TotalPages.
Responses and Fields (summary)
Do not remove core fields
- Removing or changing core fields breaks clients (including wp-admin).
- Prefer adding new fields or using
_fieldsto limit response size.
register_rest_field
- Use for computed or custom fields.
- Provide
get_callback, optionalupdate_callback, andschema. - Register on
rest_api_init.
Raw vs rendered content
- For posts,
content.renderedreflects filters (plugins like ToC inject HTML). - Use
?context=edit(authenticated) to accesscontent.raw. - Combine with
_fields=content.rawwhen you only need the editable body.
register_meta / register_post_meta / register_term_meta
- Use when the data is stored as meta.
- Set
show_in_rest => trueto expose under.meta. - For
objectorarraytypes, provide a JSON schema inshow_in_rest.schema.
Links and embedding
- Add links with
WP_REST_Response::add_link( $rel, $href, $attrs ). - Use
embeddable => trueto allow_embed. - Use IANA rels or a custom URI relation; CURIEs can be registered via
rest_response_link_curies.
Routes and Endpoints (summary)
Registering routes
- Register routes on the
rest_api_inithook withregister_rest_route( $namespace, $route, $args ). - A route is the URL pattern; an endpoint is the method + callback bound to that route.
- For non-pretty permalinks, the route is accessed via
?rest_route=/namespace/route.
Namespacing
- Always namespace routes (
vendor/v1). - Do not use the
wp/*namespace unless you are targeting core.
Methods
- Use
WP_REST_Server::READABLE(GET),CREATABLE(POST),EDITABLE(PUT/PATCH),DELETABLE(DELETE). - Multiple endpoints can share a route, one per method.
permission_callback (required)
- Always provide
permission_callback. - Public endpoints should use
__return_true. - For restricted endpoints, use capability checks (
current_user_can) or object-level authorization. - Missing
permission_callbackemits a_doing_it_wrongnotice in modern WP.
Arguments
- Register
argsto validate and sanitize inputs. - Use
type,required,default,validate_callback,sanitize_callback. - Access params via the
WP_REST_Requestobject, not$_GET/$_POST.
Return values
- Return data via
rest_ensure_response()or aWP_REST_Response. - Return
WP_Errorwith astatusindatafor error responses. - Do not call
wp_send_json()in REST callbacks.
Schema and Argument Validation (summary)
JSON Schema in WordPress
- REST API uses JSON Schema (draft 4 subset) for resource and argument definitions.
- Provide schema via
get_item_schema()on controllers orschemacallbacks on routes. - Schema enables discovery (
OPTIONS) and validation.
Validation + sanitization
- Use
rest_validate_value_from_schema( $value, $schema )thenrest_sanitize_value_from_schema( $value, $schema ). - If you override
sanitize_callback, built-in schema validation will not run; userest_validate_request_argto keep it. WP_REST_Controller::get_endpoint_args_for_item_schema()wires validation automatically.
Schema caching
- Cache the generated schema on the controller instance (
$this->schema) to avoid recomputation.
Formats and types
- Common formats:
date-time,uri,email,ip,uuid,hex-color. - For
arrayandobjecttypes, you must defineitemsorpropertiesschemas.
Related skills
How it compares
Use wp-rest-api for WordPress-native REST extension; choose generic OpenAPI skills when the backend is not WordPress PHP.
FAQ
Which WordPress version does wp-rest-api target?
WordPress 6.9+ on PHP 7.2.24+; older versions need explicit compatibility callouts.
How should external clients authenticate?
Application passwords with basic auth or an auth plugin; wp-admin JS uses cookie auth plus X-WP-Nonce.
Why are custom fields missing from REST responses?
Often show_in_rest is false, meta is not registered with show_in_rest schema, or the CPT lacks custom-fields support.
Is Wp Rest Api safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.