Is there an easy way to limit to one (per post) the number of images to upload through media upload?

  • Please be more specific or give an example why you would want to restrict the number of images to upload.
    – Chris_O
    Aug 29, 2010 at 5:21
  • To all WP authors role im removing some dashboard widgets, some menus. And im removing the visual editor from add post and edit post. Now i want to limit each author to only upload one picture per post. But wordpress media upload through post form let the user to upload as many picture he or she wants. Thanks
    – josoroma
    Aug 29, 2010 at 6:29

1 Answer 1


I won't go into the code specifics right now, because I am not sure if you need me to. You essentially need to modify the SWFUpload JavaScript settings array to set the file_upload_limit to 1. Unfortunately I don't believe SWFUpload allows you to change that settings variable after it has been inited, because it has already launched the Flash embed with the settings.

So, you would have to hook into the flash_uploader filter to disable it setting up the "normal" Flash uploader, then hook into the pre-upload-ui action and set up the Flash uploader using the same variables as WordPress does, but att the file_upload_limit setting. (Look at Line 1446 of media.php to see what I mean).

If you did it that way, you would also have to disable the HTML upload form so user's can use that to bypass the Flash uploader.

Instead, you could (easier, but maybe not so usable to the user) hook into load-async-upload.php action (see Line 202 of admin.php) to reject the upload request if the current user had already uploaded an image for the given post. That would require the user selecting the image in the Flash Uploader, then it throwing an error once it has uploaded saying "You can not upload another file"

  • Thanks Joe, im going to study load-async-upload.php and the media.php files.
    – josoroma
    Sep 1, 2010 at 12:47
  • I found this pretty plugin: wordpress.org/extend/plugins/myeasyhider
    – josoroma
    Sep 1, 2010 at 15:30
  • @josoroma -- could you provide an example please of your code so we can get an idea of how you would do this and can collaborate on it. Great question and great answer guys! Nov 5, 2010 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.