extension-command icon indicating copy to clipboard operation
extension-command copied to clipboard

Allow `--format` option in `wp theme mod set`

Open selrond opened this issue 7 years ago • 7 comments
trafficstars

Is it possible to set formatted theme_mods in wp theme mod set the same way it's possible to get them through wp theme mod get <mod> --format=json?

It'd be really useful for bulk editing theme_mods and importing them in one command instead of in current one-by-one fashion - wp theme mod set <mod> <value>

selrond avatar Feb 16 '18 15:02 selrond

Thanks for the suggestion, @selrond.

Something like wp theme mod set would be closest syntactically to wp option set, which supports --format=json to accept some array of data for the option. It doesn't set all options, only the value for the specific option.

I think yours is a reasonable suggestion, but we'd probably want to create a new command for it. wp theme mod import could be one option.

danielbachhuber avatar Feb 17 '18 13:02 danielbachhuber

@danielbachhuber while wp theme mod import sounds good, I think more versatile approach would be to implement something link pluck & patch commands as seen in wp option pluck or wp option patch.

So having theme mod pluck or theme mod patch would be good, flexible (although I'm not sure how many levels deep can you go with pluck command or if it's even possible to go down more than 1 level), and even naming would be consistent with already present implementations:

  • wp option pluck / wp option patch
  • wp network meta pluck / wp network meta patch
  • wp comment meta pluck / wp comment meta patch

selrond avatar Feb 17 '18 14:02 selrond

theme mod pluck and theme mod patch both seem like reasonable additions, although they would only permit manipulation of individual mods. My initial understanding was that you wanted to access or update all mods at once?

danielbachhuber avatar Feb 17 '18 14:02 danielbachhuber

@danielbachhuber True, but only because I didn't yet know about pluck and patch.

So all in all, both usecases are still valid.

  • --format option available in theme mod set to bulk change / import theme mods
  • theme mod pluck & theme mod patch to alter individual nested structures in theme mods

What do you think?

selrond avatar Feb 17 '18 14:02 selrond

If you want to bulk change all mods, then we'd need theme mod import. theme mod set is only for an individual mod.

Everything else seems reasonable though.

danielbachhuber avatar Feb 17 '18 14:02 danielbachhuber

Right, but I't looks a bit weird having

Name Description
wp theme mod get Gets one or more theme mods.
wp theme mod remove Removes one or more theme mods.
wp theme mod set Sets the value of a theme mod.

(from wp theme mod | WordPress Developer Resources)

Wouldn't it make sense instead to extend existing theme mod set with --format option like it's possible and already present here wp option add --format=json?

selrond avatar Feb 17 '18 14:02 selrond

Wouldn't it make sense instead to extend existing theme mod set with --format option like it's possible and already present here wp option add --format=json?

No, because theme mod set is meant to act upon an individual theme mod. option add --format=json only acts upon an individual option; it doesn't update all options when you use the --format=json flag.

danielbachhuber avatar Feb 17 '18 14:02 danielbachhuber