wp post create: Add JSON input support for tax_input#532
wp post create: Add JSON input support for tax_input#532caribe wants to merge 4 commits intowp-cli:mainfrom
wp post create: Add JSON input support for tax_input#532Conversation
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.
@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.
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.
There was a problem hiding this comment.
You can find some context in the discussion here: #207
This is a bug in the capabilities configuration of WordPress Core, and it basically means that tax_input (which is supposed to be generic) will ONLY work for custom taxonomies, but not for the built-in ones. So if you switch from category to a custom taxonomy, it should work without administrator access.
There was a problem hiding this comment.
Initially, I had thought about adding a custom work-around in WP-CLI, but also wanted to have this flagged as a bug in WP Core. Not sure what the latest status is for Core.
But I'm happy to consider a workaround. At the time, I thought that tax_input should defer to post_tag or post_catgory for those, but I can't remember how involved that would have been.
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.