SU

superpowers-sage:wp-rest-api

Tools for building and debugging WordPress REST API endpoints.

Install

mkdir -p .claude/skills/superpowers-sage-wp-rest-api && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16234" && unzip -o skill.zip -d .claude/skills/superpowers-sage-wp-rest-api && rm skill.zip

Installs to .claude/skills/superpowers-sage-wp-rest-api

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

WordPress REST API — register_rest_route, WP_REST_Controller, WP_REST_Request, REST namespace, custom endpoints, Application Passwords, JWT REST authentication, permission_callback, schema validation, WP_REST_Response, REST API versioning, rest_ensure_response, coexistence with Acorn Routes, register_rest_route vs routes/web.php decision, REST API debugging, wp rest-api namespace list, wp json discovery, CORS, REST nonce, cookie auth, REST API disable, JSON schema validation
479 charsno explicit “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Intermediate

Key capabilities

  • Choose between native WordPress REST and Acorn Routes
  • Register native REST endpoints using `register_rest_route()`
  • Implement authentication methods for REST API
  • Expose custom fields and Custom Post Types (CPTs)
  • Avoid common REST API anti-patterns
  • Troubleshoot REST API failures

How it works

The skill guides the user in choosing between native REST and Acorn Routes, registering endpoints with `register_rest_route()`, implementing authentication, and exposing custom data, while also providing anti-pattern avoidance and troubleshooting.

Inputs & outputs

You give it
API requirements, existing Acorn Routes, target consumers
You get back
Registered REST endpoints, configured authentication, exposed custom fields

When to use superpowers-sage:wp-rest-api

  • Creating custom REST endpoints
  • Debugging WordPress API
  • Validating JSON schemas

About this skill

WordPress REST API Patterns

When to use

Use this skill when the task involves creating, modifying, or debugging WordPress REST API endpoints, or when deciding between native REST and Acorn Routes for an API surface.

Inputs required

  • The API requirements: what data to expose, who consumes it, and authentication needs
  • Whether the project already uses Acorn Routes (check routes/web.php or routes/api.php)
  • The target consumers: Gutenberg editor, mobile apps, third-party integrations, or internal front-end

Procedure

Step 1 — Choose between Native REST and Acorn Routes

See references/acorn-coexistence.md for the full decision matrix.

Quick rule: use native REST for WordPress-ecosystem integration and Acorn Routes for application logic. Both can coexist in the same project.

Step 2 — Register native REST endpoints

Always use register_rest_route() inside a rest_api_init action. Never omit permission_callback.

See references/custom-endpoints.md for full examples including WP_REST_Controller pattern and JSON schema validation.

public function boot(): void
{
    add_action('rest_api_init', [$this, 'registerRoutes']);
}

public function registerRoutes(): void
{
    register_rest_route('myapp/v1', '/posts', [
        'methods'             => 'GET',
        'callback'            => [$this, 'getPosts'],
        'permission_callback' => '__return_true',
    ]);

    register_rest_route('myapp/v1', '/posts', [
        'methods'             => 'POST',
        'callback'            => [$this, 'createPost'],
        'permission_callback' => fn() => current_user_can('edit_posts'),
        'args'                => $this->getCreatePostArgs(),
    ]);
}

Step 3 — Authentication

See references/authentication.md for Application Passwords, cookie/nonce auth, and JWT patterns.

Quick reference:

  • Same-origin JS: Cookie + X-WP-Nonce header
  • External app / mobile: Application Passwords (Basic Auth)
  • Internal Acorn routes: JWT middleware with wp_set_current_user()

Step 4 — Expose custom fields and CPTs

// Expose a CPT in the REST API
register_post_type('event', [
    'show_in_rest' => true,
    'rest_base'    => 'events',
]);

// Register a custom field on an existing endpoint
add_action('rest_api_init', function () {
    register_rest_field('post', 'reading_time', [
        'get_callback' => fn($post) => (int) get_post_meta($post['id'], '_reading_time', true),
        'schema'       => ['type' => 'integer', 'description' => 'Reading time in minutes'],
    ]);
});

Step 5 — Avoid anti-patterns

