From f404c6ee86c7fdc6fa6fb3ea6427fd9043dbca26 Mon Sep 17 00:00:00 2001 From: Adam Tulloss Date: Tue, 12 Mar 2024 11:55:52 -0400 Subject: [PATCH 1/2] Display decimal value for max megabyte upload size in error message --- acf-image-aspect-ratio-crop.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acf-image-aspect-ratio-crop.php b/acf-image-aspect-ratio-crop.php index 4486492..d4a03c1 100644 --- a/acf-image-aspect-ratio-crop.php +++ b/acf-image-aspect-ratio-crop.php @@ -929,7 +929,7 @@ public function rest_api_upload_callback(WP_REST_Request $data) 'file_too_large', sprintf( __( - 'File size too large. Maximum file size is %d megabytes.', + 'File size too large. Maximum file size is %g megabytes.', 'acf-image-aspect-ratio-crop' ), $max_size From bc907fb59c052c83aa1e2029f1ae5d5c7c6fcceb Mon Sep 17 00:00:00 2001 From: Adam Tulloss Date: Tue, 12 Mar 2024 11:56:44 -0400 Subject: [PATCH 2/2] File size error message detects if KB is appropriate unit and uses it instead --- acf-image-aspect-ratio-crop.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/acf-image-aspect-ratio-crop.php b/acf-image-aspect-ratio-crop.php index d4a03c1..d6a9e60 100644 --- a/acf-image-aspect-ratio-crop.php +++ b/acf-image-aspect-ratio-crop.php @@ -925,14 +925,22 @@ public function rest_api_upload_callback(WP_REST_Request $data) !empty($max_size) && $data->get_file_params()['image']['size'] > $max_size * 1000000 ) { + // Convert to appropritate size unit + $unit = 'megabytes'; + if($max_size < 1) { + $unit = 'kilobytes'; + $max_size *= 1024; + } + return new WP_Error( 'file_too_large', sprintf( __( - 'File size too large. Maximum file size is %g megabytes.', + 'File size too large. Maximum file size is %g %s.', 'acf-image-aspect-ratio-crop' ), - $max_size + $max_size, + $unit ), 'acf-image-aspect-ratio-crop' );