@@ 335-345 (lines=11) @@ | ||
332 | * @return WP_REST_Request|WP_Error |
|
333 | */ |
|
334 | public function create_item( $request ) { |
|
335 | if ( isset( $request['parent'] ) ) { |
|
336 | if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { |
|
337 | return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); |
|
338 | } |
|
339 | ||
340 | $parent = get_term( (int) $request['parent'], $this->taxonomy ); |
|
341 | ||
342 | if ( ! $parent ) { |
|
343 | return new WP_Error( 'rest_term_invalid', __( "Parent resource doesn't exist." ), array( 'status' => 400 ) ); |
|
344 | } |
|
345 | } |
|
346 | ||
347 | $prepared_term = $this->prepare_item_for_database( $request ); |
|
348 | ||
@@ 419-429 (lines=11) @@ | ||
416 | * @return WP_REST_Request|WP_Error |
|
417 | */ |
|
418 | public function update_item( $request ) { |
|
419 | if ( isset( $request['parent'] ) ) { |
|
420 | if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { |
|
421 | return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Can not set resource parent, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); |
|
422 | } |
|
423 | ||
424 | $parent = get_term( (int) $request['parent'], $this->taxonomy ); |
|
425 | ||
426 | if ( ! $parent ) { |
|
427 | return new WP_Error( 'rest_term_invalid', __( "Parent resource doesn't exist." ), array( 'status' => 400 ) ); |
|
428 | } |
|
429 | } |
|
430 | ||
431 | $prepared_term = $this->prepare_item_for_database( $request ); |
|
432 |