public function create( $args, $assoc_args ) {

		list( $taxonomy, $term ) = $args;

		$defaults   = [
			'slug'        => sanitize_title( $term ),
			'description' => '',
			'parent'      => 0,
		];
		$assoc_args = wp_parse_args( $assoc_args, $defaults );

		$porcelain = Utils\get_flag_value( $assoc_args, 'porcelain' );
		unset( $assoc_args['porcelain'] );

		// Compatibility for < WP 4.0
		if ( $assoc_args['parent'] > 0 && ! term_exists( (int) $assoc_args['parent'] ) ) {
			WP_CLI::error( 'Parent term does not exist.' );
		}

		$assoc_args = wp_slash( $assoc_args );
		$term       = wp_slash( $term );
		$result     = wp_insert_term( $term, $taxonomy, $assoc_args );

		if ( is_wp_error( $result ) ) {
			WP_CLI::error( $result->get_error_message() );
		} else {
			if ( $porcelain ) {
				WP_CLI::line( $result['term_id'] );
			} else {
				WP_CLI::success( "Created {$taxonomy} {$result['term_id']}." );
			}
		}
	}
public function create( $args, $assoc_args ) {

		list( $taxonomy, $term ) = $args;

		$defaults   = [
			'slug'        => sanitize_title( $term ),
			'description' => '',
			'parent'      => 0,
		];
		$assoc_args = wp_parse_args( $assoc_args, $defaults );

		$porcelain = Utils\get_flag_value( $assoc_args, 'porcelain' );
		unset( $assoc_args['porcelain'] );

		// Compatibility for < WP 4.0
		if ( $assoc_args['parent'] > 0 && ! term_exists( (int) $assoc_args['parent'] ) ) {
			WP_CLI::error( 'Parent term does not exist.' );
		}

		$assoc_args = wp_slash( $assoc_args );
		$term       = wp_slash( $term );
		$result     = wp_insert_term( $term, $taxonomy, $assoc_args );

		if ( is_wp_error( $result ) ) {
			WP_CLI::error( $result->get_error_message() );
		} else {
			if ( $porcelain ) {
				WP_CLI::line( $result['term_id'] );
			} else {
				WP_CLI::success( "Created {$taxonomy} {$result['term_id']}." );
			}
		}
	}
public function create ( $ args , $ assoc_args ) { list ( $ taxonomy , $ term ) = $ args ; $ defaults = [ 'slug' => sanitize_title ( $ term ) , 'description' => '' , 'parent' => 0 , ] ; $ assoc_args = wp_parse_args ( $ assoc_args , $ defaults ) ; $ porcelain = Utils \ get_flag_value ( $ assoc_args , 'porcelain' ) ; unset ( $ assoc_args [ 'porcelain' ] ) ; // Compatibility for < WP 4.0 if ( $ assoc_args [ 'parent' ] > 0 && ! term_exists ( ( int ) $ assoc_args [ 'parent' ] ) ) { WP_CLI :: error ( 'Parent term does not exist.' ) ; } $ assoc_args = wp_slash ( $ assoc_args ) ; $ term = wp_slash ( $ term ) ; $ result = wp_insert_term ( $ term , $ taxonomy , $ assoc_args ) ; if ( is_wp_error ( $ result ) ) { WP_CLI :: error ( $ result -> get_error_message ( ) ) ; } else { if ( $ porcelain ) { WP_CLI :: line ( $ result [ 'term_id' ] ) ; } else { WP_CLI :: success ( "Created {$taxonomy} {$result['term_id']}." ) ; } } }
Creates a new term.

## OPTIONS

<taxonomy>
: Taxonomy for the new term.

<term>
: A name for the new term.

[--slug=<slug>]
: A unique slug for the new term. Defaults to sanitized version of name.

[--description=<description>]
: A description for the new term.

[--parent=<term-id>]
: A parent for the new term.

[--porcelain]
: Output just the new term id.

## EXAMPLES

# Create a new category "Apple" with a description.
$ wp term create category Apple --description="A type of fruit"
Success: Created category 199.
Creates a new term .