Limit BuddyPress User and Group Cover file size
Continuing from what I wrote yesterday about limiting the BuddyPress User and Group Avatar file size(You can limit the file size), Let us repeat the same for the cover.
In order to limit the Cover file size, we will use the same filter ".
Here is the code that limits the cover file size to 50KB. Feel free to modify and use it as you please.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * Limit BuddyPress Cover file size. * * @param int $size size in bytes. * @param string $type upload type(avatar, cover_upload). * * @return float|int */ function buddydev_limit_buddypress_cover_file_size( $size, $type ) { if ( 'cover_image' == $type ) { $size = 50 * 1024; // in bytes, 1024 bytes = 1KB } return $size; } add_filter( 'bp_attachments_get_max_upload_file_size', 'buddydev_limit_buddypress_cover_file_size', 10,2 ); |
Now, That's what I call simple.
Thanks for the snipped – that works great.
You have an idea how I can only allow JPEG uploads?
Hi Ki,
Thank you for the comment. I just posted a tutorial on how to restrict file types for BuddyPress avatar/cover images. Please have a look here
https://buddydev.com/restrict-allowed-file-types-for-buddypress-avatar-and-cover-images/
Regards
Brajesh