From b256052a39ad3ca5db5e1fa35ed5c3380dc63969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Guimara=CC=83es?= Date: Wed, 30 Dec 2020 18:25:21 -0300 Subject: [PATCH] refactors checking and filtering --- ...tainacan-rest-item-metadata-controller.php | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php b/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php index 1ba6b2d25..ed821076d 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-item-metadata-controller.php @@ -375,20 +375,16 @@ class REST_Item_Metadata_Controller extends REST_Controller { private function get_metadata_value($is_multiple, $value) { $filtered_value = $value; if ($is_multiple) { - // if metadata is multiple, leave it as array - // this has to be verified before and separately than the array check + if (is_array($filtered_value)) { + $filtered_arr = array_map(function($v) { + return $this->filter_value($v); + }, $filtered_value); + + $filtered_value = $filtered_arr; + } } elseif (is_array($value)) { - $filtered_value = implode(' ', $value); - } - - if (is_array($filtered_value)) { - $filtered_arr = array_map(function($v) { - return $this->filter_value($v); - }, $filtered_value); - - $filtered_value = $filtered_arr; - } else { - $filtered_value = $this->filter_value($filtered_value); + $string_value = implode(' ', $value); + $filtered_value = $this->filter_value($string_value); } return $filtered_value;