Repository navigation
Feature: Add wp cbt save CLI command #830
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestwp-clihandling wp-cli commands in this pluginhandling wp-cli commands in this plugin
Description
Part of #828 (which fulfills #688). Depends on the CBT_Theme_Save service refactor tracked in #828.
Goal
Expose the CBT_Theme_Save service as a WP-CLI subcommand so developers can persist Editor changes to disk from the terminal.
Scope
New file: includes/cli/class-cbt-cli-command.php
New class: CBT_CLI_Command extending WP_CLI_Command, with a save method.
Registration (in includes/class-create-block-theme.php):
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once plugin_dir_path( __DIR__ ) . 'includes/cli/class-cbt-cli-command.php';
WP_CLI::add_command( 'cbt', 'CBT_CLI_Command' );
}CLI surface
wp cbt save [--fonts] [--templates] [--styles] [--patterns]
[--all] [--only-modified-templates] [--dry-run]
- Flags are kebab-case publicly; the command translates internally to the
saveFonts/saveTemplates/ etc. keys the service expects --allis a convenience for "save everything"--only-modified-templatesmaps toprocessOnlySavedTemplates--dry-runreports what would change without writing
Required behavior
- Guard with
wp_is_block_theme()—WP_CLI::error()if not, mirroring the plugin UI gate documented in AGENTS.md WP_CLI::error()if no save flag is passed (no silent no-op success)- All user-facing strings i18n'd via
__( ..., 'create-block-theme' ) - PHPDoc with shortdesc, full
## OPTIONS, and at least two## EXAMPLES - Translate
WP_Errorfrom the service intoWP_CLI::error()
Tests
PHPUnit tests against the command class (the service itself is covered in its own issue):
- Flag normalization (kebab-case → service options)
- Guard fires on non-block themes
- Empty invocation produces an error
Out of scope
wp cbt export— separate issue tracked in [Tracking] WP-CLI support: phased implementation #828- Behat features — not in the plugin's infrastructure today
- Any other CBT operation as a CLI command
Acceptance
- Manual smoke test: install plugin in a Studio site, run each flag combination against a block theme
wp help cbt savedisplays the documented options and exampleslint:php,test:php,test:unitall green
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestwp-clihandling wp-cli commands in this pluginhandling wp-cli commands in this plugin
Activity
KarunyaChavan commentedon Jul 7, 2026
Hi @bph , I saw the implementation plan in issue #828 and noticed that the first phase (the CBT_Theme_Save extraction) has already been implemented in PR-833
I'd be interested in contributing to the remaining phases (#830, #831, and #832), if that would be helpful. Before I get started, I wanted to check with you whether you'd prefer that I build on top of the work in PR #833 in my own branch, or if you'd rather I work independently from
trunk.I just wanted to check the preferred approach first so I can avoid duplicating work and follow the direction you have in mind
bph commentedon Jul 7, 2026
Hi @KarunyaChavan Thanks for commenting. This repo also has an issue + PR policy so, so submit a new branch and when #833 is merged, the other subsequent PRs can be built upon.
bph commentedon Jul 7, 2026
Design note — multisite capability gate
Trunk PR #850 (landed after #829 / PR #833) tightened the
/saveREST route'spermission_callbackfrom an inlinecurrent_user_can( 'edit_theme_options' )closure toCBT_Theme_API::can_modify_theme(), which additionally requires super-admin on multisite.The
CBT_Theme_Saveservice does not enforce capability checks itself (by design — see its class docblock); callers are responsible. That means thewp cbt savecommand needs to replicate the gate:Without this, a non-super-admin user on a multisite install with WP-CLI shell access could persist theme changes via
wp cbt saveeven though the equivalent REST call would be rejected.CBT_Theme_API::can_modify_theme()is alreadypublic static, so the CLI command can call it directly — no visibility change needed.The Required behavior section of this issue should be updated to add capability enforcement alongside the
wp_is_block_theme()guard, and the test list should include a case for the capability check firing when the current user lacks the cap.jasalt commentedon Jul 24, 2026
Made a temporary wrapper plugin for this purpose as I needed this feature for git workflow https://github.com/jasalt/wpcli-create-block-theme.
Current version has extra workarounds with Block Pattern saving issues that have came up, plain/simple version in history: jasalt/wpcli-create-block-theme@f441dac