| @@ 449-469 (lines=21) @@ | ||
| 446 | * @param WP_REST_Request $request Full details about the request. |
|
| 447 | * @return true|WP_Error True if the request has access to delete the invoice, WP_Error object otherwise. |
|
| 448 | */ |
|
| 449 | public function delete_item_permissions_check( $request ) { |
|
| 450 | ||
| 451 | // Retrieve the invoice. |
|
| 452 | $invoice = $this->get_post( $request['id'] ); |
|
| 453 | if ( is_wp_error( $invoice ) ) { |
|
| 454 | return $invoice; |
|
| 455 | } |
|
| 456 | ||
| 457 | // Ensure the current user can delete invoices |
|
| 458 | if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'delete_invoices', $request['id'] ) ) { |
|
| 459 | return new WP_Error( |
|
| 460 | 'rest_cannot_delete', |
|
| 461 | __( 'Sorry, you are not allowed to delete this invoice.', 'invoicing' ), |
|
| 462 | array( |
|
| 463 | 'status' => rest_authorization_required_code(), |
|
| 464 | ) |
|
| 465 | ); |
|
| 466 | } |
|
| 467 | ||
| 468 | return true; |
|
| 469 | } |
|
| 470 | ||
| 471 | /** |
|
| 472 | * Deletes a single invoice. |
|
| @@ 390-410 (lines=21) @@ | ||
| 387 | * @param WP_REST_Request $request Full details about the request. |
|
| 388 | * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. |
|
| 389 | */ |
|
| 390 | public function update_item_permissions_check( $request ) { |
|
| 391 | ||
| 392 | // Retrieve the item. |
|
| 393 | $item = $this->get_post( $request['id'] ); |
|
| 394 | if ( is_wp_error( $item ) ) { |
|
| 395 | return $item; |
|
| 396 | } |
|
| 397 | ||
| 398 | if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_invoicing' ) ) { |
|
| 399 | return true; |
|
| 400 | } |
|
| 401 | ||
| 402 | return new WP_Error( |
|
| 403 | 'rest_cannot_edit', |
|
| 404 | __( 'Sorry, you are not allowed to update this item.', 'invoicing' ), |
|
| 405 | array( |
|
| 406 | 'status' => rest_authorization_required_code(), |
|
| 407 | ) |
|
| 408 | ); |
|
| 409 | ||
| 410 | } |
|
| 411 | ||
| 412 | /** |
|
| 413 | * Updates a single item. |
|
| @@ 484-506 (lines=23) @@ | ||
| 481 | * @param WP_REST_Request $request Full details about the request. |
|
| 482 | * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise. |
|
| 483 | */ |
|
| 484 | public function delete_item_permissions_check( $request ) { |
|
| 485 | ||
| 486 | // Retrieve the item. |
|
| 487 | $item = $this->get_post( $request['id'] ); |
|
| 488 | if ( is_wp_error( $item ) ) { |
|
| 489 | return $item; |
|
| 490 | } |
|
| 491 | ||
| 492 | // |
|
| 493 | ||
| 494 | // Ensure the current user can delete the item |
|
| 495 | if (! wpinv_can_delete_item( $request['id'] ) ) { |
|
| 496 | return new WP_Error( |
|
| 497 | 'rest_cannot_delete', |
|
| 498 | __( 'Sorry, you are not allowed to delete this item.', 'invoicing' ), |
|
| 499 | array( |
|
| 500 | 'status' => rest_authorization_required_code(), |
|
| 501 | ) |
|
| 502 | ); |
|
| 503 | } |
|
| 504 | ||
| 505 | return true; |
|
| 506 | } |
|
| 507 | ||
| 508 | /** |
|
| 509 | * Deletes a single item. |
|