wp-rest-api

Build and debug WordPress REST API routes with validation and permissions.

Updated Sep 22, 2024
One-click install
npx skills add https://github.com/WordPressBugBounty/plugins-woocommerce-for-japan --skill wp-rest-api-wordpressbugbounty
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: wp-rest-api
Source: https://github.com/WordPressBugBounty/plugins-woocommerce-for-japan/tree/main/woocommerce-for-japan/.claude/skills/wp-rest-api
Command: npx skills add https://github.com/WordPressBugBounty/plugins-woocommerce-for-japan --skill wp-rest-api-wordpressbugbounty

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you reliably build, extend, and troubleshoot WordPress REST API routes when endpoints fail, return the wrong data, or lack proper authentication, permissions, validation, and schema for consumers.

Core Features & Use Cases

  • Route and controller setup: Register REST routes safely using rest_api_init, prefer WP_REST_Controller for non-trivial logic, and ensure endpoints expose correctly under your namespace.
  • Permissions and authentication debugging: Diagnose 401/403/404 issues by tightening permission_callback and choosing the right auth method (cookie + nonce vs application passwords).
  • Request validation and schema correctness: Define args with type/default/required plus validation/sanitization to prevent invalid inputs and improve REST discovery via OPTIONS.

Quick Start

Use the wp-rest-api skill to implement a custom REST route at /wp-json/my-plugin/v1/orders that validates JSON inputs, enforces capability-based permissions, and returns a schema-backed response suitable for a JavaScript client.

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 route with proper validation?

Register WordPress REST API routes safely on `rest_api_init` using a proper namespace, define `args` with JSON-schema types for validation and sanitization, and enforce capabilities via `permission_callback` to ensure secure client integration.

Why does my WordPress REST API endpoint return a 404 or invalid param error?

WordPress REST API endpoints return 404 or invalid param errors when route registration is incorrect, namespaces mismatch, or `args` lack proper JSON-schema type definitions and sanitization callbacks. Tightening route registration and schema validation resolves these failures.

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

Expose custom post types and taxonomies via the WordPress REST API by setting `show_in_rest` to true during registration, ensuring they appear under the correct namespace and are accessible for JavaScript client integration and data fetching.

What is the correct way to handle WordPress REST API authentication and permissions?

WordPress REST API authentication depends on choosing between cookie plus nonce for logged-in users or application passwords for external clients, combined with a strict `permission_callback` to prevent 401 and 403 permission failures on protected endpoints.

Do I need WP_REST_Controller for non-trivial WordPress REST endpoints?

Using `WP_REST_Controller` for non-trivial WordPress REST endpoints is recommended to standardize CRUD operations, ensure consistent REST response and field handling, and maintain proper schema-backed JSON formatting for JavaScript clients.

Can I use application passwords instead of cookie nonce authentication for WordPress REST API?

Application passwords work with the WordPress REST API for external client authentication where cookie plus nonce is impractical, providing a secure alternative for machine-to-machine data exposure without requiring interactive user login sessions.