How to display a warning when an uploaded image is too small?
I want to display a warning when a user uploads an image with too low a resolution. I don't want to block the upload, just give a warning.
The only option I see is wp_handle_upload_prefilter
, but there you can only return an error which blocks the upload.
add_filter( 'wp_handle_upload_prefilter', function ( $file ) {
if ( str_contains( $file['type'], 'image' ) ) {
$image = getimagesize( $file['tmp_name'] );
if ( $image[0] 1200 ) {
//How do I display this warning but not block uploading?
$file['error'] = 'Image too small!';
}
}
return $file;
} );