Skip to content

cwp wp

shipped 1.0.0
cwp wp [args] [flags]

Acts on the local site. Name an environment to act there instead.

A conduit: standard output belongs to the program you run, so there is no --json, and cwp forwards the exit code unchanged.

ArgumentWhat it isDefault
[args]the WP-CLI command, after a mandatory --
FlagWhat it doesDefault
--env <env>run against an environment instead of the local site

Plus the shared flags -v, --verbose, -q, --quiet and --dry-run.

What it does

cwp wp is the escape hatch: every WP-CLI command cwp does not wrap, without you having to remember whether this site wants ddev wp, cloudron exec --app <app> -- wp or ssh <host> "cd <docroot> && wp".

The -- is mandatory. Everything before it belongs to cwp. Everything after it goes to WP-CLI untouched. That keeps --env or --verbose from ever colliding with WP-CLI’s own --path, --format=json or --allow-root. Leaving it out is a usage error with a fix hint, not a guess:

✗ cwp wp needs a `--` before the WP-CLI command
  → write it as `cwp wp -- plugin list`

Three things are not cwp’s business here:

  • The terminal belongs to WP-CLI. cwp inherits stdio rather than capturing it. So wp shell and wp db cli are interactive, output streams as it happens, and colour and progress bars survive.
  • The exit code is WP-CLI’s, forwarded verbatim. A pass-through that rewrites exit codes is useless in a script. cwp’s own refusals (a missing --, an unknown environment, no project) all happen before WP-CLI starts and use cwp’s exit codes.
  • There is no --json. stdout is WP-CLI’s payload and an envelope around it would corrupt it. Use WP-CLI’s own --format=json.

Example

cwp wp -- plugin list
cwp wp -- option get siteurl
cwp wp -- shell                              # interactive; the terminal is handed over
cwp wp --env dev -- option get siteurl
cwp wp --env prod --dry-run -- plugin list   # see the exact command first

Getting data out of a site needs nothing from cwp beyond staying out of the way:

cwp wp --env dev -- post list --post_type=page --format=json

What it does not do

Nothing guards it. cwp wp --env prod -- db query 'DROP TABLE …' runs. The guard ladder applies to cwp’s own operations, not to arbitrary WP-CLI you asked it to forward. Pretending otherwise would be the more dangerous claim.

--dry-run prints the exact command it would run and exits. Use it to check an unfamiliar command against a live environment before it happens.