Wp Cli Security logo

Wp Cli Security

Organization
wpultimatesecurity
wp-cli-security

Use when registering a WP-CLI command with WP_CLI::add_command or writing command logic. Validates and sanitizes positional and associative arguments, does not assume a logged-in user or capability context, avoids printing secrets, and confirms destructive operations. Prevents injection and unsafe automation through the CLI surface.

Overview

Publisherwpultimatesecurity
RepositoryWordPress-Security-Skills
Skill namewp-cli-security
Stars
54
Forks
3
Bundled files
2
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by wpultimatesecurity on GitHub. Read the source before you install it.

Installation

Install the Wp Cli Security AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/wp-cli-security
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

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
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Wp Cli Security in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Wp Cli Security on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Wp Cli Security is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Wp Cli Security AI skill do?

Use when registering a WP-CLI command with WP_CLI::add_command or writing command logic. Validates and sanitizes positional and associative arguments, does not assume a logged-in user or capability context, avoids printing secrets, and confirms destructive operations. Prevents injection and unsafe automation through the CLI surface.

Why use Wp Cli Security on TypingMind?

Because you install it once and use it with any model. Wp Cli Security is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Wp Cli Security in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/wpultimatesecurity/WordPress-Security-Skills/tree/dev/skills/wp-cli-security. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Wp Cli Security?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Wp Cli Security?

As many as you like. As long as a model supports skills, you can use Wp Cli Security with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Wp Cli Security AI skill free?

Yes. It is published on GitHub by wpultimatesecurity under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