Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
wordpress avatar

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)
At a glance

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-api

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs3.5k
repo stars1.9k
Security audit3 / 3 scanners passed
Last updatedJuly 27, 2026
Repositorywordpress/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

SKILL.mdMarkdownGitHub ↗

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_route
  • WP_REST_Controller
  • rest_api_init
  • show_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_base if needed.
  • Optionally provide rest_controller_class.
  • Read references/custom-content-types.md.
  • Custom endpoints:
  • Use register_rest_route() on rest_api_init.
  • Prefer a controller class (WP_REST_Controller subclass) for anything non-trivial.
  • Read references/routes-and-endpoints.md and references/schema.md.

2) Register routes safely (namespaces, methods, permissions)

  • Use a unique namespace vendor/v1; avoid wp/* unless core.
  • Always provide permission_callback (use __return_true for public endpoints).
  • Use WP_REST_Server::READABLE/CREATABLE/EDITABLE/DELETABLE constants.
  • Return data via rest_ensure_response() or WP_REST_Response.
  • Return errors via WP_Error with an explicit status.

Read references/routes-and-endpoints.md.

3) Validate/sanitize request args

  • Define args with type, default, required, validate_callback, sanitize_callback.
  • Prefer JSON Schema validation with rest_validate_value_from_schema then rest_sanitize_value_from_schema.
  • Never read $_GET/$_POST directly inside endpoints; use WP_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_field for computed fields; register_meta with show_in_rest for meta.
  • For object/array meta, define schema in show_in_rest.schema.
  • If you need unfiltered post content (e.g., ToC plugins injecting HTML), request ?context=edit to access content.raw (auth required). Pair with _fields=content.raw to 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 (action wp_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 (Link header or <link rel="https://api.w.org/">).
  • Support _fields, _embed, _method, _envelope, pagination headers.
  • Remember per_page is capped at 100.

Read references/discovery-and-params.md.

Verification

  • /wp-json/ index includes your namespace.
  • OPTIONS on your route returns schema (when provided).
  • Endpoint returns expected data; permission failures return 401/403 as appropriate.
  • CPT/taxonomy routes appear under wp/v2 when show_in_rest is true.
  • Run repo lint/tests and any PHP/JS build steps.

Failure modes / debugging

  • 404: rest_api_init not firing, route typo, or permalinks off (use ?rest_route=).
  • 401/403: missing nonce/auth, or permission_callback too strict.
  • _doing_it_wrong for missing permission_callback: add it (use __return_true if public).
  • Invalid params: missing/incorrect args schema or validation callbacks.
  • Fields missing: show_in_rest false, meta not registered, or CPT lacks custom-fields support.

Escalation

If version support or behavior is unclear, consult the REST API Handbook and core docs before inventing patterns.

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.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.