Yes, you can use the wp_handle_upload_prefilter
that allows you to stop the uploading process if a specific condition is not accomplished.
In your case, you could try this code snippet:
function limit_upload_size( $file ) {
// Set the desired file size limit
$file_size_limit = 1024; // 1MB in KB
// exclude admins
if ( ! current_user_can( 'manage_options' ) ) {
$current_size = $file['size'];
$current_size = $current_size / 1024; //get size in KB
if ( $current_size > $file_size_limit ) {
$file['error'] = sprintf( __( 'ERROR: File size limit is %d KB.' ), $file_size_limit );
}
}
return $file;
}
add_filter ( 'wp_handle_upload_prefilter', 'limit_upload_size', 10, 1 );
Hope it helps!
Related Posts:
- what happens to existing media files when I switch to year/month directory structure format?
- Reject upload of wrong-sized images using the Media Uploader
- Can’t upload media, permissions are correct
- upload_async.php returns 500 error
- Which filters or actions to use after a media upload and delete?
- Display attachments by ID in a wp.media frame
- Protecting direct access to PDF and ZIP unless user logged in (without plugin)
- Where do the favicons for Media Files come from
- How to manage a standalone media folder?
- How do I link directly to uploaded files?
- Is wp_read_audio_metadata() function deprecated?
- Refresh wp.media after ajax call
- Multisite, upload images directly to Amazon S3
- wp_editor with media buttons
- WordPress REST Upload Media
- Force wordpress to see uploads folder media
- How to validate the file name of the Media File Uploads?
- Disable TinyMCE Drag and Drop
- WP3.5 Media Uploader – how to make it accept multiple images?
- Setting wp_temp_dir and permissions not working for “Missing A Temporary Folder” error
- Select image sizes you want to be uploaded
- wp_temp_dir does not change the /tmp temporary default directory
- Retrieving JSON data in ajax request from media uploader
- Maximum upload size changes in php.ini ignored – How to remove upload size limit?
- How to disable WordPress Media resize different size version?
- Setting higher upload limit
- Media library storing files in uploads not folders within in uploads
- Media handle sideload not working
- How to overwrite wp_unique_filename logic
- How to change upload directory based on frontend form input name or ID?
- How to host different file formats/types for a media attachment without creating multiple attachments?
- How to delete uploads not in media library?
- Why does SVG upload in Media Library fail if the file does not have an XML tag at the beginning?
- media_handle_upload : undefined function?
- Site icons with alpha channel for self-hosted WordPress blog network
- Cannot upload .mp3 file to wordpress media
- Uploading dwg files to wordpress
- Using subdomain to upload media/images etc on 2 different blogs
- Images not being generated at correct size
- WordPress suddenly starts uploading media to an old (backdated) folder
- XML-RPC: How to add media caption to uploaded image?
- Switch between tabs on “Insert Media” dialog
- Can I change the URL of a video, or upload a video to a specific URL?
- WordPress Issue : The uploaded file could not be moved to wp-content/uploads/
- Convert (-) and (escape) signs to (_) when uploading files on wordpress media library automatically
- Move files from flat upload directory to organised by year / month
- Using wp_enqueue_media() with switch_to_blog() issue
- Media library only shows for admin. Doesn’t show editor or below [closed]
- Upload featured image from front end using media-upload.php
- How to allow logged out users to upload media?
- What relationship determines which images appear in ‘uploaded to post’ in edit/add post media dialog
- Capability to prevent upload of files
- A link (not in the post) to download a specific PDF file
- Is it possible to import all files from a uploads DIR into WP media, retaining paths to the files
- How does WordPress decides how many sizes of an image to create?
- How does wordpress handle media files?
- Big file upload give HTTP error
- Image upload to media library fails. Folder won’t create, database insert fail, XAMPP Windows
- limit media upload to once a day
- Add SWF file to wordpress through custom template
- How to change archieve frequency of the media file in uploads folder for wordpress blog
- Insert attachments from custom uploader into post (regular uploader style)
- Uploaded images result in a file url with full path on disk appended
- Migrating WordPress Uploads To S3 Object Storage
- Import media (.xml) does not attribute featured images to posts
- Blog suddenly can’t display .jpg
- Upload Video using wordpress rest api with ionic
- SVG not displaying in Media Tab in Backend
- Modify Maximum upload file size text in WordPress Media
- Missing a temporary folder not fixed
- How to remove media by filename?
- media_handle_upload() returns Specified file failed upload test
- WP media upload issues
- Images not displaying on site or media library
- Replicate Media Galley Edit view in Add Media View
- Front-End Upload media with category
- Sanitizing existing media library paths and page links from foreign characters
- Is there some way to find if media items are used anywhere on the site?
- Media URL slugs without uploads folder path
- Frontend media shows “An error occurred in the upload. Please try again later.”
- Media not displaying other users uploads – WordPress 4.9.2
- Set default “Link CSS Class” in add media admin editor
- How could you allow users to upload a video in within their profile and display it on a wordpress site?
- WP_Custom_Media_Control | Give ID to media file
- How to share media between independent blogs?
- WP Add Media Button – Can I set the default size to Original/Full Size
- WP Capabilities to Add Media, Use Media, But Not Edit Them
- wp.media – media uploader – how to destroy instance of modal?
- Limit attachment caption characters
- Issues with WordPress 3.9.6 media libraries on XAMPP
- Used Duplicator to transfer a site. Now my media uploads aren’t working
- controlling whether upload is attached to post or not
- How to split my uploaded media into directories?
- All files unattached in Media Library
- WordPress media upload multiple images
- Media Gallery doesn’t show (using WP-Read Only)
- Upload User Avatar from android to WordPress using Rest API
- Updating Media Library PDF’s in bulk
- How to properly move media files and update data?
- Is it possible to restrict the number of media uploads (photos) per user?