Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
Merged
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
10 changes: 9 additions & 1 deletion lib/endpoints/class-wp-rest-terms-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,16 @@ public function delete_item( $request ) {

// Get the actual term_id
$term = get_term_by( 'term_taxonomy_id', (int) $request['id'], $this->taxonomy );
$get_request = new WP_REST_Request( 'GET', rest_url( 'wp/v2/terms/' . $this->get_taxonomy_base( $term->taxonomy ) . '/' . (int) $request['id'] ) );
$get_request->set_param( 'context', 'view' );
$response = $this->prepare_item_for_response( $term, $get_request );

wp_delete_term( $term->term_id, $term->taxonomy );
$retval = wp_delete_term( $term->term_id, $term->taxonomy );
if ( ! $retval ) {
return new WP_Error( 'rest_cannot_delete', __( 'The term cannot be deleted.' ), array( 'status' => 500 ) );
}

return $response;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/test-rest-terms-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,12 @@ public function test_update_item_incorrect_permissions() {

public function test_delete_item() {
wp_set_current_user( $this->administrator );
$term = get_term_by( 'id', $this->factory->category->create(), 'category' );
$term = get_term_by( 'id', $this->factory->category->create( array( 'name' => 'Deleted Category' ) ), 'category' );
$request = new WP_REST_Request( 'DELETE', '/wp/v2/terms/category/' . $term->term_taxonomy_id );
$response = $this->server->dispatch( $request );
$this->assertEquals( 200, $response->get_status() );
$data = $response->get_data();
$this->assertEquals( 'Deleted Category', $data['name'] );
}

public function test_delete_item_invalid_taxonomy() {
Expand Down