* Add `--porcelain` argument to `wp term create`
* `wp term create` should include term ID in success message
* `wp term delete` includes the term ID of the deleted term
* Updated tests / doc
See https://github.com/wp-cli/wp-cli/issues/399#issuecomment-
16685216
Scenario: Creating/listing a term
Given a WP install
- When I run `wp term create 'Test term' post_tag --slug=test --description='This is a test term'`
+ When I run `wp term create 'Test term' post_tag --slug=test --description='This is a test term' --porcelain`
Then it should run without errors
- And STDOUT should be:
- """
- Success: Term created.
- """
+ And STDOUT should match '%d'
When I run the previous command again
Then STDERR should not be empty
"""
[{"name":"Test term","slug":"test","description":"This is a test term","parent":"0","count":"0"}]
"""
+
+ Scenario: Creating/deleting a term
+ Given a WP install
+
+ When I run `wp term create 'Test delete term' post_tag --slug=test-delete --description='This is a test term to be deleted' --porcelain`
+ Then it should run without errors
+ And STDOUT should match '%d'
+ And save STDOUT as {TERM_ID}
+
+ When I run `wp term delete {TERM_ID} post_tag`
+ Then it should run without errors
+ And STDOUT should contain:
+ """
+ Deleted post_tag {TERM_ID}.
+ """
+
+ When I run the previous command again
+ Then STDERR should not be empty
A parent for the new term.
+* `--porcelain`:
+
+ Output just the new term id.
+
## EXAMPLES
wp term create Apple category --description="A type of fruit"
\fBwp\-term\-create\fR \- Create a term\.
.
.SH "SYNOPSIS"
-wp term create \fIterm\fR \fItaxonomy\fR [\-\-slug=\fIslug\fR] [\-\-description=\fIdescription\fR] [\-\-parent=\fIterm\-id\fR]
+wp term create \fIterm\fR \fItaxonomy\fR [\-\-slug=\fIslug\fR] [\-\-description=\fIdescription\fR] [\-\-parent=\fIterm\-id\fR] [\-\-porcelain]
.
.SH "OPTIONS"
.
.IP
A parent for the new term\.
.
+.TP
+\fB\-\-porcelain\fR:
+.
+.IP
+Output just the new term id\.
+.
.SH "EXAMPLES"
.
.nf
/**
* Create a term.
*
- * @synopsis <term> <taxonomy> [--slug=<slug>] [--description=<description>] [--parent=<term-id>]
+ * @synopsis <term> <taxonomy> [--slug=<slug>] [--description=<description>] [--parent=<term-id>] [--porcelain]
*/
public function create( $args, $assoc_args ) {
);
$assoc_args = wp_parse_args( $assoc_args, $defaults );
+ if ( isset( $assoc_args['porcelain'] ) ) {
+ $porcelain = true;
+ unset( $assoc_args['porcelain'] );
+ } else
+ $porcelain = false;
+
$ret = wp_insert_term( $term, $taxonomy, $assoc_args );
if ( is_wp_error( $ret ) )
WP_CLI::error( $ret->get_error_message() );
- else
- WP_CLI::success( "Term created." );
+ else {
+ if ( $porcelain )
+ WP_CLI::line( $ret['term_id'] );
+ else
+ WP_CLI::success( sprintf( "Created %s %d.", $taxonomy, $ret['term_id'] ) );
+ }
}
/**
if ( is_wp_error( $ret ) )
WP_CLI::error( $ret->get_error_message() );
else if ( $ret )
- WP_CLI::success( "Term deleted." );
+ WP_CLI::success( sprintf( "Deleted %s %d.", $taxonomy, $term_id ) );
else
- WP_CLI::error( "Error deleting term." );
+ WP_CLI::error( "Term doesn't exist." );
}
}