wp-rest-api

Register and troubleshoot WordPress REST API routes with schemas and permission callbacks.

3|2|Updated Jun 9, 2021
One-click install
npx skills add https://github.com/artisanworkshop/Japanized-for-WooCommerce --skill wp-rest-api-artisanworkshop
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: wp-rest-api
Source: https://github.com/artisanworkshop/Japanized-for-WooCommerce/tree/main/.claude/skills/wp-rest-api
Command: npx skills add https://github.com/artisanworkshop/Japanized-for-WooCommerce --skill wp-rest-api-artisanworkshop

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It solves the pain of creating or modifying WordPress REST API routes safely, validating inputs, shaping responses, and fixing authentication/permission issues that cause 401/403/404 failures.

Core Features & Use Cases

  • Route and controller implementation: Register custom endpoints with register_rest_route and use WP_REST_Controller for non-trivial logic.
  • Schema-backed validation: Define args with types and required fields, and validate/sanitize using WordPress REST schema helpers.
  • Safe REST behaviors: Handle permission_callback correctly, add meta/fields via register_rest_field or register_meta, and preserve core endpoint compatibility.
  • REST exposure for content types: Enable show_in_rest for CPTs and taxonomies (including rest_base and optional rest_controller_class) so clients can discover resources consistently.
  • Debugging and troubleshooting: Triage REST usage, locate route failures, and verify discovery, OPTIONS behavior, and expected status codes.

Quick Start

Use this skill to implement a custom endpoint at /wp-json/<namespace>/<route> by following the skill procedure, starting with triaging the repo for existing REST usage and then registering routes on rest_api_init with a strict args schema and an explicit permission_callback.

Frequently Asked Questions about wp-rest-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I register a custom WordPress REST API endpoint safely?

To add custom fields to WordPress REST API responses, use register_rest_field or register_meta to expose meta data, ensuring you define the schema and apply rest_validate_value_from_schema and rest_sanitize_value_from_schema for correct data handling.

Why does my WordPress REST API route return a 401 or 403 error?

WordPress REST API routes return 401 or 403 errors when the permission_callback is missing, returns false, or fails WP_REST_Request authentication, requiring you to verify nonce handling and user capabilities before access is granted.

How do I expose custom post types and taxonomies to the WordPress REST API?

To expose custom post types and taxonomies to the WordPress REST API, set show_in_rest to true, define a rest_base for consistent URL structuring, and optionally specify a rest_controller_class for custom endpoint behavior.

What is the best way to validate and sanitize WP_REST_Request arguments?

The best way to validate and sanitize WP_REST_Request arguments is defining a schema with required types and using WordPress REST schema helpers like rest_validate_value_from_schema and rest_sanitize_value_from_schema within your register_rest_route args configuration.

Can I use WP_REST_Controller for complex WordPress REST API endpoint logic?

Yes, you can use WP_REST_Controller for complex WordPress REST API endpoint logic, extending it to handle standard CRUD operations, schema validation, and response shaping while maintaining core endpoint compatibility and discovery.