| @@ 208-231 (lines=24) @@ | ||
| 205 | * @param WP_REST_Request $request Full details about the request. |
|
| 206 | * @return bool|WP_Error True if the request has read access for the invoice item, WP_Error object otherwise. |
|
| 207 | */ |
|
| 208 | public function get_item_permissions_check( $request ) { |
|
| 209 | ||
| 210 | // Retrieve the item object. |
|
| 211 | $item = $this->get_post( $request['id'] ); |
|
| 212 | ||
| 213 | // Ensure it is valid. |
|
| 214 | if ( is_wp_error( $item ) ) { |
|
| 215 | return $item; |
|
| 216 | } |
|
| 217 | ||
| 218 | $post_type = get_post_type_object( $this->post_type ); |
|
| 219 | ||
| 220 | if ( ! current_user_can( $post_type->cap->read_post, $item->ID ) ) { |
|
| 221 | return new WP_Error( |
|
| 222 | 'rest_cannot_edit', |
|
| 223 | __( 'Sorry, you are not allowed to view this item.', 'invoicing' ), |
|
| 224 | array( |
|
| 225 | 'status' => rest_authorization_required_code(), |
|
| 226 | ) |
|
| 227 | ); |
|
| 228 | } |
|
| 229 | ||
| 230 | return $this->check_read_permission( $item ); |
|
| 231 | } |
|
| 232 | ||
| 233 | /** |
|
| 234 | * Checks if an item can be read. |
|
| @@ 354-375 (lines=22) @@ | ||
| 351 | * @param WP_REST_Request $request Full details about the request. |
|
| 352 | * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. |
|
| 353 | */ |
|
| 354 | public function update_item_permissions_check( $request ) { |
|
| 355 | ||
| 356 | // Retrieve the invoice. |
|
| 357 | $invoice = $this->get_post( $request['id'] ); |
|
| 358 | if ( is_wp_error( $invoice ) ) { |
|
| 359 | return $invoice; |
|
| 360 | } |
|
| 361 | ||
| 362 | $post_type = get_post_type_object( $this->post_type ); |
|
| 363 | ||
| 364 | if ( ! current_user_can( $post_type->cap->edit_post, $invoice->ID ) ) { |
|
| 365 | return new WP_Error( |
|
| 366 | 'rest_cannot_edit', |
|
| 367 | __( 'Sorry, you are not allowed to update this invoice.', 'invoicing' ), |
|
| 368 | array( |
|
| 369 | 'status' => rest_authorization_required_code(), |
|
| 370 | ) |
|
| 371 | ); |
|
| 372 | } |
|
| 373 | ||
| 374 | return true; |
|
| 375 | } |
|
| 376 | ||
| 377 | /** |
|
| 378 | * Updates a single invoice. |
|