| @@ -45,15 +45,13 @@ | ||
| 45 | 45 | } else if (strtoupper($maxFileUnit) == 'GB') { |
| 46 | 46 | $allowedFileSize = $maxFileSize * 1024 * 1024; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - $validator = new Validator([ | |
| 50 | - 'file' => $requestFiles | |
| 51 | - ], ); | |
| 52 | - | |
| 53 | - $validator->validate($requestFiles, [ | |
| 54 | - 'file' => 'mimetypes:' . $allowedTypes . '|max:' . $allowedFileSize, | |
| 49 | + // messages belong on the constructor: Validator::validate() takes only data and rules | |
| 50 | + $validator = Validator::make($requestFiles, [ | |
| 51 | + 'file' => 'required|mimetypes:' . $allowedTypes . '|max:' . $allowedFileSize, | |
| 55 | 52 | ], [ |
| 53 | + 'file.required' => __('No upload file was received. Please try again.', 'fluent-community'), | |
| 56 | 54 | 'file.mimetypes' => __('The file must be an image type.', 'fluent-community'), |
| 57 | 55 | /* translators: %$1s is replaced by the maximum allowed file size, %2$s is replaced by the file size unit (e.g. MB) */ |
| 58 | 56 | 'file.max' => sprintf(__('The file size must be less than %1$s%2$s.', 'fluent-community'), $maxFileSize, $maxFileUnit) |
| 59 | 57 | ]); |
| @@ -65,9 +63,17 @@ | ||
| 65 | 63 | add_filter('wp_handle_upload', [self::class, 'fixImageOrientation']); |
| 66 | 64 | $uploadedFiles = FileSystem::put($requestFiles); |
| 67 | 65 | remove_filter('wp_handle_upload', [self::class, 'fixImageOrientation']); |
| 68 | 66 | |
| 69 | - $file = $uploadedFiles[0]; | |
| 67 | + $file = Arr::get($uploadedFiles, 0); | |
| 68 | + | |
| 69 | + if (is_wp_error($file)) { | |
| 70 | + return $file; | |
| 71 | + } | |
| 72 | + | |
| 73 | + if (!is_array($file) || empty($file['url']) || empty($file['file']) || empty($file['type'])) { | |
| 74 | + return new \WP_Error('upload_error', __('No upload file was received. Please try again.', 'fluent-community')); | |
| 75 | + } | |
| 70 | 76 | |
| 71 | 77 | $upload_dir = wp_upload_dir(); |
| 72 | 78 | |
| 73 | 79 | $originalUrl = $file['url']; |