Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions features/post.feature
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,25 @@ Feature: Manage WordPress posts
post-2
"""

Scenario: Creating/updating posts with taxonomies
When I run `wp term create category "First Category" --porcelain`
And save STDOUT as {CAT_1}
And I run `wp term create category "Second Category" --porcelain`
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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Then STDOUT should be a number
And save STDOUT as {POST_ID}

When I run `wp post term list {POST_ID} category post_tag --format=table --fields=name,taxonomy`
Then STDOUT should be a table containing rows:
| name | taxonomy |
| First Category | category |
| Second Category | category |
| Term One | post_tag |
| Term Two | post_tag |

Scenario: Update categories on a post
When I run `wp term create category "Test Category" --porcelain`
Then save STDOUT as {TERM_ID}
Expand Down
2 changes: 1 addition & 1 deletion src/Post_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function create( $args, $assoc_args ) {
$assoc_args['post_category'] = $this->get_category_ids( $assoc_args['post_category'] );
}

$array_arguments = [ 'meta_input' ];
$array_arguments = [ 'meta_input', 'tax_input' ];
$assoc_args = Utils\parse_shell_arrays( $assoc_args, $array_arguments );

if ( isset( $assoc_args['from-post'] ) ) {
Expand Down
Loading