一键导入
wp-cli-command
Add a new WP-CLI command to the Saman SEO plugin. Use when adding command-line functionality, automation tools, or developer utilities.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Add a new WP-CLI command to the Saman SEO plugin. Use when adding command-line functionality, automation tools, or developer utilities.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Add a new WordPress filter hook to the Saman SEO plugin with proper documentation. Use when making functionality extensible, allowing third-party customization, or adding developer hooks.
Add a new SEO audit metric to the scoring system. Use when extending the SEO analysis, adding new quality checks, or improving the audit dashboard.
Add a new schema.org structured data type to the Saman SEO plugin. Use when adding support for new schema types like Recipe, Event, Product, etc.
Review code changes in the Saman SEO plugin for quality, security, and adherence to WordPress coding standards. Use when reviewing PRs, checking code quality, or before committing changes.
Generate a pull request title and description from the current branch's commits. Produces a concise summary, optional feature highlights, and collapsible technical details.
Create a new React admin page for the Saman SEO plugin dashboard. Use when adding new settings pages, tool interfaces, or admin features that need a UI.
| name | wp-cli-command |
| description | Add a new WP-CLI command to the Saman SEO plugin. Use when adding command-line functionality, automation tools, or developer utilities. |
Add a new WP-CLI command to the Saman SEO plugin CLI interface.
$ARGUMENTS should contain: command name (e.g., "audit") and descriptionAnalyze the command requirements:
Add to CLI service at includes/class-saman-seo-service-cli.php:
/**
* {Command description}.
*
* ## OPTIONS
*
* [<subcommand>]
* : The subcommand to run.
* ---
* options:
* - list
* - get
* - create
* - delete
* ---
*
* [--id=<id>]
* : The item ID.
*
* [--format=<format>]
* : Output format.
* ---
* default: table
* options:
* - table
* - json
* - csv
* ---
*
* ## EXAMPLES
*
* # List all items
* $ wp saman-seo {command} list
*
* # Get a specific item
* $ wp saman-seo {command} get --id=123
*
* # Export to JSON
* $ wp saman-seo {command} list --format=json
*
* @param array $args Positional arguments.
* @param array $assoc_args Associative arguments.
*/
public function {command}( $args, $assoc_args ) {
$subcommand = isset( $args[0] ) ? $args[0] : 'list';
$format = \WP_CLI\Utils\get_flag_value( $assoc_args, 'format', 'table' );
switch ( $subcommand ) {
case 'list':
$this->{command}_list( $assoc_args );
break;
case 'get':
$id = \WP_CLI\Utils\get_flag_value( $assoc_args, 'id' );
if ( ! $id ) {
\WP_CLI::error( __( 'Please provide --id parameter.', 'saman-seo' ) );
}
$this->{command}_get( $id, $format );
break;
case 'create':
$this->{command}_create( $assoc_args );
break;
case 'delete':
$id = \WP_CLI\Utils\get_flag_value( $assoc_args, 'id' );
if ( ! $id ) {
\WP_CLI::error( __( 'Please provide --id parameter.', 'saman-seo' ) );
}
$this->{command}_delete( $id );
break;
default:
\WP_CLI::error( sprintf(
__( 'Unknown subcommand: %s', 'saman-seo' ),
$subcommand
) );
}
}
/**
* List items.
*
* @param array $assoc_args Associative arguments.
*/
private function {command}_list( $assoc_args ) {
$format = \WP_CLI\Utils\get_flag_value( $assoc_args, 'format', 'table' );
$items = array(); // Fetch items
if ( empty( $items ) ) {
\WP_CLI::warning( __( 'No items found.', 'saman-seo' ) );
return;
}
\WP_CLI\Utils\format_items(
$format,
$items,
array( 'id', 'name', 'status', 'created' )
);
}
/**
* Get single item.
*
* @param int $id Item ID.
* @param string $format Output format.
*/
private function {command}_get( $id, $format ) {
$item = null; // Fetch item by ID
if ( ! $item ) {
\WP_CLI::error( sprintf(
__( 'Item not found: %d', 'saman-seo' ),
$id
) );
}
if ( 'json' === $format ) {
\WP_CLI::line( wp_json_encode( $item, JSON_PRETTY_PRINT ) );
} else {
\WP_CLI\Utils\format_items( 'table', array( $item ), array_keys( (array) $item ) );
}
}
boot() method:if ( defined( 'WP_CLI' ) && WP_CLI ) {
\WP_CLI::add_command( 'saman-seo {command}', array( $this, '{command}' ) );
}
### wp saman-seo {command}
{Description}
**Subcommands:**
- `list` - List all items
- `get` - Get a specific item
- `create` - Create a new item
- `delete` - Delete an item
**Options:**
- `--id=<id>` - Item ID
- `--format=<format>` - Output format (table, json, csv)
**Examples:**
```bash
wp saman-seo {command} list
wp saman-seo {command} get --id=123
wp saman-seo {command} list --format=json > export.json
## WP-CLI Utilities
```php
// Success message
\WP_CLI::success( 'Operation completed.' );
// Error and exit
\WP_CLI::error( 'Something went wrong.' );
// Warning (continues execution)
\WP_CLI::warning( 'This might be an issue.' );
// Simple output
\WP_CLI::line( 'Some text' );
// Progress bar
$progress = \WP_CLI\Utils\make_progress_bar( 'Processing', $count );
foreach ( $items as $item ) {
// Process item
$progress->tick();
}
$progress->finish();
// Confirmation prompt
\WP_CLI::confirm( 'Are you sure you want to delete this?' );
// Format items as table/json/csv
\WP_CLI\Utils\format_items( $format, $items, $columns );
Reference existing commands in WP_CLI.md:
wp saman-seo redirects - Manage redirects (list, create, delete, import, export)format_items(), make_progress_bar(), etc.\WP_CLI::confirm() before deletes/wp-cli-command audit Run SEO audits from command line with bulk processing