PHPackages                             idearia/wp-cli-command - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. idearia/wp-cli-command

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

idearia/wp-cli-command
======================

Simple class to create WP-CLI commands with validation with little effort.

2.0(2y ago)21.6k↓50%[1 issues](https://github.com/Idearia/wp-cli-command/issues)MITPHPPHP ^8.1

Since Dec 5Pushed 2y ago2 watchersCompare

[ Source](https://github.com/Idearia/wp-cli-command)[ Packagist](https://packagist.org/packages/idearia/wp-cli-command)[ Docs](https://github.com/Idearia/wp-cli-command)[ RSS](/packages/idearia-wp-cli-command/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (13)Used By (0)

Simple class to create WP-CLI commands with validation with little effort.

Features
========

[](#features)

- Create a WP CLI command by extending a simple class
- Easily hook into the [command lifecycle](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-add-hook/#notes) by extending methods `before_run_command`, `before_invoke`, `after_invoke`
- Advanced validation by extending method `validate`
- Support for sub-commands by defining public methods
- Support for [PHPDoc validation](https://make.wordpress.org/cli/handbook/guides/commands-cookbook/#annotating-with-phpdoc)

Quick start
===========

[](#quick-start)

1. Require `wp-cli-command` in your project: ```
    composer require idearia/wp-cli-command

    ```
2. Create a new command by extending the `Command` class. How? Have a look at the [examples folder](./examples) 🙂
3. Register your command with `MyCommand::init( 'my-command' );`
4. Run the command with `wp my-command`.

Available hooks
===============

[](#available-hooks)

In oder of execution:

- `before_run_command` &gt; Just before the command is found and executed
- `before_invoke` &gt; Just before a command is invoked
- `after_invoke` &gt; Just after a command is invoked

Example
=======

[](#example)

- A simple command from [WP-CLI docs](https://make.wordpress.org/cli/handbook/guides/commands-cookbook/#annotating-with-phpdoc) with an additional layer of validation: [examples/SimpleCommand.php](./examples/SimpleCommand.php)
- An example with two sub-commands, each with its own validation &gt; TODO!

To do
=====

[](#to-do)

- Make hook methods aware of the specific command being executed, in case the class contains more than one. Probably, we will need to switch away from static, in order to save $args in the class.
- Behat tests with [`wp scaffold package`](https://github.com/wp-cli/scaffold-package-command)
- Example with subcommands
- Find a way to execute PHPDoc validation before custom validation (maybe invoking the command and the exiting with `before_invoke:{$cmd}`)?
- Find a way to print actual usage, instead of relying on $usage property (how to force show\_usage in subcommand.php)?

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 55.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~29 days

Recently: every ~66 days

Total

12

Last Release

943d ago

Major Versions

1.5.5 → 2.02023-10-18

PHP version history (4 changes)1.0PHP ^7.0

1.4PHP ^7.4

1.5.2PHP ^7.4|^8.0

2.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17342951?v=4)[Idearia SRL](/maintainers/idearia)[@Idearia](https://github.com/Idearia)

---

Top Contributors

[![Simone-Tarantino](https://avatars.githubusercontent.com/u/53703404?v=4)](https://github.com/Simone-Tarantino "Simone-Tarantino (5 commits)")[![coccoinomane](https://avatars.githubusercontent.com/u/3920436?v=4)](https://github.com/coccoinomane "coccoinomane (3 commits)")[![HighLiuk](https://avatars.githubusercontent.com/u/65017775?v=4)](https://github.com/HighLiuk "HighLiuk (1 commits)")

---

Tags

validationwordpresswpwp-cli

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/idearia-wp-cli-command/health.svg)

```
[![Health](https://phpackages.com/badges/idearia-wp-cli-command/health.svg)](https://phpackages.com/packages/idearia-wp-cli-command)
```

###  Alternatives

[typisttech/image-optimize-command

Easily optimize images using WP CLI

1722.0k](/packages/typisttech-image-optimize-command)[phpexperts/datatype-validator

An easy to use data type validator (both strict and fuzzy).

141.1M2](/packages/phpexperts-datatype-validator)[progsmile/request-validator

Simple PHP Request Validator

33113.3k1](/packages/progsmile-request-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
