extension-command
extension-command copied to clipboard
Allow `--format` option in `wp theme mod set`
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>
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 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 patchwp network meta pluck/wp network meta patchwp comment meta pluck/wp comment meta patch
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 True, but only because I didn't yet know about pluck and patch.
So all in all, both usecases are still valid.
--formatoption available intheme mod setto bulk change / import theme modstheme mod pluck&theme mod patchto alter individual nested structures in theme mods
What do you think?
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.
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?
Wouldn't it make sense instead to extend existing
theme mod setwith--formatoption like it's possible and already present herewp 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.