From 0d0dd23bd7e8622fc12d8ab5982f579f478b3492 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Mon, 28 Sep 2020 15:38:07 -0300 Subject: [PATCH] add slug docment types on errors #388 --- .../class-tainacan-rest-items-controller.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php index 2cd0f8e53..0866e3f4b 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php @@ -1013,10 +1013,18 @@ class REST_Items_Controller extends REST_Controller { } if ((isset($document_id) && $document_id === false) || (isset($thumbnail_id) && $thumbnail_id === false)) { - if(isset($document_id) && $document_id !== false) wp_delete_attachment($document_id, true); - if(isset($thumbnail_id) && $thumbnail_id !== false) wp_delete_attachment($thumbnail_id, true); + $entities_erros = ["document", "thumbnail"]; + if(isset($document_id) && $document_id !== false) { + $entities_erros = ["thumbnail"]; + wp_delete_attachment($document_id, true); + } + if(isset($thumbnail_id) && $thumbnail_id !== false) { + $entities_erros = ["document"]; + wp_delete_attachment($thumbnail_id, true); + } return new \WP_REST_Response([ 'error_message' => __('error on create document or thumbnail.', 'tainacan'), + 'errors' => $entities_erros ], 400); } @@ -1034,6 +1042,7 @@ class REST_Items_Controller extends REST_Controller { } return new \WP_REST_Response([ 'error_message' => __('error on create attachment ', 'tainacan') . "($attachments_name[$i])", + 'errors' => ['attachment'] ], 400); } $insert_attachments[] = $attachment_id;