Skip to content

Conversation

@caribe
Copy link

@caribe caribe commented Apr 11, 2025

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.

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.
@caribe caribe requested a review from a team as a code owner April 11, 2025 15:55
@codecov
Copy link

codecov bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@swissspidy
Copy link
Member

Thanks for opening this PR.

Would you also be up for adding some tests to cover this change? See #133 for inspiration.

@swissspidy
Copy link
Member

swissspidy commented May 6, 2025

I just added a test now, but it fails because tax_input requires the current user (which there technically isn't one with WP-CLI) to have the necessary capabilities. So we need to figure that one out first...

Related: https://github.com/orgs/wp-cli/discussions/6052

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`

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?

Suggested change
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

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants