Community생산성 & 협업github.com

wordpress/wp-rest-api

WordPress REST API 엔드포인트/라우트를 구축, 확장 또는 디버깅할 때 사용: register_rest_route, WP_REST_Controller/컨트롤러 클래스, 스키마/인수 검증, permission_callback/인증, 응답 구조화, register_rest_field/register_meta, 또는 show_in_rest를 통한 CPT/분류 노출.

wp-rest-api란 무엇인가요?

이 스킬은 WordPress REST API와 관련된 모든 작업을 수행하는 AI 에이전트(예: Claude Code, Cursor, Codex)를 위한 전문 지침입니다. 개발자가 `register_rest_route`를 사용하여 커스텀 라우트를 등록하거나, `WP_REST_Controller`를 확장하여 CRUD 작업을 수행하거나, 스키마 및 인수 검증을 통해 API 요청의 유효성을 검증해야 할 때 이 스킬이 활성화됩니다. 또한 `permission_callback`을 통해 사용자 인증 및 권한 부여 로직을 구현하고, `register_rest_field` 또는 `register_meta`를 사용하여 기존 응답에 추가 필드를 포함시키는 방법을 안내합니다. 이 스킬은 `show_in_rest` 속성을 통해 커스텀 포스트 타입(CPT) 또는 분류(taxonomy)를 REST API에 노출하는 방법도 다룹니다. WordPress 개발 환경(로컬 또는 원격)에서 REST API를 디버깅하거나 확장하는 모든 시나리오에 적합하며, API 응답 구조화 및 오류 처리 모범 사례를 제공합니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/wordpress/agent-skills/tree/main/skills/wp-rest-api

Installed? Explore more 생산성 & 협업 skills: steipete/gemini, steipete/gh-issues, steipete/skill-creator · View all 6 →

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

wp-rest-api은(는) 무엇을 하나요?

WordPress REST API 엔드포인트/라우트를 구축, 확장 또는 디버깅할 때 사용: register_rest_route, WP_REST_Controller/컨트롤러 클래스, 스키마/인수 검증, permission_callback/인증, 응답 구조화, register_rest_field/register_meta, 또는 show_in_rest를 통한 CPT/분류 노출.

주요 사용 사례

  • 커스텀 REST 라우트 등록: register_rest_route() 함수를 사용하여 새로운 엔드포인트를 추가합니다.
  • WP_REST_Controller 확장: WP_REST_Controller 클래스를 상속하여 표준 CRUD 동작을 구현합니다.
  • 스키마 및 인수 검증: schema 및 args 배열을 정의하여 요청 데이터의 유효성을 검증합니다.
  • 권한 콜백 구현: permission_callback을 사용하여 현재 사용자의 액세스 권한을 확인합니다.
  • 응답 구조화: WP_REST_Response 객체를 사용하여 표준화된 응답 형식을 반환합니다.
  • 필드 및 메타 등록: register_rest_field() 또는 register_meta()를 사용하여 기존 엔드포인트에 추가 데이터를 노출합니다.
  • CPT/분류 노출: register_post_type() 또는 register_taxonomy() 호출 시 show_in_rest 인수를 true로 설정합니다.

사용 방법

  1. 플러그인 또는 테마의 functions.php 파일에서 rest_api_init 액션에 콜백 함수를 연결합니다.
  2. 콜백 함수 내에서 register_rest_route()를 호출하여 라우트를 정의합니다.
  3. 필요에 따라 WP_REST_Controller를 확장하는 별도의 컨트롤러 클래스를 생성합니다.
  4. 각 라우트에 대해 methods, callback, permission_callback, args를 지정합니다.
  5. WP_REST_Response를 반환하거나 WP_Error를 반환하여 오류를 처리합니다.

예제 코드

add_action('rest_api_init', function () {
    register_rest_route('myplugin/v1', '/items/(?P<id>\d+)', array(
        'methods' => 'GET',
        'callback' => 'myplugin_get_item',
        'permission_callback' => function () {
            return current_user_can('edit_posts');
        },
        'args' => array(
            'id' => array(
                'validate_callback' => function($param, $request, $key) {
                    return is_numeric($param);
                }
            ),
        ),
    ));
});

