Custom Fields
Support General How to display a custom file upload error in a plupload_image field?

  • Creator
  • #4931

    Hi Anh,

    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.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
  • #4947
    Anh Tran

    Hi, continuing from the previous topic, we've just updated the plugin on Github with a new parameter max_file_size that limit the file size for file/image upload fields.

    Please try it and let me know what you think.


    Hi Anh,

    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!

    On the other hand, I was trying to figure out how to display a custom error message in the plupload_image Metabox when somebody is trying to upload a file with a size that exceeds max_file_size. Based on what I have read so far, it looks like I have to use javascript / jQuery to do that. Can you confirm that is correct? Or is there a WordPress hook do do it? I would appreciate any guidance or hint I can research further. I do not expect a tested, working sample : )

    Thanks again.

    Anh Tran

    Hi @tgarda,

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.