Wp Cli Securityのロゴ

Wp Cli Security

組織
wpultimatesecurity
wp-cli-security

WP_CLI::add_commandでWP-CLIコマンドを登録するときや、コマンドのロジックを書くときに使います。位置引数と連想引数を検証・サニタイズし、ログイン中のユーザーや権限のコンテキストが存在することを前提にせず、秘密情報の出力を避け、破壊的な操作の前に確認を求めます。CLI経由のインジェクションや安全でない自動化を防ぎます。

Add to TypingMind

概要

公開者wpultimatesecurity
リポジトリWordPress-Security-Skills
スキル名wp-cli-security
スター
54
フォーク
3
同梱ファイル
2
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 2個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    wpultimatesecurityがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Wp Cli Security」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/wp-cli-security
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wpultimatesecurity/WordPress-Security-Skills.git /tmp/WordPress-Security-Skills
mkdir -p .claude/skills
cp -r /tmp/WordPress-Security-Skills/skills/wp-cli-security .claude/skills/wp-cli-security
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでWp Cli Securityを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にWp Cli Securityを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Wp Cli Securityは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

WP-CLI security

When to use this skill

Use this skill whenever code registers or implements a WP-CLI command:

  • WP_CLI::add_command( 'my-plugin thing', ... ).
  • Writing a command class method that reads $args / $assoc_args.
  • Running destructive operations (delete, reset, import, purge) from the command line.
  • Returning data or logging progress from a CLI routine.

WP-CLI runs as the system user, often as root on containers or with broad file-system permissions. It has no WordPress current user by default, so current_user_can() does not authorize CLI actions. Arguments are still untrusted input.

Related: see the capability-permission-checks skill for normal web-request authorization and the cron-background-job-security skill for scheduled jobs.

Core principles (and why they matter)

  1. No current_user_can() in CLI by default. There is no logged-in WordPress user. Either use WP_CLI::launch_self() with a --user flag, explicitly set a user with --user, or perform capability-independent maintenance tasks only.
  2. Sanitize every argument. $args and $assoc_args can come from scripts, CI, or shell history; treat them as untrusted input.
  3. Use prepared statements for database access. Do not interpolate $args into $wpdb queries.
  4. Confirm destructive actions. WP_CLI::confirm() stops accidental data loss in automated runs.
  5. Never print secrets. API keys, tokens, and passwords must not appear in CLI output, logs, or shell history.
  6. Be explicit about --allow-root. Running as root is common in containers but dangerous; document it and avoid file ownership surprises.

Step-by-step implementation

  1. Register the command with WP_CLI::add_command() and a clear docblock.
  2. In the command method, validate argument counts and sanitize each value to type.
  3. For destructive commands, call WP_CLI::confirm() unless --yes is passed.
  4. Use $wpdb->prepare() for any dynamic query.
  5. Avoid echo; use WP_CLI::log(), WP_CLI::success(), or WP_CLI::error().
  6. If the command needs a user context, require --user=<id|login|email> and load it with WP_User::get_data_by() / wp_set_current_user().

Supporting references

ReferenceLoad when
WP-CLI security checklistBefore final verification of the wp-cli security controls.
Secure WP-CLI commandImplementing a WP-CLI command with sanitized arguments, prepared queries, destructive-action confirmation, and explicit user context.

Common AI mistakes / anti-patterns

Mistake 1 — Interpolating $args into a query

php
// ❌ Insecure: SQL injection via CLI argument.
$wpdb->query( "DELETE FROM {$wpdb->prefix}my_table WHERE id = {$args[0]}" );
php
// ✅ Secure: use $wpdb->prepare().
$id = absint( $args[0] );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}my_table WHERE id = %d", $id ) );

Mistake 2 — Assuming an admin user context

php
// ❌ Insecure: current_user_can is meaningless without --user.
if ( current_user_can( 'manage_options' ) ) {
    update_option( 'my_plugin_key', $value );
}
php
// ✅ Secure: require --user or gate by filesystem/CLI policy, not web capability.
class My_Plugin_CLI_Command {
    /**
     * Update a setting.
     *
     * ## OPTIONS
     * [--user=<user>]
     * : User to run as.
     */
    public function update_setting( $args, $assoc_args ) {
        if ( isset( $assoc_args['user'] ) ) {
            $user = get_user_by( 'login', $assoc_args['user'] );
            if ( $user ) {
                wp_set_current_user( $user->ID );
            }
        }

        if ( ! current_user_can( 'manage_options' ) ) {
            WP_CLI::error( 'This command requires --user with manage_options capability.' );
        }

        update_option( 'my_plugin_key', sanitize_text_field( $args[0] ) );
        WP_CLI::success( 'Setting updated.' );
    }
}

Mistake 3 — Printing secrets in output

php
// ❌ Insecure: secret is now in shell history and terminal scrollback.
WP_CLI::log( 'Using API key: ' . $api_key );
php
// ✅ Secure: log an identifier or redacted value.
WP_CLI::log( 'Using API key ending in: ' . substr( $api_key, -4 ) );

Mistake 4 — Destructive command with no confirmation

php
// ❌ Risky: a typo in CI wipes data.
public function purge( $args ) {
    $wpdb->query( "TRUNCATE {$wpdb->prefix}my_plugin_logs" );
}
php
// ✅ Secure: require confirmation unless --yes is passed.
public function purge( $args, $assoc_args ) {
    if ( ! isset( $assoc_args['yes'] ) ) {
        WP_CLI::confirm( 'This will delete all logs. Are you sure?' );
    }
    global $wpdb;
    $wpdb->query( "TRUNCATE {$wpdb->prefix}my_plugin_logs" );
    WP_CLI::success( 'Logs purged.' );
}

Mistake 5 — Trusting associative args without defaults

php
// ❌ Fragile: missing key causes undefined array warning.
$days = $assoc_args['days'];
php
// ✅ Secure: provide defaults and sanitize.
$days = isset( $assoc_args['days'] ) ? absint( $assoc_args['days'] ) : 30;

Correct code examples

A complete secure WP-CLI command class is in references/secure-wp-cli-command.php.

Checklist

  • Every CLI argument is sanitized to its expected type.
  • Database queries use $wpdb->prepare(); no argument interpolation.
  • Destructive commands call WP_CLI::confirm() unless --yes is provided.
  • The command does not rely on current_user_can() without an explicit --user.
  • Secrets, tokens, and API keys are never printed or logged in plaintext.
  • --allow-root usage is documented and justified.
  • Output uses WP_CLI::log() / success() / error() instead of echo.
  • Command docblocks define options and examples.

Official references

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Wp Cli Security」では何ができますか?

WP_CLI::add_commandでWP-CLIコマンドを登録するときや、コマンドのロジックを書くときに使います。位置引数と連想引数を検証・サニタイズし、ログイン中のユーザーや権限のコンテキストが存在することを前提にせず、秘密情報の出力を避け、破壊的な操作の前に確認を求めます。CLI経由のインジェクションや安全でない自動化を防ぎます。

TypingMindでWp Cli Securityを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Wp Cli Securityはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにWp Cli Securityをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/wp-cli-securityを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Wp Cli Securityを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Wp Cli Securityで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもWp Cli Securityを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Wp Cli Security」は無料ですか?

はい。wpultimatesecurityがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