BuddyDev

Restrict allowed file types for BuddyPress Avatar and Cover Images

BuddyPress allows your users to use “jpeg”, “gif”, “png” file types for avatars and cover images.  If you need to restrict or change the allowed file types, there exists a filter  “bp_attachments_get_allowed_types” that allows us to do it.

Let us see some examples on how to restrict the allowed file types for avatars as well as the cover image on a BuddyPress site.

Restricting allowed file types for BuddyPress User & Group Avatars

You can put the following code in your bp-custom.php or in your theme/child theme’s functions.php to restrict the file type.

Make sure to change the $exts array with your own allowed types.

Result:-

Restricting allowed file types for BuddyPress User & Group Cover Image

Again, we use the same filter but check for the cover_image based o n type parameter.

Result:-

It works same as avatar.  You can put it in your bp-custom.php or theme’s functions.php

Have fun.

Leave a Reply

Are you looking for support?

Please ask support questions in BuddyDev Forum and help us serve you better. Please use comment for general discussion/feature suggestions.

Your email address will not be published. All the fields marked as * are required.

If you are posting code, please use <pre> { Your Code Block } </pre>. Example:- <pre> echo $name; </pre>

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">


Subscribe