| @@ 516-556 (lines=41) @@ | ||
| 513 | * @param WP_REST_Request $request Full details about the request. |
|
| 514 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
| 515 | */ |
|
| 516 | public function delete_item( $request ) { |
|
| 517 | ||
| 518 | // Retrieve the item. |
|
| 519 | $item = $this->get_post( $request['id'] ); |
|
| 520 | if ( is_wp_error( $item ) ) { |
|
| 521 | return $item; |
|
| 522 | } |
|
| 523 | ||
| 524 | $request->set_param( 'context', 'edit' ); |
|
| 525 | ||
| 526 | // Prepare the item id |
|
| 527 | $id = $item->ID; |
|
| 528 | ||
| 529 | // Prepare the response |
|
| 530 | $response = $this->prepare_item_for_response( $item, $request ); |
|
| 531 | ||
| 532 | // Check if the user wants to bypass the trash... |
|
| 533 | $force_delete = (bool) $request['force']; |
|
| 534 | ||
| 535 | // Try deleting the item. |
|
| 536 | $deleted = wp_delete_post( $id, $force_delete ); |
|
| 537 | ||
| 538 | // Abort early if we can't delete the item. |
|
| 539 | if ( ! $deleted ) { |
|
| 540 | return new WP_Error( 'rest_cannot_delete', __( 'The item cannot be deleted.', 'invoicing' ), array( 'status' => 500 ) ); |
|
| 541 | } |
|
| 542 | ||
| 543 | /** |
|
| 544 | * Fires immediately after a single item is deleted or trashed via the REST API. |
|
| 545 | * |
|
| 546 | * |
|
| 547 | * @since 1.0.13 |
|
| 548 | * |
|
| 549 | * @param WPInv_Item $item The deleted or trashed item. |
|
| 550 | * @param WP_REST_Request $request The request sent to the API. |
|
| 551 | */ |
|
| 552 | do_action( "wpinv_rest_delete_item", $item, $request ); |
|
| 553 | ||
| 554 | return $response; |
|
| 555 | ||
| 556 | } |
|
| 557 | ||
| 558 | ||
| 559 | /** |
|
| @@ 479-519 (lines=41) @@ | ||
| 476 | * @param WP_REST_Request $request Full details about the request. |
|
| 477 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
|
| 478 | */ |
|
| 479 | public function delete_item( $request ) { |
|
| 480 | ||
| 481 | // Retrieve the invoice. |
|
| 482 | $invoice = $this->get_post( $request['id'] ); |
|
| 483 | if ( is_wp_error( $invoice ) ) { |
|
| 484 | return $invoice; |
|
| 485 | } |
|
| 486 | ||
| 487 | $request->set_param( 'context', 'edit' ); |
|
| 488 | ||
| 489 | // Prepare the invoice id |
|
| 490 | $id = $invoice->ID; |
|
| 491 | ||
| 492 | // Prepare the response |
|
| 493 | $response = $this->prepare_item_for_response( $invoice, $request ); |
|
| 494 | ||
| 495 | // Check if the user wants to bypass the trash... |
|
| 496 | $force_delete = (bool) $request['force']; |
|
| 497 | ||
| 498 | // Try deleting the invoice. |
|
| 499 | $deleted = wp_delete_post( $id, $force_delete ); |
|
| 500 | ||
| 501 | // Abort early if we can't delete the invoice. |
|
| 502 | if ( ! $deleted ) { |
|
| 503 | return new WP_Error( 'rest_cannot_delete', __( 'The invoice cannot be deleted.', 'invoicing' ), array( 'status' => 500 ) ); |
|
| 504 | } |
|
| 505 | ||
| 506 | /** |
|
| 507 | * Fires immediately after a single invoice is deleted or trashed via the REST API. |
|
| 508 | * |
|
| 509 | * |
|
| 510 | * @since 1.0.13 |
|
| 511 | * |
|
| 512 | * @param WPInv_Invoice $invoice The deleted or trashed invoice. |
|
| 513 | * @param WP_REST_Request $request The request sent to the API. |
|
| 514 | */ |
|
| 515 | do_action( "wpinv_rest_delete_invoice", $invoice, $request ); |
|
| 516 | ||
| 517 | return $response; |
|
| 518 | ||
| 519 | } |
|
| 520 | ||
| 521 | ||
| 522 | /** |
|