-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import/Export options as (pretty-printed) JSON #512
Comments
wp option update
wp option update
and indented/pretty way of exporting JSON from wp option list --format=json
The true powers of WP-CLI come to shine when combined with other shell commands and things like pipes. This way you can easily call |
|
wp option update
and indented/pretty way of exporting JSON from wp option list --format=json
Doing the batch import is more unwieldy :( An attempt to export all options as JSON and then import them back: wp option list --format=json | jq '.' > exportOPTIONS.json
jq -r '.[] | [ .option_name, (.option_value | @json) ] | @tsv' exportOPTIONS.json | tr '\t' '\0' | tr '\n' '\0' | xargs -0 -n2 wp option update --format=json Unfortunately this fails with some JSON parsing errors. (replacing In the correct functioning, it should print What also fails (also unsure why wp option list --format=json | jq '.' > exportOPTIONS.json
jq -r '.[] | [ .option_name, .option_value ] | @tsv' exportOPTIONS.json | tr '\t' '\0' | tr '\n' '\0' | xargs -0 -n2 wp option update (full command printout below in the flyout) Here is the tsv file for this attempt: wpoptions.txt And here is its first line:
full command printout
Any ideas for a workaround for batch-importing options from a JSON file for the time being? Thanks! |
Also, neither
nor
work - and fail with the same problems as the |
Currently we can import options, but have to iterate
wp option update
command invocation for each option.A convenience command would be helpful which would import all options from a JSON file (e.g. produced with
wp option list --format=json
).Currently
wp option list --format=json
does produce all options in JSON, but unfortunately it's not prettified in any way and dumped in one very-long line. So some prettification options would also be very helpful (and placing default options in the top of the file)This is useful in setups where WordPress is used as a static-site-generator engine. For this usecase, it's nice to store all options in a plain JSON (or YAML) file and import them into a fresh-new WordPress installation during build.
The text was updated successfully, but these errors were encountered: