php-wordpress について
WordPress開発者向けに、テーマ、プラグイン、Gutenbergブロックの開発を扱うスキルです。トピックと習熟度に沿って学習内容を整理し、セキュリティ、REST API、WooCommerce拡張も取り上げます。
主な機能
- 01テーマ開発のガイダンス
- 02プラグイン設計とフック
- 03Gutenbergブロックとパターン
- 04REST APIエンドポイントと認証
- 05入力・出力のセキュリティ対策
- 06WooCommerce拡張のトピック
活用シーン
- 01WordPressテーマの構成を計画
- 02プラグインのフックや設定を実装
- 03Gutenbergブロックの作成とデバッグ
- 04サニタイズと出力エスケープを確認
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ pluginagentmarketplace/ custom-plugin-php --skill php-wordpressインストール後、Claude Code で/php-wordpressを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
assets/config.yamlschema.jsonreferences/GUIDE.mdPATTERNS.mdscripts/validate.py詳細
WordPress 開発スキル
WordPress のテーマとプラグイン開発を習得するためのアトミックスキル
概要
WordPress のテーマ、プラグイン、Gutenberg ブロックを構築するための包括的なスキルです。最新の開発手法とセキュリティに重点を置き、WordPress 6.x を対象としています。
スキルのパラメーター
入力の検証
interface SkillParams {
topic:
| "themes" // Classic, block, FSE
| "plugins" // Architecture, hooks, settings
| "gutenberg" // Blocks, patterns, InnerBlocks
| "rest-api" // Custom endpoints, authentication
| "security" // Nonces, sanitization, escaping
| "woocommerce"; // Store extensions
level: "beginner" | "intermediate" | "advanced";
wp_version?: "6.4" | "6.5" | "6.6" | "6.7";
theme_type?: "classic" | "block" | "hybrid";
}
検証ルール
validation:
topic:
required: true
allowed: [themes, plugins, gutenberg, rest-api, security, woocommerce]
level:
required: true
wp_version:
default: "6.6"
学習モジュール
モジュール 1:テーマ開発
beginner:
- Theme structure and files
- Template hierarchy
- Enqueuing styles/scripts
intermediate:
- Custom post types
- Theme customizer
- Block theme basics
advanced:
- Full Site Editing
- theme.json deep dive
- Performance optimization
モジュール 2:プラグイン開発
beginner:
- Plugin structure
- Actions and filters
- Shortcodes
intermediate:
- Settings API
- Custom database tables
- AJAX handling
advanced:
- Plugin architecture patterns
- WP-CLI commands
- Multisite support
モジュール 3:Gutenberg ブロック
beginner:
- Block basics and block.json
- Edit and save functions
- Block attributes
intermediate:
- InnerBlocks
- Block variations
- Server-side rendering
advanced:
- Interactivity API
- Block Bindings
- Custom block categories
エラー処理と再試行ロジック
errors:
HOOK_ERROR:
code: "WP_001"
recovery: "Check hook name and timing"
SECURITY_ERROR:
code: "WP_002"
recovery: "Add proper escaping/sanitization"
retry:
max_attempts: 3
backoff:
type: exponential
initial_delay_ms: 100
コード例
プラグインヘッダー
<?php
/**
* Plugin Name: My Custom Plugin
* Description: A custom WordPress plugin
* Version: 1.0.0
* Requires PHP: 8.0
* Author: Developer
*/
declare(strict_types=1);
defined('ABSPATH') || exit;
final class MyCustomPlugin
{
public function __construct()
{
add_action('init', [$this, 'registerPostType']);
add_action('rest_api_init', [$this, 'registerRoutes']);
}
public function registerPostType(): void
{
register_post_type('portfolio', [
'labels' => ['name' => __('Portfolio')],
'public' => true,
'show_in_rest' => true,
'supports' => ['title', 'editor', 'thumbnail'],
]);
}
public function registerRoutes(): void
{
register_rest_route('myplugin/v1', '/items', [
'methods' => 'GET',
'callback' => [$this, 'getItems'],
'permission_callback' => '__return_true',
]);
}
public function getItems(\WP_REST_Request $request): \WP_REST_Response
{
$items = get_posts(['post_type' => 'portfolio']);
return new \WP_REST_Response($items, 200);
}
}
new MyCustomPlugin();
Gutenberg ブロック(block.json)
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "myplugin/testimonial",
"title": "Testimonial",
"category": "widgets",
"icon": "format-quote",
"description": "Display a testimonial",
"supports": {
"html": false,
"align": ["wide", "full"]
},
"attributes": {
"content": { "type": "string" },
"author": { "type": "string" }
},
"textdomain": "myplugin",
"editorScript": "file:./index.js",
"style": "file:./style-index.css"
}
セキュリティのベストプラクティス
<?php
// Input sanitization
$title = sanitize_text_field($_POST['title'] ?? '');
$content = wp_kses_post($_POST['content'] ?? '');
$id = absint($_POST['id'] ?? 0);
// Output escaping
echo esc_html($title);
echo esc_attr($attribute);
echo esc_url($url);
echo wp_kses_post($content);
// Nonce verification
if (!wp_verify_nonce($_POST['_wpnonce'], 'my_action')) {
wp_die('Security check failed');
}
// Capability check
if (!current_user_can('edit_posts')) {
wp_die('Unauthorized');
}
// Database queries
global $wpdb;
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}custom_table WHERE id = %d",
$id
)
);
トラブルシューティング
| 問題 | 解決策 |
|---|---|
| フックが実行されない | フック名のスペルと実行タイミングを確認してください |
| ブロックが表示されない | block.json を確認し、npm build を実行してください |
| REST API が 403 を返す | permission_callback を確認してください |
| 画面が真っ白になる | WP_DEBUG を有効にし、error.log を確認してください |
デバッグ定数
// wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', true);
品質指標
| 指標 | 目標 |
|---|---|
| セキュリティ準拠率 | 100% |
| フックの正確性 | 100% |
| WPCS 準拠率 | 100% |
使用方法
Skill("php-wordpress", {topic: "gutenberg", level: "intermediate"})
コメント
Markdown 対応