function myplugin_get_item($request) {
    $item_id = $request['id'];
    $item = get_post($item_id);

    if (!$item) {
        return new WP_Error('not_found', '아이템을 찾을 수 없습니다.', array('status' => 404));
    }

    $response = new WP_REST_Response($item);
    $response->set_status(200);

    return $response;
}

디버깅 팁

  • WP_DEBUG 및 WP_DEBUG_LOG를 활성화하여 REST API 요청 중 발생하는 오류를 기록합니다.
  • curl 또는 Postman과 같은 도구를 사용하여 엔드포인트를 테스트합니다.
  • register_rest_route() 호출 시 namespace에 슬래시(/)가 포함되지 않도록 주의합니다.
  • permission_callback에서 true를 반환하는 것은 현재 사용자에게 권한이 있음을 의미하며, false 또는 WP_Error는 거부를 의미합니다.
  • 응답 데이터를 WP_REST_Response로 래핑하여 일관된 구조(data, headers, status)를 유지합니다.

참고 자료

Individual skills in this repo

This repo contains 13 individual skills — each has its own dedicated page.

wordpress/blueprint

Use when creating, editing, or reviewing WordPress Playground blueprint JSON files. Triggers on mentions of blueprints, playground configuration, or requests to set up a WordPress demo environment.

wordpress/wordpress-router

Use when the user asks about WordPress codebases (plugins, themes, block themes, Gutenberg blocks, WP core checkouts) and you need to quickly classify the repo and route to the correct workflow/skill (blocks, theme.json, REST API, WP-CLI, performance, security, testing, release packaging).

wordpress/wp-abilities-api

Use when working with the WordPress Abilities API (wp_register_ability, wp_register_ability_category, /wp-json/wp-abilities/v1/*, @wordpress/abilities) including defining abilities, categories, meta, REST exposure, and permissions checks for clients.

wordpress/wp-block-development

Use when developing WordPress (Gutenberg) blocks: block.json metadata, register_block_type(_from_metadata), attributes/serialization, supports, dynamic rendering (render.php/render_callback), deprecations/migrations, viewScript vs viewScriptModule, and @wordpress/scripts/@wordpress/create-block build and test workflows.

wordpress/wp-block-themes

Use when developing WordPress block themes: theme.json (global settings/styles), templates and template parts, patterns, style variations, and Site Editor troubleshooting (style hierarchy, overrides, caching).

wordpress/wpds

Use when building UIs leveraging the WordPress Design System (WPDS) and its components, tokens, patterns, etc.

wordpress/wp-interactivity-api

Use when building or debugging WordPress Interactivity API features (data-wp-* directives, @wordpress/interactivity store/state/actions, block viewScriptModule integration, wp_interactivity_*()) including performance, hydration, and directive behavior.

wordpress/wp-performance

Use when investigating or improving WordPress performance (backend-only agent): profiling and measurement (WP-CLI profile/doctor, Server-Timing, Query Monitor via REST headers), database/query optimization, autoloaded options, object caching, cron, HTTP API calls, and safe verification.

wordpress/wp-phpstan

Use when configuring, running, or fixing PHPStan static analysis in WordPress projects (plugins/themes/sites): phpstan.neon setup, baselines, WordPress-specific typing, and handling third-party plugin classes.

wordpress/wp-playground

Use for WordPress Playground workflows: fast disposable WP instances in the browser or locally via @wp-playground/cli (server, run-blueprint, build-snapshot), auto-mounting plugins/themes, switching WP/PHP versions, blueprints, and debugging (Xdebug).

wordpress/wp-plugin-development

Use when developing WordPress plugins: architecture and hooks, activation/deactivation/uninstall, admin UI and Settings API, data storage, cron/tasks, security (nonces/capabilities/sanitization/escaping), and release packaging.

wordpress/wp-project-triage

Use when you need a deterministic inspection of a WordPress repository (plugin/theme/block theme/WP core/Gutenberg/full site) including tooling/tests/version hints, and a structured JSON report to guide workflows and guardrails.

wordpress/wp-wpcli-and-ops

Use when working with WP-CLI (wp) for WordPress operations: safe search-replace, db export/import, plugin/theme/user/content management, cron, cache flushing, multisite, and scripting/automation with wp-cli.yml.

관련 스킬