@@ 365-377 (lines=13) @@ | ||
362 | $args['slug'] = $request['slug']; |
|
363 | } |
|
364 | ||
365 | if ( isset( $request['parent'] ) ) { |
|
366 | if ( ! is_taxonomy_hierarchical( $taxonomy ) ) { |
|
367 | return new WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
368 | } |
|
369 | ||
370 | $parent = get_term( (int) $request['parent'], $taxonomy ); |
|
371 | ||
372 | if ( ! $parent ) { |
|
373 | return new WP_Error( 'woocommerce_rest_term_invalid', __( "Parent resource doesn't exist.", 'woocommerce' ), array( 'status' => 404 ) ); |
|
374 | } |
|
375 | ||
376 | $args['parent'] = $parent->term_id; |
|
377 | } |
|
378 | ||
379 | $term = wp_insert_term( $name, $taxonomy, $args ); |
|
380 | if ( is_wp_error( $term ) ) { |
|
@@ 467-479 (lines=13) @@ | ||
464 | $prepared_args['slug'] = $request['slug']; |
|
465 | } |
|
466 | ||
467 | if ( isset( $request['parent'] ) ) { |
|
468 | if ( ! is_taxonomy_hierarchical( $taxonomy ) ) { |
|
469 | return new WP_Error( 'woocommerce_rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.', 'woocommerce' ), array( 'status' => 400 ) ); |
|
470 | } |
|
471 | ||
472 | $parent = get_term( (int) $request['parent'], $taxonomy ); |
|
473 | ||
474 | if ( ! $parent ) { |
|
475 | return new WP_Error( 'woocommerce_rest_term_invalid', __( "Parent resource doesn't exist.", 'woocommerce' ), array( 'status' => 400 ) ); |
|
476 | } |
|
477 | ||
478 | $prepared_args['parent'] = $parent->term_id; |
|
479 | } |
|
480 | ||
481 | // Only update the term if we haz something to update. |
|
482 | if ( ! empty( $prepared_args ) ) { |