-
Notifications
You must be signed in to change notification settings - Fork 94
wp post create: Add JSON input support for tax_input
#532
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
base: main
Are you sure you want to change the base?
Conversation
Fixes this 10 year old issue wp-cli/wp-cli#1323 (closed, but not fixed). `wp post create` parameter `--tax_input` is supposed to be an array, but no JSON parsing is done and therefore is unusable.
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
|
Thanks for opening this PR. Would you also be up for adding some tests to cover this change? See #133 for inspiration. |
|
I just added a test now, but it fails because |
| And save STDOUT as {CAT_2} | ||
| And I run `wp term create post_tag "Term One" --porcelain` | ||
| And I run `wp term create post_tag "Term Two" --porcelain` | ||
| And I run `wp post create --post_title='Test Post' --post_content='Test post content' --tax_input='{"category":[{CAT_1},{CAT_2}],"post_tag":["term-one", "term-two"]}' --porcelain` |
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.
@swissspidy, in this scenario, would passing --user=admin in this step be acceptable in your opinion?
| And I run `wp post create --post_title='Test Post' --post_content='Test post content' --tax_input='{"category":[{CAT_1},{CAT_2}],"post_tag":["term-one", "term-two"]}' --porcelain` | |
| And I run `wp post create --post_title='Test Post' --post_content='Test post content' --tax_input='{"category":[{CAT_1},{CAT_2}],"post_tag":["term-one", "term-two"]}' --user=admin --porcelain` |
This user is the default administrator when core is installed during testing:
https://github.com/wp-cli/wp-cli-tests/blob/5b42c271c96efd1072cecaa8b2923db52318b056/src/Context/FeatureContext.php#L1392
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.
That would fix the test but not the user experience in general.
We would need to document that tax_input only works in combination with --user, which is odd.
Another option could be to temporarily filter user_has_cap for this particular code path so that it would always work. But not sure if there's precedence in WP-CLI.
Perhaps @schlessera has a good idea.
Fixes this 10 year old issue wp-cli/wp-cli#1323 (closed, but not fixed).
wp post createparameter--tax_inputis supposed to be an array, but no JSON parsing is done and therefore is unusable.