wp-rest-api

Register WordPress REST API routes, controllers, and permission callbacks.

1|Updated Apr 20, 2025
One-click install
npx skills add https://github.com/j7-dev/wp-power-checkout --skill wp-rest-api-j7-dev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: wp-rest-api
Source: https://github.com/j7-dev/wp-power-checkout/tree/main/.github/skills/wp-rest-api
Command: npx skills add https://github.com/j7-dev/wp-power-checkout --skill wp-rest-api-j7-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill streamlines the creation, extension, and debugging of WordPress REST API endpoints, ensuring seamless data exchange for your applications.

Core Features & Use Cases

  • Endpoint Registration: Define new REST routes and controllers for custom data.
  • Debugging: Troubleshoot 401/403/404 errors, permission issues, and nonce problems.
  • Data Shaping: Add custom fields, meta, and control response structure.
  • Use Case: You need to expose a custom post type's data via the REST API. This Skill will guide you through registering the necessary routes and ensuring proper permissions and field exposure.

Quick Start

Use the wp-rest-api skill to register a new GET endpoint under the 'my-plugin/v1' namespace that retrieves a list of all published posts.

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 for a post type?

To register a custom WordPress REST API route, you define the route under a specific namespace, create a controller class, define permission callbacks, and shape the API response structure to expose your custom data.

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

WordPress REST API endpoints return 404 or 401 errors due to unregistered routes, missing permission callbacks, or invalid nonce authentication. Debugging involves verifying route registration and validating request arguments to resolve these permission issues.

Does building custom wp-json endpoints require a specific WordPress version?

Building and debugging custom wp-json endpoints targets WordPress 6.9 or higher. Additionally, certain workflows for managing and registering these REST API routes require WP-CLI to be installed in your environment.

How do I add custom fields and meta to a WordPress REST API response?

Adding custom fields and meta to a WordPress REST API response involves shaping the data structure within your controller class. You define the response output and register the meta fields to expose them alongside your custom post type data.

What is the best way to debug permission callbacks in WordPress REST API routes?

The best way to debug permission callbacks in WordPress REST API routes is to validate request arguments and check nonce problems directly. Troubleshooting 403 errors requires verifying that your permission logic correctly authorizes the request.

Can I shape API responses without writing a custom controller class in WordPress?

Shaping API responses in WordPress typically requires defining a controller class to properly structure the data output. Without a controller, you cannot effectively manage custom fields, meta, or implement the necessary permission callbacks for your routes.