Anti-patternProblemCorrect approach
Closure in route callbackCannot be cached; breaks serializationUse class method reference [$this, 'method']
Missing permission_callbackEmits _doing_it_wrong; endpoint unprotectedAlways include permission_callback
Returning raw arraysMissing REST response headersUse rest_ensure_response()
Hardcoded namespace versionVersion changes require find-and-replaceDefine as class constants
No schema definitionClients cannot discover endpoint shapeDefine get_item_schema() on the controller
Duplicating endpoint in both systemsConfusing and harder to maintainOne canonical endpoint per resource

Verification

  • Every register_rest_route() call includes a permission_callback
  • Argument schemas define type, required, and sanitize_callback where applicable
  • CPTs that need REST access have show_in_rest => true
  • Authentication method matches the consumer
  • Pagination headers (X-WP-Total, X-WP-TotalPages) are set on collection endpoints
  • No closures used as route callbacks
  • No direct database queries in callbacks — logic is in Service classes
  • Native REST and Acorn Routes do not duplicate the same resource

Failure modes

See references/troubleshooting.md for detailed diagnosis of 401, CORS, rest_no_route, schema validation failures, and 404 on custom namespace.

Quick reference:

SymptomCauseFix
404 on REST endpointMissing rest_api_init hook or permalink flush neededFlush permalinks: lando wp rewrite flush
rest_no_route errorTypo in namespace or route pathCheck namespace and path match
401 on authenticated endpointNonce not sent or expiredSend X-WP-Nonce header
CPT not in /wp/v2/show_in_rest not setAdd 'show_in_rest' => true

Escalation

  • If the REST API is entirely disabled (by a security plugin or custom code), check for rest_authentication_errors filters or rest_enabled overrides.
  • If performance is critical (hundreds of requests per second), recommend a dedicated caching layer (Varnish, Cloudflare) rather than transient-based caching.
  • If the API must serve a mobile app with offline support, recommend evaluating a dedicated API framework or GraphQL layer beyond the scope of this skill.

When not to use it

  • When the REST API is entirely disabled by a security plugin or custom code
  • When performance is critical and requires a dedicated caching layer
  • When the API must serve a mobile app with offline support and requires a dedicated API framework

Limitations

  • Requires `permission_callback` for every `register_rest_route()` call.
  • Argument schemas must define `type`, `required`, and `sanitize_callback` where applicable.
  • Closures in route callbacks cannot be cached and break serialization.

How it compares

This skill provides structured patterns and decision matrices for WordPress REST API development, including coexistence with Acorn Routes and anti-pattern avoidance, which is more guided than manual implementation.

Compared to similar skills

superpowers-sage:wp-rest-api side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
superpowers-sage:wp-rest-api (this skill)04moNo flagsIntermediate
laravel-specialist123moNo flagsIntermediate
developing-with-turbo-streams15moNo flagsIntermediate
payment-integration16moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

laravel-specialist

Jeffallan

Use when building Laravel 10+ applications requiring Eloquent ORM, API resources, or queue systems. Invoke for Laravel models, Livewire components, Sanctum authentication, Horizon queues.

1215

developing-with-turbo-streams

hotwired-laravel

Basics of developing with Turbo Streams in web applications. Activate when working on projects that utilize Turbo Streams for enhancing user experience through real-time updates, dynamic content changes, and partial page updates without full reloads.

15

payment-integration

mrgoonie

Integrate payments with SePay (VietQR), Polar, Stripe, Paddle (MoR subscriptions), Creem.io (licensing). Checkout, webhooks, subscriptions, QR codes, multi-provider orders.

13

developing-with-prism

prism-php

Guide for developing with Prism PHP package - a Laravel package for integrating LLMs. Activate or use when working with Prism features including text generation, structured output, embeddings, image generation, audio processing, streaming, tools/function calling, or any LLM provider integration (OpenAI, Anthropic, Gemini, Mistral, Groq, XAI, DeepSeek, OpenRouter, Ollama, VoyageAI, ElevenLabs). Activate for any Prism-related development tasks.

12

restapi-translations

mikopbx

Управление переводами REST API ключей (rest_*) для MikoPBX. Автоматически находит отсутствующие русские ключи в RestApi.php и синхронизирует их с исходным кодом. Использовать при проверке переводов API, после добавления новых endpoints или перед релизом.

11

moodle-external-api-development

davila7

Create custom external web service APIs for Moodle LMS. Use when implementing web services for course management, user tracking, quiz operations, or custom plugin functionality. Covers parameter validation, database operations, error handling, service registration, and Moodle coding standards.

10

Search skills

Search the agent skills registry