I am using Metabox 4.10.1. I defined a field like this:
'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 display a custom error message in the plupload_image field on the GUI when a user is trying to upload an image that is larger in size than the max allowed image size in Worpress. Let me know if there is an easy way to do it, or if a new custom field is the best way to implement this. If I should create a new custom field, would you give me high-level guidance how to go about it, so that the custom field remains compatible with Metabox as you keep updating Metabox?
I think an interactive custom message in the plupload_image field would be a good feature in general.
The reason I need that feature is that on my WordPress site, all kinds of users will be able to upload images. They are not necessarily good at editing posts. Currently, if they are trying to upload a very large image, the plupload_image field will not accept the image and will not do anything else (the upload error is ignored). This behavior is confusing and frustrating to end users. They do not know what the problem is, why the plupload_image field does not do anything. Most likely, users will think there is a problem with their smartphone or computer, or with their network connection, or with the web site. A quick error that indicates the image they are trying to upload is too large would be very helpful. The error can be under the Description, for example.
I tested the max_file_size parameter and it works well for stopping users from uploading large images. Thank you very much for this update!
That's true. The errors are handled by the JS of plupload. The error messages are sent to JS via the file
wp-includes/script-loader.php and then used in
wp-includes/js/plupload/wp-plupload.js (line 327). I haven't found any PHP hook or how to add a custom error while uploading.