-
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
Support arrays/JSON in pluck and patch #460
Conversation
Add support to for serialized arrays and JSON to both plick and patch. Add additional examples and a note about the stdin blocking issue with patch.
A serialized version of an array as a response is likely more useful than a var_dump quivilent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request, @BlairCooper !
I don't think the maybe_unserialize()
is necessary. get_option()
is already unserializing for us.
I wasn't able to reproduce your original issue:
$ wp shell
wp> update_option( 'my_option', array( 'myKey' => 'myValue' ) );
=> bool(true)
$ wp option pluck my_option myKey
myValue
Notably, in your original report, the string was incorrectly serialized:
The documentation for the "option pluck" and "option patch" commands suggest that they work with arrays and JSON. Specifically the reference to 'keys within the value'. However they do not.
Assuming my_option has a value of
a:1:{s:5:"myKey";s:6:"aValue"}
The serialized value should be a:1:{s:5:"myKey";s:7:"myValue";}
.
Additionally, adding support for JSON-encoded options (and meta, etc.) would be an enhancement. WordPress doesn't automatically work natively with JSON, so I'm not sure it makes sense to add that to WP-CLI.
Thoughts?
Concerning JSON, while WordPress doesn't support storing JSON natively having this functionality would be useful. WordPress does store the health-check-site-status-result (transient) option as a JSON serialized string. I may revisit this pull request and break it into smaller pieces. Can you have a look at the feature tests that were added and let me know if they're valid scenario, or if there are others that should be added? |
Add support to for serialized arrays and JSON to both pluck and patch. Add additional examples and a note about the stdin blocking issue with patch.
Fixes #459