Hi Anh,
I am using Metabox 4.10.1. I defined a field like this:
array(
'name' => esc_html__( 'Image Upload', 'textdomain' ),
'id' => 'myprefix_feature1_plupload',
'type' => 'plupload_image',
'desc' => __( 'Upload a square/circluar image image only!', 'textdomain' ),
'force_delete' => true,
'max_file_uploads' => 2,
'max_status' => true,
),
I would like to prevent uploading images to this field when they exceed certain sizes. Is that possible? If yes, can you give me some guidance?
I can check the image size with $file['size'] in a 'wp_handle_upload_prefilter' hook. My problem is that stopping the upload with adding $file['error'] does not take effect. It actually causes the GUI to hang.
Thank you.
==============================================================
FYI, I tried using the 'wp_handle_upload_prefilter' hook in functions.php (see below), but that resulted in the field HTML 'hanging' on the GUI, while Chrome debugger showed repeated calls to /wordpres/wp-admin/admin-ajax.php
function myprefix_limit_file_upload($file) {
// Calculate the image size in KB
$image_size = $file['size']/1024;
// File size limit in KB
$limit = 200;
if ( ( $image_size > $limit ) )
$file['error'] = 'Your picture is too large. It has to be smaller than '. $limit .'KB';
return $file;
}
add_filter('wp_handle_upload_prefilter', 'myprefix_limit_file_upload');